REVLib - C++
|
#include <SparkMaxPIDController.h>
Inherits rev::CANPIDController.
Inherited by rev::SparkPIDController.
Public Types | |
enum class | AccelStrategy { kTrapezoidal = 0 , kSCurve = 1 } |
enum class | ArbFFUnits { kVoltage = 0 , kPercentOut = 1 } |
Public Member Functions | |
SparkMaxPIDController (SparkMaxPIDController &&)=default | |
SparkMaxPIDController & | operator= (SparkMaxPIDController &&)=default |
SparkMaxPIDController (const SparkMaxPIDController &rhs)=default | |
~SparkMaxPIDController () override=default | |
REVLibError | SetReference (double value, CANSparkLowLevel::ControlType ctrl, int pidSlot=0, double arbFeedforward=0, SparkMaxPIDController::ArbFFUnits arbFFUnits=ArbFFUnits::kVoltage) |
REVLibError | SetReference (double value, CANSparkMaxLowLevel::ControlType ctrl, int pidSlot=0, double arbFeedforward=0, SparkMaxPIDController::ArbFFUnits arbFFUnits=ArbFFUnits::kVoltage) |
REVLibError | SetReference (double value, ControlType ctrl, int pidSlot=0, double arbFeedforward=0, CANPIDController::ArbFFUnits arbFFUnits=CANPIDController::ArbFFUnits::kVoltage) override |
REVLibError | SetP (double gain, int slotID=0) override |
REVLibError | SetI (double gain, int slotID=0) override |
REVLibError | SetD (double gain, int slotID=0) override |
REVLibError | SetDFilter (double gain, int slotID=0) override |
REVLibError | SetFF (double gain, int slotID=0) override |
REVLibError | SetIZone (double IZone, int slotID=0) override |
REVLibError | SetOutputRange (double min, double max, int slotID=0) override |
double | GetP (int slotID=0) const override |
double | GetI (int slotID=0) const override |
double | GetD (int slotID=0) const override |
double | GetDFilter (int slotID=0) const override |
double | GetFF (int slotID=0) const override |
double | GetIZone (int slotID=0) const override |
double | GetOutputMin (int slotID=0) const override |
double | GetOutputMax (int slotID=0) const override |
REVLibError | SetSmartMotionMaxVelocity (double maxVel, int slotID=0) override |
REVLibError | SetSmartMotionMaxAccel (double maxAccel, int slotID=0) override |
REVLibError | SetSmartMotionMinOutputVelocity (double minVel, int slotID=0) override |
REVLibError | SetSmartMotionAllowedClosedLoopError (double allowedErr, int slotID=0) override |
REVLibError | SetSmartMotionAccelStrategy (SparkMaxPIDController::AccelStrategy accelStrategy, int slotID=0) |
REVLibError | SetSmartMotionAccelStrategy (CANPIDController::AccelStrategy accelStrategy, int slotID=0) override |
double | GetSmartMotionMaxVelocity (int slotID=0) const override |
double | GetSmartMotionMaxAccel (int slotID=0) const override |
double | GetSmartMotionMinOutputVelocity (int slotID=0) const override |
double | GetSmartMotionAllowedClosedLoopError (int slotID=0) const override |
AccelStrategy | GetSmartMotionAccelStrategy (int slotID=0) const |
REVLibError | SetIMaxAccum (double iMaxAccum, int slotID=0) override |
double | GetIMaxAccum (int slotID=0) const override |
REVLibError | SetIAccum (double iAccum) override |
double | GetIAccum () const override |
REVLibError | SetFeedbackDevice (const CANSensor &sensor) override |
REVLibError | SetPositionPIDWrappingEnabled (bool enable) |
REVLibError | SetPositionPIDWrappingMaxInput (double value) |
REVLibError | SetPositionPIDWrappingMinInput (double value) |
bool | GetPositionPIDWrappingEnabled () const override |
double | GetPositionPIDWrappingMaxInput () const override |
double | GetPositionPIDWrappingMinInput () const override |
Friends | |
class | CANSparkBase |
class | SparkPIDController |
|
strong |
Acceleration strategy used by Smart Motion
Enumerator | |
---|---|
kTrapezoidal | |
kSCurve |
|
strong |
Units for arbitrary feed-forward
Enumerator | |
---|---|
kVoltage | |
kPercentOut |
|
default |
|
default |
|
overridedefault |
|
default |
REVLibError SparkMaxPIDController::SetReference | ( | double | value, |
CANSparkLowLevel::ControlType | ctrl, | ||
int | pidSlot = 0 , |
||
double | arbFeedforward = 0 , |
||
SparkMaxPIDController::ArbFFUnits | arbFFUnits = ArbFFUnits::kVoltage |
||
) |
Set the controller reference value based on the selected control mode.
value | The value to set depending on the control mode. For basic duty cycle control this should be a value between -1 and 1 Otherwise: Voltage Control: Voltage (volts) Velocity Control: Velocity (RPM) Position Control: Position (Rotations) Current Control: Current (Amps). The units can be changed for position and velocity by a scale factor using setPositionConversionFactor(). |
ctrl | Is the control type |
pidSlot | for this command |
arbFeedforward | A value from -32.0 to 32.0 which is a voltage applied to the motor after the result of the specified control mode. The units for the parameter is Volts. This value is set after the control mode, but before any current limits or ramp rates. |
REVLibError SparkMaxPIDController::SetReference | ( | double | value, |
CANSparkMaxLowLevel::ControlType | ctrl, | ||
int | pidSlot = 0 , |
||
double | arbFeedforward = 0 , |
||
SparkMaxPIDController::ArbFFUnits | arbFFUnits = ArbFFUnits::kVoltage |
||
) |
Set the controller reference value based on the selected control mode.
value | The value to set depending on the control mode. For basic duty cycle control this should be a value between -1 and 1 Otherwise: Voltage Control: Voltage (volts) Velocity Control: Velocity (RPM) Position Control: Position (Rotations) Current Control: Current (Amps). The units can be changed for position and velocity by a scale factor using setPositionConversionFactor(). |
ctrl | Is the control type |
pidSlot | for this command |
arbFeedforward | A value from -32.0 to 32.0 which is a voltage applied to the motor after the result of the specified control mode. The units for the parameter is Volts. This value is set after the control mode, but before any current limits or ramp rates. |
|
overridevirtual |
Set the controller reference value based on the selected control mode.
value | The value to set depending on the control mode. For basic duty cycle control this should be a value between -1 and 1 Otherwise: Voltage Control: Voltage (volts) Velocity Control: Velocity (RPM) Position Control: Position (Rotations) Current Control: Current (Amps). The units can be changed for position and velocity by a scale factor using setPositionConversionFactor(). |
ctrl | Is the control type |
pidSlot | for this command |
arbFeedforward | A value from -32.0 to 32.0 which is a voltage applied to the motor after the result of the specified control mode. The units for the parameter is Volts. This value is set after the control mode, but before any current limits or ramp rates. |
Implements rev::CANPIDController.
|
overridevirtual |
Set the Proportional Gain constant of the PIDF controller on the SPARK. This uses the Set Parameter API and should be used infrequently. The parameter does not persist unless burnFlash() is called. The recommended method to configure this parameter is to use the REV Hardware Client to tune and save parameters.
gain | The proportional gain value, must be positive |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Set the Integral Gain constant of the PIDF controller on the SPARK. This uses the Set Parameter API and should be used infrequently. The parameter does not persist unless burnFlash() is called. The recommended method to configure this parameter is to use the REV Hardware Client to tune and save parameters.
gain | The integral gain value, must be positive |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Set the Derivative Gain constant of the PIDF controller on the SPARK. This uses the Set Parameter API and should be used infrequently. The parameter does not persist unless burnFlash() is called. The recommended method to configure this parameter is to use the REV Hardware Client to tune and save parameters.
gain | The derivative gain value, must be positive |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Set the Derivative Filter constant of the PIDF controller on the SPARK. This uses the Set Parameter API and should be used infrequently. The parameter does not persist unless burnFlash() is called.
gain | The derivative filter value, must be a positive number between 0 and 1 |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Set the Feed-forward Gain constant of the PIDF controller on the SPARK. This uses the Set Parameter API and should be used infrequently. The parameter does not persist unless burnFlash() is called. The recommended method to configure this parameter is to use the REV Hardware Client to tune and save parameters.
gain | The feed-forward gain value |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Set the IZone range of the PIDF controller on the SPARK. This value specifies the range the |error| must be within for the integral constant to take effect.
This uses the Set Parameter API and should be used infrequently. The parameter does not persist unless burnFlash() is called. The recommended method to configure this parameter is to use the REV Hardware Client to tune and save parameters.
IZone | The IZone value, must be positive. Set to 0 to disable |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Set the min amd max output for the closed loop mode.
This uses the Set Parameter API and should be used infrequently. The parameter does not persist unless burnFlash() is called. The recommended method to configure this parameter is to use the REV Hardware Client to tune and save parameters.
min | Reverse power minimum to allow the controller to output |
max | Forward power maximum to allow the controller to output |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the Proportional Gain constant of the PIDF controller on the SPARK.
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)
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the Integral Gain constant of the PIDF controller on the SPARK.
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)
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the Derivative Gain constant of the PIDF controller on the SPARK.
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)
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the Derivative Filter constant of the PIDF controller on the SPARK.
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)
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the Feed-forward Gain constant of the PIDF controller on the SPARK.
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)
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the IZone constant of the PIDF controller on the SPARK.
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)
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the min output of the PIDF controller on the SPARK.
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)
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the max output of the PIDF controller on the SPARK.
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)
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Configure the maximum velocity of the SmartMotion mode. This is the velocity that is reached in the middle of the profile and is what the motor should spend most of its time at
maxVel | The maxmimum cruise velocity for the motion profile in RPM |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Configure the maximum acceleration of the SmartMotion mode. This is the accleration that the motor velocity will increase at until the max velocity is reached
maxAccel | The maxmimum acceleration for the motion profile in RPM per second |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Configure the mimimum velocity of the SmartMotion mode. Any requested velocities below this value will be set to 0.
minVel | The minimum velocity for the motion profile in RPM |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Configure the allowed closed loop error of SmartMotion mode. This value is how much deviation from your setpoint is tolerated and is useful in preventing oscillation around your setpoint.
allowedErr | The allowed deviation for your setpoint vs actual position in rotations |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
REVLibError SparkMaxPIDController::SetSmartMotionAccelStrategy | ( | SparkMaxPIDController::AccelStrategy | accelStrategy, |
int | slotID = 0 |
||
) |
NOTE: As of the 2022 FRC season, the firmware only supports the trapezoidal motion profiling acceleration strategy.
Configure the acceleration strategy used to control acceleration on the motor.
accelStrategy | The acceleration strategy to use for the automatically generated motion profile |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
|
overridevirtual |
NOTE: As of the 2022 FRC season, the firmware only supports the trapezoidal motion profiling acceleration strategy.
Configure the acceleration strategy used to control acceleration on the motor.
accelStrategy | The acceleration strategy to use for the automatically generated motion profile |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the maximum velocity of the SmartMotion mode. This is the velocity that is reached in the middle of the profile and is what the motor should spend most of its time at
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the maximum acceleration of the SmartMotion mode. This is the accleration that the motor velocity will increase at until the max velocity is reached
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the mimimum velocity of the SmartMotion mode. Any requested velocities below this value will be set to 0.
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the allowed closed loop error of SmartMotion mode. This value is how much deviation from your setpoint is tolerated and is useful in preventing oscillation around your setpoint.
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
SparkMaxPIDController::AccelStrategy SparkMaxPIDController::GetSmartMotionAccelStrategy | ( | int | slotID = 0 | ) | const |
Get the acceleration strategy used to control acceleration on the motor. The current strategy is trapezoidal motion profiling.
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
|
overridevirtual |
Configure the maximum I accumulator of the PID controller. This value is used to constrain the I accumulator to help manage integral wind-up
iMaxAccum | The max value to contrain the I accumulator to |
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Get the maximum I accumulator of the PID controller. This value is used to constrain the I accumulator to help manage integral wind-up
slotID | Is the gain schedule slot, the value is a number between 0 and 3. Each slot has its own set of gain values and can be changed in each control frame using SetReference(). |
Implements rev::CANPIDController.
|
overridevirtual |
Set the I accumulator of the PID controller. This is useful when wishing to force a reset on the I accumulator of the PID controller. You can also preset values to see how it will respond to certain I characteristics
To use this function, the controller must be in a closed loop control mode by calling setReference()
iAccum | The value to set the I accumulator to |
Implements rev::CANPIDController.
|
overridevirtual |
Get the I accumulator of the PID controller. This is useful when wishing to see what the I accumulator value is to help with PID tuning
Implements rev::CANPIDController.
|
overridevirtual |
Set the controller's feedback device.
The default feedback device is assumed to be the integrated encoder. This is used to changed to another feedback device for the controller, such as an analog sensor.
If there is a limited range on the feedback sensor that should be observed by the PIDController, it can be set by calling SetFeedbackSensorRange() on the sensor object.
sensor | The sensor to be used as a feedback device |
Implements rev::CANPIDController.
|
virtual |
Enable or disable PID Wrapping for position closed loop control
enable | Whether position PID wrapping should be enabled |
Implements rev::CANPIDController.
|
virtual |
Set the maximum input value for PID Wrapping with position closed loop control
value | The maximum input value |
Implements rev::CANPIDController.
|
virtual |
Set the minimum input value for PID Wrapping with position closed loop control
value | The minimum input value |
Implements rev::CANPIDController.
|
overridevirtual |
Get whether or not PID Wrapping for position closed loop control is enabled
Implements rev::CANPIDController.
|
overridevirtual |
Get the maximum input value for PID Wrapping with position closed loop control
Implements rev::CANPIDController.
|
overridevirtual |
Get the minimum input value for PID Wrapping with position closed loop control
Implements rev::CANPIDController.
|
friend |
|
friend |