:py:mod:`phoenix6.swerve.utility.phoenix_pid_controller` ======================================================== .. py:module:: phoenix6.swerve.utility.phoenix_pid_controller Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: phoenix6.swerve.utility.phoenix_pid_controller.input_modulus .. py:function:: input_modulus(input: float, minimum_input: float, maximum_input: float) -> float Returns modulus of input. :param input: Input value to wrap. :type input: float :param minimum_input: The minimum value expected from the input. :type minimum_input: float :param maximum_input: The maximum value expected from the input. :type minimum_input: float .. py:class:: PhoenixPIDController(Kp: float, Ki: float, Kd: float) Phoenix-centric PID controller taken from WPI's PIDController class. This class differs from the WPI implementation by using explicit timestamps for integral/derivative calculations. Ideally, these timestamps come from the StatusSignal. :param Kp: The proportional coefficient. Must be >= 0. :type Kp: float :param Ki: The integral coefficient. Must be >= 0. :type Ki: float :param Kd: The derivative coefficient. Must be >= 0. :type Kd: float .. py:method:: setPID(Kp: float, Ki: float, Kd: float) Sets the PID Controller gain parameters. Sets the proportional, integral, and differential coefficients. :param Kp: The proportional coefficient. Must be >= 0. :type Kp: float :param Ki: The integral coefficient. Must be >= 0. :type Ki: float :param Kd: The differential coefficient. Must be >= 0. :type Kd: float .. py:method:: setP(Kp: float) Sets the proportional coefficient of the PID controller gain. :param Kp: The proportional coefficient. Must be >= 0. :type Kp: float .. py:method:: setI(Ki: float) Sets the integral coefficient of the PID controller gain. :param Ki: The integral coefficient. Must be >= 0. :type Ki: float .. py:method:: setD(Kd: float) Sets the differential coefficient of the PID controller gain. :param Kd: The differential coefficient. Must be >= 0. :type Kd: float .. py:method:: setIZone(iZone: float) Sets the IZone range. When the absolute value of the position error is greater than IZone, the total accumulated error will reset to zero, disabling integral gain until the absolute value of the position error is less than IZone. This is used to prevent integral windup. Must be non-negative. Passing a value of zero will effectively disable integral gain. Passing a value of infinity disables IZone functionality. :param iZone: Maximum magnitude of error to allow integral control. Must be >= 0. :type iZone: float .. py:method:: getP() -> float Gets the proportional coefficient. :returns: proportional coefficient :rtype: float .. py:method:: getI() -> float Gets the integral coefficient. :returns: integral coefficient :rtype: float .. py:method:: getD() -> float Gets the differential coefficient. :returns: differential coefficient :rtype: float .. py:method:: getIZone() -> float Get the IZone range. :returns: Maximum magnitude of error to allow integral control :rtype: float .. py:method:: getPositionTolerance() -> float Gets the position tolerance of this controller. :returns: The position tolerance of the controller :rtype: float .. py:method:: getVelocityTolerance() -> float Gets the velocity tolerance of this controller. :returns: The velocity tolerance of the controller :rtype: float .. py:method:: getSetpoint() -> float Returns the current setpoint of the PIDController. :returns: The current setpoint :rtype: float .. py:method:: atSetpoint() -> bool Returns true if the error is within the tolerance of the setpoint. This will return false until at least one input value has been computed. :returns: True if the error is within the tolerance of the setpoint :rtype: bool .. py:method:: enableContinuousInput(minimumInput: float, maximumInput: float) Enables continuous input. Rather then using the max and min input range as constraints, it considers them to be the same point and automatically calculates the shortest route to the setpoint. :param minimumInput: The minimum value expected from the input. :type minimumInput: float :param maximumInput: The maximum value expected from the input. :type maximumInput: float .. py:method:: disableContinuousInput() Disables continuous input. .. py:method:: isContinuousInputEnabled() -> bool Returns true if continuous input is enabled. :returns: True if continuous input is enabled :rtype: bool .. py:method:: setIntegratorRange(minimumIntegral: float, maximumIntegral: float) Sets the minimum and maximum values for the integrator. When the cap is reached, the integrator value is added to the controller output rather than the integrator value times the integral gain. :param minimumIntegral: The minimum value of the integrator. :type minimumIntegral: float :param maximumIntegral: The maximum value of the integrator. :type maximumIntegral: float .. py:method:: setTolerance(positionTolerance: float, velocityTolerance: float = math.inf) Sets the error which is considered tolerable for use with AtSetpoint(). :param positionTolerance: Position error which is tolerable. :type positionTolerance: float :param velocityTolerance: Velocity error which is tolerable. :type velocityTolerance: float .. py:method:: getPositionError() -> float Returns the difference between the setpoint and the measurement. :returns: The position error :rtype: float .. py:method:: getVelocityError() -> float Returns the velocity error. :returns: The velocity error :rtype: float .. py:method:: calculate(measurement: float, setpoint: float, currentTimestamp: phoenix6.units.second) -> float Returns the next output of the PID controller. :param measurement: The current measurement of the process variable :type measurement: float :param setpoint: The new setpoint of the controller :type setpoint: float :param currentTimestamp: The current timestamp to use for calculating integral/derivative error :type currentTimestamp: second :returns: The next output :rtype: float .. py:method:: getLastAppliedOutput() -> float Returns the last applied output from this PID controller. :returns: The last applied output :rtype: float .. py:method:: reset() Reset the previous error, the integral term, and disable the controller.