REVLib - C++
rev::CANSparkLowLevel Class Reference

#include <CANSparkLowLevel.h>

Inherits frc::MotorController.

Inherited by rev::CANSparkBase.

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 , kStatus7 = 7
}
 
enum class  TelemetryID {
  kBusVoltage = 0 , kOutputCurrent , kVelocity , kPosition ,
  kIAccum , kAppliedOutput , kMotorTemp , kFaults ,
  kStickyFaults , kAnalogVoltage , kAnalogPosition , kAnalogVelocity ,
  kAltEncPosition , kAltEncVelocity , kTotalStreams
}
 
enum class  SparkModel { kSparkMax = 0 , kSparkFlex = 1 , kUnknown = 255 }
 

Public Member Functions

virtual ~CANSparkLowLevel ()
 
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)
 
REVLibError SetPeriodicFramePeriod (CANSparkMaxLowLevel::PeriodicFrame frame, int periodMs)
 
void SetPeriodicFrameTimeout (int timeoutMs)
 
void SetCANMaxRetries (int numRetries)
 
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 = c_SparkMax_kAPIMajorVersion
 
static const uint8_t kAPIMinorVersion = c_SparkMax_kAPIMinorVersion
 
static const uint8_t kAPIBuildVersion = c_SparkMax_kAPIBuildVersion
 
static const uint32_t kAPIVersion = c_SparkMax_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, CANSparkLowLevel::ControlType ctrl=ControlType::kDutyCycle, int pidSlot=0, double arbFeedforward=0, int arbFFUnits=0)
 
float GetSafeFloat (float f)
 

Protected Attributes

MotorType m_motorType
 
SparkModel m_expectedSparkModel
 
void * m_sparkMaxHandle
 

Friends

class CANAnalog
 
class CANDigitalInput
 
class CANEncoder
 
class CANPIDController
 
class CANSensor
 
class CANSparkBase
 
class CANSparkMax
 
class CANSparkFlex
 
class MotorFeedbackSensor
 
class SparkMaxAnalogSensor
 
class SparkMaxAlternateEncoder
 
class SparkMaxLimitSwitch
 
class SparkMaxPIDController
 
class SparkMaxRelativeEncoder
 
class SparkMaxAbsoluteEncoder
 
class SparkFlexExternalEncoder
 
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 
kStatus7 

◆ TelemetryID

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

◆ SparkModel

Enumerator
kSparkMax 
kSparkFlex 
kUnknown 

◆ FeedbackSensorType

enum class rev::CANSparkLowLevel::FeedbackSensorType
strongprotected
Enumerator
kNoSensor 
kHallSensor 
kQuadrature 
kSensorless 
kAnalog 
kAltQuadrature 
kDutyCycleSensor 

Constructor & Destructor Documentation

◆ ~CANSparkLowLevel()

rev::CANSparkLowLevel::~CANSparkLowLevel ( )
virtual

Closes the SPARK motor controller

Member Function Documentation

◆ GetFirmwareVersion() [1/2]

uint32_t rev::CANSparkLowLevel::GetFirmwareVersion ( )

Get the firmware version of the SPARK.

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

◆ GetFirmwareVersion() [2/2]

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

◆ GetFirmwareString()

std::string rev::CANSparkLowLevel::GetFirmwareString ( )

Get the firmware version of the SPARK as a string.

Returns
std::string Human readable firmware version string

◆ GetSerialNumber()

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

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

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

◆ GetDeviceId()

int rev::CANSparkLowLevel::GetDeviceId ( ) const

Get the configured Device ID of the SPARK.

Returns
int device ID

◆ GetInitialMotorType()

CANSparkLowLevel::MotorType rev::CANSparkLowLevel::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()

CANSparkLowLevel::MotorType rev::CANSparkLowLevel::GetMotorType ( )

Get the motor type setting for the SPARK.

Returns
MotorType Motor type setting

◆ SetPeriodicFramePeriod() [1/2]

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

Set the rate of transmission for periodic frames from the SPARK

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 Status7 - 250ms

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

Refer to the SPARK 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

◆ SetPeriodicFramePeriod() [2/2]

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

Set the rate of transmission for periodic frames from the SPARK

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 Status7 - 250ms

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

Refer to the SPARK 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
Deprecated:
Use SetPeriodicFramePeriod(CANSparkLowLevel::PeriodicFrame, int) instead

◆ SetPeriodicFrameTimeout()

void rev::CANSparkLowLevel::SetPeriodicFrameTimeout ( int  timeoutMs)

Set the amount of time to wait for a periodic status frame before returning a timeout error. This timeout will apply to all periodic status frames for the SPARK motor controller.

To prevent invalid timeout errors, the minimum timeout for a given periodic status is 2.1 times its period. To use the minimum timeout for all status frames, set timeoutMs to 0.

The default timeout is 500ms.

Parameters
timeoutMsThe timeout in milliseconds

◆ SetCANMaxRetries()

void rev::CANSparkLowLevel::SetCANMaxRetries ( int  numRetries)

Set the maximum number of times to retry an RTR CAN frame. This applies to calls such as SetParameter* and GetParameter* where a request is made to the SPARK motor controller and a response is expected. Anytime sending the request or receiving the response fails, it will retry the request a number of times, no more than the value set by this method. If an attempt succeeds, it will immediately return. The minimum number of retries is 0, where only a single attempt will be made and will return regardless of success or failure.

If the CAN timeout is set to 0 with CANSparkBase::setCANTimeout(), this will have no effect when getting the response from the SPARK motor controller fails. However, it will retry when sending the request from the roboRIO fails.

The default maximum is 5 retries.

Parameters
numRetriesThe maximum number of retries

◆ SetControlFramePeriodMs()

void rev::CANSparkLowLevel::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::CANSparkLowLevel::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()

void rev::CANSparkLowLevel::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()

void rev::CANSparkLowLevel::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()

CANSparkLowLevel::PeriodicStatus0 rev::CANSparkLowLevel::GetPeriodicStatus0 ( )
protected

◆ GetPeriodicStatus1()

CANSparkLowLevel::PeriodicStatus1 rev::CANSparkLowLevel::GetPeriodicStatus1 ( )
protected

◆ GetPeriodicStatus2()

CANSparkLowLevel::PeriodicStatus2 rev::CANSparkLowLevel::GetPeriodicStatus2 ( )
protected

◆ SetFollow()

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

◆ SetpointCommand()

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

◆ GetSafeFloat()

float rev::CANSparkLowLevel::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

◆ CANSparkBase

friend class CANSparkBase
friend

◆ CANSparkMax

friend class CANSparkMax
friend

◆ CANSparkFlex

friend class CANSparkFlex
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

◆ SparkFlexExternalEncoder

friend class SparkFlexExternalEncoder
friend

◆ ::ConfigBase

friend class ::ConfigBase
friend

Member Data Documentation

◆ kAPIMajorVersion

const uint8_t rev::CANSparkLowLevel::kAPIMajorVersion = c_SparkMax_kAPIMajorVersion
static

◆ kAPIMinorVersion

const uint8_t rev::CANSparkLowLevel::kAPIMinorVersion = c_SparkMax_kAPIMinorVersion
static

◆ kAPIBuildVersion

const uint8_t rev::CANSparkLowLevel::kAPIBuildVersion = c_SparkMax_kAPIBuildVersion
static

◆ kAPIVersion

const uint32_t rev::CANSparkLowLevel::kAPIVersion = c_SparkMax_kAPIVersion
static

◆ m_motorType

MotorType rev::CANSparkLowLevel::m_motorType
protected

◆ m_expectedSparkModel

SparkModel rev::CANSparkLowLevel::m_expectedSparkModel
protected

◆ m_sparkMaxHandle

void* rev::CANSparkLowLevel::m_sparkMaxHandle
protected

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