Class CANPIDController


  • public class CANPIDController
    extends java.lang.Object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double getD()
      Get the Derivative Gain constant of the PIDF controller on the SPARK MAX.
      double getD​(int slotID)
      Get the Derivative Gain constant of the PIDF controller on the SPARK MAX.
      double getFF()
      Get the Feed-forward Gain constant of the PIDF controller on the SPARK MAX.
      double getFF​(int slotID)
      Get the Feed-forward Gain constant of the PIDF controller on the SPARK MAX.
      double getI()
      Get the Integral Gain constant of the PIDF controller on the SPARK MAX.
      double getI​(int slotID)
      Get the Integral Gain constant of the PIDF controller on the SPARK MAX.
      double getIZone()
      Get the IZone constant of the PIDF controller on the SPARK MAX.
      double getIZone​(int slotID)
      Get the IZone constant of the PIDF controller on the SPARK MAX.
      double getOutputMax()
      Get the max output of the PIDF controller on the SPARK MAX.
      double getOutputMax​(int slotID)
      Get the max output of the PIDF controller on the SPARK MAX.
      double getOutputMin()
      Get the min output of the PIDF controller on the SPARK MAX.
      double getOutputMin​(int slotID)
      Get the min output of the PIDF controller on the SPARK MAX.
      double getP()
      Get the Proportional Gain constant of the PIDF controller on the SPARK MAX.
      double getP​(int slotID)
      Get the Proportional Gain constant of the PIDF controller on the SPARK MAX.
      CANError setD​(double gain)
      Set the Derivative Gain constant of the PIDF controller on the SPARK MAX.
      CANError setD​(double gain, int slotID)
      Set the Derivative Gain constant of the PIDF controller on the SPARK MAX.
      CANError setFF​(double gain)
      Set the Feed-froward Gain constant of the PIDF controller on the SPARK MAX.
      CANError setFF​(double gain, int slotID)
      Set the Feed-froward Gain constant of the PIDF controller on the SPARK MAX.
      CANError setI​(double gain)
      Set the Integral Gain constant of the PIDF controller on the SPARK MAX.
      CANError setI​(double gain, int slotID)
      Set the Integral Gain constant of the PIDF controller on the SPARK MAX.
      CANError setIZone​(double IZone)
      Set the IZone range of the PIDF controller on the SPARK MAX.
      CANError setIZone​(double IZone, int slotID)
      Set the IZone range of the PIDF controller on the SPARK MAX.
      CANError setOutputRange​(double min, double max)
      Set the min amd max output for the closed loop mode.
      CANError setOutputRange​(double min, double max, int slotID)
      Set the min amd max output for the closed loop mode.
      CANError setP​(double gain)
      Set the Proportional Gain constant of the PIDF controller on the SPARK MAX.
      CANError setP​(double gain, int slotID)
      Set the Proportional Gain constant of the PIDF controller on the SPARK MAX.
      CANError setReference​(double value, ControlType ctrl)
      Set the controller reference value based on the selected control mode.
      CANError setReference​(double value, ControlType ctrl, int pidSlot)
      Set the controller reference value based on the selected control mode.
      CANError setReference​(double value, ControlType ctrl, int pidSlot, double arbFeedforward)
      Set the controller reference value based on the selected control mode.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CANPIDController

        public CANPIDController​(CANSparkMax device)
        Constructs a CANPIDController.
        Parameters:
        device - The Spark Max this object configures.
    • Method Detail

      • setReference

        public CANError setReference​(double value,
                                     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)
        ctrl - Is the control type
        Returns:
        CANError Set to REV_OK if successful
      • setReference

        public CANError setReference​(double value,
                                     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)
        ctrl - Is the control type to override with
        pidSlot - for this command
        Returns:
        CANError Set to REV_OK if successful
      • setReference

        public CANError setReference​(double value,
                                     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)
        ctrl - Is the control type to override with
        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:
        CANError Set to REV_OK if successful
      • setP

        public CANError setP​(double gain)
        Set the Proportional Gain constant of the PIDF controller on the SPARK MAX. 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 use to SPARK MAX GUI to tune and save parameters.
        Parameters:
        gain - The proportional gain value, must be positive
        Returns:
        CANError Set to REV_OK if successful
      • setP

        public CANError setP​(double gain,
                             int slotID)
        Set the Proportional Gain constant of the PIDF controller on the SPARK MAX. 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 use to SPARK MAX GUI 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:
        CANError Set to REV_OK if successful
      • setI

        public CANError setI​(double gain)
        Set the Integral Gain constant of the PIDF controller on the SPARK MAX. 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 use to SPARK MAX GUI to tune and save parameters.
        Parameters:
        gain - The integral gain value, must be positive
        Returns:
        CANError Set to REV_OK if successful
      • setI

        public CANError setI​(double gain,
                             int slotID)
        Set the Integral Gain constant of the PIDF controller on the SPARK MAX. 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 use to SPARK MAX GUI 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:
        CANError Set to REV_OK if successful
      • setD

        public CANError setD​(double gain)
        Set the Derivative Gain constant of the PIDF controller on the SPARK MAX. 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 use to SPARK MAX GUI to tune and save parameters.
        Parameters:
        gain - The derivative gain value, must be positive
        Returns:
        CANError Set to REV_OK if successful
      • setD

        public CANError setD​(double gain,
                             int slotID)
        Set the Derivative Gain constant of the PIDF controller on the SPARK MAX. 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 use to SPARK MAX GUI 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:
        CANError Set to REV_OK if successful
      • setFF

        public CANError setFF​(double gain)
        Set the Feed-froward Gain constant of the PIDF controller on the SPARK MAX. 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 use to SPARK MAX GUI to tune and save parameters.
        Parameters:
        gain - The feed-forward gain value
        Returns:
        CANError Set to REV_OK if successful
      • setFF

        public CANError setFF​(double gain,
                              int slotID)
        Set the Feed-froward Gain constant of the PIDF controller on the SPARK MAX. 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 use to SPARK MAX GUI 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:
        CANError Set to REV_OK if successful
      • setIZone

        public CANError setIZone​(double IZone)
        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
        Returns:
        CANError Set to REV_OK if successful
      • setIZone

        public CANError setIZone​(double IZone,
                                 int slotID)
        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:
        CANError Set to REV_OK if successful
      • setOutputRange

        public CANError setOutputRange​(double min,
                                       double max)
        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 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:
        min - Reverse power minimum to allow the controller to output
        max - Forward power maximum to allow the controller to output
        Returns:
        CANError Set to REV_OK if successful
      • setOutputRange

        public CANError setOutputRange​(double min,
                                       double max,
                                       int slotID)
        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 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:
        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:
        CANError Set to REV_OK if successful
      • getP

        public double getP()
        Get the Proportional Gain constant of the PIDF controller on the SPARK MAX. 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)
        Returns:
        double P Gain value
      • getP

        public double getP​(int slotID)
        Get the Proportional Gain constant of the PIDF controller on the SPARK MAX. 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
      • getI

        public double getI()
        Get the Integral Gain constant of the PIDF controller on the SPARK MAX. 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)
        Returns:
        double I Gain value
      • getI

        public double getI​(int slotID)
        Get the Integral Gain constant of the PIDF controller on the SPARK MAX. 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
      • getD

        public double getD()
        Get the Derivative Gain constant of the PIDF controller on the SPARK MAX. 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)
        Returns:
        double D Gain value
      • getD

        public double getD​(int slotID)
        Get the Derivative Gain constant of the PIDF controller on the SPARK MAX. 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
      • getFF

        public double getFF()
        Get the Feed-forward Gain constant of the PIDF controller on the SPARK MAX. 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)
        Returns:
        double F Gain value
      • getFF

        public double getFF​(int slotID)
        Get the Feed-forward Gain constant of the PIDF controller on the SPARK MAX. 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
      • getIZone

        public double getIZone()
        Get the IZone constant of the PIDF controller on the SPARK MAX. 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)
        Returns:
        double IZone value
      • getIZone

        public double getIZone​(int slotID)
        Get the IZone constant of the PIDF controller on the SPARK MAX. 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
      • getOutputMin

        public double getOutputMin()
        Get the min output of the PIDF controller on the SPARK MAX. 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)
        Returns:
        double min value
      • getOutputMin

        public double getOutputMin​(int slotID)
        Get the min output of the PIDF controller on the SPARK MAX. 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
      • getOutputMax

        public double getOutputMax()
        Get the max output of the PIDF controller on the SPARK MAX. 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)
        Returns:
        double max value
      • getOutputMax

        public double getOutputMax​(int slotID)
        Get the max output of the PIDF controller on the SPARK MAX. 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