Implementing PID Control

By: Ryan Guenette – Control Systems Sub-Project

The objective of this rover was to implement a PID control algorithm to make it travel in a straight line.

I began by calibrating the gyroscope to minimize DC offset, drift and noise using the following code:

Code – Gyro Calibration Arduino Code

Gyro – http://www.pololu.com/product/2125

Datasheet – http://www.pololu.com/file/0J563/L3GD20.pdf

Arduino Library – https://github.com/pololu/l3g-arduino

Connections

Figure 1. Gyroscope Connections

After making sure the gyroscope had noise lower than one or two in the Arduino serial monitor, I was able to test the angular feedback for accuracy. I tested the degree feedback by turning the rover and seeing the values displayed in the serial monitor. I compared the serial monitor readings with a protractor. I chose to use positive angles when the rover turns clockwise and negative angles when turned counter-clockwise because it is simpler to use with the PID code.

Gyro Calibrating Serial Image

Figure 2. Serial Monitor Outputs

Information About Gyroscope Calibration –

http://www.csulb.edu/~hill/ee444/Labs/5%20Gyro/5%20Arduino%20IDE%20Gyro.pdf

The PID control code uses the updatePID function for the PID subroutine. There are a surplus of examples and information on the internet about updatePID. When this subroutine is called from the main loop it returns a pwm value that is then applied to each of the two DC motors. All of the values can be viewed from the serial monitor as each loop iteration occurs.

I tuned the Kp, Ki, and Kd values by visually watching the rover to see what worked best. I began the Kp value at 1 and lowered it until the rover was responsive to changes. I then began the Kd value at 0.5 and had to raise it very slowly to increase responsiveness. I began the Ki value at 0.01 to see if it altered the response at all and ended up raising it to 0.015. There are also graphical ways to tune, however, I chose to do it by actually watching the rover to see how it responded to different values.

PID Code – PID Arduino Code

Youtube Video – https://www.youtube.com/watch?v=fB0Jlewv36o&feature=youtu.be

Motor Shield – http://www.adafruit.com/products/1438

Information –

http://www.csulb.edu/~hill/ee400d/Reference%20Folder/PID%20Controller/Arduino%20PID%20design.pdf

http://en.wikipedia.org/wiki/PID_controller

http://ardadv.blogspot.com/2012/05/using-l3g4200d-with-arduino.html

1 reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *