10 #include "HAL/HAL.hpp"
11 #include "CounterBase.h"
12 #include "SensorBase.h"
14 #include "PIDSource.h"
15 #include "LiveWindow/LiveWindowSendable.h"
52 Encoder(uint32_t aChannel, uint32_t bChannel,
bool reverseDirection =
false,
53 EncodingType encodingType = k4X);
54 Encoder(std::shared_ptr<DigitalSource> aSource,
55 std::shared_ptr<DigitalSource> bSource,
56 bool reverseDirection =
false, EncodingType encodingType = k4X);
58 bool reverseDirection =
false, EncodingType encodingType = k4X);
60 bool reverseDirection =
false, EncodingType encodingType = k4X);
64 int32_t
Get()
const override;
67 void Reset()
override;
82 void SetIndexSource(uint32_t channel, IndexingType type = kResetOnRisingEdge);
83 DEPRECATED(
"Use pass-by-reference instead.")
85 IndexingType type = kResetOnRisingEdge);
87 IndexingType type = kResetOnRisingEdge);
93 void InitTable(std::shared_ptr<ITable> subTable)
override;
94 std::shared_ptr<ITable>
GetTable()
const override;
96 int32_t GetFPGAIndex()
const {
return m_index; }
99 void InitEncoder(
bool _reverseDirection, EncodingType encodingType);
100 double DecodingScaleFactor()
const;
102 std::shared_ptr<DigitalSource> m_aSource;
103 std::shared_ptr<DigitalSource> m_bSource;
104 void *m_encoder =
nullptr;
106 double m_distancePerPulse = 1.0;
107 std::unique_ptr<Counter> m_counter =
109 EncodingType m_encodingType;
110 int32_t m_encodingScale;
112 std::shared_ptr<ITable> m_table;
int32_t Get() const override
Gets the current count.
Definition: Encoder.cpp:225
Class to enable glitch filtering on a set of digital inputs.
Definition: DigitalGlitchFilter.h:24
Encoder(uint32_t aChannel, uint32_t bChannel, bool reverseDirection=false, EncodingType encodingType=k4X)
Encoder constructor.
Definition: Encoder.cpp:98
DigitalSource Interface.
Definition: DigitalSource.h:22
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:18
double GetRate() const
Get the current rate of the encoder.
Definition: Encoder.cpp:367
void SetIndexSource(uint32_t channel, IndexingType type=kResetOnRisingEdge)
Set the index source for the encoder.
Definition: Encoder.cpp:493
int GetSamplesToAverage() const
Get the Samples to Average which specifies the number of samples of the timer to average when calcula...
Definition: Encoder.cpp:453
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: Encoder.cpp:537
void SetReverseDirection(bool reverseDirection)
Set the direction sensing for this encoder.
Definition: Encoder.cpp:409
bool GetDirection() const override
The last direction the encoder value changed.
Definition: Encoder.cpp:319
void SetSamplesToAverage(int samplesToAverage)
Set the Samples to Average which specifies the number of samples of the timer to average when calcula...
Definition: Encoder.cpp:427
void SetDistancePerPulse(double distancePerPulse)
Set the distance per pulse for this encoder.
Definition: Encoder.cpp:397
Class to read quad encoders.
Definition: Encoder.h:40
void SetMinRate(double minRate)
Set the minimum rate of the device before the hardware reports it stopped.
Definition: Encoder.cpp:378
std::string GetSmartDashboardType() const override
Definition: Encoder.cpp:549
virtual ~Encoder()
Free the resources for an Encoder.
Definition: Encoder.cpp:184
Interface for counting the number of ticks on a digital input channel.
Definition: CounterBase.h:20
Base class for all sensors.
Definition: SensorBase.h:20
double GetDistance() const
Get the distance the robot has driven since the last reset.
Definition: Encoder.cpp:355
double GetPeriod() const override
Returns the period of the most recent pulse.
Definition: Encoder.cpp:255
bool GetStopped() const override
Determine if the encoder is stopped.
Definition: Encoder.cpp:303
void Reset() override
Reset the Encoder distance to zero.
Definition: Encoder.cpp:234
void SetMaxPeriod(double maxPeriod) override
Sets the maximum period for stopped detection.
Definition: Encoder.cpp:283
double PIDGet() override
Implement the PIDSource interface.
Definition: Encoder.cpp:474
void InitTable(std::shared_ptr< ITable > subTable) override
Initializes a table for this sendable object.
Definition: Encoder.cpp:556
PIDSource interface is a generic sensor source for the PID class.
Definition: PIDSource.h:18
int32_t GetRaw() const
Gets the raw value from the encoder.
Definition: Encoder.cpp:204
std::shared_ptr< ITable > GetTable() const override
Definition: Encoder.cpp:561
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: Encoder.cpp:547
int32_t GetEncodingScale() const
The encoding scale factor 1x, 2x, or 4x, per the requested encodingType.
Definition: Encoder.cpp:196
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: Encoder.cpp:545