SPARK MAX - C++ Documentation
rev::CANSparkMaxLowLevel Class Reference

Inherits ErrorBase, and SpeedController.

Inherited by rev::CANSparkMax.

Classes

struct  FollowConfig
 
struct  PeriodicStatus0
 
struct  PeriodicStatus1
 
struct  PeriodicStatus2
 

Public Types

enum  MotorType { kBrushed = 0, kBrushless = 1 }
 
enum  ParameterStatus {
  kOK = 0, kInvalidID = 1, kMismatchType = 2, kAccessMode = 3,
  kInvalid = 4, kNotImplementedDeprecated = 5
}
 
enum  PeriodicFrame { kStatus0 = 0, kStatus1 = 1, kStatus2 = 2 }
 

Public Member Functions

 CANSparkMaxLowLevel (int deviceID, MotorType type)
 
 ~CANSparkMaxLowLevel ()
 
uint32_t GetFirmwareVersion ()
 
uint32_t GetFirmwareVersion (bool &isDebugBuild)
 
std::string GetFirmwareString ()
 
std::vector< uint8_t > GetSerialNumber ()
 
int GetDeviceId () const
 
MotorType GetInitialMotorType ()
 
CANError SetMotorType (MotorType type)
 
MotorType GetMotorType ()
 
CANError SetPeriodicFramePeriod (PeriodicFrame frame, int periodMs)
 
void SetControlFramePeriodMs (int periodMs)
 
CANError RestoreFactoryDefaults (bool persist=false)
 

Static Public Member Functions

static void EnableExternalUSBControl (bool enable)
 
static void SetEnable (bool enable)
 

Static Public Attributes

static const uint8_t kAPIMajorVersion
 
static const uint8_t kAPIMinorVersion
 
static const uint8_t kAPIBuildVersion
 
static const uint32_t kAPIVersion
 

Protected Member Functions

CANError SetEncPosition (double value)
 
CANError SetIAccum (double value)
 
PeriodicStatus0 GetPeriodicStatus0 ()
 
PeriodicStatus1 GetPeriodicStatus1 ()
 
PeriodicStatus2 GetPeriodicStatus2 ()
 
CANError SetFollow (FollowConfig config)
 
CANError FollowerInvert (bool invert)
 
CANError SetpointCommand (double value, ControlType ctrl=ControlType::kDutyCycle, int pidSlot=0, double arbFeedforward=0, int arbFFUnits=0)
 
float GetSafeFloat (float f)
 

Protected Attributes

void * m_sparkMax
 
MotorType m_motorType
 

Friends

class CANPIDController
 
class CANDigitalInput
 
class CANEncoder
 
class CANAnalog
 

Constructor & Destructor Documentation

◆ CANSparkMaxLowLevel()

rev::CANSparkMaxLowLevel::CANSparkMaxLowLevel ( int  deviceID,
MotorType  type 
)
explicit

Create a new SPARK MAX Controller

Parameters
deviceIDThe device ID.
typeThe 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.

◆ ~CANSparkMaxLowLevel()

rev::CANSparkMaxLowLevel::~CANSparkMaxLowLevel ( )

Closes the SPARK MAX Controller

Member Function Documentation

◆ EnableExternalUSBControl()

static void rev::CANSparkMaxLowLevel::EnableExternalUSBControl ( bool  enable)
static

Allow external controllers to recieve control commands over USB. For example, a configuration where the heartbeat (and enable/disable) is sent by the main controller, but control frames are sent by other CAN devices over USB.

This is global for all controllers on the same bus.

This does not disable sending control frames from this device. To prevent conflicts, do not enable this feature and also send Set() for SetReference() from the controllers you wish to control.

Parameters
enableEnable or disable external control

◆ GetDeviceId()

int rev::CANSparkMaxLowLevel::GetDeviceId ( ) const

Get the configured Device ID of the SPARK MAX.

Returns
int device ID

◆ GetFirmwareString()

std::string rev::CANSparkMaxLowLevel::GetFirmwareString ( )

Get the firmware version of the SPARK MAX as a string.

Returns
std::string Human readable firmware version string

◆ GetFirmwareVersion()

uint32_t rev::CANSparkMaxLowLevel::GetFirmwareVersion ( )

Get the firmware version of the SPARK MAX.

Returns
uint32_t Firmware version integer. Value is represented as 4 bytes, Major.Minor.Build H.Build L

◆ GetInitialMotorType()

MotorType rev::CANSparkMaxLowLevel::GetInitialMotorType ( )

Get the motor type setting from when the SparkMax was created.

This does not use the Get Parameter API which means it does not read what motor type is stored on the SparkMax itself. Instead, it reads the stored motor type from when the SparkMax object was first created.

Returns
MotorType Motor type setting

◆ GetMotorType()

MotorType rev::CANSparkMaxLowLevel::GetMotorType ( )

Get the motor type 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
MotorType Motor type setting

◆ GetSerialNumber()

std::vector<uint8_t> rev::CANSparkMaxLowLevel::GetSerialNumber ( )

Get the unique serial number of the SPARK MAX. Currently not implemented.

Returns
std::vector<uint8_t> Vector of bytes representig the unique serial number

◆ RestoreFactoryDefaults()

CANError rev::CANSparkMaxLowLevel::RestoreFactoryDefaults ( bool  persist = false)

Restore motor controller parameters to factory default

Parameters
persistIf true, burn the flash with the factory default parameters
Returns
CANError Set to CANError::kOk if successful

◆ SetControlFramePeriodMs()

void rev::CANSparkMaxLowLevel::SetControlFramePeriodMs ( int  periodMs)

Set the control frame send period for the native CAN Send thread.

Parameters
periodMsThe send period in milliseconds between 1ms and 100ms

◆ SetEnable()

static void rev::CANSparkMaxLowLevel::SetEnable ( bool  enable)
static

Send enabled or disabled command to controllers. This is global for all controllers on the same bus, and will only work for non-roboRIO targets in non-competiton use. This function will also not work if a roboRIO is present on the CAN bus.

This does not disable sending control frames from this device. To prevent conflicts, do not enable this feature and also send Set() for SetReference() from the controllers you wish to control.

Parameters
enableEnable or disable external control

◆ SetMotorType()

CANError rev::CANSparkMaxLowLevel::SetMotorType ( MotorType  type)

Set the motor type connected to the SPARK MAX.

This uses the Set Parameter API and should be used infrequently. The parameter does not presist unless burnFlash() is called. The recommended method to configure this parameter is to use the SPARK MAX GUI to tune and save parameters.

Parameters
typeThe type of motor 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.
Returns
CANError Set to CANError::kOk if successful

◆ SetPeriodicFramePeriod()

CANError rev::CANSparkMaxLowLevel::SetPeriodicFramePeriod ( PeriodicFrame  frame,
int  periodMs 
)

Set the rate of transmission for periodic frames from the SPARK MAX

Each motor controller sends back three status frames with different data at set rates. Use this function to change the default rates.

Defaults: Status0 - 10ms Status1 - 20ms Status2 - 50ms

This value is not stored in the FLASH after calling burnFlash() and is reset on powerup.

Refer to the SPARK MAX reference manual on details for how and when to configure this parameter.

Parameters
frameIDThe frame ID can be one of PeriodicFrame type
periodMsThe rate the controller sends the frame to the controller.
Returns
CANError Set to CANError::kOk if successful

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