public class Counter extends SensorBase implements CounterBase, LiveWindowSendable, PIDSource
All counters will immediately start counting - reset() them if you need them to be zeroed before use.
Modifier and Type | Class and Description |
---|---|
static class |
Counter.Mode
Mode determines how and what the counter counts.
|
CounterBase.EncodingType
Modifier and Type | Field and Description |
---|---|
protected DigitalSource |
m_downSource |
protected DigitalSource |
m_upSource |
kAnalogInputChannels, kAnalogOutputChannels, kDigitalChannels, kPCMModules, kPDPChannels, kPDPModules, kPwmChannels, kRelayChannels, kSolenoidChannels, kSystemClockTicksPerMicrosecond
Constructor and Description |
---|
Counter()
Create an instance of a counter where no sources are selected.
|
Counter(AnalogTrigger trigger)
Create an instance of a Counter object.
|
Counter(Counter.Mode mode)
Create an instance of a counter with the given mode.
|
Counter(CounterBase.EncodingType encodingType,
DigitalSource upSource,
DigitalSource downSource,
boolean inverted)
Create an instance of a Counter object.
|
Counter(DigitalSource source)
Create an instance of a counter from a Digital Input.
|
Counter(int channel)
Create an instance of a Counter object.
|
Modifier and Type | Method and Description |
---|---|
void |
clearDownSource()
Disable the down counting source to the counter.
|
void |
clearUpSource()
Disable the up counting source to the counter.
|
void |
free()
Free the resources used by this object.
|
int |
get()
Read the current counter value.
|
boolean |
getDirection()
The last direction the counter value changed.
|
double |
getDistance()
Read the current scaled counter value.
|
int |
getFPGAIndex()
The counter's FPGA index.
|
double |
getPeriod()
Get the Period of the most recent count.
|
PIDSourceType |
getPIDSourceType()
Get which parameter of the device you are using as a process control variable.
|
double |
getRate()
Get the current rate of the Counter.
|
int |
getSamplesToAverage()
Get the Samples to Average which specifies the number of samples of the timer to average when
calculating the period.
|
java.lang.String |
getSmartDashboardType()
The string representation of the named data type that will be used by the smart dashboard for
this
Sendable . |
boolean |
getStopped()
Determine if the clock is stopped.
|
ITable |
getTable()
The table that is associated with this
Sendable . |
void |
initTable(ITable subtable)
Initializes a table for this
Sendable object. |
double |
pidGet()
Get the result to use in PIDController.
|
void |
reset()
Reset the Counter to zero.
|
void |
setDistancePerPulse(double distancePerPulse)
Set the distance per pulse for this counter.
|
void |
setDownSource(AnalogTrigger analogTrigger,
AnalogTriggerOutput.AnalogTriggerType triggerType)
Set the down counting source to be an analog trigger.
|
void |
setDownSource(DigitalSource source)
Set the source object that causes the counter to count down.
|
void |
setDownSource(int channel)
Set the down counting source to be a digital input channel.
|
void |
setDownSourceEdge(boolean risingEdge,
boolean fallingEdge)
Set the edge sensitivity on a down counting source.
|
void |
setExternalDirectionMode()
Set external direction mode on this counter.
|
void |
setMaxPeriod(double maxPeriod)
Set the maximum period where the device is still considered "moving".
|
void |
setPIDSourceType(PIDSourceType pidSource)
Set which parameter of the encoder you are using as a process control variable.
|
void |
setPulseLengthMode(double threshold)
Configure the counter to count in up or down based on the length of the input pulse.
|
void |
setReverseDirection(boolean reverseDirection)
Set the Counter to return reversed sensing on the direction.
|
void |
setSamplesToAverage(int samplesToAverage)
Set the Samples to Average which specifies the number of samples of the timer to average when
calculating the period.
|
void |
setSemiPeriodMode(boolean highSemiPeriod)
Set Semi-period mode on this counter.
|
void |
setUpdateWhenEmpty(boolean enabled)
Select whether you want to continue updating the event timer output when there are no samples
captured.
|
void |
setUpDownCounterMode()
Set standard up / down counting mode on this counter.
|
void |
setUpSource(AnalogTrigger analogTrigger,
AnalogTriggerOutput.AnalogTriggerType triggerType)
Set the up counting source to be an analog trigger.
|
void |
setUpSource(DigitalSource source)
Set the source object that causes the counter to count up.
|
void |
setUpSource(int channel)
Set the upsource for the counter as a digital input channel.
|
void |
setUpSourceEdge(boolean risingEdge,
boolean fallingEdge)
Set the edge sensitivity on an up counting source.
|
void |
startLiveWindowMode()
Start having this sendable object automatically respond to value changes reflect the value on
the table.
|
void |
stopLiveWindowMode()
Stop having this sendable object automatically respond to value changes.
|
void |
updateTable()
Update the table for this sendable object with the latest values.
|
checkAnalogInputChannel, checkAnalogOutputChannel, checkDigitalChannel, checkPDPChannel, checkPDPModule, checkPWMChannel, checkRelayChannel, checkSolenoidChannel, checkSolenoidModule, getDefaultSolenoidModule, setDefaultSolenoidModule
protected DigitalSource m_upSource
protected DigitalSource m_downSource
public Counter(Counter.Mode mode)
public Counter()
The counter will start counting immediately.
public Counter(DigitalSource source)
The counter will start counting immediately.
source
- the digital source to countpublic Counter(int channel)
The counter will start counting immediately.
channel
- the DIO channel to use as the up source. 0-9 are on-board, 10-25 are on the MXPpublic Counter(CounterBase.EncodingType encodingType, DigitalSource upSource, DigitalSource downSource, boolean inverted)
The counter will start counting immediately.
encodingType
- which edges to countupSource
- first source to countdownSource
- second source for directioninverted
- true to invert the countpublic Counter(AnalogTrigger trigger)
The counter will start counting immediately.
trigger
- the analog trigger to countpublic void free()
SensorBase
free
in class SensorBase
public int getFPGAIndex()
public void setUpSource(int channel)
channel
- the DIO channel to count 0-9 are on-board, 10-25 are on the MXPpublic void setUpSource(DigitalSource source)
source
- the digital source to countpublic void setUpSource(AnalogTrigger analogTrigger, AnalogTriggerOutput.AnalogTriggerType triggerType)
analogTrigger
- The analog trigger object that is used for the Up SourcetriggerType
- The analog trigger output that will trigger the counter.public void setUpSourceEdge(boolean risingEdge, boolean fallingEdge)
risingEdge
- true to count rising edgefallingEdge
- true to count falling edgepublic void clearUpSource()
public void setDownSource(int channel)
channel
- the DIO channel to count 0-9 are on-board, 10-25 are on the MXPpublic void setDownSource(DigitalSource source)
source
- the digital source to countpublic void setDownSource(AnalogTrigger analogTrigger, AnalogTriggerOutput.AnalogTriggerType triggerType)
analogTrigger
- The analog trigger object that is used for the Down SourcetriggerType
- The analog trigger output that will trigger the counter.public void setDownSourceEdge(boolean risingEdge, boolean fallingEdge)
risingEdge
- true to count the rising edgefallingEdge
- true to count the falling edgepublic void clearDownSource()
public void setUpDownCounterMode()
public void setExternalDirectionMode()
public void setSemiPeriodMode(boolean highSemiPeriod)
highSemiPeriod
- true to count up on both rising and fallingpublic void setPulseLengthMode(double threshold)
threshold
- The pulse length beyond which the counter counts the opposite direction. Units
are seconds.public int get()
get
in interface CounterBase
public double getDistance()
public void reset()
reset
in interface CounterBase
public void setMaxPeriod(double maxPeriod)
setMaxPeriod
in interface CounterBase
maxPeriod
- The maximum period where the counted device is considered moving in seconds.public void setUpdateWhenEmpty(boolean enabled)
enabled
- true to continue updatingpublic boolean getStopped()
getStopped
in interface CounterBase
public boolean getDirection()
getDirection
in interface CounterBase
public void setReverseDirection(boolean reverseDirection)
reverseDirection
- true if the value counted should be negated.public double getPeriod()
getPeriod
in interface CounterBase
public double getRate()
public void setSamplesToAverage(int samplesToAverage)
samplesToAverage
- The number of samples to average from 1 to 127.public int getSamplesToAverage()
public void setDistancePerPulse(double distancePerPulse)
distancePerPulse
- The scale factor that will be used to convert pulses to useful units.public void setPIDSourceType(PIDSourceType pidSource)
setPIDSourceType
in interface PIDSource
pidSource
- An enum to select the parameter.public PIDSourceType getPIDSourceType()
PIDSource
getPIDSourceType
in interface PIDSource
public double pidGet()
PIDSource
public java.lang.String getSmartDashboardType()
Sendable
Sendable
.getSmartDashboardType
in interface Sendable
Sendable
.public void initTable(ITable subtable)
Sendable
Sendable
object.public ITable getTable()
Sendable
Sendable
.public void updateTable()
LiveWindowSendable
updateTable
in interface LiveWindowSendable
public void startLiveWindowMode()
LiveWindowSendable
startLiveWindowMode
in interface LiveWindowSendable
public void stopLiveWindowMode()
LiveWindowSendable
stopLiveWindowMode
in interface LiveWindowSendable