WPILibC++ 2025.2.1
Loading...
Searching...
No Matches
frc::DutyCycleEncoder Class Reference

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>

Inheritance diagram for frc::DutyCycleEncoder:
wpi::Sendable wpi::SendableHelper< DutyCycleEncoder >

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
 
DutyCycleEncoderoperator= (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 SendableHelperoperator= (const SendableHelper &rhs)=default
 
constexpr SendableHelperoperator= (SendableHelper &&rhs)
 

Additional Inherited Members

- Protected Member Functions inherited from wpi::SendableHelper< DutyCycleEncoder >
constexpr SendableHelper ()=default
 
constexpr ~SendableHelper ()
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ DutyCycleEncoder() [1/15]

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
channelthe channel to attach to

◆ DutyCycleEncoder() [2/15]

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
dutyCyclethe duty cycle to attach to

◆ DutyCycleEncoder() [3/15]

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
dutyCyclethe duty cycle to attach to

◆ DutyCycleEncoder() [4/15]

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
dutyCyclethe duty cycle to attach to

◆ DutyCycleEncoder() [5/15]

frc::DutyCycleEncoder::DutyCycleEncoder ( DigitalSource & digitalSource)
explicit

Construct a new DutyCycleEncoder attached to a DigitalSource object.

This has a fullRange of 1 and an expectedZero of 0.

Parameters
digitalSourcethe digital source to attach to

◆ DutyCycleEncoder() [6/15]

frc::DutyCycleEncoder::DutyCycleEncoder ( DigitalSource * digitalSource)
explicit

Construct a new DutyCycleEncoder attached to a DigitalSource object.

This has a fullRange of 1 and an expectedZero of 0.

Parameters
digitalSourcethe digital source to attach to

◆ DutyCycleEncoder() [7/15]

frc::DutyCycleEncoder::DutyCycleEncoder ( std::shared_ptr< DigitalSource > digitalSource)
explicit

Construct a new DutyCycleEncoder attached to a DigitalSource object.

This has a fullRange of 1 and an expectedZero of 0.

Parameters
digitalSourcethe digital source to attach to

◆ DutyCycleEncoder() [8/15]

frc::DutyCycleEncoder::DutyCycleEncoder ( int channel,
double fullRange,
double expectedZero )

Construct a new DutyCycleEncoder on a specific channel.

Parameters
channelthe channel to attach to
fullRangethe value to report at maximum travel
expectedZerothe reading where you would expect a 0 from get()

◆ DutyCycleEncoder() [9/15]

frc::DutyCycleEncoder::DutyCycleEncoder ( DutyCycle & dutyCycle,
double fullRange,
double expectedZero )

Construct a new DutyCycleEncoder attached to an existing DutyCycle object.

Parameters
dutyCyclethe duty cycle to attach to
fullRangethe value to report at maximum travel
expectedZerothe reading where you would expect a 0 from get()

◆ DutyCycleEncoder() [10/15]

frc::DutyCycleEncoder::DutyCycleEncoder ( DutyCycle * dutyCycle,
double fullRange,
double expectedZero )

Construct a new DutyCycleEncoder attached to an existing DutyCycle object.

Parameters
dutyCyclethe duty cycle to attach to
fullRangethe value to report at maximum travel
expectedZerothe reading where you would expect a 0 from get()

◆ DutyCycleEncoder() [11/15]

frc::DutyCycleEncoder::DutyCycleEncoder ( std::shared_ptr< DutyCycle > dutyCycle,
double fullRange,
double expectedZero )

Construct a new DutyCycleEncoder attached to an existing DutyCycle object.

Parameters
dutyCyclethe duty cycle to attach to
fullRangethe value to report at maximum travel
expectedZerothe reading where you would expect a 0 from get()

◆ DutyCycleEncoder() [12/15]

frc::DutyCycleEncoder::DutyCycleEncoder ( DigitalSource & digitalSource,
double fullRange,
double expectedZero )

Construct a new DutyCycleEncoder attached to a DigitalSource object.

Parameters
digitalSourcethe digital source to attach to
fullRangethe value to report at maximum travel
expectedZerothe reading where you would expect a 0 from get()

◆ DutyCycleEncoder() [13/15]

frc::DutyCycleEncoder::DutyCycleEncoder ( DigitalSource * digitalSource,
double fullRange,
double expectedZero )

Construct a new DutyCycleEncoder attached to a DigitalSource object.

Parameters
digitalSourcethe digital source to attach to
fullRangethe value to report at maximum travel
expectedZerothe reading where you would expect a 0 from get()

◆ DutyCycleEncoder() [14/15]

frc::DutyCycleEncoder::DutyCycleEncoder ( std::shared_ptr< DigitalSource > digitalSource,
double fullRange,
double expectedZero )

Construct a new DutyCycleEncoder attached to a DigitalSource object.

Parameters
digitalSourcethe digital source to attach to
fullRangethe value to report at maximum travel
expectedZerothe reading where you would expect a 0 from get()

◆ ~DutyCycleEncoder()

frc::DutyCycleEncoder::~DutyCycleEncoder ( )
overridedefault

◆ DutyCycleEncoder() [15/15]

frc::DutyCycleEncoder::DutyCycleEncoder ( DutyCycleEncoder && )
default

Member Function Documentation

◆ Get()

double frc::DutyCycleEncoder::Get ( ) const

Get the encoder value.

Returns
the encoder value scaled by the full range input

◆ GetFPGAIndex()

int frc::DutyCycleEncoder::GetFPGAIndex ( ) const

Get the FPGA index for the DutyCycleEncoder.

Returns
the FPGA index

◆ 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

◆ GetSourceChannel()

int frc::DutyCycleEncoder::GetSourceChannel ( ) const

Get the channel of the source.

Returns
the source channel

◆ InitSendable()

void frc::DutyCycleEncoder::InitSendable ( wpi::SendableBuilder & builder)
overridevirtual

Initializes this Sendable object.

Parameters
buildersendable builder

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=()

DutyCycleEncoder & frc::DutyCycleEncoder::operator= ( DutyCycleEncoder && )
default

◆ 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
frequencythe assumed frequency of the sensor

◆ SetConnectedFrequencyThreshold()

void frc::DutyCycleEncoder::SetConnectedFrequencyThreshold ( int frequency)

Change the frequency threshold for detecting connection used by IsConnected.

Parameters
frequencythe minimum frequency in Hz.

◆ 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
minminimum duty cycle (0-1 range)
maxmaximum duty cycle (0-1 range)

◆ SetInverted()

void frc::DutyCycleEncoder::SetInverted ( bool inverted)

Set if this encoder is inverted.

Parameters
invertedtrue to invert the encoder, false otherwise

The documentation for this class was generated from the following file: