|
REVLib - C++
|
#include <SparkBase.h>
Classes | |
| struct | Faults |
| struct | Warnings |
Public Types | |
| 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 , kCurrent = 4 , kMAXMotionPositionControl = 5 , kMAXMotionVelocityControl = 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 , kStatus8 = 8 , kStatus9 = 9 } |
| enum class | SparkModel { kUnknown = 0 , kSparkFlex = 1 , kSparkMax = 2 } |
Protected Member Functions | |
| SparkBase (int busID, int deviceID, MotorType type, SparkModel model) | |
| SparkRelativeEncoder | GetEncoderEvenIfAlreadyCreated () |
| uint8_t | GetMotorInterface () |
| SparkBase::SparkModel | GetSparkModel () |
Protected Member Functions inherited from rev::spark::SparkLowLevel | |
| REVLibError | SetpointCommand (double value, SparkLowLevel::ControlType ctrl=ControlType::kDutyCycle, ClosedLoopSlot pidSlot=ClosedLoopSlot::kSlot0, double arbFeedforward=0, int arbFFUnits=0) |
| float | GetSafeFloat (float f) |
Protected Attributes | |
| 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} |
| SparkSoftLimit | m_ForwardSoftLimit |
| std::atomic< bool > | m_forwardSoftLimitCreated {false} |
| SparkSoftLimit | m_ReverseSoftLimit |
| std::atomic< bool > | m_reverseSoftLimitCreated {false} |
Protected Attributes inherited from rev::spark::SparkLowLevel | |
| MotorType | m_motorType |
| SparkModel | m_expectedSparkModel |
| void * | m_sparkMaxHandle {} |
Friends | |
| class | SparkMax |
| class | SparkFlex |
| class | SparkLimitSwitch |
| class | SparkSoftLimit |
| class | SparkRelativeEncoder |
| class | SparkMaxAlternateEncoder |
| class | SparkAbsoluteEncoder |
| class | SparkSim |
| class | SparkClosedLoopController |
| class | ::ConfigBase |
Additional Inherited Members | |
Static Public Attributes inherited from rev::spark::SparkLowLevel | |
| static const uint16_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 |
|
strong |
|
strong |
|
strong |
|
strong |
|
overridedefault |
Closes the SPARK motor controller
|
protected |
Create a new object to control a SPARK motor Controller
| busID | The CAN bus ID this device will be on. |
| deviceID | The device ID. |
| type | The 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. |
| model | The model (kSparkMax or kSparkFlex) of the motor. |
|
override |
Sets the throttle of the motor controller.
| throttle | The throttle where -1 indicates full reverse and 1 indicates full forward. |
|
override |
Sets the voltage output of the SpeedController. This is equivalent to a call to SetReference(output, SparkBase::ControlType::kVoltage). The behavior of this call differs slightly from the WPILib documentation for this call since the device internally sets the desired voltage (not a compensation value). That means that this can be a 'set-and-forget' call.
| output | The voltage to output. |
|
override |
Gets the throttle of the motor controller.
|
override |
Common interface for inverting direction of a speed controller.
This call has no effect if the controller is a follower. To invert a follower, see the follow() method.
| isInverted | The state of inversion, true is inverted. |
|
override |
Common interface for returning the inversion state of a speed controller.
This call has no effect if the controller is a follower.
|
override |
Common interface for disabling a motor.
| void SparkBase::StopMotor | ( | ) |
Common interface to stop the motor until Set is called again.
|
virtual |
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.
| config | The desired SPARK configuration |
| resetMode | Whether to reset safe parameters before setting the configuration |
| persistMode | Whether to persist the parameters after setting the configuration |
Reimplemented in rev::spark::SparkMax.
|
virtual |
Set the configuration for the SPARK without waiting for a response.
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.
NOTE: This method will immediately return REVLibError::kOk and the action will be done in the background. Any errors that occur will be reported to the driver station.
| config | The desired SPARK configuration |
| resetMode | Whether to reset safe parameters before setting the configuration |
| persistMode | Whether to persist the parameters after setting the configuration |
| SparkRelativeEncoder & SparkBase::GetEncoder | ( | ) |
Returns an object for interfacing with the encoder connected to the encoder pins or front port of the SPARK MAX or the motor interface of the SPARK Flex.
| SparkAnalogSensor & SparkBase::GetAnalog | ( | ) |
Returns an object for interfacing with a connected analog sensor. By default, the mode is set to kAbsolute, thus treating the sensor as an absolute sensor.
|
virtual |
Returns an object for interfacing with a connected absolute encoder.
The default encoder type is assumed to be a duty cycle sensor.
Reimplemented in rev::spark::SparkMax.
| SparkClosedLoopController & SparkBase::GetClosedLoopController | ( | ) |
Returns an object for interfacing with the integrated Closed Loop Controller.
|
virtual |
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 in rev::spark::SparkMax.
|
virtual |
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 in rev::spark::SparkMax.
| SparkSoftLimit & SparkBase::GetForwardSoftLimit | ( | ) |
Returns an object for interfacing with the forward soft limit switch
| SparkSoftLimit & SparkBase::GetReverseSoftLimit | ( | ) |
Returns an object for interfacing with the reverse soft limit switch
| rev::REVLibError SparkBase::ResumeFollowerMode | ( | ) |
Resume follower mode if the SPARK has a valid follower mode config.
NOTE: Follower mode will start automatically upon configuring follower mode. If the SPARK experiences a power cycle and has follower mode configured, follower mode will automatically restart. This method is only useful after PauseFollowerMode() has been called.
| rev::REVLibError SparkBase::ResumeFollowerModeAsync | ( | ) |
Resume follower mode if the SPARK has a valid follower mode config without waiting for a response.
NOTE: Follower mode will start automatically upon configuring follower mode. If the SPARK experiences a power cycle and has follower mode configured, follower mode will automatically restart. This method is only useful after PauseFollowerMode() has been called.
NOTE: This method will immediately return REVLibError::kOk and the action will be done in the background. Any errors that occur will be reported to the driver station.
| rev::REVLibError SparkBase::PauseFollowerMode | ( | ) |
Pause follower mode.
NOTE: If the SPARK experiences a power cycle and has follower mode configured, follower mode will automatically restart.
| rev::REVLibError SparkBase::PauseFollowerModeAsync | ( | ) |
Pause follower mode without waiting for a response.
NOTE: If the SPARK experiences a power cycle and has follower mode configured, follower mode will automatically restart.
NOTE: This method will immediately return REVLibError::kOk and the action will be done in the background. Any errors that occur will be reported to the driver station.
| Signal< bool > SparkBase::IsFollower | ( | ) | const |
Returns whether the controller is following another controller
| Signal< bool > SparkBase::HasActiveFault | ( | ) | const |
Get whether the SPARK has one or more active faults.
| Signal< bool > SparkBase::HasStickyFault | ( | ) | const |
Get whether the SPARK has one or more sticky faults.
| Signal< bool > SparkBase::HasActiveWarning | ( | ) | const |
Get whether the SPARK has one or more active warnings.
| Signal< bool > SparkBase::HasStickyWarning | ( | ) | const |
Get whether the SPARK has one or more sticky warnings.
| Signal< SparkBase::Faults > SparkBase::GetFaults | ( | ) | const |
Get the active faults that are currently present on the SPARK. Faults are fatal errors that prevent the motor from running.
| Signal< SparkBase::Faults > SparkBase::GetStickyFaults | ( | ) | const |
Get the sticky faults that were present on the SPARK at one point since the sticky faults were last cleared. Faults are fatal errors that prevent the motor from running.
Sticky faults can be cleared with SparkBase::ClearFaults().
| Signal< SparkBase::Warnings > SparkBase::GetWarnings | ( | ) | const |
Get the active warnings that are currently present on the SPARK. Warnings are non-fatal errors.
| Signal< SparkBase::Warnings > SparkBase::GetStickyWarnings | ( | ) | const |
Get the sticky warnings that were present on the SPARK at one point since the sticky warnings were last cleared. Warnings are non-fatal errors.
Sticky warnings can be cleared with SparkBase::clearFaults().
| Signal< double > SparkBase::GetBusVoltage | ( | ) | const |
Returns the voltage fed into the motor controller.
| Signal< double > SparkBase::GetAppliedOutput | ( | ) | const |
Simulation note: this value will not be updated during simulation unless SparkSim#iterate is called
Returns motor controller's output duty cycle.
| Signal< double > SparkBase::GetOutputCurrent | ( | ) | const |
Returns motor controller's output current in Amps.
| Signal< double > SparkBase::GetMotorTemperature | ( | ) | const |
Returns the motor temperature in Celsius.
| rev::REVLibError SparkBase::ClearFaults | ( | ) |
Clears all sticky faults.
| rev::REVLibError SparkBase::SetCANTimeout | ( | int | milliseconds | ) |
Sets the timeout duration for waiting for CAN responses from the device.
| milliseconds | The timeout in milliseconds. |
| rev::REVLibError SparkBase::GetLastError | ( | ) |
All device errors are tracked on a per thread basis for all devices in that thread. This is meant to be called immediately following another call that has the possibility of throwing an error to validate if an error has occurred.
|
protected |
|
protected |
Get the current motor interface for the SPARK.
|
protected |
Get the Model of this SPARK Device. Useful for determining if this is a Flex, MAX, or other device
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |