SPARK MAX - C++ Documentation
rev::CANAnalog Class Reference

Inherits rev::CANSensor.

Public Types

enum  AnalogMode { kAbsolute = 0, kRelative = 1 }
 

Public Member Functions

 CANAnalog (CANSparkMax &device, AnalogMode mode)
 
 CANAnalog (CANAnalog &&)=default
 
CANAnalogoperator= (CANAnalog &&)=default
 
double GetVoltage ()
 
double GetPosition ()
 
double GetVelocity ()
 
CANError SetPositionConversionFactor (double factor)
 
double GetPositionConversionFactor ()
 
CANError SetVelocityConversionFactor (double factor)
 
double GetVelocityConversionFactor ()
 
CANError SetAverageDepth (uint32_t depth)
 
CANError SetMeasurementPeriod (uint32_t period_ms)
 
uint32_t GetAverageDepth ()
 
uint32_t GetMeasurementPeriod ()
 
CANError SetInverted (bool inverted) override
 
bool GetInverted () const override
 
- Public Member Functions inherited from rev::CANSensor
 CANSensor (CANSparkMax &device)
 

Protected Member Functions

int GetID () const override
 

Additional Inherited Members

- Protected Types inherited from rev::CANSensor
enum  FeedbackSensorType {
  kNoSensor = 0, kHallSensor = 1, kQuadrature = 2, kSensorless = 3,
  kAnalog = 4, kAltQuadrature = 5
}
 
- Protected Attributes inherited from rev::CANSensor
CANSparkMaxm_device
 

Member Enumeration Documentation

◆ AnalogMode

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.

Constructor & Destructor Documentation

◆ CANAnalog()

CANAnalog::CANAnalog ( CANSparkMax device,
AnalogMode  mode 
)
explicit

Constucts a CANAnalog.

Parameters
deviceThe Spark Max to which the analog sensor is attached.

Member Function Documentation

◆ GetAverageDepth()

uint32_t CANAnalog::GetAverageDepth ( )

Get the averafe sampling depth for a quadrature encoder.

Returns
The average sampling depth

◆ GetID()

int CANAnalog::GetID ( ) const
overrideprotectedvirtual

Get the ID of the sensor that is connected to the SparkMax through the encoder port on the front of the controller (not the top port).

Returns
The ID of the sensor

Implements rev::CANSensor.

◆ GetInverted()

bool CANAnalog::GetInverted ( ) const
overridevirtual

Get the phase of the CANSensor. 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::CANSensor.

◆ GetMeasurementPeriod()

uint32_t CANAnalog::GetMeasurementPeriod ( )

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

◆ GetPosition()

double CANAnalog::GetPosition ( )

Get the position of the motor. 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

◆ GetPositionConversionFactor()

double CANAnalog::GetPositionConversionFactor ( )

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

Returns
Analog position conversion factor

◆ GetVelocity()

double CANAnalog::GetVelocity ( )

Get the velocity of the motor. 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

◆ GetVelocityConversionFactor()

double CANAnalog::GetVelocityConversionFactor ( )

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

Returns
Analog velocity conversion factor

◆ GetVoltage()

double CANAnalog::GetVoltage ( )

Get the voltage of the analog sensor.

Returns
Voltage of the sensor

◆ SetAverageDepth()

CANError CANAnalog::SetAverageDepth ( uint32_t  depth)

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
CANError.kOK if successful

◆ SetInverted()

CANError CANAnalog::SetInverted ( bool  inverted)
overridevirtual

Set the phase of the CANSensor 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
CANError.kOK if successful

Implements rev::CANSensor.

◆ SetMeasurementPeriod()

CANError CANAnalog::SetMeasurementPeriod ( uint32_t  period_ms)

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_usMeasurement period in milliseconds. This number may be between 1 and 100 (default).
Returns
CANError.kOK if successful

◆ SetPositionConversionFactor()

CANError CANAnalog::SetPositionConversionFactor ( double  factor)

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
CANError Set to CANError.kOK if successful

◆ SetVelocityConversionFactor()

CANError CANAnalog::SetVelocityConversionFactor ( double  factor)

Set the conversion factor for the veolocity 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
CANError Set to CANError.kOK is successful

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