Package com.revrobotics.spark
Class SparkClosedLoopController
java.lang.Object
com.revrobotics.spark.SparkClosedLoopController
Get an instance of this class by using
SparkBase.getClosedLoopController()
.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionGet the selected control type used whensetReference(double, SparkBase.ControlType)
was last called.double
Get the I accumulator of the closed loop controller.double
Get the MAXMotion internal setpoint position.double
Get the MAXMotion internal setpoint velocity.Get the selected closed loop PID slot.double
Get the internal setpoint of the closed loop controller.boolean
Determine if the setpoint has been reached.setIAccum
(double iAccum) Set the I accumulator of the closed loop controller.setReference
(double setpoint, SparkBase.ControlType ctrl) Deprecated, for removal: This API element is subject to removal in a future version.setReference
(double setpoint, SparkBase.ControlType ctrl, ClosedLoopSlot slot) Deprecated, for removal: This API element is subject to removal in a future version.setReference
(double setpoint, SparkBase.ControlType ctrl, ClosedLoopSlot slot, double arbFeedforward) Deprecated, for removal: This API element is subject to removal in a future version.setReference
(double setpoint, SparkBase.ControlType ctrl, ClosedLoopSlot slot, double arbFeedforward, SparkClosedLoopController.ArbFFUnits arbFFUnits) Deprecated, for removal: This API element is subject to removal in a future version.setSetpoint
(double setpoint, SparkBase.ControlType ctrl) Set the controller setpoint based on the selected control mode.setSetpoint
(double setpoint, SparkBase.ControlType ctrl, ClosedLoopSlot slot) Set the controller setpoint based on the selected control mode.setSetpoint
(double setpoint, SparkBase.ControlType ctrl, ClosedLoopSlot slot, double arbFeedforward) Set the controller setpoint based on the selected control mode.setSetpoint
(double setpoint, SparkBase.ControlType ctrl, ClosedLoopSlot slot, double arbFeedforward, SparkClosedLoopController.ArbFFUnits arbFFUnits) Set the controller setpoint based on the selected control mode.
-
Method Details
-
setSetpoint
Set the controller setpoint based on the selected control mode.- Parameters:
setpoint
- The setpoint 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). Native units can be changed usingAlternateEncoderConfig.positionConversionFactor(double)
, orExternalEncoderConfig.positionConversionFactor(double)
, orEncoderConfig.positionConversionFactor(double)
orAlternateEncoderConfig.velocityConversionFactor(double)
, orExternalEncoderConfig.velocityConversionFactor(double)
, orEncoderConfig.velocityConversionFactor(double)
ctrl
- the control type- Returns:
REVLibError.kOk
if successful
-
setSetpoint
Set the controller setpoint based on the selected control mode. This will override the pre-programmed control mode but not change what is programmed to the controller.- Parameters:
setpoint
- The setpoint 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). Native units can be changed usingAlternateEncoderConfig.positionConversionFactor(double)
, orExternalEncoderConfig.positionConversionFactor(double)
, orEncoderConfig.positionConversionFactor(double)
orAlternateEncoderConfig.velocityConversionFactor(double)
, orExternalEncoderConfig.velocityConversionFactor(double)
, orEncoderConfig.velocityConversionFactor(double)
ctrl
- Is the control type to override withslot
- TheClosedLoopSlot
to use- Returns:
REVLibError.kOk
if successful
-
setSetpoint
public REVLibError setSetpoint(double setpoint, SparkBase.ControlType ctrl, ClosedLoopSlot slot, double arbFeedforward) Set the controller setpoint based on the selected control mode. This will override the pre-programmed control mode but not change what is programmed to the controller.- Parameters:
setpoint
- The setpoint 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). Native units can be changed usingAlternateEncoderConfig.positionConversionFactor(double)
, orExternalEncoderConfig.positionConversionFactor(double)
, orEncoderConfig.positionConversionFactor(double)
orAlternateEncoderConfig.velocityConversionFactor(double)
, orExternalEncoderConfig.velocityConversionFactor(double)
, orEncoderConfig.velocityConversionFactor(double)
ctrl
- Is the control type to override withslot
- TheClosedLoopSlot
to usearbFeedforward
- A value from which is represented in 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
-
setSetpoint
public REVLibError setSetpoint(double setpoint, SparkBase.ControlType ctrl, ClosedLoopSlot slot, double arbFeedforward, SparkClosedLoopController.ArbFFUnits arbFFUnits) Set the controller setpoint based on the selected control mode. This will override the pre-programmed control mode but not change what is programmed to the controller.- Parameters:
setpoint
- The setpoint 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). Native units can be changed usingAlternateEncoderConfig.positionConversionFactor(double)
, orExternalEncoderConfig.positionConversionFactor(double)
, orEncoderConfig.positionConversionFactor(double)
orAlternateEncoderConfig.velocityConversionFactor(double)
, orExternalEncoderConfig.velocityConversionFactor(double)
, orEncoderConfig.velocityConversionFactor(double)
ctrl
- Is the control type to override withslot
- TheClosedLoopSlot
to usearbFeedforward
- A value from which is represented in 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.arbFFUnits
- The units the arbitrary feed forward term is in- Returns:
REVLibError.kOk
if successful
-
setReference
@Deprecated(forRemoval=true) public REVLibError setReference(double setpoint, SparkBase.ControlType ctrl) Deprecated, for removal: This API element is subject to removal in a future version.UsesetSetpoint(double, SparkBase.ControlType)
insteadSet the controller setpoint based on the selected control mode.- Parameters:
setpoint
- The setpoint 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). Native units can be changed usingAlternateEncoderConfig.positionConversionFactor(double)
, orExternalEncoderConfig.positionConversionFactor(double)
, orEncoderConfig.positionConversionFactor(double)
orAlternateEncoderConfig.velocityConversionFactor(double)
, orExternalEncoderConfig.velocityConversionFactor(double)
, orEncoderConfig.velocityConversionFactor(double)
ctrl
- the control type- Returns:
REVLibError.kOk
if successful
-
setReference
@Deprecated(forRemoval=true) public REVLibError setReference(double setpoint, SparkBase.ControlType ctrl, ClosedLoopSlot slot) Deprecated, for removal: This API element is subject to removal in a future version.Set the controller setpoint based on the selected control mode. This will override the pre-programmed control mode but not change what is programmed to the controller.- Parameters:
setpoint
- The setpoint 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). Native units can be changed usingAlternateEncoderConfig.positionConversionFactor(double)
, orExternalEncoderConfig.positionConversionFactor(double)
, orEncoderConfig.positionConversionFactor(double)
orAlternateEncoderConfig.velocityConversionFactor(double)
, orExternalEncoderConfig.velocityConversionFactor(double)
, orEncoderConfig.velocityConversionFactor(double)
ctrl
- Is the control type to override withslot
- TheClosedLoopSlot
to use- Returns:
REVLibError.kOk
if successful
-
setReference
@Deprecated(forRemoval=true) public REVLibError setReference(double setpoint, SparkBase.ControlType ctrl, ClosedLoopSlot slot, double arbFeedforward) Deprecated, for removal: This API element is subject to removal in a future version.Set the controller setpoint based on the selected control mode. This will override the pre-programmed control mode but not change what is programmed to the controller.- Parameters:
setpoint
- The setpoint 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). Native units can be changed usingAlternateEncoderConfig.positionConversionFactor(double)
, orExternalEncoderConfig.positionConversionFactor(double)
, orEncoderConfig.positionConversionFactor(double)
orAlternateEncoderConfig.velocityConversionFactor(double)
, orExternalEncoderConfig.velocityConversionFactor(double)
, orEncoderConfig.velocityConversionFactor(double)
ctrl
- Is the control type to override withslot
- TheClosedLoopSlot
to usearbFeedforward
- A value from which is represented in 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
-
setReference
@Deprecated(forRemoval=true) public REVLibError setReference(double setpoint, SparkBase.ControlType ctrl, ClosedLoopSlot slot, double arbFeedforward, SparkClosedLoopController.ArbFFUnits arbFFUnits) Deprecated, for removal: This API element is subject to removal in a future version.Set the controller setpoint based on the selected control mode. This will override the pre-programmed control mode but not change what is programmed to the controller.- Parameters:
setpoint
- The setpoint 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). Native units can be changed usingAlternateEncoderConfig.positionConversionFactor(double)
, orExternalEncoderConfig.positionConversionFactor(double)
, orEncoderConfig.positionConversionFactor(double)
orAlternateEncoderConfig.velocityConversionFactor(double)
, orExternalEncoderConfig.velocityConversionFactor(double)
, orEncoderConfig.velocityConversionFactor(double)
ctrl
- Is the control type to override withslot
- TheClosedLoopSlot
to usearbFeedforward
- A value from which is represented in 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.arbFFUnits
- The units the arbitrary feed forward term is in- Returns:
REVLibError.kOk
if successful
-
getControlType
Get the selected control type used whensetReference(double, SparkBase.ControlType)
was last called.- Returns:
- The selected control type
-
setIAccum
Set the I accumulator of the closed loop controller. This is useful when wishing to force a reset on the I accumulator of the closed loop controller. You can also preset values to see how it will respond to certain I characteristicsTo 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
-
getIAccum
public double getIAccum()Get the I accumulator of the closed loop 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
-
getSetpoint
public double getSetpoint()Get the internal setpoint of the closed loop controller.- Returns:
- The internal setpoint
-
isAtSetpoint
public boolean isAtSetpoint()Determine if the setpoint has been reached.- Returns:
- true if the setpoint is reached; false otherwise
-
getSelectedSlot
Get the selected closed loop PID slot.- Returns:
- The selected closed loop PID slot
-
getMAXMotionSetpointPosition
public double getMAXMotionSetpointPosition()Get the MAXMotion internal setpoint position.This will be 0 if the controller is not in a MAXMotion control mode.
- Returns:
- The MAXMotion internal setpoint position in rotations or units specified by the conversion factor.
-
getMAXMotionSetpointVelocity
public double getMAXMotionSetpointVelocity()Get the MAXMotion internal setpoint velocity.This will be 0 if the controller is not in a MAXMotion control mode.
- Returns:
- The MAXMotion internal setpoint velocity in rotations per minute or units specified by the conversion factor.
-
setSetpoint(double, SparkBase.ControlType)
instead