class wpilib.command.PIDCommand(p, i, d, period=None, f=0.0, name=None)[source]

Bases: wpilib.command.Command

This class defines a Command which interacts heavily with a PID loop.

It provides some convenience methods to run an internal PIDController. It will also start and stop said PIDController when the PIDCommand is first initialized and ended/interrupted.

Instantiates a PIDCommand that will use the given p, i and d values. It will use the class name as its name unless otherwise specified. It will also space the time between PID loop calculations to be equal to the given period.

  • p – the proportional value
  • i – the integral value
  • d – the derivative value
  • period – the time (in seconds) between calculations (optional)
  • f – the feed forward value
  • name – the name (optional)

Returns the PIDController used by this PIDCommand. Use this if you would like to fine tune the pid loop.

Notice that calling setSetpoint(...) on the controller will not result in the setpoint being trimmed to be in the range defined by setSetpointRange(...).

Returns:the PIDController used by this PIDCommand

Returns the current position

Returns:the current position

Returns the setpoint.

Returns:the setpoint

Returns the input for the pid loop.

It returns the input for the pid loop, so if this command was based off of a gyro, then it should return the angle of the gyro

All subclasses of PIDCommand must override this method.

This method will be called in a different thread then the Scheduler thread.

Returns:the value the pid loop should use as input

Sets the setpoint to the given value. If setRange() was called, then the given setpoint will be trimmed to fit within the range.

Parameters:setpoint – the new setpoint

Adds the given value to the setpoint. If setRange() was used, then the bounds will still be honored by this method.

Parameters:deltaSetpoint – the change in the setpoint

Uses the value that the pid loop calculated. The calculated value is the “output” parameter. This method is a good time to set motor values, maybe something along the lines of driveline.tankDrive(output, -output).

All subclasses of PIDCommand should override this method.

This method will be called in a different thread then the Scheduler thread.

Parameters:output – the value the pid loop calculated