CANEncoder

class rev.CANEncoder(*args, **kwargs)

Bases: rev.CANSensor

Overloaded function.

  1. __init__(self: rev._rev.CANEncoder, device: rev._rev.CANSparkMax, sensorType: rev._rev.CANEncoder.EncoderType = <EncoderType.kHallSensor: 1>, counts_per_rev: int = 42) -> None

  2. __init__(self: rev._rev.CANEncoder, device: rev._rev.CANSparkMax, sensorType: rev._rev.CANEncoder.AlternateEncoderType, counts_per_rev: int) -> None

class AlternateEncoderType(self: rev._rev.CANEncoder.AlternateEncoderType, value: int) → None

Bases: pybind11_builtins.pybind11_object

Members:

kQuadrature

kQuadrature = <AlternateEncoderType.kQuadrature: 0>
property name
class EncoderType(self: rev._rev.CANEncoder.EncoderType, value: int) → None

Bases: pybind11_builtins.pybind11_object

Members:

kNoSensor

kHallSensor

kQuadrature

kSensorless

kHallSensor = <EncoderType.kHallSensor: 1>
kNoSensor = <EncoderType.kNoSensor: 0>
kQuadrature = <EncoderType.kQuadrature: 2>
kSensorless = <EncoderType.kSensorless: 3>
property name
getAverageDepth(self: rev.CANEncoder) → int

Get the averafe sampling depth for a quadrature encoder.

Returns

The average sampling depth

getCPR(self: rev.CANEncoder) → int
getCountsPerRevolution(self: rev.CANEncoder) → 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(self: rev.CANEncoder) → bool

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

getMeasurementPeriod(self: rev.CANEncoder) → int

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(self: rev.CANEncoder) → 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(self: rev.CANEncoder) → 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(self: rev.CANEncoder) → 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(self: rev.CANEncoder) → 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(self: rev.CANEncoder, depth: int)rev.CANError

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

depth – The average sampling depth between 1 and 64 (default)

Returns

CANError.kOK if successful

setInverted(self: rev.CANEncoder, inverted: bool)rev.CANError

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

inverted – The phase of the encoder

Returns

CANError.kOK if successful

setMeasurementPeriod(self: rev.CANEncoder, period_ms: int)rev.CANError

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_us – Measurement period in milliseconds. This number may be between 1 and 100 (default).

Returns

CANError.kOK if successful

setPosition(self: rev.CANEncoder, position: float)rev.CANError

Set the position of the encoder.

Parameters

position – Number of rotations of the motor

Returns

CANError Set to CANError.kOK if successful

setPositionConversionFactor(self: rev.CANEncoder, factor: float)rev.CANError

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

CANError Set to CANError.kOK if successful

setVelocityConversionFactor(self: rev.CANEncoder, factor: float)rev.CANError

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

CANError Set to CANError.kOK if successful