sparkcan Documentation  1.0
SparkMax Class Reference

A class for controlling REV Robotics SPARK MAX via CAN bus. More...

#include <SparkMax.hpp>

Inheritance diagram for SparkMax:
Collaboration diagram for SparkMax:

Public Member Functions

 SparkMax (const std::string &interfaceName, uint8_t deviceId)
 
 ~SparkMax () override=default
 
- Public Member Functions inherited from SparkBase
 SparkBase (const std::string &interfaceName, uint8_t deviceId)
 Initializes SparkBase with the specified CAN interface and ID. More...
 
virtual ~SparkBase ()
 Destructor for SparkBase. More...
 
void ResetFaults ()
 Resets all faults on the SPARK controller. More...
 
void ClearStickyFaults ()
 Clears sticky faults on the SPARK controller. More...
 
void BurnFlash ()
 Burns the current configuration to the SPARK controller's flash memory. More...
 
void FactoryDefaults ()
 Resets the SPARK controller to factory default settings. More...
 
void FactoryReset ()
 Performs a factory reset on the SPARK controller. More...
 
void Identify ()
 Triggers the SPARK controller to identify itself. More...
 
void SetSetpoint (float setpoint)
 Sets the value for the currently set control type. More...
 
void SetDutyCycle (float dutyCycle)
 Sets the motor's applied output. More...
 
void SetVelocity (float velocity)
 Sets the motor's velocity. More...
 
void SetSmartVelocity (float smartVelocity)
 Sets the motor's smart velocity. More...
 
void SetPosition (float position)
 Sets the motor's position. More...
 
void SetVoltage (float voltage)
 Sets the motor's voltage. More...
 
void SetCurrent (float current)
 Sets the motor's current. More...
 
void SetSmartMotion (float smartMotion)
 Sets the motor's smart motion. More...
 
float GetDutyCycle () const
 Retrieves the current applied output. More...
 
uint16_t GetFaults () const
 Retrieves the current faults. More...
 
uint16_t GetStickyFaults () const
 Retrieves the sticky faults. More...
 
bool GetInverted () const
 Checks if the motor is inverted. More...
 
bool GetIdleMode () const
 Gets the current idle mode. More...
 
bool IsFollower () const
 Checks if the SPARK controller is in follower mode. More...
 
float GetVelocity () const
 Gets the current velocity. More...
 
float GetTemperature () const
 Gets the current temperature of the SPARK controller. More...
 
float GetVoltage () const
 Gets the current voltage of the SPARK controller. More...
 
float GetCurrent () const
 Gets the current drawn by the SPARK controller. More...
 
float GetPosition () const
 Gets the current position of the motor. More...
 
float GetAnalogVoltage () const
 Gets the current analog voltage. More...
 
float GetAnalogVelocity () const
 Gets the current analog velocity. More...
 
float GetAnalogPosition () const
 Gets the current analog position. More...
 
float GetAlternateEncoderVelocity () const
 Gets the velocity from the alternate encoder. More...
 
float GetAlternateEncoderPosition () const
 Gets the position from the alternate encoder. More...
 
void SetInputMode (uint8_t mode)
 Sets the input mode. More...
 
void SetMotorType (MotorType type)
 Sets the motor type. More...
 
void SetSensorType (SensorType sensor)
 Sets the sensor type. More...
 
void SetIdleMode (IdleMode mode)
 Sets the idle mode. More...
 
void SetInputDeadband (float deadband)
 Sets the input deadband. More...
 
void SetInverted (bool inverted)
 Sets whether the motor is inverted. More...
 
void SetRampRate (float rate)
 Sets the ramp rate. More...
 
void SetMotorKv (uint16_t kv)
 Sets the motor Kv (velocity constant) More...
 
void SetMotorR (uint16_t r)
 Sets the motor resistance. More...
 
void SetMotorL (uint16_t l)
 Sets the motor inductance. More...
 
void SetCtrlType (CtrlType type)
 Sets the control type. More...
 
void SetFeedbackSensorPID0 (uint16_t sensor)
 Sets the feedback sensor for PID0. More...
 
void SetClosedLoopVoltageMode (uint8_t mode)
 Sets the closed loop voltage mode. More...
 
void SetCompensatedNominalVoltage (float voltage)
 Sets the compensated nominal voltage. More...
 
void SetPositionPIDWrapEnable (bool enable)
 Enables or disables position PID wrap. More...
 
void SetPositionPIDMinInput (float minInput)
 Sets the minimum input for position PID. More...
 
void SetPositionPIDMaxInput (float maxInput)
 Sets the maximum input for position PID. More...
 
void SetPolePairs (uint16_t pairs)
 Sets the number of pole pairs for brushless motors. More...
 
void SetCurrentChop (float chop)
 Sets the current chop limit. More...
 
void SetCurrentChopCycles (uint16_t cycles)
 Sets the number of cycles for current chopping. More...
 
void SetSmartCurrentStallLimit (uint16_t limit)
 Sets the smart current stall limit. More...
 
void SetSmartCurrentFreeLimit (uint16_t limit)
 Sets the smart current free limit. More...
 
void SetSmartCurrentConfig (uint16_t config)
 Sets the smart current configuration. More...
 
void SetP (uint8_t slot, float p)
 Sets the proportional gain for the specified PID slot. More...
 
void SetI (uint8_t slot, float i)
 Sets the integral gain for the specified PID slot. More...
 
void SetD (uint8_t slot, float d)
 Sets the derivative gain for the specified PID slot. More...
 
void SetF (uint8_t slot, float f)
 Sets the feedforward gain for the specified PID slot. More...
 
void SetIZone (uint8_t slot, float iZone)
 Sets the integral zone for the specified PID slot. More...
 
void SetDFilter (uint8_t slot, float dFilter)
 Sets the derivative filter for the specified PID slot. More...
 
void SetOutputMin (uint8_t slot, float min)
 Sets the output minimum for the specified PID slot. More...
 
void SetOutputMax (uint8_t slot, float max)
 Sets the output maximum for the specified PID slot. More...
 
void SetHardLimitFwdEn (bool enable)
 Enables or disables the forward hard limit switch. More...
 
void SetHardLimitRevEn (bool enable)
 Enables or disables the reverse hard limit switch. More...
 
void SetLimitSwitchFwdPolarity (bool polarity)
 Sets the polarity of the forward limit switch. More...
 
void SetLimitSwitchRevPolarity (bool polarity)
 Sets the polarity of the reverse limit switch. More...
 
void SetSoftLimitFwdEn (bool enable)
 Enables or disables the forward soft limit. More...
 
void SetSoftLimitRevEn (bool enable)
 Enables or disables the reverse soft limit. More...
 
void SetSoftLimitFwd (float limit)
 Sets the forward soft limit. More...
 
void SetSoftLimitRev (float limit)
 Sets the reverse soft limit. More...
 
void SetFollowerID (uint32_t id)
 Sets the follower ID for this SparkBase. More...
 
void SetFollowerConfig (uint32_t config)
 Sets the follower configuration. More...
 
void SetEncoderCountsPerRev (uint16_t counts)
 Sets the encoder counts per revolution. More...
 
void SetEncoderAverageDepth (uint8_t depth)
 Sets the encoder average depth. More...
 
void SetEncoderSampleDelta (uint8_t delta)
 Sets the encoder sample delta. More...
 
void SetEncoderInverted (bool inverted)
 Sets whether the encoder is inverted. More...
 
void SetPositionConversionFactor (float factor)
 Sets the position conversion factor. More...
 
void SetVelocityConversionFactor (float factor)
 Sets the velocity conversion factor. More...
 
void SetClosedLoopRampRate (float rampRate)
 Sets the closed loop ramp rate. More...
 
void SetHallSensorSampleRate (float rate)
 Sets the hall sensor sample rate. More...
 
void SetHallSensorAverageDepth (uint16_t depth)
 Sets the hall sensor average depth. More...
 
void SetSmartMotionMaxVelocity (uint8_t slot, float maxVel)
 Sets the maximum velocity for Smart Motion in the specified slot. More...
 
void SetSmartMotionMaxAccel (uint8_t slot, float maxAccel)
 Sets the maximum acceleration for Smart Motion in the specified slot. More...
 
void SetSmartMotionMinVelOutput (uint8_t slot, float minVel)
 Sets the minimum velocity output for Smart Motion in the specified slot. More...
 
void SetSmartMotionAllowedClosedLoopError (uint8_t slot, float error)
 Sets the allowed closed loop error for Smart Motion in the specified slot. More...
 
void SetSmartMotionAccelStrategy (uint8_t slot, float strategy)
 Sets the acceleration strategy for Smart Motion in the specified slot. More...
 
void SetIMaxAccum (uint8_t slot, float maxAccum)
 Sets the maximum accumulator value for the I term in the specified slot. More...
 
void SetSlot3Placeholder1 (uint8_t slot, float value)
 Sets a placeholder value for slot 3 (purpose undefined) More...
 
void SetSlot3Placeholder2 (uint8_t slot, float value)
 Sets a placeholder value for slot 3 (purpose undefined) More...
 
void SetSlot3Placeholder3 (uint8_t slot, float value)
 Sets a placeholder value for slot 3 (purpose undefined) More...
 
void SetAnalogPositionConversion (float factor)
 Sets the conversion factor for analog position readings. More...
 
void SetAnalogVelocityConversion (float factor)
 Sets the conversion factor for analog velocity readings. More...
 
void SetAnalogAverageDepth (uint16_t depth)
 Sets the average depth for analog readings. More...
 
void SetAnalogSensorMode (uint8_t mode)
 Sets the analog sensor mode. More...
 
void SetAnalogInverted (bool inverted)
 Sets whether the analog sensor is inverted. More...
 
void SetAnalogSampleDelta (uint16_t delta)
 Sets the sample delta for analog readings. More...
 
void SetDataPortConfig (uint8_t config)
 Configures the data port. More...
 
void SetAltEncoderCountsPerRev (uint16_t counts)
 Sets the counts per revolution for the alternate encoder. More...
 
void SetAltEncoderAverageDepth (uint8_t depth)
 Sets the average depth for the alternate encoder. More...
 
void SetAltEncoderSampleDelta (uint8_t delta)
 Sets the sample delta for the alternate encoder. More...
 
void SetAltEncoderInverted (bool inverted)
 Sets whether the alternate encoder is inverted. More...
 
void SetAltEncoderPositionFactor (float factor)
 Sets the position factor for the alternate encoder. More...
 
void SetAltEncoderVelocityFactor (float factor)
 Sets the velocity factor for the alternate encoder. More...
 
void SetDutyCyclePositionFactor (float factor)
 Sets the position factor for the duty cycle encoder. More...
 
void SetDutyCycleVelocityFactor (float factor)
 Sets the velocity factor for the duty cycle encoder. More...
 
void SetDutyCycleInverted (bool inverted)
 Sets whether the duty cycle encoder is inverted. More...
 
void SetDutyCycleAverageDepth (uint8_t depth)
 Sets the average depth for the duty cycle encoder. More...
 
void SetDutyCyclePrescalar (uint8_t prescalar)
 Sets the prescalar for the duty cycle encoder. More...
 
void SetDutyCycleZeroOffset (float offset)
 Sets the zero offset for the duty cycle encoder. More...
 
uint8_t GetMotorType ()
 Get the motor type. More...
 
uint8_t GetSensorType ()
 Get the sensor type. More...
 
uint8_t GetIdleMode ()
 Get the idle mode. More...
 
float GetInputDeadband ()
 Get the input deadband. More...
 
bool GetInverted ()
 Get whether the motor is inverted. More...
 
float GetRampRate ()
 Get the ramp rate. More...
 
uint16_t GetMotorKv ()
 Get the motor Kv rating. More...
 
uint16_t GetMotorR ()
 Get the motor resistance. More...
 
uint16_t GetMotorL ()
 Get the motor inductance. More...
 
uint8_t GetCtrlType ()
 Get the control type. More...
 
uint16_t GetFeedbackSensorPID0 ()
 Get the feedback sensor PID0 value. More...
 
uint8_t GetClosedLoopVoltageMode ()
 Get the closed loop voltage mode. More...
 
float GetCompensatedNominalVoltage ()
 Get the compensated nominal voltage. More...
 
bool GetPositionPIDWrapEnable ()
 Get the position PID wrap enable state. More...
 
float GetPositionPIDMinInput ()
 Get the position PID minimum input. More...
 
float GetPositionPIDMaxInput ()
 Get the position PID maximum input. More...
 
uint16_t GetPolePairs ()
 Get the number of pole pairs. More...
 
float GetCurrentChop ()
 Get the current chop value. More...
 
uint16_t GetCurrentChopCycles ()
 Get the current chop cycles. More...
 
uint16_t GetSmartCurrentStallLimit ()
 Get the smart current stall limit. More...
 
uint16_t GetSmartCurrentFreeLimit ()
 Get the smart current free limit. More...
 
uint16_t GetSmartCurrentConfig ()
 Get the smart current configuration. More...
 
float GetP (uint8_t slot)
 Get the proportional (P) constant for a given slot. More...
 
float GetI (uint8_t slot)
 Get the integral (I) constant for a given slot. More...
 
float GetD (uint8_t slot)
 Get the derivative (D) constant for a given slot. More...
 
float GetF (uint8_t slot)
 Get the feedforward (F) constant for a given slot. More...
 
float GetIZone (uint8_t slot)
 Get the IZone value for a given slot. More...
 
float GetDFilter (uint8_t slot)
 Get the DFilter value for a given slot. More...
 
float GetOutputMin (uint8_t slot)
 Get the output minimum value for a given slot. More...
 
float GetOutputMax (uint8_t slot)
 Get the output maximum value for a given slot. More...
 
bool GetHardLimitFwdEn ()
 Get the forward hard limit enable state. More...
 
bool GetHardLimitRevEn ()
 Get the reverse hard limit enable state. More...
 
bool GetLimitSwitchFwdPolarity ()
 Get the forward limit switch polarity. More...
 
bool GetLimitSwitchRevPolarity ()
 Get the reverse limit switch polarity. More...
 
bool GetSoftLimitFwdEn ()
 Get the forward soft limit enable state. More...
 
bool GetSoftLimitRevEn ()
 Get the reverse soft limit enable state. More...
 
float GetSoftLimitFwd ()
 Get the forward soft limit value. More...
 
float GetSoftLimitRev ()
 Get the reverse soft limit value. More...
 
uint32_t GetFollowerID ()
 Get the follower ID. More...
 
uint32_t GetFollowerConfig ()
 Get the follower configuration. More...
 
uint16_t GetEncoderCountsPerRev ()
 Get the encoder counts per revolution. More...
 
uint8_t GetEncoderAverageDepth ()
 Get the encoder average depth. More...
 
uint8_t GetEncoderSampleDelta ()
 Get the encoder sample delta. More...
 
bool GetEncoderInverted ()
 Get the encoder inversion state. More...
 
float GetPositionConversionFactor ()
 Get the position conversion factor. More...
 
float GetVelocityConversionFactor ()
 Get the velocity conversion factor. More...
 
float GetClosedLoopRampRate ()
 Get the closed loop ramp rate. More...
 
float GetHallSensorSampleRate ()
 Get the Hall sensor sample rate. More...
 
uint16_t GetHallSensorAverageDepth ()
 Get the Hall sensor average depth. More...
 
float GetSmartMotionMaxVelocity (uint8_t slot)
 Get the maximum velocity for Smart Motion in a given slot. More...
 
float GetSmartMotionMaxAccel (uint8_t slot)
 Get the maximum acceleration for Smart Motion in a given slot. More...
 
float GetSmartMotionMinVelOutput (uint8_t slot)
 Get the minimum velocity output for Smart Motion in a given slot. More...
 
float GetSmartMotionAllowedClosedLoopError (uint8_t slot)
 Get the allowed closed-loop error for Smart Motion in a given slot. More...
 
float GetSmartMotionAccelStrategy (uint8_t slot)
 Get the acceleration strategy for Smart Motion in a given slot. More...
 
float GetIMaxAccum (uint8_t slot)
 Get the maximum accumulated I term for Smart Motion in a given slot. More...
 
float GetSlot3Placeholder1 (uint8_t slot)
 Get the value for Slot 3 Placeholder 1 in a given slot. More...
 
float GetSlot3Placeholder2 (uint8_t slot)
 Get the value for Slot 3 Placeholder 2 in a given slot. More...
 
float GetSlot3Placeholder3 (uint8_t slot)
 Get the value for Slot 3 Placeholder 3 in a given slot. More...
 
float GetAnalogPositionConversion ()
 Get the analog position conversion factor. More...
 
float GetAnalogVelocityConversion ()
 Get the analog velocity conversion factor. More...
 
uint16_t GetAnalogAverageDepth ()
 Get the analog average depth. More...
 
uint8_t GetAnalogSensorMode ()
 Get the analog sensor mode. More...
 
bool GetAnalogInverted ()
 Get the analog inversion state. More...
 
uint16_t GetAnalogSampleDelta ()
 Get the analog sample delta. More...
 
uint8_t GetDataPortConfig ()
 Get the data port configuration. More...
 
uint16_t GetAltEncoderCountsPerRev ()
 Get the alternate encoder counts per revolution. More...
 
uint8_t GetAltEncoderAverageDepth ()
 Get the alternate encoder average depth. More...
 
uint8_t GetAltEncoderSampleDelta ()
 Get the alternate encoder sample delta. More...
 
bool GetAltEncoderInverted ()
 Get the alternate encoder inversion state. More...
 
float GetAltEncoderPositionFactor ()
 Get the alternate encoder position factor. More...
 
float GetAltEncoderVelocityFactor ()
 Get the alternate encoder velocity factor. More...
 
float GetDutyCyclePositionFactor ()
 Get the duty cycle position factor. More...
 
float GetDutyCycleVelocityFactor ()
 Get the duty cycle velocity factor. More...
 
bool GetDutyCycleInverted ()
 Get the duty cycle inversion state. More...
 
uint8_t GetDutyCycleAverageDepth ()
 Get the duty cycle average depth. More...
 
uint8_t GetDutyCyclePrescalar ()
 Get the duty cycle prescalar. More...
 
float GetDutyCycleZeroOffset ()
 Get the duty cycle zero offset. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from SparkBase
static void Heartbeat ()
 Sends a heartbeat signal to keep all SPARK controllers active. More...
 

Detailed Description

A class for controlling REV Robotics SPARK MAX via CAN bus.

This class provides methods to configure, control, and monitor the SPARK MAX. It supports various control modes, parameter settings, and status readings.

Constructor & Destructor Documentation

◆ SparkMax()

SparkMax::SparkMax ( const std::string &  interfaceName,
uint8_t  deviceId 
)
explicit

◆ ~SparkMax()

SparkMax::~SparkMax ( )
overridedefault

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