Pages: [1]   Go Down
Author Topic: 90 Degree turns at nodes for grid follower robot.  (Read 3380 times)
0 Members and 1 Guest are viewing this topic.
India
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hii everyone,
I am making a Grid solver which will move to the exact same coordinate as specified in the program on 5x5 grid. The grid is made up of black line on white background.I am using two DC motors for navigation, two IR photo detector diodes for node detection and other two for the black line.The sensors are connected to analog pins of arduino.
I am able to move the robot on the line i.e it does not escapes from the line, but the problem i am facing is that it does not takeFull 90 degree Turns on the intersections i.e @ nodes. It senses the presence of node but is unable to rotate 90 degrees. I don't want to use encoders and instead want to do this by programming only .
here's the whole code i am using..
Code:
int LMen=5;//enable of LEFT motor
int RMen=6;//enable of Right motor
int LM1=3;//direction pin1 of first motor
int LM2=4;//direction pin2 of first motor
int RM1=7;//direction pin1 of right motor
int RM2=8;//direction pin1 of right motor
int N1=A7;//node detector1
int N2=A4;//node detector2
int T1=A6;//tracing sensor1
int T3=A5;//tracing sensor2
int LED=13;//arduino LED
int sensitivity=400;//threshold for sensors

void setup()
{
  pinMode(LED,OUTPUT);
  pinMode(LMen, OUTPUT);
pinMode(RMen, OUTPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
pinMode(N1,INPUT);
pinMode(N2,INPUT);
pinMode(T1,INPUT);
pinMode(T3,INPUT);
digitalWrite(LM1, LOW);//direction forward
digitalWrite(LM2, HIGH);//direction forward
digitalWrite(RM1, HIGH);//direction forward
digitalWrite(RM2, LOW);//direction forward
digitalWrite(LMen, LOW);
digitalWrite(RMen, LOW);
Serial.begin(9600);
}

void loop()
{
  if(analogRead(N1)>sensitivity && analogRead(N2)>sensitivity && analogRead(T1)>sensitivity  && analogRead(T3)>sensitivity )
    {
      digitalWrite(LED,HIGH);
      right90();
    }
  else
  {
    followline();
   digitalWrite(LED,LOW);
  }
}


void followline()
{
  if(analogRead(T1)>sensitivity && analogRead(T3)<sensitivity)
  {
    left();
  }
  else if(analogRead(T1)<sensitivity && analogRead(T3)>sensitivity)
  {
    right();
  }
  else
  {
    straight();
  }
}

void straight()
{
  digitalWrite(LMen,HIGH);
  digitalWrite(RMen,HIGH);
}


void left()
{
  digitalWrite(LMen,LOW);
  digitalWrite(RMen,HIGH);
}

void right()
{
  digitalWrite(LMen,HIGH);
  digitalWrite(RMen,LOW);
}

void right90()
{
  int i=1;
  right();
  straight();
  while(analogRead(N1)<sensitivity && analogRead(N2)<sensitivity && i==1)
  {
    right();
    if(analogRead(T1)>sensitivity && analogRead(T3)>sensitivity)
    {
      i++;//loop break condition
    }
  }
}
.
need help, can anyone tell me where am i going wrong,??
Logged

"The way I die for Open-Source"
Arduino Promini 328/5V/16Mhz

India
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

IF there is a black line analog value of sensor >400 and when there is white surface analogsensor value< 400. Hence "sensitivity=400".
one more thing i forgot to mention is that its only a part of the code, as i am interested in only full 90 degree turn of the bot i had to code this. I think robot is not able to execute "void right90()" correctly...
« Last Edit: December 30, 2012, 09:11:31 am by Aman24 » Logged

"The way I die for Open-Source"
Arduino Promini 328/5V/16Mhz

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26485
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
i++;//loop break condition

Or, more simply
Code:
break;

Other than that, why aren't you using the serial port to give you debug prints?

Code:
right();
  straight();
How many microseconds between those two calls?
« Last Edit: December 30, 2012, 09:41:45 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would think you want to use the IR photo detectors to find when you are aligned with the 'new' line to tell when you have completed the turn. The logic to achieve that would depend where the four sensors are in relation to each other and to the wheels.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

India
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thnk you very much for your Kind response smiley-wink
@ALOW: Yes, that can be an another way.. i am amateur in serial communication,so it would be better if u could tell me how I can tell u the time difference between those two calls.. smiley-confuse
@Peter H: yeah, i have used the same alignment technique as u are suggesting... smiley-neutral
Code:
if(analogRead(T1)>sensitivity && analogRead(T3)>sensitivity)
    {
      i++;//loop break condition
    }
i have re-modified this code or say the whole function as
Code:
void right90()
{
  int i=1;
 
  while(i!=2)
  {
    if(analogRead(T1)<sensitivity && analogRead(T3)<sensitivity && analogRead(N1)>sensitivity && analogRead(N2)>sensitivity)
    {
      i++;//loop break condition
    }
    right();
  }
}
...
Logged

"The way I die for Open-Source"
Arduino Promini 328/5V/16Mhz

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Peter H: yeah, i have used the same alignment technique as u are suggesting... smiley-neutral

Are you starting out correctly lined up on one line, and trying to turn until it is correctly aligned on a different line? If so, you may find that the turn is appearing as completed immediately you start it, because it is already aligned on a line. You would need to turn until it was no longer aligned on the original line, and then keep turning until it was aligned on the new line.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: