CANSparkMax

class rev.CANSparkMax(self: rev.CANSparkMax, deviceID: int, type: rev._rev.CANSparkMaxLowLevel.MotorType) → None

Bases: rev.CANSparkMaxLowLevel

Create a new SPARK MAX Controller

Parameters
  • deviceID – The device ID.

  • type – The motor type connected to the controller. Brushless motors must be connected to their matching color and the hall sensor plugged in. Brushed motors must be connected to the Red and Black terminals only.

class ExternalFollower(self: rev._rev.CANSparkMax.ExternalFollower) → None

Bases: pybind11_builtins.pybind11_object

property arbId
property configId
class FaultID(self: rev._rev.CANSparkMax.FaultID, value: int) → None

Bases: pybind11_builtins.pybind11_object

Members:

kBrownout

kOvercurrent

kIWDTReset

kMotorFault

kSensorFault

kStall

kEEPROMCRC

kCANTX

kCANRX

kHasReset

kDRVFault

kOtherFault

kSoftLimitFwd

kSoftLimitRev

kHardLimitFwd

kHardLimitRev

kBrownout = <FaultID.kBrownout: 0>
kCANRX = <FaultID.kCANRX: 8>
kCANTX = <FaultID.kCANTX: 7>
kDRVFault = <FaultID.kDRVFault: 10>
kEEPROMCRC = <FaultID.kEEPROMCRC: 6>
kHardLimitFwd = <FaultID.kHardLimitFwd: 14>
kHardLimitRev = <FaultID.kHardLimitRev: 15>
kHasReset = <FaultID.kHasReset: 9>
kIWDTReset = <FaultID.kIWDTReset: 2>
kMotorFault = <FaultID.kMotorFault: 3>
kOtherFault = <FaultID.kOtherFault: 11>
kOvercurrent = <FaultID.kOvercurrent: 1>
kSensorFault = <FaultID.kSensorFault: 4>
kSoftLimitFwd = <FaultID.kSoftLimitFwd: 12>
kSoftLimitRev = <FaultID.kSoftLimitRev: 13>
kStall = <FaultID.kStall: 5>
property name
class IdleMode(self: rev._rev.CANSparkMax.IdleMode, value: int) → None

Bases: pybind11_builtins.pybind11_object

Members:

kCoast

kBrake

kBrake = <IdleMode.kBrake: 1>
kCoast = <IdleMode.kCoast: 0>
property name
class InputMode(self: rev._rev.CANSparkMax.InputMode, value: int) → None

Bases: pybind11_builtins.pybind11_object

Members:

kPWM

kCAN

kCAN = <InputMode.kCAN: 1>
kPWM = <InputMode.kPWM: 0>
property name
PIDWrite(self: rev.CANSparkMax, output: float) → None
class SoftLimitDirection(self: rev._rev.CANSparkMax.SoftLimitDirection, value: int) → None

Bases: pybind11_builtins.pybind11_object

Members:

kForward

kReverse

kForward = <SoftLimitDirection.kForward: 0>
kReverse = <SoftLimitDirection.kReverse: 1>
property name
burnFlash(self: rev.CANSparkMax)rev.CANError

Writes all settings to flash.

clearFaults(self: rev.CANSparkMax)rev.CANError

Clears all non-sticky faults.

Sticky faults must be cleared by resetting the motor controller.

disable(self: rev.CANSparkMax) → None

Common interface for disabling a motor.

disableVoltageCompensation(self: rev.CANSparkMax)rev.CANError

Disables the voltage compensation setting for all modes on the SPARK MAX.

Returns

CANError Set to CANError.kOK if successful

enableSoftLimit(self: rev.CANSparkMax, direction: rev._rev.CANSparkMax.SoftLimitDirection, enable: bool)rev.CANError

Enable soft limits

Parameters
  • direction – the direction of motion to restrict

  • enable – set true to enable soft limits

enableVoltageCompensation(self: rev.CANSparkMax, nominalVoltage: float)rev.CANError

Sets the voltage compensation setting for all modes on the SPARK MAX and enables voltage compensation.

Parameters

nominalVoltage – Nominal voltage to compensate output to

Returns

CANError Set to CANError.kOK if successful

follow(*args, **kwargs)

Overloaded function.

  1. follow(self: rev._rev.CANSparkMax, leader: rev._rev.CANSparkMax, invert: bool = False) -> rev._rev.CANError

Causes this controller’s output to mirror the provided leader.

Only voltage output is mirrored. Settings changed on the leader do not affect the follower.

Following anything other than a CAN SPARK MAX is not officially supported.

Parameters
  • leader – The motor controller to follow.

  • invert – Set the follower to output opposite of the leader

  1. follow(self: rev._rev.CANSparkMax, leader: rev._rev.CANSparkMax.ExternalFollower, deviceID: int, invert: bool = False) -> rev._rev.CANError

Causes this controller’s output to mirror the provided leader.

Only voltage output is mirrored. Settings changed on the leader do not affect the follower.

Following anything other than a CAN SPARK MAX is not officially supported.

Parameters
  • leader – The type of motor controller to follow (Talon SRX, Spark Max, etc.).

  • deviceID – The CAN ID of the device to follow.

  • invert – Set the follower to output opposite of the leader

get(self: rev.CANSparkMax) → float

Common interface for getting the current set speed of a speed controller.

Returns

The current set speed. Value is between -1.0 and 1.0.

getAlternateEncoder(self: rev.CANSparkMax, sensorType: rev._rev.CANEncoder.AlternateEncoderType, counts_per_rev: int)rev.CANEncoder

Returns an object for interfacing with a quadrature encoder connected to the alternate encoder mode data port pins. These are defined as:

Pin 4 (Forward Limit Switch): Index Pin 6 (Multi-function): Encoder A Pin 8 (Reverse Limit Switch): Encoder B

This call will disable support for the limit switch inputs.

getAnalog(mode: rev._rev.CANAnalog.AnalogMode = <AnalogMode.kAbsolute: 0>)rev.CANAnalog

Returns an object for interfacing with a connected analog sensor. By default, the AnalogMode is set to kAbsolute, thus treating the sensor as an absolute sensor.

getAppliedOutput(self: rev.CANSparkMax) → float

Returns motor controller’s output duty cycle.

getBusVoltage(self: rev.CANSparkMax) → float

Returns the voltage fed into the motor controller.

getClosedLoopRampRate(self: rev.CANSparkMax) → float

Get the configured closed loop ramp rate

This is the maximum rate at which the motor controller’s output is allowed to change.

Returns

rampte rate time in seconds to go from 0 to full throttle.

getEncoder(sensorType: rev._rev.CANEncoder.EncoderType = <EncoderType.kHallSensor: 1>, counts_per_rev: int = 0)rev.CANEncoder

Returns an object for interfacing with the encoder connected to the encoder pins or front port of the SPARK MAX.

The default encoder type is assumed to be the hall effect for brushless. This can be modified for brushed DC to use an quadrature encoder.

getFault(self: rev.CANSparkMax, faultID: rev._rev.CANSparkMax.FaultID) → bool

Returns whether the fault with the given ID occurred.

getFaults(self: rev.CANSparkMax) → int

Returns fault bits.

getForwardLimitSwitch(self: rev.CANSparkMax, polarity: rev._rev.CANDigitalInput.LimitSwitchPolarity)rev.CANDigitalInput

Returns an object for interfacing with the forward limit switch connected to the appropriate pins on the data port.

This call will disable support for the alternate encoder.

Parameters

polarity – Whether the limit switch is normally open or normally closed.

getIdleMode(self: rev.CANSparkMax) → rev._rev.CANSparkMax.IdleMode

Gets the idle mode setting for the SPARK MAX.

This uses the Get Parameter API and should be used infrequently. This function uses a non-blocking call and will return a cached value if the parameter is not returned by the timeout. The timeout can be changed by calling SetCANTimeout(int milliseconds)

Returns

IdleMode Idle mode setting

getInverted(self: rev.CANSparkMax) → bool

Common interface for returning the inversion state of a speed controller.

This call has no effect if the controller is a follower.

Returns

isInverted The state of inversion, true is inverted.

getLastError(self: rev.CANSparkMax)rev.CANError

All device errors are tracked on a per thread basis for all devices in that thread. This is meant to be called immediately following another call that has the possibility of throwing an error to validate if an error has occurred.

Returns

the last error that was generated.

getMotorTemperature(self: rev.CANSparkMax) → float

Returns the motor temperature in Celsius.

getOpenLoopRampRate(self: rev.CANSparkMax) → float

Get the configured open loop ramp rate

This is the maximum rate at which the motor controller’s output is allowed to change.

Returns

rampte rate time in seconds to go from 0 to full throttle.

getOutputCurrent(self: rev.CANSparkMax) → float

Returns motor controller’s output current in Amps.

getPIDController(self: rev.CANSparkMax)rev.CANPIDController

Returns an object for interfacing with the integrated PID controller.

getReverseLimitSwitch(self: rev.CANSparkMax, polarity: rev._rev.CANDigitalInput.LimitSwitchPolarity)rev.CANDigitalInput

Returns an object for interfacing with the reverse limit switch connected to the appropriate pins on the data port.

This call will disable support for the alternate encoder.

Parameters

polarity – Whether the limit switch is normally open or normally closed.

getSoftLimit(self: rev.CANSparkMax, direction: rev._rev.CANSparkMax.SoftLimitDirection) → float

Get the soft limit setting in the controller

Parameters

direction – the direction of motion to restrict

Returns

position soft limit setting of the controller

getStickyFault(self: rev.CANSparkMax, faultID: rev._rev.CANSparkMax.FaultID) → bool

Returns whether the sticky fault with the given ID occurred.

getStickyFaults(self: rev.CANSparkMax) → int

Returns sticky fault bits.

getVoltageCompensationNominalVoltage(self: rev.CANSparkMax) → float

Get the configured voltage compensation nominal voltage value

Returns

The nominal voltage for voltage compensation mode.

isFollower(self: rev.CANSparkMax) → bool

Returns whether the controller is following another controller

Returns

True if this device is following another controller false otherwise

isSoftLimitEnabled(self: rev.CANSparkMax, direction: rev._rev.CANSparkMax.SoftLimitDirection) → bool

Returns true if the soft limit is enabled.

set(self: rev.CANSparkMax, speed: float) → None

Common interface for setting the speed of a speed controller.

Parameters

speed – The speed to set. Value should be between -1.0 and 1.0.

setCANTimeout(self: rev.CANSparkMax, milliseconds: int)rev.CANError

Sets timeout for sending CAN messages. A timeout of 0 also means that error handling will be done automatically by registering calls and waiting for responses, rather than needing to call GetLastError().

Parameters

milliseconds – The timeout in milliseconds.

setClosedLoopRampRate(self: rev.CANSparkMax, rate: float)rev.CANError

Sets the ramp rate for closed loop control modes.

This is the maximum rate at which the motor controller’s output is allowed to change.

Parameters

rate – Time in seconds to go from 0 to full throttle.

setIdleMode(self: rev.CANSparkMax, mode: rev._rev.CANSparkMax.IdleMode)rev.CANError

Sets the idle mode setting for the SPARK MAX.

Parameters

mode – Idle mode (coast or brake).

setInverted(self: rev.CANSparkMax, isInverted: bool) → None

Common interface for inverting direction of a speed controller.

This call has no effect if the controller is a follower. To invert a follower, see the follow() method.

Parameters

isInverted – The state of inversion, true is inverted.

setOpenLoopRampRate(self: rev.CANSparkMax, rate: float)rev.CANError

Sets the ramp rate for open loop control modes.

This is the maximum rate at which the motor controller’s output is allowed to change.

Parameters

rate – Time in seconds to go from 0 to full throttle.

setSecondaryCurrentLimit(self: rev.CANSparkMax, limit: float, limitCycles: int = 0)rev.CANError

Sets the secondary current limit in Amps.

The motor controller will disable the output of the controller briefly if the current limit is exceeded to reduce the current. This limit is a simplified ‘on/off’ controller. This limit is enabled by default but is set higher than the default Smart Current Limit.

The time the controller is off after the current limit is reached is determined by the parameter limitCycles, which is the number of PWM cycles (20kHz). The recommended value is the default of 0 which is the minimum time and is part of a PWM cycle from when the over current is detected. This allows the controller to regulate the current close to the limit value.

The total time is set by the equation

@code t = (50us - t0) + 50us * limitCycles t = total off time after over current t0 = time from the start of the PWM cycle until over current is detected @endcode

Parameters
  • limit – The current limit in Amps.

  • limitCycles – The number of additional PWM cycles to turn the driver off after overcurrent is detected.

setSmartCurrentLimit(*args, **kwargs)

Overloaded function.

  1. setSmartCurrentLimit(self: rev._rev.CANSparkMax, limit: int) -> rev._rev.CANError

Sets the current limit in Amps.

The motor controller will reduce the controller voltage output to avoid surpassing this limit. This limit is enabled by default and used for brushless only. This limit is highly recommended when using the NEO brushless motor.

The NEO Brushless Motor has a low internal resistance, which can mean large current spikes that could be enough to cause damage to the motor and controller. This current limit provides a smarter strategy to deal with high current draws and keep the motor and controller operating in a safe region.

Parameters

limit – The current limit in Amps.

  1. setSmartCurrentLimit(self: rev._rev.CANSparkMax, stallLimit: int, freeLimit: int, limitRPM: int = 20000) -> rev._rev.CANError

Sets the current limit in Amps.

The motor controller will reduce the controller voltage output to avoid surpassing this limit. This limit is enabled by default and used for brushless only. This limit is highly recommended when using the NEO brushless motor.

The NEO Brushless Motor has a low internal resistance, which can mean large current spikes that could be enough to cause damage to the motor and controller. This current limit provides a smarter strategy to deal with high current draws and keep the motor and controller operating in a safe region.

The controller can also limit the current based on the RPM of the motor in a linear fashion to help with controllability in closed loop control. For a response that is linear the entire RPM range leave limit RPM at 0.

Parameters
  • stallLimit – The current limit in Amps at 0 RPM.

  • freeLimit – The current limit at free speed (5700RPM for NEO).

  • limitRPM – RPM less than this value will be set to the stallLimit, RPM values greater than limitRPM will scale linearly to freeLimit

setSoftLimit(self: rev.CANSparkMax, direction: rev._rev.CANSparkMax.SoftLimitDirection, limit: float)rev.CANError

Set the soft limit based on position. The default unit is rotations, but will match the unit scaling set by the user.

Note that this value is not scaled internally so care must be taken to make sure these units match the desired conversion

Parameters
  • direction – the direction of motion to restrict

  • limit – position soft limit of the controller

setVoltage(self: rev.CANSparkMax, output: volts) → None

Sets the voltage output of the SpeedController. This is equivillant to a call to SetReference(output, rev::ControlType::kVoltage). The behavior of this call differs slightly from the WPILib documetation for this call since the device internally sets the desired voltage (not a compensation value). That means that this can be a ‘set-and-forget’ call.

Parameters

output – The voltage to output.

stopMotor(self: rev.CANSparkMax) → None

Common interface to stop the motor until Set is called again.