SparkMaxRelativeEncoder

class rev.SparkMaxRelativeEncoder

Bases: RelativeEncoder

Get an instance of this class by using CANSparkBase::GetEncoder() or CANSparkBase::GetEncoder(SparkMaxRelativeEncoder::Type, int).

Deprecated:

Use SparkRelativeEncoder instead

class Type(value: int)

Bases: pybind11_object

The type of encoder connected to a SPARK MAX

Deprecated:

Use SparkRelativeEncoder::Type instead

Members:

kNoSensor

kHallSensor

kQuadrature

kHallSensor = <Type.kHallSensor: 1>
kNoSensor = <Type.kNoSensor: 0>
kQuadrature = <Type.kQuadrature: 2>
property name
property value
getAverageDepth() int

Get the velocity calculation process’s sampling depth for a quadrature or hall sensor encoder.

Returns:

The velocity calculation averaging process’s sampling depth

getCountsPerRevolution() int

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

getInverted() bool

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

getMeasurementPeriod() int

Get the position measurement period used to calculate the velocity of a quadrature or hall sensor encoder.

Returns:

Measurement period in milliseconds

getPosition() float

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

getPositionConversionFactor() float

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

getVelocity() float

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

getVelocityConversionFactor() float

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

setAverageDepth(depth: int) rev._rev.REVLibError

Set the sampling depth of the velocity calculation process for a quadrature or hall sensor encoder. This value sets the number of samples in the average for velocity readings. For a quadrature encoder, this can be any value from 1 to 64 (default). For a hall sensor, it must be either 1, 2, 4, or 8 (default).

Parameters:

depth – The velocity calculation process’s sampling depth

Returns:

REVLibError::kOk if successful

setInverted(inverted: bool) rev._rev.REVLibError

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:

inverted – The phase of the encoder

Returns:

REVLibError::kOk if successful

setMeasurementPeriod(period_ms: int) rev._rev.REVLibError

Set the position measurement period used to calculate the velocity of a quadrature or hall sensor encoder. For a quadrature encoder, this number may be between 1 and 100 (default). For a hall sensor, this number may be between 8 and 64. The default for a hall sensor is 32ms.

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

Parameters:

period_ms – Measurement period in milliseconds

Returns:

REVLibError::kOk if successful

setPosition(position: float) rev._rev.REVLibError

Set the position of the encoder.

Parameters:

position – Number of rotations of the motor

Returns:

REVLibError::kOk if successful

setPositionConversionFactor(factor: float) rev._rev.REVLibError

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

Parameters:

factor – The conversion factor to multiply the native units by

Returns:

REVLibError::kOk if successful

setVelocityConversionFactor(factor: float) rev._rev.REVLibError

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

Parameters:

factor – The conversion factor to multiply the native units by

Returns:

REVLibError::kOk if successful