Society of Robots - Robot Forum
Software => Software => Topic started by: andreahmed 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 !!
(http://www.electro-tech-online.com/attachments/robotics-chat/18008-line-following-zig-zag-line-following.png?thumb=1&d=1205699426)
-
please give us more details!!!
Your code, how the sensors are arranged, motor specs, your circuit, etc.
We need those vital points !!
-
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
-
#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 mS
void 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 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=-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 Side
else 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_limit
if (correction<-30) correction=-30;// lower limit
pwm_l=max_speed-correction;
pwm_r=max_speed+correction;
delay5mS(); // delay function ~ 5 mS
}
}
-
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 (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
-
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
-
adjust motor speeds by adjusting PWM for each individual motor or by adding a resistor to the motor.
-
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
-
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 ...
#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 mS
void 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 2
TH0=0x9B; //Chu ki cai dat thong qua VDK la 1 chu ky may : 1.085us
TL0=0x9B;
PWM=0;
ET0=1; //Cho phep ngat do Timer0 //Khoi dong Timer0
EA=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 Side
else 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
}
}
-
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
-
how did u make it do 90 degree it can it be done with 3 sensors
-
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
-
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
-
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?
-
wat kind means ?????????????????
simple line following course and also i have made it in such a way that it should know where to end
-
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...).
-
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
-
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? :P
(superchiku, try to work on your spelling/grammar - I have trouble understanding you :-X)
-
admin , i really waited ur answer , would you tell me a soultion to my problem ?
-
Oh, well airman00 said what I would say:
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.
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
Follow these instructions to debug your circuit, and let us know your findings:
http://www.societyofrobots.com/robot_faq.shtml#circuit_debug
-
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 !
-
You should read this article: http://www.seattlerobotics.org/encoder/200108/using_a_pid.html (http://www.seattlerobotics.org/encoder/200108/using_a_pid.html)
And this article: http://www.wrighthobbies.net/guides/linefollower.htm (http://www.wrighthobbies.net/guides/linefollower.htm)
-
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...