Skip to content

PID Control

Jeffrey Shen edited this page Aug 5, 2017 · 4 revisions

This functionality requires using the sensor struct. See how to use that here.

A PID control, or a Proportional Integral Derivative control, is a way to accurately control the motion of your robot. For a more thorough explanation, check out this video. This library provides a variety of methods to help use a PID control.

Setup

First, create a struct of type pid. This stores the PID constants: kp, ki, and kd (Read on to discover how to set these values). These are floats. If a constant is not initialized it will be automatically set to 0.

Next, this pid struct must be bound to a sensor in order for it to be useful. To do this, initialize the sensor with a pointer to the pid struct. You can read more about sensors here.

Your sensor is now set up with the relevant PID constants and can be used with the included PID methods.

Example

pid PID;
pid.kp = 0.1;
pid.kd = 0.1;

sensor Sensor;
initializeSensor(&Sensor, 1.0, dgtl1, &PID); //Notice that the PID struct is added as an additional argument.

Usage

Getting the control parameters