Have you ever heard about PID controller?
Refer to: Wikipedia Definition
It is a controller that is widely used in industrial to control various process variables such as temperature, pressure, force, feed rate, flow rate, chemical composition (component concentrations), weight, position, speed, and practically every other variable for which a measurement exists.
In this article, I focus on using PID to control position and speed of Brushed DC motor.
What decides performance of a PID controller?
Performance of PID is decided by Kp, Ki and Kd gain (coefficients for the proportional, integral, and derivative terms). Each system has its own optimal PID gain. Finding the best PID gains is difficult task. Therefore, we usually use an acceptable gain. This link give an illustration of impact of Kp, Ki and Kd on system
The process of finding value of these parameters is called "tuning". PID controller can manually tuning and auto-tuning...
- Manually tuning: This method requires experienced personnel
- Auto-tuning: the tuning is done by a software.
I implemented Auto-tuning library for position and speed of DC motor (see the source code) using Relay On/Off method. This code is written for PHPoC platform.
PID gain from auto-tuning is not the best gain. You can manually fine-tune based on PID gain from auto-tuning.
PID is closed-loop system, we need a feedback from DC motor. Therefore, to use PID control, DC motor need to has an encoder.
Encoder will output the signal, which is used to calculated the real position and speed. The calculation of position and speed is performed by DC motor controller. DC motor sends the calculated value (called feedback value) back to PHPoC Blue or Black. Library on PHPoC will perform adjustment based on the feedback value, desired value, Kp, Ki and Kd gain, and staling factor. after adjusting, PHPoC send command along with PWM duty-cycle value to DC motor controller, DC motor will output PWM signal to control DC motor. This process is repeated in a infinite loop.
- Stack DC motor controller on PHPoC Blue/Black
- Connect DC motor to DC motor controller (see User Manual of DC motor Controller)
Note that, different motor has different behavior. You may need to adjust some parameters such as:
- Scaling factor:
- Sampling time:
- Limit of integral:
$pid[INDEX_INT_MAX] and $pid[INDEX_INT_MIN]
To meet your system requirement.
In the example, setpoint of position is changed. No overshoot occurs:
In the example, setpoint of speed is changed.