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:
Datasheet – http://www.pololu.com/file/0J563/L3GD20.pdf
Arduino Library – https://github.com/pololu/l3g-arduino
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.
Figure 2. Serial Monitor Outputs
Information About Gyroscope Calibration –
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