SparkBase

class rev.SparkBase(deviceID: SupportsInt | SupportsIndex, type: rev._rev.SparkLowLevel.MotorType, model: rev._rev.SparkLowLevel.SparkModel)

Bases: SparkLowLevel

Create a new object to control a SPARK motor Controller

Parameters:
  • deviceID – The device ID.

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

  • model – The model (kSparkMax or kSparkFlex) of the motor.

class Faults(*args, **kwargs)

Bases: pybind11_object

Overloaded function.

  1. __init__(self: rev._rev.SparkBase.Faults) -> None

  2. __init__(self: rev._rev.SparkBase.Faults, faults: typing.SupportsInt | typing.SupportsIndex) -> None

property can
property escEeprom
property firmware
property gateDriver
property motorType
property other
property rawBits
property sensor
property temperature
class IdleMode(value: SupportsInt | SupportsIndex)

Bases: pybind11_object

Members:

kCoast

kBrake

kBrake = <IdleMode.kBrake: 1>
kCoast = <IdleMode.kCoast: 0>
SparkBase.IdleMode.name -> str
property value
class SoftLimitDirection(value: SupportsInt | SupportsIndex)

Bases: pybind11_object

Members:

kForward

kReverse

kForward = <SoftLimitDirection.kForward: 0>
kReverse = <SoftLimitDirection.kReverse: 1>
SparkBase.SoftLimitDirection.name -> str
property value
class Warnings(*args, **kwargs)

Bases: pybind11_object

Overloaded function.

  1. __init__(self: rev._rev.SparkBase.Warnings) -> None

  2. __init__(self: rev._rev.SparkBase.Warnings, warnings: typing.SupportsInt | typing.SupportsIndex) -> None

property brownout
property escEeprom
property extEeprom
property hasReset
property other
property overcurrent
property rawBits
property sensor
property stall
clearFaults() rev._rev.REVLibError

Clears all sticky faults.

configure(config: rev._rev.SparkBaseConfig, resetMode: rev._rev.ResetMode, persistMode: rev._rev.PersistMode) rev._rev.REVLibError

Set the configuration for the SPARK.

If @c resetMode is ResetMode::kResetSafeParameters, this method will reset safe writable parameters to their default values before setting the given configuration. The following parameters will not be reset by this action: CAN ID, Motor Type, Idle Mode, PWM Input Deadband, and Duty Cycle Offset.

If @c persistMode is PersistMode::kPersistParameters, this method will save all parameters to the SPARK’s non-volatile memory after setting the given configuration. This will allow parameters to persist across power cycles.

Parameters:
  • config – The desired SPARK configuration

  • resetMode – Whether to reset safe parameters before setting the configuration

  • persistMode – Whether to persist the parameters after setting the configuration

Returns:

REVLibError::kOk if successful

configureAsync(config: rev._rev.SparkBaseConfig, resetMode: rev._rev.ResetMode, persistMode: rev._rev.PersistMode) rev._rev.REVLibError

Set the configuration for the SPARK without waiting for a response.

If @c resetMode is ResetMode::kResetSafeParameters, this method will reset safe writable parameters to their default values before setting the given configuration. The following parameters will not be reset by this action: CAN ID, Motor Type, Idle Mode, PWM Input Deadband, and Duty Cycle Offset.

If @c persistMode is PersistMode::kPersistParameters, this method will save all parameters to the SPARK’s non-volatile memory after setting the given configuration. This will allow parameters to persist across power cycles.

NOTE: This method will immediately return REVLibError::kOk and the action will be done in the background. Any errors that occur will be reported to the driver station.

Parameters:
  • config – The desired SPARK configuration

  • resetMode – Whether to reset safe parameters before setting the configuration

  • persistMode – Whether to persist the parameters after setting the configuration

Returns:

REVLibError::kOk @see Configure()

disable() None

Common interface for disabling a motor.

get() 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.

getAbsoluteEncoder() rev._rev.SparkAbsoluteEncoder

Returns an object for interfacing with a connected absolute encoder.

The default encoder type is assumed to be a duty cycle sensor.

getAnalog() rev._rev.SparkAnalogSensor

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

getAppliedOutput() float

Simulation note: this value will not be updated during simulation unless {@link SparkSim#iterate} is called

Returns motor controller’s output duty cycle.

getBusVoltage() float

Returns the voltage fed into the motor controller.

getClosedLoopController() rev._rev.SparkClosedLoopController

Returns an object for interfacing with the integrated Closed Loop Controller.

getEncoder() rev._rev.SparkRelativeEncoder

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

getFaults() rev._rev.SparkBase.Faults

Get the active faults that are currently present on the SPARK. Faults are fatal errors that prevent the motor from running.

Returns:

A struct with each fault and their active value

getForwardLimitSwitch() rev._rev.SparkLimitSwitch

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.

getForwardSoftLimit() rev._rev.SparkSoftLimit

Returns an object for interfacing with the forward soft limit switch

getInverted() bool

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

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

Deprecated:

Use SparkBaseConfigAccessor.GetInverted() via SparkMax.configAccessor or SparkFlex.configAccessor instead

Returns:

isInverted The state of inversion, true is inverted.

getLastError() rev._rev.REVLibError

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() float

Returns the motor temperature in Celsius.

getOutputCurrent() float

Returns motor controller’s output current in Amps.

getReverseLimitSwitch() rev._rev.SparkLimitSwitch

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.

getReverseSoftLimit() rev._rev.SparkSoftLimit

Returns an object for interfacing with the reverse soft limit switch

getStickyFaults() rev._rev.SparkBase.Faults

Get the sticky faults that were present on the SPARK at one point since the sticky faults were last cleared. Faults are fatal errors that prevent the motor from running.

Sticky faults can be cleared with SparkBase::ClearFaults().

Returns:

A struct with each fault and their sticky value

getStickyWarnings() rev._rev.SparkBase.Warnings

Get the sticky warnings that were present on the SPARK at one point since the sticky warnings were last cleared. Warnings are non-fatal errors.

Sticky warnings can be cleared with SparkBase::clearFaults().

Returns:

A struct with each warning and their sticky value

getWarnings() rev._rev.SparkBase.Warnings

Get the active warnings that are currently present on the SPARK. Warnings are non-fatal errors.

Returns:

A struct with each warning and their active value

hasActiveFault() bool
hasActiveWarning() bool

Get whether the SPARK has one or more active warnings.

Returns:

true if there is an active warning @see GetWarnings()

hasStickyFault() bool

Get whether the SPARK has one or more sticky faults.

Returns:

true if there is a sticky fault @see GetStickyFaults()

hasStickyWarning() bool

Get whether the SPARK has one or more sticky warnings.

Returns:

true if there is a sticky warning @see GetStickyWarnings()

isFollower() bool

Returns whether the controller is following another controller

Returns:

True if this device is following another controller false otherwise

pauseFollowerMode() rev._rev.REVLibError

Pause follower mode.

NOTE: If the SPARK experiences a power cycle and has follower mode configured, follower mode will automatically restart.

Returns:

REVLibError::kOk if successful

pauseFollowerModeAsync() rev._rev.REVLibError

Pause follower mode without waiting for a response.

NOTE: If the SPARK experiences a power cycle and has follower mode configured, follower mode will automatically restart.

NOTE: This method will immediately return REVLibError::kOk and the action will be done in the background. Any errors that occur will be reported to the driver station.

Returns:

REVLibError::kOk @see PauseFollowerMode()

resumeFollowerMode() rev._rev.REVLibError

Resume follower mode if the SPARK has a valid follower mode config.

NOTE: Follower mode will start automatically upon configuring follower mode. If the SPARK experiences a power cycle and has follower mode configured, follower mode will automatically restart. This method is only useful after PauseFollowerMode() has been called.

Returns:

REVLibError::kOk if successful

resumeFollowerModeAsync() rev._rev.REVLibError

Resume follower mode if the SPARK has a valid follower mode config without waiting for a response.

NOTE: Follower mode will start automatically upon configuring follower mode. If the SPARK experiences a power cycle and has follower mode configured, follower mode will automatically restart. This method is only useful after PauseFollowerMode() has been called.

NOTE: This method will immediately return REVLibError::kOk and the action will be done in the background. Any errors that occur will be reported to the driver station.

Returns:

REVLibError::kOk @see ResumeFollowerMode()

set(speed: SupportsFloat | SupportsIndex) 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(milliseconds: SupportsInt | SupportsIndex) rev._rev.REVLibError

Sets the timeout duration for waiting for CAN responses from the device.

Parameters:

milliseconds – The timeout in milliseconds.

setInverted(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.

Deprecated:

Use SparkBaseConfig.Inverted() with Configure() instead

Parameters:

isInverted – The state of inversion, true is inverted.

setVoltage(output: wpimath.units.volts) None

Sets the voltage output of the SpeedController. This is equivalent to a call to SetReference(output, SparkBase::ControlType::kVoltage). The behavior of this call differs slightly from the WPILib documentation 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() None

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