SparkMaxPIDController
- class rev.SparkMaxPIDController
Bases:
pybind11_object
- Deprecated:
Use SparkPIDController instead
- class AccelStrategy(value: int)
Bases:
pybind11_object
Acceleration strategy used by Smart Motion
- Deprecated:
Use SparkPIDController::AccelStrategy instead
Members:
kTrapezoidal
kSCurve
- kSCurve = <AccelStrategy.kSCurve: 1>
- kTrapezoidal = <AccelStrategy.kTrapezoidal: 0>
- property name
- property value
- class ArbFFUnits(value: int)
Bases:
pybind11_object
Units for arbitrary feed-forward
- Deprecated:
Use SparkPIDController::ArbFFUnits instead
Members:
kVoltage
kPercentOut
- kPercentOut = <ArbFFUnits.kPercentOut: 1>
- kVoltage = <ArbFFUnits.kVoltage: 0>
- property name
- property value
- getD(slotID: int = 0) float
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)
- Parameters:
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().
- Returns:
double D Gain value
- getDFilter(slotID: int = 0) float
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)
- Parameters:
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().
- Returns:
double D Filter value
- getFF(slotID: int = 0) float
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)
- Parameters:
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().
- Returns:
double F Gain value
- getI(slotID: int = 0) float
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)
- Parameters:
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().
- Returns:
double I Gain value
- getIAccum() float
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
- Returns:
The value of the I accumulator
- getIMaxAccum(slotID: int = 0) float
Get the maximum I accumulator of the PID controller. This value is used to constrain the I accumulator to help manage integral wind-up
- Parameters:
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().
- Returns:
The max value to contrain the I accumulator to
- getIZone(slotID: int = 0) float
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)
- Parameters:
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().
- Returns:
double IZone value
- getOutputMax(slotID: int = 0) float
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)
- Parameters:
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().
- Returns:
double max value
- getOutputMin(slotID: int = 0) float
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)
- Parameters:
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().
- Returns:
double min value
- getP(slotID: int = 0) float
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)
- Parameters:
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().
- Returns:
double P Gain value
- getPositionPIDWrappingEnabled() bool
Get whether or not PID Wrapping for position closed loop control is enabled
- Returns:
true if PID Wrapping is enabled
- getPositionPIDWrappingMaxInput() float
Get the maximum input value for PID Wrapping with position closed loop control
- Returns:
the maximum input value
- getPositionPIDWrappingMinInput() float
Get the minimum input value for PID Wrapping with position closed loop control
- Returns:
the minimum in put value
- getSmartMotionAccelStrategy(slotID: int = 0) rev._rev.SparkMaxPIDController.AccelStrategy
Get the acceleration strategy used to control acceleration on the motor. The current strategy is trapezoidal motion profiling.
- Parameters:
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().
- Returns:
The acceleration strategy to use for the automatically generated motion profile
- getSmartMotionAllowedClosedLoopError(slotID: int = 0) float
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.
- Parameters:
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().
- Returns:
The allowed deviation for your setpoint vs actual position in rotations
- getSmartMotionMaxAccel(slotID: int = 0) float
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
- Parameters:
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().
- Returns:
The maxmimum acceleration for the motion profile in RPM per second
- getSmartMotionMaxVelocity(slotID: int = 0) float
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
- Parameters:
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().
- Returns:
The maxmimum cruise velocity for the motion profile in RPM
- getSmartMotionMinOutputVelocity(slotID: int = 0) float
Get the mimimum velocity of the SmartMotion mode. Any requested velocities below this value will be set to 0.
- Parameters:
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().
- Returns:
The minimum velocity for the motion profile in RPM
- setD(gain: float, slotID: int = 0) rev._rev.REVLibError
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.
- 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().
- Returns:
REVLibError::kOk if successful
- setDFilter(gain: float, slotID: int = 0) rev._rev.REVLibError
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.
- Parameters:
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().
- Returns:
REVLibError::kOk if successful
- setFF(gain: float, slotID: int = 0) rev._rev.REVLibError
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.
- 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().
- Returns:
REVLibError::kOk if successful
- setFeedbackDevice(sensor: rev._rev.CANSensor) rev._rev.REVLibError
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.
- Parameters:
sensor – The sensor to be used as a feedback device
- Returns:
REVLibError::kOk if successful
- setI(gain: float, slotID: int = 0) rev._rev.REVLibError
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.
- 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().
- Returns:
REVLibError::kOk if successful
- setIAccum(iAccum: float) rev._rev.REVLibError
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()
- Parameters:
iAccum – The value to set the I accumulator to
- Returns:
REVLibError::kOk if successful
- setIMaxAccum(iMaxAccum: float, slotID: int = 0) rev._rev.REVLibError
Configure the maximum I accumulator of the PID controller. This value is used to constrain the I accumulator to help manage integral wind-up
- Parameters:
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().
- Returns:
REVLibError::kOk if successful
- setIZone(IZone: float, slotID: int = 0) rev._rev.REVLibError
Set the IZone range of the PIDF controller on the SPARK MAX. 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 presist unless
burnFlash()
is called. The recommended method to configure this parameter is to use the SPARK MAX GUI to tune and save parameters.- 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()
.
- Returns:
REVLibError.kOk if successful
- setOutputRange(min: float, max: float, slotID: int = 0) rev._rev.REVLibError
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.
- 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().
- Returns:
REVLibError::kOk if successful
- setP(gain: float, slotID: int = 0) rev._rev.REVLibError
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.
- 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().
- Returns:
REVLibError::kOk if successful
- setPositionPIDWrappingEnabled(enable: bool) rev._rev.REVLibError
Enable or disable PID Wrapping for position closed loop control
- Parameters:
enable – Whether position PID wrapping should be enabled
- Returns:
REVLibError::kOk if successful
- setPositionPIDWrappingMaxInput(value: float) rev._rev.REVLibError
Set the maximum input value for PID Wrapping with position closed loop control
- Parameters:
value – The maximum input value
- Returns:
REVLibError::kOk if successful
- setPositionPIDWrappingMinInput(value: float) rev._rev.REVLibError
Set the minimum input value for PID Wrapping with position closed loop control
- Parameters:
value – The minimum input value
- Returns:
REVLibError::kOk if successful
- setReference(value: float, ctrl: rev._rev.CANSparkLowLevel.ControlType, pidSlot: int = 0, arbFeedforward: float = 0, arbFFUnits: rev._rev.SparkMaxPIDController.ArbFFUnits = <ArbFFUnits.kVoltage: 0>) rev._rev.REVLibError
Set the controller reference value based on the selected control mode.
- Parameters:
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.
- Returns:
REVLibError::kOk if successful
- setSmartMotionAccelStrategy(accelStrategy: rev._rev.SparkMaxPIDController.AccelStrategy, slotID: int = 0) rev._rev.REVLibError
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.
- Parameters:
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().
- Returns:
REVLibError::kOk if successful
- setSmartMotionAllowedClosedLoopError(allowedErr: float, slotID: int = 0) rev._rev.REVLibError
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.
- Parameters:
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().
- Returns:
REVLibError::kOk if successful
- setSmartMotionMaxAccel(maxAccel: float, slotID: int = 0) rev._rev.REVLibError
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
- Parameters:
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().
- Returns:
REVLibError::kOk if successful
- setSmartMotionMaxVelocity(maxVel: float, slotID: int = 0) rev._rev.REVLibError
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
- Parameters:
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().
- Returns:
REVLibError::kOk if successful
- setSmartMotionMinOutputVelocity(minVel: float, slotID: int = 0) rev._rev.REVLibError
Configure the mimimum velocity of the SmartMotion mode. Any requested velocities below this value will be set to 0.
- Parameters:
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().
- Returns:
REVLibError::kOk if successful