Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Line Follower robot (with PID controller)

 Line Follower Robot (with PID controller)

An independent excessive speed line follower robot primarily based on PID manage.

story

Line following robots are one of the maximum simplistic forms of robots that plays a easy task: tracking a black or a white line on a white, respectively on a black surface.

In a competition of this kind, the introduced task is that the robots need to compete against time, and the fastest wins the competition. as a consequence, it's miles a hassle of manage and accuracy, particularly at narrow curves, but additionally a problem of pace.

So, I wanted to participate in a comparable competition, with a robotic completely designed on my own. After studying for a few months how those models work, I controlled to give you an acceptable model, it may be significantly advanced, in phrases of the code, in addition to the design itself.

Things used in this project

Hardware components

SparkFun Arduino Pro Mini 328 - 5V/16MHz
null
 DRV8835 Dual Motor Driver Carrier

5V Step-Up/Step-Down Voltage Regulator S7V7F5
Any other 5V step-down voltage regulator will do -- i chose the S7V7F5 because it has a lot of features, presented on their website.

Li-Po Battery 7.4 V
In this project I used a Turnigy Nano-tech 300mah 2S 45~90C Lipo Pack, but any battery that is 7.4V will do.

QTR-8RC Reflectance Sensor Array

Micro Metal Gearmotor HPCB 6V

Solarbotics RW2i Wheel
These are the only wheels that are decent in my country.

Ball Caster with 3/8″ Metal Ball
HC-05 Bluetooth Module
Button 6x6x6

Resistor 1k ohm

Software apps and online services

Arduino IDE

EasyEDA
PCB Design Tool

SketchUp
3D Design Software
MIT App Inventor 2
App maker

and tools and fabrication machines

Soldering iron (generic)
3D Printer (generic)


Hardware

on this mission, I used all the components proven in the hardware phase. further, I used a custom PCB sketched by means of me, which replaces the breadboard and the huge amount of wires. in the end, I designed three-D parts that join all of the additives and thus compose the robot (figure 1).



As for the energy source, i've used a 7.four V 300mAh LiPo battery. It materials at once the DRV8835 motor-driver and the 5V step-down voltage regulator, which offers a solid 5V to the microcontroller. The handiest downside of those LiPo batteries is if the electricity drops beneath half of, you're now not capable of rate them. The Arduino pro Mini has its voltage regulator (with an input ranging among five - 12 V), so the voltage regulator may be elective.


i have used two Micro metallic Gearmotor HPCB 6V from Polulu, with a 10:1 gear ratio and 3000 RPM. you may find extra about this segment of motors on the Polulu hyperlink: https://www.pololu.com/class/60/micro-steel-gearmotors.


2. making plans the design of the robot

initially, I made this robot with the thought that it will have to admire sure policies of the opposition - the robot should not have dimensions better than 30x30 cm and the curve radius of the track must be at least 7.five cm - a few examples of the tracks i have used for trying out may be visible in parent 2).





I designed it as a "racing vehicle", with 2 automobiles within the returned and a ball caster in the front. I placed the QTR-8RC Sensor array within the the front of the robot in order that the ball caster will usually be on the line (parent 3).


right here comes the primary problem: what dimensions must the robotic take, if you want to discover a balance between speed and the ability to take the curves without leaving the music. For my first version, I didn't realize how narrow the curves have been, and the robot could not take them off the track. The most effective alternative I had left became to put into effect an set of rules wherein the 2 cars rotate inversely to every other. thus, the robot can make a one hundred eighty degree with out converting its position, however best the orientation. here comes the main hassle: what dimensions ought to the robot take, for you to discover a stability between velocity and the capability to take the curves without leaving the track. on the other hand, the rate at which the robot had to take the ones curves become some distance too low, so I decreased the element that holds the PCB to the ball caster (in discern four).


Sensors


in case you want to observe a code improvement from zero that I made for this robot (and is the reason all of the wiring, hardware and how to integrate the whole lot to make a useful self sustaining line follower):

to apply the QTR-8RC reflectance sensor array inside an Arduino assignment, you have to first set up the unique library. you could search in "control Libraries" for "QTRSensors", or, if it does not work, open this hyperlink: https://www.pololu.com/doctors/0J19/all. It affords the stairs on how to install the library and documentation about how the sensor works.

as soon as hooked up the library, there are a few things that want to be noted:

you could either calibrate the robot and then study the values of the sensors which depend on the preliminary values ​​from the calibration or examine the raw values of the sensors. the first case could be greater correct. in case you seek in report > Examples > QTRSensors, you'll find an example for each instances.

uint16_t function = qtr.readLineBlack(sensorValues);

with this line of code, the sensor array will return the placement of the black line. it could be among 0 and 7000. If the position is 3500, it means the sensor array is at the centre of the road

for (uint8_t i = 0; i

 {

   Serial.print(sensorValues[i]);

   Serial.print('t');

 }

if you want to get right of entry to a selected sensor from the sensor array, you could call a loop feature or surely name sensorValues[anumberfrom0to7]. It may not work in case you didn't name first the qtr.readLineBlack(sensorValues);

in my very last program, I failed to make the calibration automatic. So, at the beginning of this system, during this section, you have to expose every reflectance sensor to the lightest and darkest readings they will come across. as an instance, if you are creating a line follower, you need to slide the sensors across the line in the course of the calibration section in order that each sensor can get a reading of how darkish the line is and how mild the ground is. mistaken calibration will bring about bad readings.

 PCB and 3-D printing

on this venture, I desired to do something different and strive no longer to apply breadboard and wires in making the robotic. So I hooked up all of the additives on a PCB, to store area and no longer have issues with the connections. Designing this wasn't so difficult. First I made the schematic circuit with EasyEDA. Then, this software has a characteristic which could convert the schematic right into a PCB, so making the connections between the components might be extra simple. I best had to outline the PCB, vicinity the additives inside the define and then wire them (you can do it manually or automated with an automobile-router). I ordered five pieces at once from their website (the PCB stores in my united states asked me to pay 4 times the normal price for them) and the delivery turned into in 3 weeks. Then I soldered a number of the additives immediately at the PCB and the other additives with a girl header on the PCB - the HC-05 and the wires from the sensor array (in order that manner I could reuse and take away them).

the alternative additives (the battery and sensor guide) I crafted from 3-D published components. I used CAD software program (SketchUp) and then for every element I imported one as an STL file. After that, I published them at an electronics keep. I had few troubles with the screws due to the fact the holes have been too small or the 3D published components came over them. I used M3X16 screws for the motors brackets and the battery and sensor help, and M2X10 screws for the ball caster.



!!you would possibly want to check the STL of battery guide as it won't be excellent for some other battery. it may be bigger or the wires that connect the battery may not fit inside the hollow made specifically for them.

The line following algorithm and PID control

the line following algorithm is pretty easy. If the placement is better or lower than 3500, then the robot have to flip left or proper.


however if we positioned this in a loop, the robotic will oscillate until it eventually gets off track. And this is wherein PID control comes in reachable. In realistic phrases, it routinely applies an correct and responsive correction to a manipulate feature (Wikipedia). because of this the robot will not oscillate and will be able to take specific styles of curves at unique curve radius without getting off the line. To make it easier to apprehend this system, we can use an indispensable known as errors. it could be each tremendous and terrible.


int errors = 3500 - position;

The distinguishing characteristic of the PID controller is the ability to use the three control phrases of proportional, fundamental and by-product have an impact on at the controller output to apply correct and most beneficial control (Wikipedia). however this is not all. For every term, it corresponds to a regular, Kp, Ki and Kd, that ought to be adjusted in order that the robotic can observe a line without oscillating or slowing down or getting off the tune.

here, the proportional time period is the mistake. It directly controls the way to take the curves - if Kp is a small fee he's going to take the curves less difficult (he'll cross almost directly); if it's far a huge cost it'll take the curves all of sudden (both it will oscillate on a instantly line, or it'll take the curve too tight and it will depart the song).

int P = error;

The quintessential time period accumulates all errors. The crucial term seeks to eliminate the residual error with the aid of including a manage effect due to the historic cumulative value of the mistake. when the mistake is removed, the crucial term will cease to develop. this can result in the proportional impact diminishing as the mistake decreases, but that is compensated for by the developing fundamental effect (Wikipedia). In other phrases, it helps the robot forestall oscillating. but at a Ki that is too excessive, it'll do the other.

int I = I + mistakes;

The by-product term calculates the current error and the remaining error. whilst the robotic  hits a tight curve, this cost may be excessive and could force the robotic to take the desired curve. The extra speedy the alternate, the greater the controlling or dampening effect (Wikipedia). At a Kd too small, this cost won't take place. At a Kd too excessive, it can provide mistakes to the complete software and the robot can oscillate, run very slowly or take very narrow curves that don't even exist.

int D = errors - lastError;

lastError = blunders;

in the end, the equation of speed in order to be carried out to the vehicles could be:


drift motorspeed = P*Kp + I*Ki + D*Kd;

int motorspeeda = basespeeda + motorspeed;

int motorspeedb = basespeedb - motorspeed;

//where basespeed is the rate of each motor whilst the robot is going in a immediately line - 100 or a hundred and fifty

The entire factor of this algorithm is finding the 3 constants. They may be something. for example, for my robot Kp is 0.07, Ki is zero.0008 and Kd is 0.6. you may alternate their values ​​whenever in the software, or you can put a Bluetooth module wherein you could manipulate these values ​​at once from the smartphone.

6. Bluetooth manipulate

in this challenge, I made my robot with an HC-05 Bluetooth module to make it less difficult for me to find the ones values. i can deliver an Arduino report wherein I did the manipulate thru Bluetooth, in addition to the APK file (placed within the schematics part). The PCB schematic additionally contains the Bluetooth module.


I used MIT App Inventor because i'm able to make this type of apps rapid. although, it isn't always the best. First, you design the look of the app and 2d you block-code it.


The concept of how I made the connection between the Arduino (HC-05) and the smartphone is straightforward. because I could not ship a cost higher than 255 (I most effective should send one byte), I needed to do it in one of these manner that for each instruction (as an instance the change of sliders) I first sent a number of that represented the coaching (1 for Kp, three for Ki, five for Kd and 7 for the buttons). however which means that the constants could be between zero and 255. And as an instance for my robot Ki is 0.0008. So I made a second value for each consistent(multiP, multiI and multiD), that divides by means of a strength of 10 the constants. for example, the Arduino receives the values 1, 55 and then 2, 2. which means the Kp is first fifty five, then multiP is 100. on the quit Kp is fifty five / one hundred = zero.fifty five. due to the fact Ki is the smallest variety and has four decimals, the slider of the multi takes a range of between zero and five (10^5 = one hundred thousand). The code that has in its name (+ Bluetooth conversation) is made in particular for cellphone communication.

Schematics



Schematic Line Follower EasyEDA



Code
#include 
QTRSensors qtr;
const uint8_t SensorCount = 8;
uint16_t sensorValues[SensorCount];

int lastError = 0;
boolean onoff = 0;
int val, cnt = 0, v[3];

const uint16_t threshold = 500; // adjustable - can take values between 0 and 1000

//the speed can be between 0 and 255 - 0 is LOW and 255 is HIGH. At a high value, 
//you may risk burning the motors, because the voltage supplied by the PWM control
//is higher than 6V.
const int maxspeeda = 150;
const int maxspeedb 

Share the post

Line Follower robot (with PID controller)

×

Subscribe to Power Up Your Iphone With Our Premium Charging Cable - The Ultimate Accessory For Uninterrupted Connectivity

Get updates delivered right to your inbox!

Thank you for your subscription

×