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/8]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
int |
channel | ) |
|
|
explicit |
Construct a new DutyCycleEncoder on a specific channel.
- Parameters
-
channel | the channel to attach to |
◆ DutyCycleEncoder() [2/8]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
DutyCycle & |
dutyCycle | ) |
|
|
explicit |
◆ DutyCycleEncoder() [3/8]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
DutyCycle * |
dutyCycle | ) |
|
|
explicit |
◆ DutyCycleEncoder() [4/8]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
std::shared_ptr< DutyCycle > |
dutyCycle | ) |
|
|
explicit |
◆ DutyCycleEncoder() [5/8]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
DigitalSource & |
digitalSource | ) |
|
|
explicit |
◆ DutyCycleEncoder() [6/8]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
DigitalSource * |
digitalSource | ) |
|
|
explicit |
◆ DutyCycleEncoder() [7/8]
frc::DutyCycleEncoder::DutyCycleEncoder |
( |
std::shared_ptr< DigitalSource > |
digitalSource | ) |
|
|
explicit |
◆ ~DutyCycleEncoder()
frc::DutyCycleEncoder::~DutyCycleEncoder |
( |
| ) |
|
|
overridedefault |
◆ DutyCycleEncoder() [8/8]
◆ Get()
units::turn_t frc::DutyCycleEncoder::Get |
( |
| ) |
const |
Get the encoder value since the last reset.
This is reported in rotations since the last reset.
- Returns
- the encoder value in rotations
◆ GetAbsolutePosition()
double frc::DutyCycleEncoder::GetAbsolutePosition |
( |
| ) |
const |
Get the absolute position of the duty cycle encoder encoder.
GetAbsolutePosition() - GetPositionOffset() will give an encoder absolute position relative to the last reset. This could potentially be negative, which needs to be accounted for.
This will not account for rollovers, and will always be just the raw absolute position.
- Returns
- the absolute position
◆ GetDistance()
double frc::DutyCycleEncoder::GetDistance |
( |
| ) |
const |
Get the distance the sensor has driven since the last reset as scaled by the value from SetDistancePerRotation.
- Returns
- The distance driven since the last reset
◆ GetDistancePerRotation()
double frc::DutyCycleEncoder::GetDistancePerRotation |
( |
| ) |
const |
Get the distance per rotation for this encoder.
- Returns
- The scale factor that will be used to convert rotation to useful units.
◆ GetFPGAIndex()
int frc::DutyCycleEncoder::GetFPGAIndex |
( |
| ) |
const |
◆ GetFrequency()
int frc::DutyCycleEncoder::GetFrequency |
( |
| ) |
const |
Get the frequency in Hz of the duty cycle signal from the encoder.
- Returns
- duty cycle frequency in Hz
◆ GetPositionOffset()
double frc::DutyCycleEncoder::GetPositionOffset |
( |
| ) |
const |
Get the offset of position relative to the last reset.
GetAbsolutePosition() - GetPositionOffset() will give an encoder absolute position relative to the last reset. This could potentially be negative, which needs to be accounted for.
- Returns
- the position offset
◆ 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=()
◆ Reset()
void frc::DutyCycleEncoder::Reset |
( |
| ) |
|
Reset the Encoder distance to zero.
◆ SetConnectedFrequencyThreshold()
void frc::DutyCycleEncoder::SetConnectedFrequencyThreshold |
( |
int |
frequency | ) |
|
Change the frequency threshold for detecting connection used by IsConnected.
- Parameters
-
frequency | the minimum frequency in Hz. |
◆ SetDistancePerRotation()
void frc::DutyCycleEncoder::SetDistancePerRotation |
( |
double |
distancePerRotation | ) |
|
Set the distance per rotation of the encoder.
This sets the multiplier used to determine the distance driven based on the rotation value from the encoder. Set this value based on the how far the mechanism travels in 1 rotation of the encoder, and factor in gearing reductions following the encoder shaft. This distance can be in any units you like, linear or angular.
- Parameters
-
distancePerRotation | the distance per rotation of the encoder |
◆ 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) |
◆ SetPositionOffset()
void frc::DutyCycleEncoder::SetPositionOffset |
( |
double |
offset | ) |
|
Set the position offset.
This must be in the range of 0-1.
- Parameters
-
The documentation for this class was generated from the following file: