[wpilib] Counter: Fix default distance per pulse, add distance and rate to C++ (#5796)

- Default distance per pulse in java was 0; 1 is a more reasonable default
- C++ was missing this functionality
This commit is contained in:
Ryan Blue
2023-10-20 02:42:53 -04:00
committed by GitHub
parent b14a61e1c0
commit abb2857e03
3 changed files with 42 additions and 1 deletions

View File

@@ -343,6 +343,34 @@ class Counter : public CounterBase,
int GetFPGAIndex() const;
/**
* Set the distance per pulse for this counter. This sets the multiplier used
* to determine the distance driven based on the count value from the encoder.
* Set this value based on the Pulses per Revolution and factor in any gearing
* reductions. This distance can be in any units you like, linear or angular.
*
* @param distancePerPulse The scale factor that will be used to convert
* pulses to useful units.
*/
void SetDistancePerPulse(double distancePerPulse);
/**
* Read the current scaled counter value. Read the value at this instant,
* scaled by the distance per pulse (defaults to 1).
*
* @return The distance since the last reset
*/
double GetDistance() const;
/**
* Get the current rate of the Counter. Read the current rate of the counter
* accounting for the distance per pulse value. The default value for distance
* per pulse (1) yields units of pulses per second.
*
* @return The rate in units/sec
*/
double GetRate() const;
// CounterBase interface
/**
* Read the current counter value.
@@ -434,6 +462,7 @@ class Counter : public CounterBase,
private:
int m_index = 0; // The index of this counter.
double m_distancePerPulse = 1;
friend class DigitalGlitchFilter;
};