Class SparkClosedLoopController

java.lang.Object
com.revrobotics.spark.SparkClosedLoopController

public class SparkClosedLoopController extends Object
Get an instance of this class by using SparkBase.getClosedLoopController().
  • Method Details

    • setSetpoint

      public REVLibError setSetpoint(double setpoint, SparkLowLevel.ControlType ctrl)
      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).
      ctrl - the control type
      Returns:
      REVLibError.kOk if successful
    • setSetpoint

      public REVLibError setSetpoint(double setpoint, SparkLowLevel.ControlType ctrl, ClosedLoopSlot slot)
      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).
      ctrl - Is the control type to override with
      slot - The ClosedLoopSlot to use
      Returns:
      REVLibError.kOk if successful
    • setSetpoint

      public REVLibError setSetpoint(double setpoint, SparkLowLevel.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).
      ctrl - Is the control type to override with
      slot - The ClosedLoopSlot to use
      arbFeedforward - 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, SparkLowLevel.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).
      ctrl - Is the control type to override with
      slot - The ClosedLoopSlot to use
      arbFeedforward - 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

      public SparkLowLevel.ControlType getControlType()
      Get the selected control type used when setSetpoint(double, ControlType) was last called.
      Returns:
      The selected control type
    • setIAccum

      public REVLibError setIAccum(double iAccum)
      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 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
    • getIAccum

      public Signal<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:
      Signal containing the value of the I accumulator
    • getSetpoint

      public Signal<Double> getSetpoint()
      Get the internal setpoint of the closed loop controller.
      Returns:
      Signal containing the internal setpoint
    • isAtSetpoint

      public Signal<Boolean> isAtSetpoint()
      Determine if the setpoint has been reached.
      Returns:
      Signal containing true if the setpoint is reached; false otherwise
    • getSelectedSlot

      public Signal<ClosedLoopSlot> getSelectedSlot()
      Get the selected closed loop PID slot.
      Returns:
      Signal containing the selected closed loop PID slot
    • getMAXMotionSetpointPosition

      public Signal<Double> getMAXMotionSetpointPosition()
      Get the MAXMotion internal setpoint position.

      This will be 0 if the controller is not in a MAXMotion control mode.

      Returns:
      Signal containing the MAXMotion internal setpoint position in rotations.
    • getMAXMotionSetpointVelocity

      public Signal<Double> getMAXMotionSetpointVelocity()
      Get the MAXMotion internal setpoint velocity.

      This will be 0 if the controller is not in a MAXMotion control mode.

      Returns:
      Signal containing the MAXMotion internal setpoint velocity in rotations per minute.