WPILibC++ 2023.4.3-108-ge5452e3
frc::AnalogEncoder Class Reference

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

#include <frc/AnalogEncoder.h>

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

Public Member Functions

 AnalogEncoder (int channel)
 Construct a new AnalogEncoder attached to a specific AnalogIn channel. More...
 
 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 () override=default
 
 AnalogEncoder (AnalogEncoder &&)=default
 
AnalogEncoderoperator= (AnalogEncoder &&)=default
 
void Reset ()
 Reset the Encoder distance to zero. More...
 
units::turn_t Get () const
 Get the encoder value since the last reset. More...
 
double GetAbsolutePosition () const
 Get the absolute position of the analog encoder. More...
 
double GetPositionOffset () const
 Get the offset of position relative to the last reset. More...
 
void SetPositionOffset (double offset)
 Set the position offset. 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...
 
int GetChannel () const
 Get the channel number. More...
 
void InitSendable (wpi::SendableBuilder &builder) override
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from wpi::Sendable
virtual ~Sendable ()=default
 
virtual void InitSendable (SendableBuilder &builder)=0
 Initializes this Sendable object. More...
 
- Public Member Functions inherited from wpi::SendableHelper< AnalogEncoder >
 SendableHelper (const SendableHelper &rhs)=default
 
 SendableHelper (SendableHelper &&rhs)
 
SendableHelperoperator= (const SendableHelper &rhs)=default
 
SendableHelperoperator= (SendableHelper &&rhs)
 

Additional Inherited Members

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

Detailed Description

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

Constructor & Destructor Documentation

◆ AnalogEncoder() [1/5]

frc::AnalogEncoder::AnalogEncoder ( int  channel)
explicit

Construct a new AnalogEncoder attached to a specific AnalogIn channel.

Parameters
channelthe analog input channel to attach to

◆ AnalogEncoder() [2/5]

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

Construct a new AnalogEncoder attached to a specific AnalogInput.

Parameters
analogInputthe analog input to attach to

◆ AnalogEncoder() [3/5]

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

Construct a new AnalogEncoder attached to a specific AnalogInput.

Parameters
analogInputthe analog input to attach to

◆ AnalogEncoder() [4/5]

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

◆ ~AnalogEncoder()

frc::AnalogEncoder::~AnalogEncoder ( )
overridedefault

◆ AnalogEncoder() [5/5]

frc::AnalogEncoder::AnalogEncoder ( AnalogEncoder &&  )
default

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

◆ GetAbsolutePosition()

double frc::AnalogEncoder::GetAbsolutePosition ( ) const

Get the absolute position of the analog 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

◆ GetChannel()

int frc::AnalogEncoder::GetChannel ( ) const

Get the channel number.

Returns
The channel number.

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

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

◆ InitSendable()

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

Initializes this Sendable object.

Parameters
buildersendable builder

Implements wpi::Sendable.

◆ operator=()

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

◆ Reset()

void frc::AnalogEncoder::Reset ( )

Reset the Encoder distance to zero.

◆ 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

◆ SetPositionOffset()

void frc::AnalogEncoder::SetPositionOffset ( double  offset)

Set the position offset.

This must be in the range of 0-1.

Parameters
offsetthe offset

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