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>
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.
◆ DutyCycleEncoder() [1/9]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
int | channel | ) |
|
|
explicit |
Construct a new DutyCycleEncoder on a specific channel.
This has a fullRange of 1 and an expectedZero of 0.
- Parameters
-
channel | the channel to attach to |
◆ DutyCycleEncoder() [2/9]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
DutyCycle & | dutyCycle | ) |
|
|
explicit |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
This has a fullRange of 1 and an expectedZero of 0.
- Parameters
-
dutyCycle | the duty cycle to attach to |
◆ DutyCycleEncoder() [3/9]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
DutyCycle * | dutyCycle | ) |
|
|
explicit |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
This has a fullRange of 1 and an expectedZero of 0.
- Parameters
-
dutyCycle | the duty cycle to attach to |
◆ DutyCycleEncoder() [4/9]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
std::shared_ptr< DutyCycle > | dutyCycle | ) |
|
|
explicit |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
This has a fullRange of 1 and an expectedZero of 0.
- Parameters
-
dutyCycle | the duty cycle to attach to |
◆ DutyCycleEncoder() [5/9]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
int | channel, |
|
|
double | fullRange, |
|
|
double | expectedZero ) |
Construct a new DutyCycleEncoder on a specific channel.
- Parameters
-
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() |
◆ DutyCycleEncoder() [6/9]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
DutyCycle & | dutyCycle, |
|
|
double | fullRange, |
|
|
double | expectedZero ) |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
- Parameters
-
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() |
◆ DutyCycleEncoder() [7/9]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
DutyCycle * | dutyCycle, |
|
|
double | fullRange, |
|
|
double | expectedZero ) |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
- Parameters
-
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() |
◆ DutyCycleEncoder() [8/9]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
std::shared_ptr< DutyCycle > | dutyCycle, |
|
|
double | fullRange, |
|
|
double | expectedZero ) |
Construct a new DutyCycleEncoder attached to an existing DutyCycle object.
- Parameters
-
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() |
◆ ~DutyCycleEncoder()
frc::DutyCycleEncoder::~DutyCycleEncoder |
( |
| ) |
|
|
overridedefault |
◆ DutyCycleEncoder() [9/9]
◆ Get()
double frc::DutyCycleEncoder::Get |
( |
| ) |
const |
Get the encoder value.
- Returns
- the encoder value scaled by the full range input
◆ GetFrequency()
units::hertz_t frc::DutyCycleEncoder::GetFrequency |
( |
| ) |
const |
Get the frequency of the duty cycle signal from the encoder.
- Returns
- duty cycle frequency
◆ GetSourceChannel()
int frc::DutyCycleEncoder::GetSourceChannel |
( |
| ) |
const |
Get the channel of the source.
- Returns
- the source channel
◆ InitSendable()
Initializes this Sendable object.
- Parameters
-
Implements wpi::Sendable.
◆ IsConnected()
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.
- Returns
- true if the sensor is connected
◆ operator=()
◆ SetAssumedFrequency()
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.
- Parameters
-
frequency | the assumed frequency of the sensor |
◆ SetConnectedFrequencyThreshold()
void frc::DutyCycleEncoder::SetConnectedFrequencyThreshold |
( |
units::hertz_t | frequency | ) |
|
Change the frequency threshold for detecting connection used by IsConnected.
- Parameters
-
frequency | the minimum frequency. |
◆ SetDutyCycleRange()
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.
- Parameters
-
min | minimum duty cycle (0-1 range) |
max | maximum duty cycle (0-1 range) |
◆ SetInverted()
void frc::DutyCycleEncoder::SetInverted |
( |
bool | inverted | ) |
|
Set if this encoder is inverted.
- Parameters
-
inverted | true to invert the encoder, false otherwise |
The documentation for this class was generated from the following file: