REVLib - C++
rev::CANAnalog Class Referenceabstract

#include <CANAnalog.h>

Inherits rev::MotorFeedbackSensor.

Inherited by rev::SparkMaxAnalogSensor.

Public Types

enum class  AnalogMode { kAbsolute = 0 , kRelative = 1 }
 

Public Member Functions

virtual ~CANAnalog ()
 
virtual double GetVoltage () const =0
 
virtual double GetPosition () const =0
 
virtual double GetVelocity () const =0
 
virtual REVLibError SetPositionConversionFactor (double factor)=0
 
virtual double GetPositionConversionFactor () const =0
 
virtual REVLibError SetVelocityConversionFactor (double factor)=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
 
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 SparkMaxAnalogSensor
 

Detailed Description

Member Enumeration Documentation

◆ AnalogMode

enum class rev::CANAnalog::AnalogMode
strong

Analog sensors have the ability to either be absolute or relative. By default, GetAnalog() will return an absolute analog sensor, but it can also be configured to be a relative sensor instead.

Deprecated:
Use SparkMaxAnalogSensor::Mode instead
Enumerator
kAbsolute 
kRelative 

Constructor & Destructor Documentation

◆ ~CANAnalog()

virtual rev::CANAnalog::~CANAnalog ( )
inlinevirtual

Member Function Documentation

◆ GetVoltage()

virtual double rev::CANAnalog::GetVoltage ( ) const
pure virtual

Get the voltage of the analog sensor.

Returns
Voltage of the sensor

Implemented in rev::SparkMaxAnalogSensor.

◆ GetPosition()

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

Get the position of the sensor. Returns value in the native unit of 'volt' by default, and can be changed by a scale factor using setPositionConversionFactor().

Returns
Position of the sensor in volts

Implemented in rev::SparkMaxAnalogSensor.

◆ GetVelocity()

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

Get the velocity of the sensor. Returns value in the native units of 'volts per second' by default, and can be changed by a scale factor using setVelocityConversionFactor().

Returns
Velocity of the sensor in volts per second

Implemented in rev::SparkMaxAnalogSensor.

◆ SetPositionConversionFactor()

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

Set the conversion factor for the position of the analog sensor. By default, revolutions per volt is 1. Changing the position conversion factor will also change the position units.

Parameters
factorThe conversion factor which will be multiplied by volts
Returns
REVLibError::kOk if successful

Implemented in rev::SparkMaxAnalogSensor.

◆ GetPositionConversionFactor()

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

Get the current conversion factor for the position of the analog sensor.

Returns
Analog position conversion factor

Implemented in rev::SparkMaxAnalogSensor.

◆ SetVelocityConversionFactor()

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

Set the conversion factor for the velocity of the analog sensor. By default, revolutions per volt second is 1. Changing the velocity conversion factor will also change the velocity units.

Parameters
factorThe conversion factor which will be multipled by volts per second
Returns
REVLibError::kOk if successful

Implemented in rev::SparkMaxAnalogSensor.

◆ GetVelocityConversionFactor()

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

Get the current conversion factor for the velocity of the analog sensor.

Returns
Analog velocity conversion factor

Implemented in rev::SparkMaxAnalogSensor.

◆ SetAverageDepth()

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

Set 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::SparkMaxAnalogSensor.

◆ SetMeasurementPeriod()

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

Set the measurement period for velocity calculations.

The basic formula to calculate velocity is change in position / 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::SparkMaxAnalogSensor.

◆ GetAverageDepth()

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

Get the number of samples included in the average for velocity readings.

Returns
The average sampling depth

Implemented in rev::SparkMaxAnalogSensor.

◆ GetMeasurementPeriod()

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

Get the measurement period used for velocity calculation.

Returns
Measurement period in microseconds

Implemented in rev::SparkMaxAnalogSensor.

◆ SetInverted()

REVLibError rev::CANAnalog::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::SparkMaxAnalogSensor.

◆ GetInverted()

bool rev::CANAnalog::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::SparkMaxAnalogSensor.

Friends And Related Function Documentation

◆ SparkMaxAnalogSensor

friend class SparkMaxAnalogSensor
friend

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