REVLib - C++
rev::spark::SparkMax Class Reference

#include <SparkMax.h>

Inherits rev::spark::SparkBase.

Public Member Functions

 SparkMax (int deviceID, MotorType type)
 
 ~SparkMax () override=default
 
REVLibError Configure (SparkBaseConfig &config, ResetMode resetMode, PersistMode persistMode) override
 
SparkMaxAlternateEncoderGetAlternateEncoder ()
 
SparkAbsoluteEncoderGetAbsoluteEncoder () override
 
SparkLimitSwitchGetForwardLimitSwitch () override
 
SparkLimitSwitchGetReverseLimitSwitch () override
 
- Public Member Functions inherited from rev::spark::SparkBase
 ~SparkBase () override=default
 
void Set (double speed) override
 
void SetVoltage (units::volt_t output) override
 
double Get () const override
 
void SetInverted (bool isInverted) override
 
bool GetInverted () const override
 
void Disable () override
 
void StopMotor () override
 
SparkRelativeEncoderGetEncoder ()
 
SparkAnalogSensorGetAnalog ()
 
SparkClosedLoopControllerGetClosedLoopController ()
 
rev::REVLibError ResumeFollowerMode ()
 
rev::REVLibError PauseFollowerMode ()
 
bool IsFollower ()
 
bool HasActiveFault ()
 
bool HasStickyFault ()
 
bool HasActiveWarning ()
 
bool HasStickyWarning ()
 
Faults GetFaults ()
 
Faults GetStickyFaults ()
 
Warnings GetWarnings ()
 
Warnings GetStickyWarnings ()
 
double GetBusVoltage ()
 
double GetAppliedOutput ()
 
double GetOutputCurrent ()
 
double GetMotorTemperature ()
 
REVLibError ClearFaults ()
 
REVLibError SetCANTimeout (int milliseconds)
 
REVLibError GetLastError ()
 
- Public Member Functions inherited from rev::spark::SparkLowLevel
virtual ~SparkLowLevel ()
 
uint32_t GetFirmwareVersion ()
 
uint32_t GetFirmwareVersion (bool &isDebugBuild)
 
std::string GetFirmwareString ()
 
std::vector< uint8_t > GetSerialNumber ()
 
int GetDeviceId () const
 
MotorType GetMotorType ()
 
void SetPeriodicFrameTimeout (int timeoutMs)
 
void SetCANMaxRetries (int numRetries)
 
void SetControlFramePeriodMs (int periodMs)
 
void CreateSimFaultManager ()
 

Public Attributes

SparkMaxConfigAccessor configAccessor
 

Friends

class SparkMaxAlternateEncoder
 

Additional Inherited Members

- Public Types inherited from rev::spark::SparkBase
enum class  IdleMode { kCoast = 0 , kBrake = 1 }
 
enum class  SoftLimitDirection { kForward , kReverse }
 
enum class  ResetMode { kNoResetSafeParameters , kResetSafeParameters }
 
enum class  PersistMode { kNoPersistParameters , kPersistParameters }
 
- Public Types inherited from rev::spark::SparkLowLevel
enum class  MotorType { kBrushed = 0 , kBrushless = 1 }
 
enum class  ControlType {
  kDutyCycle = 0 , kVelocity = 1 , kVoltage = 2 , kPosition = 3 ,
  kSmartMotion = 4 , kCurrent = 5 , kSmartVelocity = 6 , kMAXMotionPositionControl = 7 ,
  kMAXMotionVelocityControl = 8
}
 
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  SparkModel { kSparkMax = 0 , kSparkFlex = 1 , kUnknown = 255 }
 
- Static Public Attributes inherited from rev::spark::SparkLowLevel
static const uint8_t kAPIMajorVersion = c_Spark_kAPIMajorVersion
 
static const uint8_t kAPIMinorVersion = c_Spark_kAPIMinorVersion
 
static const uint8_t kAPIBuildVersion = c_Spark_kAPIBuildVersion
 
static const uint32_t kAPIVersion = c_Spark_kAPIVersion
 
- Protected Member Functions inherited from rev::spark::SparkBase
 SparkBase (int deviceID, MotorType type, SparkModel model)
 
SparkRelativeEncoder GetEncoderEvenIfAlreadyCreated ()
 
uint8_t GetMotorInterface ()
 
SparkBase::SparkModel GetSparkModel ()
 
- Protected Member Functions inherited from rev::spark::SparkLowLevel
PeriodicStatus0 GetPeriodicStatus0 ()
 
PeriodicStatus1 GetPeriodicStatus1 ()
 
PeriodicStatus2 GetPeriodicStatus2 ()
 
PeriodicStatus3 GetPeriodicStatus3 ()
 
PeriodicStatus4 GetPeriodicStatus4 ()
 
PeriodicStatus5 GetPeriodicStatus5 ()
 
PeriodicStatus6 GetPeriodicStatus6 ()
 
PeriodicStatus7 GetPeriodicStatus7 ()
 
REVLibError SetpointCommand (double value, SparkLowLevel::ControlType ctrl=ControlType::kDutyCycle, int pidSlot=0, double arbFeedforward=0, int arbFFUnits=0)
 
float GetSafeFloat (float f)
 
- Protected Attributes inherited from rev::spark::SparkBase
double m_setpoint {0.0}
 
SparkRelativeEncoder m_RelativeEncoder
 
std::atomic< bool > m_relativeEncoderCreated {false}
 
SparkAnalogSensor m_AnalogSensor
 
std::atomic< bool > m_analogSensorCreated {false}
 
SparkAbsoluteEncoder m_AbsoluteEncoder
 
std::atomic< bool > m_absoluteEncoderCreated {false}
 
SparkClosedLoopController m_ClosedLoopController
 
std::atomic< bool > m_closedLoopControllerCreated {false}
 
SparkLimitSwitch m_ForwardLimitSwitch
 
std::atomic< bool > m_forwardLimitSwitchCreated {false}
 
SparkLimitSwitch m_ReverseLimitSwitch
 
std::atomic< bool > m_reverseLimitSwitchCreated {false}
 
- Protected Attributes inherited from rev::spark::SparkLowLevel
MotorType m_motorType
 
SparkModel m_expectedSparkModel
 
void * m_sparkMaxHandle
 

Constructor & Destructor Documentation

◆ SparkMax()

SparkMax::SparkMax ( int  deviceID,
MotorType  type 
)
explicit

Create a new object to control a SPARK MAX motor Controller

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

◆ ~SparkMax()

rev::spark::SparkMax::~SparkMax ( )
overridedefault

Closes the SPARK MAX Controller

Member Function Documentation

◆ Configure()

rev::REVLibError SparkMax::Configure ( SparkBaseConfig config,
ResetMode  resetMode,
PersistMode  persistMode 
)
overridevirtual

***** Extended Functions ****** Set the configuration for the SPARK.

If 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 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
configThe desired SPARK configuration
resetModeWhether to reset safe parameters before setting the configuration
persistModeWhether to persist the parameters after setting the configuration
Returns
REVLibError::kOk if successful

Reimplemented from rev::spark::SparkBase.

◆ GetAlternateEncoder()

SparkMaxAlternateEncoder & SparkMax::GetAlternateEncoder ( )

Returns an object for interfacing with a quadrature encoder connected to the alternate encoder mode data port pins. These are defined as:

Pin 4 (Forward Limit Switch): Index Pin 6 (Multi-function): Encoder A Pin 8 (Reverse Limit Switch): Encoder B

This call will disable support for the limit switch inputs.

◆ GetAbsoluteEncoder()

SparkAbsoluteEncoder & SparkMax::GetAbsoluteEncoder ( )
overridevirtual

Returns an object for interfacing with a connected absolute encoder.

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

Reimplemented from rev::spark::SparkBase.

◆ GetForwardLimitSwitch()

SparkLimitSwitch & SparkMax::GetForwardLimitSwitch ( )
overridevirtual

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.

Reimplemented from rev::spark::SparkBase.

◆ GetReverseLimitSwitch()

SparkLimitSwitch & SparkMax::GetReverseLimitSwitch ( )
overridevirtual

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.

Reimplemented from rev::spark::SparkBase.

Friends And Related Function Documentation

◆ SparkMaxAlternateEncoder

friend class SparkMaxAlternateEncoder
friend

Member Data Documentation

◆ configAccessor

SparkMaxConfigAccessor rev::spark::SparkMax::configAccessor

Accessor for SPARK parameter values. This object contains fields and methods to retrieve parameters that have been applied to the device. To set parameters, see SparkBaseConfig and SparkBase::Configure.

NOTE: This uses calls that are blocking to retrieve parameters and should be used infrequently.


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