WPILibC++  2020.3.2-60-g3011ebe
frc::AnalogEncoder Class Reference

Class for supporting continuous analog encoders, such as the US Digital MA3. More...

#include <AnalogEncoder.h>

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

Public Member Functions

 AnalogEncoder (AnalogInput &analogInput)
 Construct a new AnalogEncoder attached to a specific AnalogInput. More...
 
 AnalogEncoder (AnalogInput *analogInput)
 Construct a new AnalogEncoder attached to a specific AnalogInput. More...
 
 AnalogEncoder (std::shared_ptr< AnalogInput > analogInput)
 Construct a new AnalogEncoder attached to a specific AnalogInput. More...
 
 AnalogEncoder (AnalogEncoder &&)=default
 
AnalogEncoderoperator= (AnalogEncoder &&)=default
 
void Reset ()
 Reset the Encoder distance to zero.
 
units::turn_t Get () const
 Get the encoder value since the last reset. More...
 
double GetPositionOffset () const
 Get the offset of position relative to 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< AnalogEncoder >
 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< AnalogEncoder >
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 continuous analog encoders, such as the US Digital MA3.

Constructor & Destructor Documentation

◆ AnalogEncoder() [1/3]

frc::AnalogEncoder::AnalogEncoder ( AnalogInput analogInput)
explicit

Construct a new AnalogEncoder attached to a specific AnalogInput.

Parameters
analogInputthe analog input to attach to

◆ AnalogEncoder() [2/3]

frc::AnalogEncoder::AnalogEncoder ( AnalogInput analogInput)
explicit

Construct a new AnalogEncoder attached to a specific AnalogInput.

Parameters
analogInputthe analog input to attach to

◆ AnalogEncoder() [3/3]

frc::AnalogEncoder::AnalogEncoder ( std::shared_ptr< AnalogInput analogInput)
explicit

Construct a new AnalogEncoder attached to a specific AnalogInput.

Parameters
analogInputthe analog input to attach to

Member Function Documentation

◆ Get()

units::turn_t frc::AnalogEncoder::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::AnalogEncoder::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::AnalogEncoder::GetDistancePerRotation ( ) const

Get the distance per rotation for this encoder.

Returns
The scale factor that will be used to convert rotation to useful units.

◆ GetPositionOffset()

double frc::AnalogEncoder::GetPositionOffset ( ) const

Get the offset of position relative to the last reset.

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

◆ InitSendable()

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

Initializes this Sendable object.

Parameters
buildersendable builder

Implements frc::Sendable.

◆ SetDistancePerRotation()

void frc::AnalogEncoder::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: