REVLib - C++
rev::SparkMaxRelativeEncoder Class Reference

#include <SparkMaxRelativeEncoder.h>

Inherits rev::RelativeEncoder.

Public Types

enum class  Type { kNoSensor = 0 , kHallSensor = 1 , kQuadrature = 2 }
 
- Public Types inherited from rev::CANEncoder
enum class  EncoderType { kNoSensor = 0 , kHallSensor = 1 , kQuadrature = 2 }
 
enum class  AlternateEncoderType { kQuadrature }
 

Public Member Functions

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

Friends

class CANSparkMax
 

Detailed Description

Member Enumeration Documentation

◆ Type

The type of encoder connected to a SPARK MAX

Enumerator
kNoSensor 
kHallSensor 
kQuadrature 

Constructor & Destructor Documentation

◆ SparkMaxRelativeEncoder() [1/2]

rev::SparkMaxRelativeEncoder::SparkMaxRelativeEncoder ( SparkMaxRelativeEncoder &&  rhs)
default

◆ SparkMaxRelativeEncoder() [2/2]

rev::SparkMaxRelativeEncoder::SparkMaxRelativeEncoder ( const SparkMaxRelativeEncoder rhs)
default

◆ ~SparkMaxRelativeEncoder()

rev::SparkMaxRelativeEncoder::~SparkMaxRelativeEncoder ( )
overridedefault

Member Function Documentation

◆ operator=()

SparkMaxRelativeEncoder & rev::SparkMaxRelativeEncoder::operator= ( SparkMaxRelativeEncoder &&  rhs)
default

◆ GetPosition()

double SparkMaxRelativeEncoder::GetPosition ( ) const
overridevirtual

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

Implements rev::RelativeEncoder.

◆ GetVelocity()

double SparkMaxRelativeEncoder::GetVelocity ( ) const
overridevirtual

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

Implements rev::RelativeEncoder.

◆ SetPosition()

REVLibError SparkMaxRelativeEncoder::SetPosition ( double  position)
overridevirtual

Set the position of the encoder.

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

Implements rev::RelativeEncoder.

◆ SetPositionConversionFactor()

REVLibError SparkMaxRelativeEncoder::SetPositionConversionFactor ( double  factor)
overridevirtual

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

Implements rev::RelativeEncoder.

◆ SetVelocityConversionFactor()

REVLibError SparkMaxRelativeEncoder::SetVelocityConversionFactor ( double  factor)
overridevirtual

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

Implements rev::RelativeEncoder.

◆ GetPositionConversionFactor()

double SparkMaxRelativeEncoder::GetPositionConversionFactor ( ) const
overridevirtual

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

Implements rev::RelativeEncoder.

◆ GetVelocityConversionFactor()

double SparkMaxRelativeEncoder::GetVelocityConversionFactor ( ) const
overridevirtual

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

Implements rev::RelativeEncoder.

◆ SetAverageDepth()

REVLibError SparkMaxRelativeEncoder::SetAverageDepth ( uint32_t  depth)
overridevirtual

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

Implements rev::RelativeEncoder.

◆ SetMeasurementPeriod()

REVLibError SparkMaxRelativeEncoder::SetMeasurementPeriod ( uint32_t  period_ms)
overridevirtual

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

Implements rev::RelativeEncoder.

◆ GetAverageDepth()

uint32_t SparkMaxRelativeEncoder::GetAverageDepth ( ) const
overridevirtual

Get the average sampling depth for a quadrature encoder.

Returns
The average sampling depth

Implements rev::RelativeEncoder.

◆ GetMeasurementPeriod()

uint32_t SparkMaxRelativeEncoder::GetMeasurementPeriod ( ) const
overridevirtual

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

Implements rev::RelativeEncoder.

◆ GetCountsPerRevolution()

uint32_t SparkMaxRelativeEncoder::GetCountsPerRevolution ( ) const
overridevirtual

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

Implements rev::RelativeEncoder.

◆ SetInverted()

REVLibError SparkMaxRelativeEncoder::SetInverted ( bool  inverted)
overridevirtual

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::RelativeEncoder.

◆ GetInverted()

bool SparkMaxRelativeEncoder::GetInverted ( ) const
overridevirtual

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::RelativeEncoder.

Friends And Related Function Documentation

◆ CANSparkMax

friend class CANSparkMax
friend

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