Make a FAST Line Follower Robot Using PID!

by the Technowright in Circuits > Robots

32821 Views, 19 Favorites, 0 Comments

Make a FAST Line Follower Robot Using PID!

thumbnail.jpg
I made a SUPER FAST Line Follower Robot Using PID!

Making a line follower robot is a great way to get started with robotics and arduino. But I had assumed it was a simple project and never tried to make one. But when a friend of mine challenged me to join a line follower robot competition, I had to design the fastest robot in the competition. On the day of the competition, my robot refused follow any line and it was infact actively avoiding the line. My friend had won that challenge with his bot hitting a speed of 0.7m/s. So, I decided to find out where I went wrong and make a faster line follower robot.

The Simple Version

lfsimp_1.1.3.jpg
circuit.png
lf_1.1.1.jpg

I had to find out where I went wrong. So I started by making a simple Line follower with two IR Sensors and arduino. It works on the simple principle of a bang-bang controller. If the left sensor is on black then it turns right. And if the right sensor is on black then it turns left. I first tested it out using AA battery pack. But it wasnt delivering enough power. I used a 12V LiPo battery. Then it worked.

Downloads

Designing the Advanced Version

instructables_1.1.2.jpg
instructables_1.1.3.jpg
instructables_1.1.5.jpg
instructables_1.1.9.jpg
instructables_1.1.12.jpg

I then designed a custom chassis to reduce the weight and make a design that is efficient. I replaced the DC motors with N20 DC motors. I used an IR Sensor array instead of the 2 IR sensors. This is will be used to implement the PID controller. I replaced the arduino with an ESP32 becasue it had Bluetooth which was very helpful while tuning the robot.

PCB Design

instructables_1.1.10.jpg
instructables_1.1.11.jpg
kicad.png
PCB.png

I then designed a PCB to incorporate all the elcetronics on a compact board. I used JLCPCB to manufacture the PCBs. Also I the motor drivers I was using were wasting too much power as heat. So, I replaced them with the TB6612FNG Motor driver Chip which is more efficient. And I and I used the PCB Assembly services from JLCPCB to get the chip presoldered onto the board. You can download the gerber file(zip file) from https://github.com/theTechnowright/PID-Line-Follower-Robot and upload it to JLCPCB to get them manufactured.

Implementing PID Controller

instructables_1.1.13.jpg
instructables_1.1.14.jpg
instructables_1.1.15.jpg

I then wrote the code for implementing the PID algorithm to make the Line Follower more faster and smoother. But,what is PID? Well, it is a feedback loop which measures an error and uses it to actively correct its current position. In this case, the 5 IR sensor array gives a value of how far away from the line the bot is and uses it calculate a steering value. If the error is multiplied by a constant Kp. The steering value is proportional to the error. The greater the error is, the faster it turns to correct it. But the steering value also depends on the constant Kp. A high Kp value will make turns fast and it will oscillate. Whereas, a smaller Kp value will make the turns slow, and it will be lagging. This is explained well in the video at 4:50. I used a Bluetooth app to try out different Kp, Kd, Ki values. After spending hours I was able get the perfect set of values. Now these values are uniqe for each robot.

Speed Test

instructables_1.1.16.jpg
track_1.1.16.jpg
Untitled_1.1.18.jpg

I built a huge track all around my living room floor to test the it. The track had 3 important parts which really test the ability of the Line follower:

  1. The 90° turn
  2. The "Meanders"
  3. Intersections

The results are include in the video @ 8:12. The bot was able to go through all three of these with quite an ease. I then tested the speed of the Line follower by marking two points 1m apart and measuring the time taken. The max speed was around 1m/s. The 3D Printed cover was making it quite heavy, and it was able to go faster without it. It stilll needs more improvements to increase the speed. This could be by replacing the motors for a higher rpm dc motor, tuning the algorithm better and by trying out different wheel diameters.