This project is about a simple and low cost way to implement a PID controller to a DC motor with feedback from an incremental encoder. No prior experience in programming or electronics is required; it is a plug and play setup. An Arduino board is used to run the controller, and a user interface built in Matlab to help the user communicate with the hardware (give commands, change parameters, see plots etc.)
By the time one has gathered the necessary parts, it is a matter of 30 minutes to get the whole thing running.
Hardware
You will need:
1. Program the Arduino board
If you haven't used an Arduino before, first follow the guide found here. After installation, run the first example blinking the on-board LED to make sure you did everything right.
In this project, I simply combined two existing libraries which have to be downloaded for the project to work. The first one, the Encoder Library, is used for reading the encoder signal using the Arduino interrupts. Follow the steps described in the link, and you should be able to read the encoder. The second one, the Arduino PID Library, is used for implementing the PID controller. Again, follow the steps described in the link and you should be ready for what follows.
I wrote a program that combines these libraries. Download the program at the end of this page. Except for controlling the motor, the program communicates with a Matlab program running in an external computer. More on this in a next step. After downloading the program, upload it to the Arduino board.
2. Connect the parts
The encoder should be connected to the Arduino as described here, and the motor shield as shown here.
3. Download the Matlab program
The Matlab program can be downloaded at the end of this page, and it is used to interface with the hardware. See the experiments below.
4. Drive the motor
To drive the motor follow these steps:
5. Experiments
P Controller
The gains were set to: kp = 0.55 , ki = kd = 0, and the motor was commanded to go to 5000, 13000, and 3000 counts.
Although this was a P controller, no oscillations were observed due to the high friction of the geared motor.
PD Controller
The gains were set to: kp = 0.55 , kd = 0.3, ki = 0, and the motor was commanded to go to 5000, 13000, and 3000 counts.
PID Controller
The gains were set to: kp = 0.55 , kd = 0.3, ki = 1.3, and the motor was commanded to go to 5000, 13000, and 3000 counts.