Skip to main content

A backport of the upcoming (in 2020) WPILib PIDController.

Project description

wpilib-controller

A backport of the upcoming (in 2020) WPILib PIDController.

This is a backport of wpilibsuite/allwpilib#1300, which is planned to be merged for the 2020 season, for RobotPy.

@calcmogul has some in-progress docs on this.

Note that if you are moving from the old WPILib PIDController, your PID constants will need to change, as it did not consider the discretization period:

  • divide your Ki gain by 0.05, and
  • multiply your Kd gain by 0.05,
  • where 0.05 is the original default period (use the period you used otherwise).

Installation

For a computer with an internet connection:

pip install wpilib-controller

To install onto an offline roboRIO:

pip download wpilib-controller -d pip_cache  # with an internet connection
robotpy-installer install-pip wpilib-controller  # connected to your robot

Example

from wpilib_controller import PIDController

# assume gyro is a gyro object created prior
controller = PIDController(1, 0, 0, measurement_source=gyro.getAngle)
controller.setInputRange(0, 360)
controller.setContinuous()

# setSetpoint is now called setReference
controller.setReference(180)

# elsewhere...

output = controller.update()
# do something with the output, for example:
motor.set(output)

Major differences

  • The PID gains are no longer time dependent.
  • This does not distinguish between displacement and rate “PID source types”. Instead this PIDController takes a function as its measurement source.
  • The feedforward is calculated by a function passed into the PIDController.
  • This provides a simple way of running a PID controller synchronously in your robot code (as opposed to having it run in a thread). Simply call the update() method which will give you the controller output.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wpilib-controller-0.7.tar.gz (8.3 kB view hashes)

Uploaded Source

Built Distribution

wpilib_controller-0.7-py3-none-any.whl (12.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page