Thursday 12 March 2015

Line Follower with PID Controller


I am sharing the leJOS line follower program with PID controller. Here is the reference literature for PID controller. As we all know the PID Controller works based on continuous feedback from the system relative to a given set-point. If the system moves away from the set-point, the feedback is provided such that, it will return back to the set-point. The PID algorithm works so as to minimize the error between the actual and the set-point. In case of the Line-Follower program below, the system is the Line-Follower itself. The set-point is the light intensity which the system has to follow in order to continue moving on the black line and should not lose the track. In our case, we define the set-point as the average light intensity of black and white colors. We call the set-point as threshold. The way of configuring the threshold being average = (black + white)/2, the line-follower follows the edge of the black stripe placed on the white paper. I have put two perpendicular stripes for the line follower as a challenge, to know how precisely it can follow the turn. (It is relatively easy for the line follower to follow smooth curves. But most of the time in real-life scenario, we do not get smooth turns. We encounter perpendicular sharp turns). The other challenge was to find out how effectively the line-follower faces a dead-end. Hence in the below small experiment, I have incorporated two perpendicular turns and two dead-ends with black stripes. You can imagine it as a road, on which the car is moving with a relatively slow speed. The speed is kept slow in order for the Line-Follower not to lose its track. We can even increase the speed and try the same experiment, but let us keep that for some other time. 

Now let us look at the digitized-PID controller algorithm which I have incorporated in the LeJOS program below. The set-point is the threshold as described in the above paragraph. The feedback is provided in the form of error, which is the difference between the actual-light-intensity at any given instance and the threshold value. If the actual-light-intensity of the robot is more towards black or more towards white, the system will pull it back towards the threshold, i.e. the edge of the line. In the below digitized-PID algorithm, we convert the error, its integral and its derivative into power value which will be supplied to the right and left motors. The power will be supplied to the motors such that, if the car is too much on the black surface, it will be pulled on to the white surface and vice-versa. In the digitized version of the integral error, the past error value is added to the current error value iteratively. While the digitized version of derivative, the last error is subtracted from the current error iteratively. Please take a look into the following three lines of code for illustration, where color represents the current light intensity based on the robot's position on the black or white surface.


  
The correction variable represents the calculated value of power, where error term gets multiplied by Kp (the proportional coefficient), the integral term gets multiplied by Ki (the integral coefficient) and the derivative term gets multiplied by Kd (the derivative coefficient). The Kp, Ki and Kd need to be tuned in order for the Line-Follower to follow the line appropriately with a certain speed. In my case the default power of the Line-Follower is set to 20. This value is based on trial and error in order for the speed to be relatively slow. Below is the video clip to show the performance of the program for given kp, ki and kd parameters.  




NOTE - In order for the Calibration details of Black and White intensities, it would better to take a look at my Line Follower program first.




Observations: The program seems to be following the perpendicular turn well with the current Kp, Kd and Ki coefficients and the given speed. However, it does not take the U turn at the dead-end very well. For taking an in-place U turn there is a need for more fine-tuning of PID coefficients. To know about how a better in-place U-turn looks like, please take a look at my video In-Place U turn. I have not yet concluded anything about the 'effect of tuning the parameters' over the line follower. However, that would be reserved for the future. 

I hope you liked this article!

No comments:

Post a Comment