WPILibC++ 2025.2.1
|
Class for supporting duty cycle/PWM encoders, such as the US Digital MA3 with PWM Output, the CTRE Mag Encoder, the Rev Hex Encoder, and the AM Mag Encoder. More...
#include <frc/DutyCycleEncoder.h>
Public Member Functions | |
DutyCycleEncoder (int channel) | |
Construct a new DutyCycleEncoder on a specific channel. | |
DutyCycleEncoder (DutyCycle &dutyCycle) | |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object. | |
DutyCycleEncoder (DutyCycle *dutyCycle) | |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object. | |
DutyCycleEncoder (std::shared_ptr< DutyCycle > dutyCycle) | |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object. | |
DutyCycleEncoder (DigitalSource &digitalSource) | |
Construct a new DutyCycleEncoder attached to a DigitalSource object. | |
DutyCycleEncoder (DigitalSource *digitalSource) | |
Construct a new DutyCycleEncoder attached to a DigitalSource object. | |
DutyCycleEncoder (std::shared_ptr< DigitalSource > digitalSource) | |
Construct a new DutyCycleEncoder attached to a DigitalSource object. | |
DutyCycleEncoder (int channel, double fullRange, double expectedZero) | |
Construct a new DutyCycleEncoder on a specific channel. | |
DutyCycleEncoder (DutyCycle &dutyCycle, double fullRange, double expectedZero) | |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object. | |
DutyCycleEncoder (DutyCycle *dutyCycle, double fullRange, double expectedZero) | |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object. | |
DutyCycleEncoder (std::shared_ptr< DutyCycle > dutyCycle, double fullRange, double expectedZero) | |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object. | |
DutyCycleEncoder (DigitalSource &digitalSource, double fullRange, double expectedZero) | |
Construct a new DutyCycleEncoder attached to a DigitalSource object. | |
DutyCycleEncoder (DigitalSource *digitalSource, double fullRange, double expectedZero) | |
Construct a new DutyCycleEncoder attached to a DigitalSource object. | |
DutyCycleEncoder (std::shared_ptr< DigitalSource > digitalSource, double fullRange, double expectedZero) | |
Construct a new DutyCycleEncoder attached to a DigitalSource object. | |
~DutyCycleEncoder () override=default | |
DutyCycleEncoder (DutyCycleEncoder &&)=default | |
DutyCycleEncoder & | operator= (DutyCycleEncoder &&)=default |
int | GetFrequency () const |
Get the frequency in Hz of the duty cycle signal from the encoder. | |
bool | IsConnected () const |
Get if the sensor is connected. | |
void | SetConnectedFrequencyThreshold (int frequency) |
Change the frequency threshold for detecting connection used by IsConnected. | |
double | Get () const |
Get the encoder value. | |
void | SetDutyCycleRange (double min, double max) |
Set the encoder duty cycle range. | |
void | SetAssumedFrequency (units::hertz_t frequency) |
Sets the assumed frequency of the connected device. | |
void | SetInverted (bool inverted) |
Set if this encoder is inverted. | |
int | GetFPGAIndex () const |
Get the FPGA index for the DutyCycleEncoder. | |
int | GetSourceChannel () const |
Get the channel of the source. | |
void | InitSendable (wpi::SendableBuilder &builder) override |
Initializes this Sendable object. | |
Public Member Functions inherited from wpi::Sendable | |
virtual constexpr | ~Sendable ()=default |
Public Member Functions inherited from wpi::SendableHelper< DutyCycleEncoder > | |
constexpr | SendableHelper (const SendableHelper &rhs)=default |
constexpr | SendableHelper (SendableHelper &&rhs) |
constexpr SendableHelper & | operator= (const SendableHelper &rhs)=default |
constexpr SendableHelper & | operator= (SendableHelper &&rhs) |
Additional Inherited Members | |
Protected Member Functions inherited from wpi::SendableHelper< DutyCycleEncoder > | |
constexpr | SendableHelper ()=default |
constexpr | ~SendableHelper () |
Class for supporting duty cycle/PWM encoders, such as the US Digital MA3 with PWM Output, the CTRE Mag Encoder, the Rev Hex Encoder, and the AM Mag Encoder.
|
explicit |
Construct a new DutyCycleEncoder on a specific channel.
This has a fullRange of 1 and an expectedZero of 0.
channel | the channel to attach to |
|
explicit |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
This has a fullRange of 1 and an expectedZero of 0.
dutyCycle | the duty cycle to attach to |
|
explicit |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
This has a fullRange of 1 and an expectedZero of 0.
dutyCycle | the duty cycle to attach to |
|
explicit |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
This has a fullRange of 1 and an expectedZero of 0.
dutyCycle | the duty cycle to attach to |
|
explicit |
Construct a new DutyCycleEncoder attached to a DigitalSource object.
This has a fullRange of 1 and an expectedZero of 0.
digitalSource | the digital source to attach to |
|
explicit |
Construct a new DutyCycleEncoder attached to a DigitalSource object.
This has a fullRange of 1 and an expectedZero of 0.
digitalSource | the digital source to attach to |
|
explicit |
Construct a new DutyCycleEncoder attached to a DigitalSource object.
This has a fullRange of 1 and an expectedZero of 0.
digitalSource | the digital source to attach to |
frc::DutyCycleEncoder::DutyCycleEncoder | ( | int | channel, |
double | fullRange, | ||
double | expectedZero ) |
Construct a new DutyCycleEncoder on a specific channel.
channel | the channel to attach to |
fullRange | the value to report at maximum travel |
expectedZero | the reading where you would expect a 0 from get() |
frc::DutyCycleEncoder::DutyCycleEncoder | ( | DutyCycle & | dutyCycle, |
double | fullRange, | ||
double | expectedZero ) |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
dutyCycle | the duty cycle to attach to |
fullRange | the value to report at maximum travel |
expectedZero | the reading where you would expect a 0 from get() |
frc::DutyCycleEncoder::DutyCycleEncoder | ( | DutyCycle * | dutyCycle, |
double | fullRange, | ||
double | expectedZero ) |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
dutyCycle | the duty cycle to attach to |
fullRange | the value to report at maximum travel |
expectedZero | the reading where you would expect a 0 from get() |
frc::DutyCycleEncoder::DutyCycleEncoder | ( | std::shared_ptr< DutyCycle > | dutyCycle, |
double | fullRange, | ||
double | expectedZero ) |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
dutyCycle | the duty cycle to attach to |
fullRange | the value to report at maximum travel |
expectedZero | the reading where you would expect a 0 from get() |
frc::DutyCycleEncoder::DutyCycleEncoder | ( | DigitalSource & | digitalSource, |
double | fullRange, | ||
double | expectedZero ) |
Construct a new DutyCycleEncoder attached to a DigitalSource object.
digitalSource | the digital source to attach to |
fullRange | the value to report at maximum travel |
expectedZero | the reading where you would expect a 0 from get() |
frc::DutyCycleEncoder::DutyCycleEncoder | ( | DigitalSource * | digitalSource, |
double | fullRange, | ||
double | expectedZero ) |
Construct a new DutyCycleEncoder attached to a DigitalSource object.
digitalSource | the digital source to attach to |
fullRange | the value to report at maximum travel |
expectedZero | the reading where you would expect a 0 from get() |
frc::DutyCycleEncoder::DutyCycleEncoder | ( | std::shared_ptr< DigitalSource > | digitalSource, |
double | fullRange, | ||
double | expectedZero ) |
Construct a new DutyCycleEncoder attached to a DigitalSource object.
digitalSource | the digital source to attach to |
fullRange | the value to report at maximum travel |
expectedZero | the reading where you would expect a 0 from get() |
|
overridedefault |
|
default |
double frc::DutyCycleEncoder::Get | ( | ) | const |
Get the encoder value.
int frc::DutyCycleEncoder::GetFPGAIndex | ( | ) | const |
Get the FPGA index for the DutyCycleEncoder.
int frc::DutyCycleEncoder::GetFrequency | ( | ) | const |
Get the frequency in Hz of the duty cycle signal from the encoder.
int frc::DutyCycleEncoder::GetSourceChannel | ( | ) | const |
Get the channel of the source.
|
overridevirtual |
bool frc::DutyCycleEncoder::IsConnected | ( | ) | const |
Get if the sensor is connected.
This uses the duty cycle frequency to determine if the sensor is connected. By default, a value of 100 Hz is used as the threshold, and this value can be changed with SetConnectedFrequencyThreshold.
|
default |
void frc::DutyCycleEncoder::SetAssumedFrequency | ( | units::hertz_t | frequency | ) |
Sets the assumed frequency of the connected device.
By default, the DutyCycle engine has to compute the frequency of the input signal. This can result in both delayed readings and jumpy readings. To solve this, you can pass the expected frequency of the sensor to this function. This will use that frequency to compute the DutyCycle percentage, rather than the computed frequency.
frequency | the assumed frequency of the sensor |
void frc::DutyCycleEncoder::SetConnectedFrequencyThreshold | ( | int | frequency | ) |
Change the frequency threshold for detecting connection used by IsConnected.
frequency | the minimum frequency in Hz. |
void frc::DutyCycleEncoder::SetDutyCycleRange | ( | double | min, |
double | max ) |
Set the encoder duty cycle range.
As the encoder needs to maintain a duty cycle, the duty cycle cannot go all the way to 0% or all the way to 100%. For example, an encoder with a 4096 us period might have a minimum duty cycle of 1 us / 4096 us and a maximum duty cycle of 4095 / 4096 us. Setting the range will result in an encoder duty cycle less than or equal to the minimum being output as 0 rotation, the duty cycle greater than or equal to the maximum being output as 1 rotation, and values in between linearly scaled from 0 to 1.
min | minimum duty cycle (0-1 range) |
max | maximum duty cycle (0-1 range) |
void frc::DutyCycleEncoder::SetInverted | ( | bool | inverted | ) |
Set if this encoder is inverted.
inverted | true to invert the encoder, false otherwise |