PIDSubsystem

class commands2.PIDSubsystem(*arg, **kwargs)[source]

Bases: Subsystem

A subsystem that uses a wpimath.controller.PIDController to control an output. The controller is run synchronously from the subsystem’s periodic() method.

Creates a new PIDSubsystem.

Parameters:
  • controller – The PIDController to use.

  • initial_position – The initial setpoint of the subsystem.

disable()[source]

Disables the PID control. Sets output to zero.

enable()[source]

Enables the PID control. Resets the controller.

getController() PIDController[source]

Returns the PIDController used by the subsystem.

Returns:

The PIDController.

getMeasurement() float[source]

Returns the measurement of the process variable used by the PIDController.

Returns:

The measurement of the process variable.

getSetpoint() float[source]

Returns the current setpoint of the subsystem.

Returns:

The current setpoint.

isEnabled() bool[source]

Returns whether the controller is enabled.

Returns:

Whether the controller is enabled.

periodic()[source]

Executes the PID control logic during each periodic update.

This method is called synchronously from the subsystem’s periodic() method.

setSetpoint(setpoint: float)[source]

Sets the setpoint for the subsystem.

Parameters:

setpoint – The setpoint for the subsystem.

useOutput(output: float, setpoint: float)[source]

Uses the output from the PIDController.

Parameters:
  • output – The output of the PIDController.

  • setpoint – The setpoint of the PIDController (for feedforward).