Author Topic: Line follower problem  (Read 4710 times)

0 Members and 1 Guest are viewing this topic.

andreahmed

• Jr. Member
• Posts: 37
Line follower problem
« on: March 16, 2008, 02:55:55 PM »
Hi, im trying to follow a line using 6 sensors and it does not follow the line smooth and the motors are so fast really ... and one motor is faster than the other .. how do i solve that problem ? also when the robot is positioned like figure 2 and make it to follow the line it doesnt ... it just cross it as it and doesnt follow it !!

airman00

• Contest Winner
• Supreme Robot
• Posts: 3,653
• narobo.com
Re: Line follower problem
« Reply #1 on: March 16, 2008, 06:10:57 PM »
Your code, how the sensors are arranged, motor specs, your circuit, etc.

We need those vital points !!
Check out the Roboduino, Arduino-compatible board!

www.Narobo.com

andreahmed

• Jr. Member
• Posts: 37
Re: Line follower problem
« Reply #2 on: March 17, 2008, 03:18:56 AM »
sorry !

The sensors are arranged like that  X X X | X X X   , i just use a simple code ...  sensor to pwm values .

111111  : junction

000000 : fast motor move

100000 : pwm left wheel , right wheel fast speed
000001 : pwm right wheel , left wheel fast speed
001000:  pwm left wheel , right wheel fast speed
000100: pwm right wheel : left wheel fast speed
110000: pwm left wheel  : right wheel fast speed
000011: pwm right wheel : left wheel fast speed

just that
i use 89S52 , and LM324 for sensors , L298 for motor drivers

andreahmed

• Jr. Member
• Posts: 37
Re: Line follower problem
« Reply #3 on: March 17, 2008, 03:58:44 AM »
Code: [Select]
`#include <REGX52.h> #include <math.h>unsigned char pwm_r,pwm_l,PWM;unsigned char stuck_counter;float line,max_speed;float error;float prop;float deriv;float integral;float correction;float previous_error=0;int mpos;float rate;unsigned char center=0;void delay5mS(void);         // delay function ~ 5 mSvoid init_timer0(void);sbit Sensor_1 = P1^0; sbit Sensor_2 = P1^1;sbit Sensor_3 = P1^2;sbit Sensor_4 = P1^3;sbit Sensor_5 = P1^4;sbit Sensor_6 = P1^5;sbit sw       = P3^7;sbit Motor1_2 = P3^0; // Motor 1_ Input1 sbit Motor1_3 = P3^1; // Motor 1_ Input2 sbit Motor2_2 = P2^0; // Motor 2_ Input1 sbit Motor2_3 = P2^1; // Motor 2_ Input2 #define KP 19 // proportionality coefficient#define KI 0.4   // Integral coefficient #define KD 0.4   // derviative coefficient   void timer0(void) interrupt 1 using 0{                                                TR0=0;   PWM++;                            TL0=0x9B;                     //  ___   TF0=0;                        // |   |_____                                 if (PWM==11) PWM=0;    //      if (PWM <= pwm_l) Motor1_2=0;   else Motor1_2=1;;    if (PWM <= pwm_r) Motor2_2=0;   else Motor2_2=1;   TR0=1;   }void init_timer0(void)      {EA=0;                                               TMOD=0x02;    // 0000 0010   TH0=0x9B;      TL0=0x9B; PWM=0;                          ET0=1;EA=1;                  }fwd(){P2_0 = 1 ;P2_1 = 0 ;P3_0 = 1 ;P3_1 = 0 ;}stop(){P3_0 = 0 ;P3_1 = 0 ;P2_1 = 0 ;P2_0 = 0 ;}pivot_right(){P3_0 = 1 ;P3_1 = 0 ;P2_0 = 0 ;P2_1 = 1 ;}pivot_left(){P3_0 = 0 ;P3_1 = 1 ;P2_0 = 1 ;P2_1 = 0 ;}void main(){PWM= 11;pwm_r = 5;pwm_l = 5;max_speed =0;P0=0xFF;P1=0xFF;P2=0xFF;P3=0xFF;init_timer0();   while(1)      {         TR0=1;// start timer      // Right Sidefwd();if (Sensor_1==0&&Sensor_2==0 && Sensor_3==0 &&Sensor_4==0 && Sensor_5==0&&Sensor_6==0){if (mpos<0)mpos=-5; else mpos=5;}else  if (Sensor_1==0&&Sensor_2==0 && Sensor_3==0 &&Sensor_4==0 && Sensor_5==0&&Sensor_6==0){mpos=0;}else  if (Sensor_1==0&&Sensor_2==0 &&Sensor_3==0&&Sensor_4==0 &&Sensor_5==0&&Sensor_6==1){mpos=6;}else  if (Sensor_1==0&&Sensor_2==0&& Sensor_3==0&&Sensor_4==0&&Sensor_5==1&&Sensor_6==0){mpos=5;}else  if (Sensor_1==0&&Sensor_2==0&& Sensor_3==0&&Sensor_4==0&&Sensor_5==1&&Sensor_6==1){mpos=5;}else  if (Sensor_1==0&&Sensor_2==0 &&Sensor_3==0&&Sensor_4==1 &&Sensor_5==1&&Sensor_6==0){mpos=5;}else  if (Sensor_1==0&&Sensor_2==0&& Sensor_3==1&&Sensor_4==1&&Sensor_5==1&&Sensor_6==0) {mpos=3;}else  if (Sensor_1==0&&Sensor_2==0 &&Sensor_3==0&&Sensor_4==1 &&Sensor_5==0&&Sensor_6==0){mpos=2;}else  if (Sensor_1==0&&Sensor_2==0 &&Sensor_3==0&&Sensor_4==1 &&Sensor_5==1&&Sensor_6==1){mpos=1;}// Left Sideelse  if (Sensor_1==1&&Sensor_2==0 && Sensor_3==0&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-6;}else  if (Sensor_1==0&&Sensor_2==1 && Sensor_3==0&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-5;}else  if (Sensor_1==0&&Sensor_2==1 && Sensor_3==1&&Sensor_4==1&&Sensor_5==0&&Sensor_6==0){mpos=-4;}else  if (Sensor_1==1&&Sensor_2==1 && Sensor_3==0&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-4;}else  if (Sensor_1==1&&Sensor_2==1 && Sensor_3==1&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-3;}else  if (Sensor_1==0&&Sensor_2==1 && Sensor_3==1&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-2;}else  if (Sensor_1==0&&Sensor_2==0 && Sensor_3==1&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-1;}error=center-mpos;prop=error*KP;integral+=error;integral*=KI;rate=error - previous_error;deriv=rate*KD;previous_error=error;correction= prop+deriv+integral;if (correction>30) correction=30; // upper_limitif (correction<-30) correction=-30;// lower limitpwm_l=max_speed-correction;pwm_r=max_speed+correction;delay5mS();         // delay function ~ 5 mS}  }`

airman00

• Contest Winner
• Supreme Robot
• Posts: 3,653
• narobo.com
Re: Line follower problem
« Reply #4 on: March 17, 2008, 06:39:41 AM »
Why are you using 6 sensors arranged like that ?

Two or three sensors in that style are OK   are fine

Have a look at this
http://www.societyofrobots.com/programming_mobot.shtml

and at these  ( note how the sensors are arranged):

http://www.societyofrobots.com/member_tutorials/node/66

http://www.societyofrobots.com/member_tutorials/node/55

Check out the Roboduino, Arduino-compatible board!

www.Narobo.com

superchiku

• Supreme Robot
• Posts: 953
• cooll
Re: Line follower problem
« Reply #5 on: March 17, 2008, 07:10:17 AM »
hey six sensors arranged like that will never make the bot move 90 degree angular turns change the sensor's position and also try experimenting with ur algorithm to get the best and when dc motors are used ,they will never move at the same speed... so u have to adjust it accordingly
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

airman00

• Contest Winner
• Supreme Robot
• Posts: 3,653
• narobo.com
Re: Line follower problem
« Reply #6 on: March 17, 2008, 07:13:13 AM »
adjust motor speeds by adjusting PWM for each individual motor or by adding a resistor to the motor.
Check out the Roboduino, Arduino-compatible board!

www.Narobo.com

superchiku

• Supreme Robot
• Posts: 953
• cooll
Re: Line follower problem
« Reply #7 on: March 17, 2008, 07:13:29 AM »
and about the member robot tutorial , it will also never be able to take 90degree turns coz the sensors are all arranged linearly thats the problem with my bot too as i have used just 3 sensors
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

andreahmed

• Jr. Member
• Posts: 37
Re: Line follower problem
« Reply #8 on: March 17, 2008, 09:14:15 AM »
yea i understood thanks ... while googling .. i found that i've to use PD , and hence i wrote this !! check it guys , i still didnt test it on real ...

Code: [Select]
`#include <REGX52.h> #include <math.h>int pwm_r,pwm_l,PWM;unsigned char stuck_counter;float line,max_speed;float error;float prop;float deriv;float integral;float correction;float previous_error=0;int mpos;float rate;unsigned char center=0;void delay5mS(void); // delay function ~ 5 mSvoid init_timer0(void);sbit Sensor_1 = P1^0; sbit Sensor_2 = P1^1;sbit Sensor_3 = P1^2;sbit Sensor_4 = P1^3;sbit Sensor_5 = P1^4;sbit Sensor_6 = P1^5;sbit sw       = P3^7;sbit Motor1_2 = P3^0; // Motor 1_ Input1 sbit Motor1_3 = P3^1; // Motor 1_ Input2 sbit Motor2_2 = P2^0; // Motor 2_ Input1 sbit Motor2_3 = P2^1; // Motor 2_ Input2  #define KP 3 // proportionality coefficient#define KI 0.4   // Integral coefficient #define KD 0.4   // derviative coefficient   void timer0(void) interrupt 1 using 0{                                              TR0=0; PWM++;     TL0=0x9B; //  ___  TF0=0; // |   |_____ if (PWM==11) PWM=0; // if (PWM <= pwm_l) Motor1_2=0; else Motor1_2=1;; if (PWM <= pwm_r) Motor2_2=0; else Motor2_2=1; TR0=1; }void init_timer0(void)      {EA=0;                          //Cam cac ngat hoat dong, xem thanh ghi IE TMOD=0x02; // 0000 0010 //Cai dat che do tu dong quay lai: che do 2TH0=0x9B; //Chu ki cai dat thong qua VDK la 1 chu ky may : 1.085usTL0=0x9B; PWM=0;                          ET0=1; //Cho phep ngat do Timer0 //Khoi dong Timer0EA=1; //Cho phep tat ca cac ngat hoat dong }fwd(){P2_0 = 1 ;P2_1 = 0 ;P3_0 = 1 ;P3_1 = 0 ;}stop(){P3_0 = 0 ;P3_1 = 0 ;P2_1 = 0 ;P2_0 = 0 ;}pivot_right(){P3_0 = 1 ;P3_1 = 0 ;P2_0 = 0 ;P2_1 = 1 ;}pivot_left(){P3_0 = 0 ;P3_1 = 1 ;P2_0 = 1 ;P2_1 = 0 ;}void main(){PWM= 11;max_speed =0; P0=0xFF;P1=0xFF;P2=0xFF;P3=0xFF;init_timer0(); while(1) {    TR0=1;// start timer // Right Side fwd();if (Sensor_1==0&&Sensor_2==0 && Sensor_3==0 &&Sensor_4==0 && Sensor_5==0&&Sensor_6==0){if (mpos<0)mpos=-7; else mpos=7;}else  if (Sensor_1==1&&Sensor_2==1 && Sensor_3==1 &&Sensor_4==1 && Sensor_5==1&&Sensor_6==1){mpos=0;}else  if (Sensor_1==0&&Sensor_2==0 &&Sensor_3==0&&Sensor_4==0 &&Sensor_5==0&&Sensor_6==1){mpos=6;}else  if (Sensor_1==0&&Sensor_2==0&& Sensor_3==0&&Sensor_4==0&&Sensor_5==1&&Sensor_6==0){mpos=5;}else  if (Sensor_1==0&&Sensor_2==0&& Sensor_3==0&&Sensor_4==0&&Sensor_5==1&&Sensor_6==1){mpos=4;}else  if (Sensor_1==0&&Sensor_2==0 &&Sensor_3==0&&Sensor_4==1 &&Sensor_5==1&&Sensor_6==0){mpos=4;}else  if (Sensor_1==0&&Sensor_2==0&& Sensor_3==1&&Sensor_4==1&&Sensor_5==1&&Sensor_6==0) {mpos=3;}else  if (Sensor_1==0&&Sensor_2==0 &&Sensor_3==0&&Sensor_4==1 &&Sensor_5==0&&Sensor_6==0){mpos=2;}else  if (Sensor_1==0&&Sensor_2==0 &&Sensor_3==0&&Sensor_4==1 &&Sensor_5==1&&Sensor_6==1){mpos=1;}// Left Sideelse  if (Sensor_1==1&&Sensor_2==0 && Sensor_3==0&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-6;}else  if (Sensor_1==0&&Sensor_2==1 && Sensor_3==0&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-5;}else  if (Sensor_1==1&&Sensor_2==1 && Sensor_3==0&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-4;}else  if (Sensor_1==0&&Sensor_2==1 && Sensor_3==1&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-4;}else  if (Sensor_1==1&&Sensor_2==1 && Sensor_3==1&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-3;}else  if (Sensor_1==0&&Sensor_2==0 && Sensor_3==1&&Sensor_4==0&&Sensor_5==0&&Sensor_6==0){mpos=-2;}else  if (Sensor_1==0&&Sensor_2==1 && Sensor_3==1&&Sensor_4==1&&Sensor_5==0&&Sensor_6==0){mpos=-1;} error=center-mpos; prop=error*KP; integral+=error; integral*=KI; rate=error - previous_error; deriv=rate*KD; previous_error=error;correction = (prop-deriv);if (correction >10.0)correction=10.0;if (correction <-30.0)correction=0.0;pwm_l=max_speed+correction;pwm_r=max_speed-(correction);delay5mS(); // delay function ~ 5 mS  }   }`

airman00

• Contest Winner
• Supreme Robot
• Posts: 3,653
• narobo.com
Re: Line follower problem
« Reply #9 on: March 17, 2008, 11:00:07 AM »
and about the member robot tutorial , it will also never be able to take 90degree turns coz the sensors are all arranged linearly thats the problem with my bot too as i have used just 3 sensors
the second one does , its my robot, it can do 90 degree turns
Check out the Roboduino, Arduino-compatible board!

www.Narobo.com

superchiku

• Supreme Robot
• Posts: 953
• cooll
Re: Line follower problem
« Reply #10 on: March 17, 2008, 11:23:25 AM »
how did u make it do 90 degree it can it be done with 3 sensors
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

airman00

• Contest Winner
• Supreme Robot
• Posts: 3,653
• narobo.com
Re: Line follower problem
« Reply #11 on: March 17, 2008, 11:57:04 AM »
how did u make it do 90 degree it can it be done with 3 sensors

look through the tutorial

also ,

use your imagination how to do it with three sensors!

I think an array like this would work

X            X
X

Now Im sure u could think of some code that uses that array
Check out the Roboduino, Arduino-compatible board!

www.Narobo.com

superchiku

• Supreme Robot
• Posts: 953
• cooll
Re: Line follower problem
« Reply #12 on: March 17, 2008, 12:39:18 PM »
what u have done was already thought earlier by me ,it has a problems as the first 2 will always come out first and the bot wouldnt be able to know where to turn ,also the ending point will not be recognised by the bot
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

airman00

• Contest Winner
• Supreme Robot
• Posts: 3,653
• narobo.com
Re: Line follower problem
« Reply #13 on: March 17, 2008, 12:43:57 PM »
what u have done was already thought earlier by me ,it has a problems as the first 2 will always come out first and the bot wouldnt be able to know where to turn ,also the ending point will not be recognised by the bot

Wait , what kind of line following course do you need to travel through?
Check out the Roboduino, Arduino-compatible board!

www.Narobo.com

superchiku

• Supreme Robot
• Posts: 953
• cooll
Re: Line follower problem
« Reply #14 on: March 17, 2008, 12:52:24 PM »
wat kind means ??

simple line following course and also i have made it in such a way that it should know where to end
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Ro-Bot-X

• Contest Winner
• Supreme Robot
• Posts: 1,431
• Store: RoBotXDesigns.ca
Re: Line follower problem
« Reply #15 on: March 17, 2008, 02:16:28 PM »
I have participated at 3 types of line following events:
- simple line following - a simple looping circuit
- advanced line following - a loop circuit but with zig-zags, dashes, wider line, even a bridge sometimes...
- line maze - a maze made from lines instead of walls

So airman's question "what kind of line following course do you need to travel through?" was pertinent.

There are many ways to build a line follower. Starting from 1 sensor and going up to 5 sensors. I have seen even 7 sensors on a robot at a contest and that robot was really fast! The sensor arangements I've seen were all different, so it all depends on the robot's type of chassis and speed. Not allways the robot has a standard differential drive system. So, be creative and do your homework (search the web...).

Check out the uBotino robot controller!

superchiku

• Supreme Robot
• Posts: 953
• cooll
Re: Line follower problem
« Reply #16 on: March 17, 2008, 02:25:49 PM »
ok that was cool but i have been thinking for all possible combinations and ihavent yet been able to find out a solution using 3 sensors so if u could help then it would be cool
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

• Supreme Robot
• Posts: 11,680
Re: Line follower problem
« Reply #17 on: March 23, 2008, 11:35:48 AM »
Quote
ihavent yet been able to find out a solution using 3 sensors so if u could help then it would be cool
Then why are you using 3 sensors?

Just use two and call it a day, no?

(superchiku, try to work on your spelling/grammar - I have trouble understanding you )

andreahmed

• Jr. Member
• Posts: 37
Re: Line follower problem
« Reply #18 on: March 23, 2008, 02:25:06 PM »
admin , i really waited ur answer , would you tell me a soultion to my problem ?

• Supreme Robot
• Posts: 11,680
Re: Line follower problem
« Reply #19 on: March 23, 2008, 02:48:18 PM »
Oh, well airman00 said what I would say:
Quote
adjust motor speeds by adjusting PWM for each individual motor or by adding a resistor to the motor.
But don't use the resistor, just change the PWM.

You might also want to check to see if there is more friction in your mechanical connection on the slower wheel, maybe you can fix it with grease or whatever.

Quote
also when the robot is positioned like figure 2 and make it to follow the line it doesnt ... it just cross it as it and doesnt follow it !!
also, the image you linked isn't working

http://www.societyofrobots.com/robot_faq.shtml#circuit_debug

andreahmed

• Jr. Member
• Posts: 37
Re: Line follower problem
« Reply #20 on: March 24, 2008, 08:21:30 AM »
admin , about the image , suppose the there's a straight line in which u want to follow ok like that  |  and the robot is a bit deviated to right at 45degree and the robot is moving straight  , i want the robot to track the line again and move around it  its like that  /  |  where / is the robot  ...

also what about writting a PD line follower code? i wish you write a PID line follower robot tutorial ...

thanks !

Ro-Bot-X

• Contest Winner
• Supreme Robot
• Posts: 1,431
• Store: RoBotXDesigns.ca
Re: Line follower problem
« Reply #21 on: March 24, 2008, 09:31:28 AM »
Check out the uBotino robot controller!

superchiku

• Supreme Robot
• Posts: 953
• cooll
Re: Line follower problem
« Reply #22 on: March 25, 2008, 04:34:21 AM »
hmm the best way to make a robot is to do research

try to start certain ideas u have and then if u got problems , just ask...
« Last Edit: March 25, 2008, 04:35:02 AM by superchiku »
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"