Showing posts with label line follower robot. Show all posts
Showing posts with label line follower robot. Show all posts

Saturday, 14 March 2020

Virtual Line Follower

This post is about the Virtual line follower android app. This app lets you learn about line follower without any complex circuit. In this app, you can adjust parameters like the number of sensors, the distance between sensors which is a very time consuming and costly task to do with a practical line follower. You can write your own logic and run the robot.
If you don't have an android device then you can download any Android emulator available and run this app.

Let us look at the geometry of the robot.
Following parameters of line follower bot are adjustable
1. The number of sensors. You can use as many sensors you want in a straight array fashion.
2. Distance between sensors (x): Distance between sensors can be chosen in terms of pixel length. The distance between consecutive sensors is the same for all sensors.
3. Distance between motors (L) can also be changed.
4. The distance of the sensor array from the motor axis can be changed.
5. Sensors are arranged from left to right as shown in the figure below.
Line Follower Geometry


The sensor state is written from the leftmost sensor to the rightmost sensor. For example for two sensors S0, S1 possible states are 00, 01, 10, 11.
Motor output can be from -1 to +1. Where -1 is for maximum reverse speed and +1 for maximum forward speed.

Examples to try inside the app:

1) Two sensors:

for "00" state go forward by left motor=1 and right motor=1 
for "01" state go right by left motor=1 and right motor=0 
for "10" state go left by left motor=0 and right motor=1  
for "11" state go forward by left motor=1 and right motor=1 

Inside App, the following should be input
Sensor state:
00
01
10
11

Left Motor:
1
1
0
1

Right Motor:
1
0
1
1

2) Three sensors:

for "001" and "011" states go right by left motor=1 and right motor=0 
for "110" and "100" state go left by left motor=0 and right motor=1  
for "010" state go forward by left motor=1 and right motor=1 
Otherwise, go forward in simple robot. 

Inside App, the following should be input
Sensor state:
001
011
100
110
010

Left Motor:
1
1
0
0
1

Right Motor:
0
0
1
1
1

For PID go here https://crackeconcept.blogspot.com/2020/03/virtual-pid-line-follower.html


the app is out! Try now.

Tuesday, 11 March 2014

3 sensor Line follower Arduino code(without PID) but just like PID

Line follower bot is basically a robot that follows a black line. If you have already made a simple line follower robot and looking forward to improve its performance than you are at the right place. To make an improvement to the performance of anything feedback is the best choice. In this post, a new method of using feedback is introduced which you can use to improve your line follower bot.
 
You will find most people use PID feedback to improve the performance of a system. PID controller has its own challenges. It is very hard to code and tune.  But here we are looking for something more simple and easy. The method discussed in this post is best suited with at least three sensors but you can try it two sensors but just little adjustments in code.
Let us start discussing the method. The basic idea is to memorize the current readings of the line follower bot at the end of the loop. In the next loop, If the bot finds itself out of line it trusts on reading taken in the previous loop. So our line follower bot becomes more intelligent by feedback and can deal with such a situation by taking suitable actions.

Example of three sensor bot: Let's say there are three sensors giving binary readings. Here 0 means the sensor is on the line and 1 means sensor is not on the line.

The following actions are taken according to sensors reading:
* Go forward if current readings of sensors are 101.
* Go right if current readings of sensors are 110.
* Go left if current readings of sensors are 011.
* Go right if current readings of sensors are 111 and previous are 110.
* Go left if current readings of sensors are 111 and previous are 011.

Since we are using readings taken only one step before we can call it first-order feedback. You can also use the readings from the last 2 readings. In that case, the complexity of the algorithm will go high.


//The code is

int rightmotor1=12;
int leftmotor1=10;
int rightmotor2=13;
int leftmotor2=11;


int sensorleft=14;
int sensorcenter=15;
int sensorright=16;


int l1=1;
int l2=1;
int l3=1;

int f1=0;
int f2=0;
int f3=0;

//////////////////////////////////////

void setup()
{

 pinMode(rightmotor1,OUTPUT);
 pinMode(leftmotor1,OUTPUT);
 pinMode(rightmotor2,OUTPUT);
 pinMode(leftmotor2,OUTPUT);

 pinMode(sensorleft,INPUT);
 pinMode(sensorcenter,INPUT);
 pinMode(sensorright,INPUT);

}
///////////////////////////////////////////////////

void loop()
{
l1=digitalRead(sensorleft);
l2=digitalRead(sensorcenter);
l3=digitalRead(sensorright);

/////////////////////////////////////////////////////////////////////
if(l1==1&&l2==1&&l3==1)   //feedback when comes all sensor on white
{
l1=f1;
l2=f2;
l3=f3;
}

////////////////////////////////////////////////////////////////////////////
if(l1==0&&l2==1&&l3==1||l1==0&&l2==0&&l3==1)   //left turn
{
  digitalWrite(rightmotor1,1);
  digitalWrite(rightmotor2,0);
  digitalWrite(leftmotor1,0);
  digitalWrite(leftmotor2,0);
}
else
if(l1==1&&l2==1&&l3==0||l1==1&&l2==0&&l3==0)  //right turn
{
  digitalWrite(rightmotor1,0);
  digitalWrite(rightmotor2,0);
  digitalWrite(leftmotor1,1);
  digitalWrite(leftmotor2,0);
}
else
if(l1==1&&l2==0&&l3==1)  //go forward straight
{
  digitalWrite(rightmotor1,1);
  digitalWrite(rightmotor2,0);
  digitalWrite(leftmotor1,1);
  digitalWrite(leftmotor2,0);
}
else
if(l1==0&&l2==0&&l3==0) //stop
{
  digitalWrite(rightmotor1,0);
  digitalWrite(rightmotor2,0);
  digitalWrite(leftmotor1,0);
  digitalWrite(leftmotor2,0);
}

///////////////////////////////////////////////////////////////////
f1=l1;
f2=l2;
f3=l3;        //memory variables
////////////////////////////////////////////////////////////////////
}




Here f1, f2, and f3 are our feedback variable or we can say memory variables.
This is a simple code you can change the code according to our needs.

This idea is also possible with two sensors but you will see the bot oscillating on the line. This idea best works with three sensors.
Check out this post for two sensor version. https://crackeconcept.blogspot.com/2020/01/two-sensor-code-for-line-follower-using.html
You can see the video is given below in which line follower works on the same algorithm but with four sensors. That is how a three IR sensor line follower will also work.
This line follower robot is also available in the Virtual line follower app given link below. Try yourself and see its performance there.
Hope this post will help you.
 /////////////////////////////////////////////////////////////////////////////////////
My free android apps.
https://play.google.com/store/apps/developer?id=Gaur+Tavm
Thank you.