REVLib - C++
rev::CANEncoder Class Referenceabstract

#include <CANEncoder.h>

Inherits rev::MotorFeedbackSensor.

Inherited by rev::RelativeEncoder.

Public Types

enum class  EncoderType { kNoSensor = 0 , kHallSensor = 1 , kQuadrature = 2 }
 
enum class  AlternateEncoderType { kQuadrature }
 

Public Member Functions

virtual ~CANEncoder ()
 
virtual double GetPosition () const =0
 
virtual double GetVelocity () const =0
 
virtual REVLibError SetPosition (double position)=0
 
virtual REVLibError SetPositionConversionFactor (double factor)=0
 
virtual REVLibError SetVelocityConversionFactor (double factor)=0
 
virtual double GetPositionConversionFactor () const =0
 
virtual double GetVelocityConversionFactor () const =0
 
virtual REVLibError SetAverageDepth (uint32_t depth)=0
 
virtual REVLibError SetMeasurementPeriod (uint32_t period_ms)=0
 
virtual uint32_t GetAverageDepth () const =0
 
virtual uint32_t GetMeasurementPeriod () const =0
 
virtual uint32_t GetCountsPerRevolution () const =0
 
REVLibError SetInverted (bool inverted) override=0
 
bool GetInverted () const override=0
 
- Public Member Functions inherited from rev::MotorFeedbackSensor
virtual ~MotorFeedbackSensor ()
 
- Public Member Functions inherited from rev::CANSensor
virtual ~CANSensor ()
 

Friends

class RelativeEncoder
 

Detailed Description

Member Enumeration Documentation

◆ EncoderType

enum class rev::CANEncoder::EncoderType
strong
Deprecated:
Use SparkMaxRelativeEncoder::Type instead
Enumerator
kNoSensor 
kHallSensor 
kQuadrature 

◆ AlternateEncoderType

Deprecated:
Use SparkMaxAlternateEncoder::Type instead
Enumerator
kQuadrature 

Constructor & Destructor Documentation

◆ ~CANEncoder()

virtual rev::CANEncoder::~CANEncoder ( )
inlinevirtual

Member Function Documentation

◆ GetPosition()

virtual double rev::CANEncoder::GetPosition ( ) const
pure virtual

Get the position of the motor. This returns the native units of 'rotations' by default, and can be changed by a scale factor using setPositionConversionFactor().

Returns
Number of rotations of the motor

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ GetVelocity()

virtual double rev::CANEncoder::GetVelocity ( ) const
pure virtual

Get the velocity of the motor. This returns the native units of 'RPM' by default, and can be changed by a scale factor using setVelocityConversionFactor().

Returns
Number the RPM of the motor

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ SetPosition()

virtual REVLibError rev::CANEncoder::SetPosition ( double  position)
pure virtual

Set the position of the encoder.

Parameters
positionNumber of rotations of the motor
Returns
REVLibError::kOk if successful

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ SetPositionConversionFactor()

virtual REVLibError rev::CANEncoder::SetPositionConversionFactor ( double  factor)
pure virtual

Set the conversion factor for position of the encoder. Multiplied by the native output units to give you position

Parameters
factorThe conversion factor to multiply the native units by
Returns
REVLibError::kOk if successful

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ SetVelocityConversionFactor()

virtual REVLibError rev::CANEncoder::SetVelocityConversionFactor ( double  factor)
pure virtual

Set the conversion factor for velocity of the encoder. Multiplied by the native output units to give you velocity

Parameters
factorThe conversion factor to multiply the native units by
Returns
REVLibError::kOk if successful

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ GetPositionConversionFactor()

virtual double rev::CANEncoder::GetPositionConversionFactor ( ) const
pure virtual

Get the conversion factor for position of the encoder. Multiplied by the native output units to give you position

Returns
The conversion factor for position

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ GetVelocityConversionFactor()

virtual double rev::CANEncoder::GetVelocityConversionFactor ( ) const
pure virtual

Get the conversion factor for velocity of the encoder. Multiplied by the native output units to give you velocity

Returns
The conversion factor for velocity

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ SetAverageDepth()

virtual REVLibError rev::CANEncoder::SetAverageDepth ( uint32_t  depth)
pure virtual

Set the average sampling depth for a quadrature encoder. This value sets the number of samples in the average for velocity readings. This can be any value from 1 to 64.

When the SparkMax controller is in Brushless mode, this will not change any behavior.

Parameters
depthThe average sampling depth between 1 and 64 (default)
Returns
REVLibError::kOk if successful

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ SetMeasurementPeriod()

virtual REVLibError rev::CANEncoder::SetMeasurementPeriod ( uint32_t  period_ms)
pure virtual

Set the measurement period for velocity measurements of a quadrature encoder. When the SparkMax controller is in Brushless mode, this will not change any behavior.

The basic formula to calculate velocity is change in positon / change in time. This parameter sets the change in time for measurement.

Parameters
period_msMeasurement period in milliseconds. This number may be between 1 and 100 (default).
Returns
REVLibError::kOk if successful

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ GetAverageDepth()

virtual uint32_t rev::CANEncoder::GetAverageDepth ( ) const
pure virtual

Get the average sampling depth for a quadrature encoder.

Returns
The average sampling depth

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ GetMeasurementPeriod()

virtual uint32_t rev::CANEncoder::GetMeasurementPeriod ( ) const
pure virtual

Get the number of samples for reading from a quadrature encoder. This value sets the number of samples in the average for velocity readings.

Returns
Measurement period in microseconds

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ GetCountsPerRevolution()

virtual uint32_t rev::CANEncoder::GetCountsPerRevolution ( ) const
pure virtual

Get the counts per revolution of the quadrature encoder.

For a description on the difference between CPR, PPR, etc. go to https://www.cuidevices.com/blog/what-is-encoder-ppr-cpr-and-lpr

Returns
Counts per revolution

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ SetInverted()

REVLibError rev::CANEncoder::SetInverted ( bool  inverted)
overridepure virtual

Set the phase of the MotorFeedbackSensor so that it is set to be in phase with the motor itself. This only works for quadrature encoders. This will throw an error if the user tries to set inverted while the SparkMax is Brushless and using the hall effect sensor.

Parameters
invertedThe phase of the encoder
Returns
REVLibError::kOk if successful

Implements rev::MotorFeedbackSensor.

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

◆ GetInverted()

bool rev::CANEncoder::GetInverted ( ) const
overridepure virtual

Get the phase of the MotorFeedbackSensor. This will just return false if the user tries to get inverted while the SparkMax is Brushless and using the hall effect sensor.

Returns
The phase of the encoder

Implements rev::MotorFeedbackSensor.

Implemented in rev::SparkFlexExternalEncoder, rev::SparkMaxAlternateEncoder, rev::SparkMaxRelativeEncoder, and rev::RelativeEncoder.

Friends And Related Function Documentation

◆ RelativeEncoder

friend class RelativeEncoder
friend

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