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

    • setReference

      public REVLibError setReference(double value, SparkBase.ControlType ctrl)
      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). Native units can be changed using the setPositionConversionFactor() or setVelocityConversionFactor() methods of the RelativeEncoder class
      ctrl - the control type
      Returns:
      REVLibError.kOk if successful
    • setReference

      public REVLibError setReference(double value, SparkBase.ControlType ctrl, int pidSlot)
      Set the controller reference value based on the selected control mode. This will override the pre-programmed control mode but not change what is programmed to the controller.
      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). Native units can be changed using the setPositionConversionFactor() or setVelocityConversionFactor() methods of the RelativeEncoder class
      ctrl - Is the control type to override with
      pidSlot - for this command
      Returns:
      REVLibError.kOk if successful
    • setReference

      public REVLibError setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedforward)
      Set the controller reference value based on the selected control mode. This will override the pre-programmed control mode but not change what is programmed to the controller.
      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). Native units can be changed using the setPositionConversionFactor() or setVelocityConversionFactor() methods of the RelativeEncoder class
      ctrl - Is the control type to override with
      pidSlot - for this command
      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
    • setReference

      public REVLibError setReference(double value, SparkBase.ControlType ctrl, int pidSlot, double arbFeedforward, SparkClosedLoopController.ArbFFUnits arbFFUnits)
      Set the controller reference value based on the selected control mode. This will override the pre-programmed control mode but not change what is programmed to the controller.
      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). Native units can be changed using the setPositionConversionFactor() or setVelocityConversionFactor() methods of the RelativeEncoder class
      ctrl - Is the control type to override with
      pidSlot - for this command
      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
    • 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 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