WPILibC++  2020.3.2-60-g3011ebe
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 <DutyCycleEncoder.h>

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

Public Member Functions

 DutyCycleEncoder (int channel)
 Construct a new DutyCycleEncoder on a specific channel. More...
 
 DutyCycleEncoder (DutyCycle &dutyCycle)
 Construct a new DutyCycleEncoder attached to an existing DutyCycle object. More...
 
 DutyCycleEncoder (DutyCycle *dutyCycle)
 Construct a new DutyCycleEncoder attached to an existing DutyCycle object. More...
 
 DutyCycleEncoder (std::shared_ptr< DutyCycle > dutyCycle)
 Construct a new DutyCycleEncoder attached to an existing DutyCycle object. More...
 
 DutyCycleEncoder (DigitalSource &digitalSource)
 Construct a new DutyCycleEncoder attached to a DigitalSource object. More...
 
 DutyCycleEncoder (DigitalSource *digitalSource)
 Construct a new DutyCycleEncoder attached to a DigitalSource object. More...
 
 DutyCycleEncoder (std::shared_ptr< DigitalSource > digitalSource)
 Construct a new DutyCycleEncoder attached to a DigitalSource object. More...
 
 DutyCycleEncoder (DutyCycleEncoder &&)=default
 
DutyCycleEncoderoperator= (DutyCycleEncoder &&)=default
 
int GetFrequency () const
 Get the frequency in Hz of the duty cycle signal from the encoder. More...
 
bool IsConnected () const
 Get if the sensor is connected. More...
 
void SetConnectedFrequencyThreshold (int frequency)
 Change the frequency threshold for detecting connection used by IsConnected. More...
 
void Reset ()
 Reset the Encoder distance to zero.
 
units::turn_t Get () const
 Get the encoder value since the last reset. More...
 
void SetDistancePerRotation (double distancePerRotation)
 Set the distance per rotation of the encoder. More...
 
double GetDistancePerRotation () const
 Get the distance per rotation for this encoder. More...
 
double GetDistance () const
 Get the distance the sensor has driven since the last reset as scaled by the value from SetDistancePerRotation. More...
 
void InitSendable (SendableBuilder &builder) override
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from frc::ErrorBase
 ErrorBase (const ErrorBase &)=default
 
ErrorBaseoperator= (const ErrorBase &)=default
 
 ErrorBase (ErrorBase &&)=default
 
ErrorBaseoperator= (ErrorBase &&)=default
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 Retrieve the current error. More...
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual void SetErrnoError (const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetErrorRange (Error::Code code, int32_t minRange, int32_t maxRange, int32_t requestedValue, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (const wpi::Twine &errorMessage, Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 
void ClearGlobalErrors ()
 Clear global errors.
 
- Public Member Functions inherited from frc::SendableHelper< DutyCycleEncoder >
 SendableHelper (const SendableHelper &rhs)=default
 
 SendableHelper (SendableHelper &&rhs)
 
SendableHelperoperator= (const SendableHelper &rhs)=default
 
SendableHelperoperator= (SendableHelper &&rhs)
 
std::string GetName () const
 Gets the name of this Sendable object. More...
 
void SetName (const wpi::Twine &name)
 Sets the name of this Sendable object. More...
 
void SetName (const wpi::Twine &subsystem, const wpi::Twine &name)
 Sets both the subsystem name and device name of this Sendable object. More...
 
std::string GetSubsystem () const
 Gets the subsystem name of this Sendable object. More...
 
void SetSubsystem (const wpi::Twine &subsystem)
 Sets the subsystem name of this Sendable object. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from frc::ErrorBase
static void SetGlobalError (Error::Code code, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static void SetGlobalWPIError (const wpi::Twine &errorMessage, const wpi::Twine &contextMessage, wpi::StringRef filename, wpi::StringRef function, int lineNumber)
 
static Error GetGlobalError ()
 Retrieve the last global error.
 
static std::vector< ErrorGetGlobalErrors ()
 Retrieve all global errors.
 
- Protected Member Functions inherited from frc::SendableHelper< DutyCycleEncoder >
void SetName (const wpi::Twine &moduleType, int channel)
 Sets the name of the sensor with a channel number. More...
 
void SetName (const wpi::Twine &moduleType, int moduleNumber, int channel)
 Sets the name of the sensor with a module and channel number. More...
 
void AddChild (std::shared_ptr< Sendable > child)
 Add a child component. More...
 
void AddChild (void *child)
 Add a child component. More...
 
- Protected Attributes inherited from frc::ErrorBase
Error m_error
 

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/7]

frc::DutyCycleEncoder::DutyCycleEncoder ( int  channel)
explicit

Construct a new DutyCycleEncoder on a specific channel.

Parameters
channelthe channel to attach to

◆ DutyCycleEncoder() [2/7]

frc::DutyCycleEncoder::DutyCycleEncoder ( DutyCycle dutyCycle)
explicit

Construct a new DutyCycleEncoder attached to an existing DutyCycle object.

Parameters
dutyCyclethe duty cycle to attach to

◆ DutyCycleEncoder() [3/7]

frc::DutyCycleEncoder::DutyCycleEncoder ( DutyCycle dutyCycle)
explicit

Construct a new DutyCycleEncoder attached to an existing DutyCycle object.

Parameters
dutyCyclethe duty cycle to attach to

◆ DutyCycleEncoder() [4/7]

frc::DutyCycleEncoder::DutyCycleEncoder ( std::shared_ptr< DutyCycle dutyCycle)
explicit

Construct a new DutyCycleEncoder attached to an existing DutyCycle object.

Parameters
dutyCyclethe duty cycle to attach to

◆ DutyCycleEncoder() [5/7]

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

Construct a new DutyCycleEncoder attached to a DigitalSource object.

Parameters
sourcethe digital source to attach to

◆ DutyCycleEncoder() [6/7]

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

Construct a new DutyCycleEncoder attached to a DigitalSource object.

Parameters
sourcethe digital source to attach to

◆ DutyCycleEncoder() [7/7]

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

Construct a new DutyCycleEncoder attached to a DigitalSource object.

Parameters
sourcethe digital source to attach to

Member Function Documentation

◆ 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

◆ 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.

◆ 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

◆ InitSendable()

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

Initializes this Sendable object.

Parameters
buildersendable builder

Implements frc::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

◆ SetConnectedFrequencyThreshold()

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

Change the frequency threshold for detecting connection used by IsConnected.

Parameters
frequencythe 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
distancePerRotationthe distance per rotation of the encoder

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