|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.wpi.first.wpilibj.SensorBase
edu.wpi.first.wpilibj.Counter
public class Counter
Class for counting the number of ticks on a digital input channel. This is a general purpose class for counting repetitive events. It can return the number of counts, the period of the most recent cycle, and detect when the signal being counted has stopped by supplying a maximum cycle time.
Nested Class Summary | |
---|---|
static class |
Counter.Mode
Mode determines how and what the counter counts |
Nested classes/interfaces inherited from interface edu.wpi.first.wpilibj.CounterBase |
---|
CounterBase.EncodingType |
Nested classes/interfaces inherited from interface edu.wpi.first.wpilibj.PIDSource |
---|
PIDSource.PIDSourceParameter |
Field Summary |
---|
Fields inherited from class edu.wpi.first.wpilibj.SensorBase |
---|
kAnalogChannels, kAnalogModules, kDigitalChannels, kPwmChannels, kRelayChannels, kSolenoidChannels, kSolenoidModules, kSystemClockTicksPerMicrosecond |
Constructor Summary | |
---|---|
Counter()
Create an instance of a counter where no sources are selected. |
|
Counter(AnalogTrigger trigger)
Create an instance of a Counter object. |
|
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. |
|
Counter(int slot,
int channel)
Create an instance of a Counter object. |
Method Summary | |
---|---|
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. |
double |
getPeriod()
Get the Period of the most recent count. |
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()
Live Window code, only does anything if live window is activated. |
boolean |
getStopped()
Determine if the clock is stopped. |
ITable |
getTable()
|
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.Type 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 |
setDownSource(int slot,
int channel)
Set the down counting source to be a digital input slot and 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 |
setPIDSourceParameter(PIDSource.PIDSourceParameter 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.Type 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 |
setUpSource(int slot,
int channel)
Set the up source for the counter as digital input channel and slot. |
void |
setUpSourceEdge(boolean risingEdge,
boolean fallingEdge)
Set the edge sensitivity on an up counting source. |
void |
start()
Start the Counter counting. |
void |
startLiveWindowMode()
Start having this sendable object automatically respond to value changes reflect the value on the table. |
void |
stop()
Stop the Counter. |
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. |
Methods inherited from class edu.wpi.first.wpilibj.SensorBase |
---|
checkAnalogChannel, checkAnalogModule, checkDigitalChannel, checkDigitalModule, checkPWMChannel, checkPWMModule, checkRelayChannel, checkRelayModule, checkSolenoidChannel, checkSolenoidModule, getDefaultAnalogModule, getDefaultDigitalModule, getDefaultSolenoidModule, setDefaultAnalogModule, setDefaultDigitalModule, setDefaultSolenoidModule |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Counter()
public Counter(DigitalSource source)
source
- the digital source to countpublic Counter(int channel)
channel
- the digital input channel to countpublic Counter(int slot, int channel)
slot
- The cRIO chassis slot for the digital module usedchannel
- The channel in the digital modulepublic Counter(CounterBase.EncodingType encodingType, DigitalSource upSource, DigitalSource downSource, boolean inverted)
encodingType
- which edges to countupSource
- first source to countdownSource
- second source for directioninverted
- true to invert the countpublic Counter(AnalogTrigger trigger)
trigger
- the analog trigger to countMethod Detail |
---|
public void free()
SensorBase
free
in class SensorBase
public void setUpSource(int slot, int channel)
slot
- the location of the digital module to usechannel
- the digital port to countpublic void setUpSource(int channel)
channel
- the digital port to countpublic void setUpSource(DigitalSource source)
source
- the digital source to countpublic void setUpSource(AnalogTrigger analogTrigger, AnalogTriggerOutput.Type 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 digital port to countpublic void setDownSource(int slot, int channel)
slot
- the location of the digital module to usechannel
- the digital port to countpublic void setDownSource(DigitalSource source)
source
- the digital source to countpublic void setDownSource(AnalogTrigger analogTrigger, AnalogTriggerOutput.Type 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 void start()
start
in interface CounterBase
public int get()
get
in interface CounterBase
public double getDistance()
public void reset()
reset
in interface CounterBase
public void stop()
stop
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 setPIDSourceParameter(PIDSource.PIDSourceParameter pidSource)
pidSource
- An enum to select the parameter.public double pidGet()
PIDSource
pidGet
in interface PIDSource
public java.lang.String getSmartDashboardType()
getSmartDashboardType
in interface Sendable
public void initTable(ITable subtable)
initTable
in interface Sendable
subtable
- The table to put the values in.public ITable getTable()
getTable
in interface Sendable
public void updateTable()
updateTable
in interface LiveWindowSendable
public void startLiveWindowMode()
startLiveWindowMode
in interface LiveWindowSendable
public void stopLiveWindowMode()
stopLiveWindowMode
in interface LiveWindowSendable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |