REVLib - C++
rev::CANSparkMaxLowLevel Class Reference

#include <CANSparkMaxLowLevel.h>

Inherits frc::MotorController.

Inherited by rev::CANSparkMax.

Classes

struct  FollowConfig
 
struct  FollowConfigBits
 
struct  PeriodicStatus0
 
struct  PeriodicStatus1
 
struct  PeriodicStatus2
 
struct  TelemetryMessage
 

Public Types

enum class  MotorType { kBrushed = 0 , kBrushless = 1 }
 
enum class  ControlType {
  kDutyCycle = 0 , kVelocity = 1 , kVoltage = 2 , kPosition = 3 ,
  kSmartMotion = 4 , kCurrent = 5 , kSmartVelocity = 6
}
 
enum class  ParameterStatus {
  kOK = 0 , kInvalidID = 1 , kMismatchType = 2 , kAccessMode = 3 ,
  kInvalid = 4 , kNotImplementedDeprecated = 5
}
 
enum class  PeriodicFrame {
  kStatus0 = 0 , kStatus1 = 1 , kStatus2 = 2 , kStatus3 = 3 ,
  kStatus4 = 4 , kStatus5 = 5 , kStatus6 = 6
}
 
enum class  TelemetryID {
  kBusVoltage = 0 , kOutputCurrent , kVelocity , kPosition ,
  kIAccum , kAppliedOutput , kMotorTemp , kFaults ,
  kStickyFaults , kAnalogVoltage , kAnalogPosition , kAnalogVelocity ,
  kAltEncPosition , kAltEncVelocity , kTotalStreams
}
 

Public Member Functions

virtual ~CANSparkMaxLowLevel ()
 
uint32_t GetFirmwareVersion ()
 
uint32_t GetFirmwareVersion (bool &isDebugBuild)
 
std::string GetFirmwareString ()
 
std::vector< uint8_t > GetSerialNumber ()
 
int GetDeviceId () const
 
MotorType GetInitialMotorType ()
 
MotorType GetMotorType ()
 
REVLibError SetPeriodicFramePeriod (PeriodicFrame frame, int periodMs)
 
void SetControlFramePeriodMs (int periodMs)
 
REVLibError 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 Types

enum class  FeedbackSensorType {
  kNoSensor = 0 , kHallSensor = 1 , kQuadrature = 2 , kSensorless = 3 ,
  kAnalog = 4 , kAltQuadrature = 5 , kDutyCycleSensor = 6
}
 

Protected Member Functions

PeriodicStatus0 GetPeriodicStatus0 ()
 
PeriodicStatus1 GetPeriodicStatus1 ()
 
PeriodicStatus2 GetPeriodicStatus2 ()
 
REVLibError SetFollow (FollowConfig config)
 
REVLibError SetpointCommand (double value, CANSparkMaxLowLevel::ControlType ctrl=ControlType::kDutyCycle, int pidSlot=0, double arbFeedforward=0, int arbFFUnits=0)
 
float GetSafeFloat (float f)
 

Protected Attributes

MotorType m_motorType
 
void * m_sparkMaxHandle
 

Friends

class CANAnalog
 
class CANDigitalInput
 
class CANEncoder
 
class CANPIDController
 
class CANSensor
 
class CANSparkMax
 
class MotorFeedbackSensor
 
class SparkMaxAnalogSensor
 
class SparkMaxAlternateEncoder
 
class SparkMaxLimitSwitch
 
class SparkMaxPIDController
 
class SparkMaxRelativeEncoder
 
class SparkMaxAbsoluteEncoder
 
class ::ConfigBase
 

Member Enumeration Documentation

◆ MotorType

Enumerator
kBrushed 
kBrushless 

◆ ControlType

Enumerator
kDutyCycle 
kVelocity 
kVoltage 
kPosition 
kSmartMotion 
kCurrent 
kSmartVelocity 

◆ ParameterStatus

Enumerator
kOK 
kInvalidID 
kMismatchType 
kAccessMode 
kInvalid 
kNotImplementedDeprecated 

◆ PeriodicFrame

Enumerator
kStatus0 
kStatus1 
kStatus2 
kStatus3 
kStatus4 
kStatus5 
kStatus6 

◆ TelemetryID

Enumerator
kBusVoltage 
kOutputCurrent 
kVelocity 
kPosition 
kIAccum 
kAppliedOutput 
kMotorTemp 
kFaults 
kStickyFaults 
kAnalogVoltage 
kAnalogPosition 
kAnalogVelocity 
kAltEncPosition 
kAltEncVelocity 
kTotalStreams 

◆ FeedbackSensorType

Enumerator
kNoSensor 
kHallSensor 
kQuadrature 
kSensorless 
kAnalog 
kAltQuadrature 
kDutyCycleSensor 

Constructor & Destructor Documentation

◆ ~CANSparkMaxLowLevel()

virtual rev::CANSparkMaxLowLevel::~CANSparkMaxLowLevel ( )
virtual

Closes the SPARK MAX Controller

Member Function Documentation

◆ GetFirmwareVersion() [1/2]

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

◆ GetFirmwareVersion() [2/2]

uint32_t rev::CANSparkMaxLowLevel::GetFirmwareVersion ( bool &  isDebugBuild)

◆ 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

◆ 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

◆ GetDeviceId()

int rev::CANSparkMaxLowLevel::GetDeviceId ( ) const

Get the configured Device ID of the SPARK MAX.

Returns
int device ID

◆ 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
Deprecated:
Use GetMotorType() instead

◆ GetMotorType()

MotorType rev::CANSparkMaxLowLevel::GetMotorType ( )

Get the motor type setting for the SPARK MAX.

Returns
MotorType Motor type setting

◆ SetPeriodicFramePeriod()

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

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

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

Defaults: Status0 - 10ms Status1 - 20ms Status2 - 20ms Status3 - 50ms Status4 - 20ms Status5 - 200ms Status6 - 200ms

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
frameWhich periodic frame to change the period of
periodMsThe rate the controller sends the frame to the controller.
Returns
REVLibError::kOk if successful

◆ SetControlFramePeriodMs()

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

Set the control frame send period for the native CAN Send thread. To disable periodic sends, set periodMs to 0.

Parameters
periodMsThe send period in milliseconds between 1ms and 100ms or set to 0 to disable periodic sends. Note this is not updated until the next call to Set() or SetReference().

◆ RestoreFactoryDefaults()

REVLibError 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
REVLibError::kOk if successful

◆ 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

◆ 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

◆ GetPeriodicStatus0()

PeriodicStatus0 rev::CANSparkMaxLowLevel::GetPeriodicStatus0 ( )
protected

◆ GetPeriodicStatus1()

PeriodicStatus1 rev::CANSparkMaxLowLevel::GetPeriodicStatus1 ( )
protected

◆ GetPeriodicStatus2()

PeriodicStatus2 rev::CANSparkMaxLowLevel::GetPeriodicStatus2 ( )
protected

◆ SetFollow()

REVLibError rev::CANSparkMaxLowLevel::SetFollow ( FollowConfig  config)
protected

◆ SetpointCommand()

REVLibError rev::CANSparkMaxLowLevel::SetpointCommand ( double  value,
CANSparkMaxLowLevel::ControlType  ctrl = ControlType::kDutyCycle,
int  pidSlot = 0,
double  arbFeedforward = 0,
int  arbFFUnits = 0 
)
protected

◆ GetSafeFloat()

float rev::CANSparkMaxLowLevel::GetSafeFloat ( float  f)
protected

Friends And Related Function Documentation

◆ CANAnalog

friend class CANAnalog
friend

◆ CANDigitalInput

friend class CANDigitalInput
friend

◆ CANEncoder

friend class CANEncoder
friend

◆ CANPIDController

friend class CANPIDController
friend

◆ CANSensor

friend class CANSensor
friend

◆ CANSparkMax

friend class CANSparkMax
friend

◆ MotorFeedbackSensor

friend class MotorFeedbackSensor
friend

◆ SparkMaxAnalogSensor

friend class SparkMaxAnalogSensor
friend

◆ SparkMaxAlternateEncoder

friend class SparkMaxAlternateEncoder
friend

◆ SparkMaxLimitSwitch

friend class SparkMaxLimitSwitch
friend

◆ SparkMaxPIDController

friend class SparkMaxPIDController
friend

◆ SparkMaxRelativeEncoder

friend class SparkMaxRelativeEncoder
friend

◆ SparkMaxAbsoluteEncoder

friend class SparkMaxAbsoluteEncoder
friend

◆ ::ConfigBase

friend class ::ConfigBase
friend

Member Data Documentation

◆ kAPIMajorVersion

const uint8_t rev::CANSparkMaxLowLevel::kAPIMajorVersion
static

◆ kAPIMinorVersion

const uint8_t rev::CANSparkMaxLowLevel::kAPIMinorVersion
static

◆ kAPIBuildVersion

const uint8_t rev::CANSparkMaxLowLevel::kAPIBuildVersion
static

◆ kAPIVersion

const uint32_t rev::CANSparkMaxLowLevel::kAPIVersion
static

◆ m_motorType

MotorType rev::CANSparkMaxLowLevel::m_motorType
protected

◆ m_sparkMaxHandle

void* rev::CANSparkMaxLowLevel::m_sparkMaxHandle
protected

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