REVLib - C++
rev::SparkMaxAnalogSensor Class Reference

#include <SparkMaxAnalogSensor.h>

Inherits rev::AnalogInput, and rev::CANAnalog.

Public Types

enum class  Mode { kAbsolute = 0 , kRelative = 1 }
 
- Public Types inherited from rev::CANAnalog
enum class  AnalogMode { kAbsolute = 0 , kRelative = 1 }
 

Public Member Functions

 SparkMaxAnalogSensor (SparkMaxAnalogSensor &&)=default
 
SparkMaxAnalogSensoroperator= (SparkMaxAnalogSensor &&)=default
 
 SparkMaxAnalogSensor (const SparkMaxAnalogSensor &rhs)=default
 
 ~SparkMaxAnalogSensor () override=default
 
double GetVoltage () const override
 
double GetPosition () const override
 
double GetVelocity () const override
 
REVLibError SetPositionConversionFactor (double factor) override
 
double GetPositionConversionFactor () const override
 
REVLibError SetVelocityConversionFactor (double factor) 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
 
REVLibError SetInverted (bool inverted) override
 
bool GetInverted () const override
 
- Public Member Functions inherited from rev::AnalogInput
virtual ~AnalogInput ()
 
- Public Member Functions inherited from rev::CANAnalog
virtual ~CANAnalog ()
 
- Public Member Functions inherited from rev::MotorFeedbackSensor
virtual ~MotorFeedbackSensor ()
 
- Public Member Functions inherited from rev::CANSensor
virtual ~CANSensor ()
 

Friends

class CANSparkMax
 

Member Enumeration Documentation

◆ Mode

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

Enumerator
kAbsolute 
kRelative 

Constructor & Destructor Documentation

◆ SparkMaxAnalogSensor() [1/2]

rev::SparkMaxAnalogSensor::SparkMaxAnalogSensor ( SparkMaxAnalogSensor &&  )
default

◆ SparkMaxAnalogSensor() [2/2]

rev::SparkMaxAnalogSensor::SparkMaxAnalogSensor ( const SparkMaxAnalogSensor rhs)
default

◆ ~SparkMaxAnalogSensor()

rev::SparkMaxAnalogSensor::~SparkMaxAnalogSensor ( )
overridedefault

Member Function Documentation

◆ operator=()

SparkMaxAnalogSensor & rev::SparkMaxAnalogSensor::operator= ( SparkMaxAnalogSensor &&  )
default

◆ GetVoltage()

double SparkMaxAnalogSensor::GetVoltage ( ) const
overridevirtual

Get the voltage of the analog sensor.

Returns
Voltage of the sensor

Implements rev::AnalogInput.

◆ GetPosition()

double SparkMaxAnalogSensor::GetPosition ( ) const
overridevirtual

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

Implements rev::AnalogInput.

◆ GetVelocity()

double SparkMaxAnalogSensor::GetVelocity ( ) const
overridevirtual

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

Implements rev::CANAnalog.

◆ SetPositionConversionFactor()

REVLibError SparkMaxAnalogSensor::SetPositionConversionFactor ( double  factor)
overridevirtual

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

Implements rev::AnalogInput.

◆ GetPositionConversionFactor()

double SparkMaxAnalogSensor::GetPositionConversionFactor ( ) const
overridevirtual

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

Returns
Analog position conversion factor

Implements rev::AnalogInput.

◆ SetVelocityConversionFactor()

REVLibError SparkMaxAnalogSensor::SetVelocityConversionFactor ( double  factor)
overridevirtual

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 is successful

Implements rev::CANAnalog.

◆ GetVelocityConversionFactor()

double SparkMaxAnalogSensor::GetVelocityConversionFactor ( ) const
overridevirtual

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

Returns
Analog velocity conversion factor

Implements rev::CANAnalog.

◆ SetAverageDepth()

REVLibError SparkMaxAnalogSensor::SetAverageDepth ( uint32_t  depth)
overridevirtual

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

Implements rev::CANAnalog.

◆ SetMeasurementPeriod()

REVLibError SparkMaxAnalogSensor::SetMeasurementPeriod ( uint32_t  period_ms)
overridevirtual

Set the measurement period for velocity readings.

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

Implements rev::CANAnalog.

◆ GetAverageDepth()

uint32_t SparkMaxAnalogSensor::GetAverageDepth ( ) const
overridevirtual

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

Returns
The average sampling depth

Implements rev::CANAnalog.

◆ GetMeasurementPeriod()

uint32_t SparkMaxAnalogSensor::GetMeasurementPeriod ( ) const
overridevirtual

Get the measurement period used for velocity readings.

Returns
Measurement period in microseconds

Implements rev::CANAnalog.

◆ SetInverted()

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

◆ GetInverted()

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

Friends And Related Function Documentation

◆ CANSparkMax

friend class CANSparkMax
friend

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