Now you can download a copy of these docs so you can use them offline! Download now

#include <Counter.h>

Inheritance diagram for Counter:
Collaboration diagram for Counter:

Public Types

enum  Mode { kTwoPulse =0, kSemiperiod =1, kPulseLength =2, kExternalDirection =3 }
 
- Public Types inherited from CounterBase
enum  EncodingType { k1X, k2X, k4X }
 

Public Member Functions

 Counter ()
 
 Counter (uint32_t channel)
 
 Counter (uint8_t moduleNumber, uint32_t channel)
 
 Counter (DigitalSource *source)
 
 Counter (DigitalSource &source)
 
 Counter (AnalogTrigger *trigger)
 
 Counter (AnalogTrigger &trigger)
 
 Counter (EncodingType encodingType, DigitalSource *upSource, DigitalSource *downSource, bool inverted)
 
virtual ~Counter ()
 
void SetUpSource (uint32_t channel)
 
void SetUpSource (uint8_t moduleNumber, uint32_t channel)
 
void SetUpSource (AnalogTrigger *analogTrigger, AnalogTriggerOutput::Type triggerType)
 
void SetUpSource (AnalogTrigger &analogTrigger, AnalogTriggerOutput::Type triggerType)
 
void SetUpSource (DigitalSource *source)
 
void SetUpSource (DigitalSource &source)
 
void SetUpSourceEdge (bool risingEdge, bool fallingEdge)
 
void ClearUpSource ()
 
void SetDownSource (uint32_t channel)
 
void SetDownSource (uint8_t moduleNumber, uint32_t channel)
 
void SetDownSource (AnalogTrigger *analogTrigger, AnalogTriggerOutput::Type triggerType)
 
void SetDownSource (AnalogTrigger &analogTrigger, AnalogTriggerOutput::Type triggerType)
 
void SetDownSource (DigitalSource *source)
 
void SetDownSource (DigitalSource &source)
 
void SetDownSourceEdge (bool risingEdge, bool fallingEdge)
 
void ClearDownSource ()
 
void SetUpDownCounterMode ()
 
void SetExternalDirectionMode ()
 
void SetSemiPeriodMode (bool highSemiPeriod)
 
void SetPulseLengthMode (float threshold)
 
void SetReverseDirection (bool reverseDirection)
 
void Start ()
 
int32_t Get ()
 
void Reset ()
 
void Stop ()
 
double GetPeriod ()
 
void SetMaxPeriod (double maxPeriod)
 
void SetUpdateWhenEmpty (bool enabled)
 
bool GetStopped ()
 
bool GetDirection ()
 
void SetSamplesToAverage (int samplesToAverage)
 
int GetSamplesToAverage ()
 
uint32_t GetIndex ()
 
void UpdateTable ()
 
void StartLiveWindowMode ()
 
void StopLiveWindowMode ()
 
virtual std::string GetSmartDashboardType ()
 
void InitTable (ITable *subTable)
 
ITableGetTable ()
 
- Public Member Functions inherited from SensorBase
 SensorBase ()
 
virtual ~SensorBase ()
 
- Public Member Functions inherited from ErrorBase
virtual ErrorGetError ()
 Retrieve the current error. Get the current error information associated with this sensor.
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (ErrorBase *rhs) const
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 

Protected Attributes

DigitalSourcem_upSource
 What makes the counter count up.
 
DigitalSourcem_downSource
 What makes the counter count down.
 
tCounter * m_counter
 The FPGA counter object.
 
- Protected Attributes inherited from ErrorBase
Error m_error
 

Additional Inherited Members

- Static Public Member Functions inherited from SensorBase
static void DeleteSingletons ()
 
static uint32_t GetDefaultAnalogModule ()
 
static uint32_t GetDefaultDigitalModule ()
 
static uint32_t GetDefaultSolenoidModule ()
 
static bool CheckAnalogModule (uint8_t moduleNumber)
 
static bool CheckDigitalModule (uint8_t moduleNumber)
 
static bool CheckPWMModule (uint8_t moduleNumber)
 
static bool CheckRelayModule (uint8_t moduleNumber)
 
static bool CheckSolenoidModule (uint8_t moduleNumber)
 
static bool CheckDigitalChannel (uint32_t channel)
 
static bool CheckRelayChannel (uint32_t channel)
 
static bool CheckPWMChannel (uint32_t channel)
 
static bool CheckAnalogChannel (uint32_t channel)
 
static bool CheckSolenoidChannel (uint32_t channel)
 
- Static Public Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static void SetGlobalWPIError (const char *errorMessage, const char *contextMessage, const char *filename, const char *function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 
- Static Public Attributes inherited from SensorBase
static const uint32_t kSystemClockTicksPerMicrosecond = 40
 
static const uint32_t kDigitalChannels = 14
 
static const uint32_t kAnalogChannels = 8
 
static const uint32_t kAnalogModules = 2
 
static const uint32_t kDigitalModules = 2
 
static const uint32_t kSolenoidChannels = 8
 
static const uint32_t kSolenoidModules = 2
 
static const uint32_t kPwmChannels = 10
 
static const uint32_t kRelayChannels = 8
 
static const uint32_t kChassisSlots = 8
 
- Protected Member Functions inherited from SensorBase
void AddToSingletonList ()
 
- Protected Member Functions inherited from ErrorBase
 ErrorBase ()
 Initialize the instance status to 0 for now.
 
- Static Protected Attributes inherited from ErrorBase
static SEM_ID _globalErrorMutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE)
 
static Error _globalError
 

Detailed Description

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.

Definition at line 21 of file Counter.h.

Constructor & Destructor Documentation

Counter::Counter ( )

Create an instance of a counter where no sources are selected. Then they all must be selected by calling functions to specify the upsource and the downsource independently.

Definition at line 49 of file Counter.cpp.

Counter::Counter ( uint32_t  channel)
explicit

Create an instance of a Counter object. Create an up-Counter instance given a channel. The default digital module is assumed.

Definition at line 86 of file Counter.cpp.

Counter::Counter ( uint8_t  moduleNumber,
uint32_t  channel 
)

Create an instance of a Counter object. Create an instance of an up-Counter given a digital module and a channel.

Parameters
moduleNumberThe digital module (1 or 2).
channelThe channel in the digital module

Definition at line 102 of file Counter.cpp.

Counter::Counter ( DigitalSource source)
explicit

Create an instance of a counter from a Digital Input. This is used if an existing digital input is to be shared by multiple other objects such as encoders.

Definition at line 62 of file Counter.cpp.

Counter::Counter ( AnalogTrigger trigger)
explicit

Create an instance of a Counter object. Create an instance of a simple up-Counter given an analog trigger. Use the trigger state output from the analog trigger.

Definition at line 117 of file Counter.cpp.

Counter::~Counter ( )
virtual

Delete the Counter object.

Definition at line 172 of file Counter.cpp.

Member Function Documentation

void Counter::ClearDownSource ( )

Disable the down counting source to the counter.

Definition at line 433 of file Counter.cpp.

void Counter::ClearUpSource ( )

Disable the up counting source to the counter.

Definition at line 300 of file Counter.cpp.

int32_t Counter::Get ( )
virtual

Read the current counter value. Read the value at this instant. It may still be running, so it reflects the current value. Next time it is read, it might have a different value.

Implements CounterBase.

Definition at line 555 of file Counter.cpp.

bool Counter::GetDirection ( )
virtual

The last direction the counter value changed.

Returns
The last direction the counter value changed.

Implements CounterBase.

Definition at line 671 of file Counter.cpp.

int Counter::GetSamplesToAverage ( )

Get the Samples to Average which specifies the number of samples of the timer to average when calculating the period. Perform averaging to account for mechanical imperfections or as oversampling to increase resolution.

Returns
SamplesToAverage The number of samples being averaged (from 1 to 127)

Definition at line 514 of file Counter.cpp.

std::string Counter::GetSmartDashboardType ( )
virtual
Returns
the string representation of the named data type that will be used by the smart dashboard for this sendable

Implements Sendable.

Reimplemented in GearTooth.

Definition at line 715 of file Counter.cpp.

bool Counter::GetStopped ( )
virtual

Determine if the clock is stopped. Determine if the clocked input is stopped based on the MaxPeriod value set using the SetMaxPeriod method. If the clock exceeds the MaxPeriod, then the device (and counter) are assumed to be stopped and it returns true.

Returns
Returns true if the most recent counter period exceeds the MaxPeriod value set by SetMaxPeriod.

Implements CounterBase.

Definition at line 659 of file Counter.cpp.

ITable * Counter::GetTable ( )
virtual
Returns
the table that is currently associated with the sendable

Implements Sendable.

Definition at line 724 of file Counter.cpp.

void Counter::InitTable ( ITable subtable)
virtual

Initializes a table for this sendable object.

Parameters
subtableThe table to put the values in.

Implements Sendable.

Definition at line 719 of file Counter.cpp.

void Counter::Reset ( )
virtual

Reset the Counter to zero. Set the counter value to zero. This doesn't effect the running state of the counter, just sets the current value to zero.

Implements CounterBase.

Definition at line 569 of file Counter.cpp.

void Counter::SetDownSource ( uint32_t  channel)

Set the down counting source to be a digital input channel. The slot will be set to the default digital module slot.

Definition at line 325 of file Counter.cpp.

void Counter::SetDownSource ( uint8_t  moduleNumber,
uint32_t  channel 
)

Set the down counting source to be a digital input slot and channel.

Parameters
moduleNumberThe digital module (1 or 2).
channelThe digital channel (1..14).

Definition at line 338 of file Counter.cpp.

void Counter::SetDownSource ( AnalogTrigger analogTrigger,
AnalogTriggerOutput::Type  triggerType 
)

Set the down counting source to be an analog trigger.

Parameters
analogTriggerThe analog trigger object that is used for the Down Source
triggerTypeThe analog trigger output that will trigger the counter.

Definition at line 350 of file Counter.cpp.

void Counter::SetDownSource ( AnalogTrigger analogTrigger,
AnalogTriggerOutput::Type  triggerType 
)

Set the down counting source to be an analog trigger.

Parameters
analogTriggerThe analog trigger object that is used for the Down Source
triggerTypeThe analog trigger output that will trigger the counter.

Definition at line 362 of file Counter.cpp.

void Counter::SetDownSource ( DigitalSource source)

Set the source object that causes the counter to count down. Set the down counting DigitalSource.

Definition at line 371 of file Counter.cpp.

void Counter::SetDownSource ( DigitalSource source)

Set the source object that causes the counter to count down. Set the down counting DigitalSource.

Definition at line 408 of file Counter.cpp.

void Counter::SetDownSourceEdge ( bool  risingEdge,
bool  fallingEdge 
)

Set the edge sensitivity on a down counting source. Set the down source to either detect rising edges or falling edges.

Definition at line 417 of file Counter.cpp.

void Counter::SetExternalDirectionMode ( )

Set external direction mode on this counter. Counts are sourced on the Up counter input. The Down counter input represents the direction to count.

Definition at line 471 of file Counter.cpp.

void Counter::SetMaxPeriod ( double  maxPeriod)
virtual

Set the maximum period where the device is still considered "moving". Sets the maximum period where the device is considered moving. This value is used to determine the "stopped" state of the counter using the GetStopped method.

Parameters
maxPeriodThe maximum period where the counted device is considered moving in seconds.

Implements CounterBase.

Definition at line 623 of file Counter.cpp.

void Counter::SetPulseLengthMode ( float  threshold)

Configure the counter to count in up or down based on the length of the input pulse. This mode is most useful for direction sensitive gear tooth sensors.

Parameters
thresholdThe pulse length beyond which the counter counts the opposite direction. Units are seconds.

Definition at line 498 of file Counter.cpp.

void Counter::SetReverseDirection ( bool  reverseDirection)

Set the Counter to return reversed sensing on the direction. This allows counters to change the direction they are counting in the case of 1X and 2X quadrature encoding only. Any other counter mode isn't supported.

Parameters
reverseDirectiontrue if the value counted should be negated.

Definition at line 686 of file Counter.cpp.

void Counter::SetSamplesToAverage ( int  samplesToAverage)

Set the Samples to Average which specifies the number of samples of the timer to average when calculating the period. Perform averaging to account for mechanical imperfections or as oversampling to increase resolution.

Parameters
samplesToAverageThe number of samples to average from 1 to 127.

Definition at line 527 of file Counter.cpp.

void Counter::SetSemiPeriodMode ( bool  highSemiPeriod)

Set Semi-period mode on this counter. Counts up on both rising and falling edges.

Definition at line 483 of file Counter.cpp.

void Counter::SetUpdateWhenEmpty ( bool  enabled)

Select whether you want to continue updating the event timer output when there are no samples captured. The output of the event timer has a buffer of periods that are averaged and posted to a register on the FPGA. When the timer detects that the event source has stopped (based on the MaxPeriod) the buffer of samples to be averaged is emptied. If you enable the update when empty, you will be notified of the stopped source and the event time will report 0 samples. If you disable update when empty, the most recent average will remain on the output until a new sample is acquired. You will never see 0 samples output (except when there have been no events since an FPGA reset) and you will likely not see the stopped bit become true (since it is updated at the end of an average and there are no samples to average).

Definition at line 643 of file Counter.cpp.

void Counter::SetUpDownCounterMode ( )

Set standard up / down counting mode on this counter. Up and down counts are sourced independently from two inputs.

Definition at line 458 of file Counter.cpp.

void Counter::SetUpSource ( uint32_t  channel)

Set the upsource for the counter as a digital input channel. The slot will be the default digital module slot.

Definition at line 207 of file Counter.cpp.

void Counter::SetUpSource ( uint8_t  moduleNumber,
uint32_t  channel 
)

Set the up source for the counter as digital input channel and slot.

Parameters
moduleNumberThe digital module (1 or 2).
channelThe digital channel (1..14).

Definition at line 196 of file Counter.cpp.

void Counter::SetUpSource ( AnalogTrigger analogTrigger,
AnalogTriggerOutput::Type  triggerType 
)

Set the up counting source to be an analog trigger.

Parameters
analogTriggerThe analog trigger object that is used for the Up Source
triggerTypeThe analog trigger output that will trigger the counter.

Definition at line 219 of file Counter.cpp.

void Counter::SetUpSource ( AnalogTrigger analogTrigger,
AnalogTriggerOutput::Type  triggerType 
)

Set the up counting source to be an analog trigger.

Parameters
analogTriggerThe analog trigger object that is used for the Up Source
triggerTypeThe analog trigger output that will trigger the counter.

Definition at line 231 of file Counter.cpp.

void Counter::SetUpSource ( DigitalSource source)

Set the source object that causes the counter to count up. Set the up counting DigitalSource.

Definition at line 240 of file Counter.cpp.

void Counter::SetUpSource ( DigitalSource source)

Set the source object that causes the counter to count up. Set the up counting DigitalSource.

Definition at line 275 of file Counter.cpp.

void Counter::SetUpSourceEdge ( bool  risingEdge,
bool  fallingEdge 
)

Set the edge sensitivity on an up counting source. Set the up source to either detect rising edges or falling edges.

Definition at line 284 of file Counter.cpp.

void Counter::Start ( )
virtual

Start the Counter counting. This enables the counter and it starts accumulating counts from the associated input channel. The counter value is not reset on starting, and still has the previous value.

Implements CounterBase.

Definition at line 542 of file Counter.cpp.

void Counter::StartLiveWindowMode ( )
virtual

Start having this sendable object automatically respond to value changes reflect the value on the table.

Implements LiveWindowSendable.

Definition at line 707 of file Counter.cpp.

void Counter::Stop ( )
virtual

Stop the Counter. Stops the counting but doesn't effect the current value.

Implements CounterBase.

Definition at line 581 of file Counter.cpp.

void Counter::StopLiveWindowMode ( )
virtual

Stop having this sendable object automatically respond to value changes.

Implements LiveWindowSendable.

Definition at line 711 of file Counter.cpp.

void Counter::UpdateTable ( )
virtual

Update the table for this sendable object with the latest values.

Implements LiveWindowSendable.

Definition at line 701 of file Counter.cpp.


The documentation for this class was generated from the following files:

Generated on Sat Apr 26 2014 12:26:46 for WPILibC++ by doxygen 1.8.6