https___mail-attachment.googleusercontent.com_attachment_u_0__ui2ik8c5c1f4b4cviewattth13ee923cdead7e83attid0.pdf (907158Bytes)
https___mail-attachment.googleusercontent.com_attachment_u_0__ui2ik8c5c1f4b4cviewattth13ee923cdead7e83attid0.pdf (907158Bytes)
Well I am making an obstacle avoiding robot with my friends its for a competion to win 2000 dollars.
I programed the robot and everything It works pretty good, whenever the robot "sees" an obstacle it moves a servo with a sensor right and left and decides which way to go.
The problem is that it has to got through a course which has 11 90 degree turns I attached a pdf with rules and diagram.
So whenever the robot sees something it moves its head and goes towards the correct direction as expected but then even though there is nothing in front of it, the robot moves its head again unnecessarily and goes a different direction but these happens only like 8 out of 10 times and while the robot moves through the course the person cant touch it. Please help I have to win :)
here is the code;
#include <Servo.h> int right1 = 11; int right2 = 12; int left1 = 6; int left2 = 7; Servo anshul; int pos = 0; int sensor = A0; int object = 150; int rightval,leftval,frontval;void setup() {
pinMode(right1, OUTPUT);
pinMode(right2, OUTPUT);
pinMode(left1, OUTPUT);
pinMode(left2, OUTPUT);
Serial.begin(9600);
anshul.attach(5);
anshul.write(90);
}void loop()
{
/frontval = analogRead(sensor);
Serial.print(frontval);
Serial.print("\t");
Serial.print(rightval);
Serial.print("\t");
Serial.print(leftval);
Serial.println();
/if(frontval < object)
{
forward();
anshul.write(90);
}
else//if(frontval > object)
{stop();
anshul.write(0);
delay(500);
checkright();
delay(500);
anshul.write(180);
delay(700);
checkleft();
delay(500);
anshul.write(90);
delay(100);
comparedistance();}
}void checkright()
{
rightval = analogRead(sensor);
}
void checkleft()
{
leftval = analogRead(sensor);
}void comparedistance()
{
if(rightval<leftval)
{
right();
delay(270);
}
if(leftval<rightval)
{
left();
delay(270);
}
}
void right()
{
digitalWrite(right1, LOW);
digitalWrite(right2, HIGH);
digitalWrite(left1, LOW);
digitalWrite(left2, HIGH);
}void left()
{
digitalWrite(right1, HIGH);
digitalWrite(right2, LOW);
digitalWrite(left1, HIGH);
digitalWrite(left2, LOW);
}
void backward()
{
digitalWrite(right1, LOW);
digitalWrite(right2, HIGH);
digitalWrite(left1, HIGH);
digitalWrite(left2, LOW);
}
void forward()
{
digitalWrite(right1, HIGH);
digitalWrite(right2, LOW);
digitalWrite(left1, LOW);
digitalWrite(left2, HIGH);
}
void stop()
{
digitalWrite(right1, LOW);
digitalWrite(right2, LOW);
digitalWrite(left1, LOW);
digitalWrite(left2, LOW);
}