Robot Programming

Posts 12 of 2 · Page 1 of 1
Robot Programming
I need help to do this. This is the task that my teacher gave but i really cant do it. Tried with node.js, arduino and much more. Try to read it too but still hard. I hope someone can solve this and teach me how to do it because i also need to explain and present it to my teacher how i got the solution.

Here are the question and the code:


Code:
int motorLeft = 9; int motorRight = 10;

int calibrateLED = 13; int mid = 0;

int mn = 0; int mx = 0;

void setup()
{

pinMode(calibrateLED, OUTPUT); digitalWrite(calibrateLED, LOW); pinMode(motorLeft, OUTPUT); pinMode(motorRight, OUTPUT); digitalWrite(MotorLeft, LOW); digitalWrite(MotorRight, LOW);

for(int i=0; i<5000; i++)
{
digitalWrite(calibrateLED, HIGH);

int val = 0;
for(int j=0; j<=4; j++)
{

val = analogRead(j); if(val >= mx)

mx = val; if(val <= mn) mn = val;
}
delay(1);
}

mid = ((mx + mn)/2); digitalWrite(calibrateLED, LOW);
}

void loop()
{
while(!DetectRightLine)
forward();

turnRight();

while(!DetectRightLine)
forward();

turnRight();

while(!DetectLeftLine)
forward();

turnLeft();

while(!DetectLeftLine)
forward();

turnLeft();

while(!DetectRightLine)
forward();

turnRight();

while(!DetectLeftLine)
forward();
 
turnLeft();

while(!DetectLeftLine)
forward();

turnLeft();

while(!DetectRightLine)
forward();

turnRight();

while(!DetectRightLine)
forward();

turnRight();

while(!DetectLeftLine)
forward();

turnLeft();

while(!DetectRightLine)
forward();

turnRight();

while(!DetectLeftLine)
forward();

turnLeft();

while(!DetectAllSensor)
forward();

digitalWrite(motorLeft,LOW);
digitalWrite(motorRight,LOW);
while(true);
}

boolean DetectLeftLine()
{

int LeftSideSensor = 0; LeftSideSensor = analogRead(3);

if(LeftSideSensor > mid) return true;

else
return false;
}

boolean DetectRightLine()
{

int RightSideSensor = 0; RightSideSensor = analogRead(4);

if(RightSideSensor > mid) return true;

else
return false;
}
 
boolean DetectAllSensor()
{

int frontSensorLeft = 0; int frontSensorMiddle = 0; int frontSensorRight = 0; int LeftSideSensor = 0;

int RightSideSensor = 0; frontSensorLeft = analogRead(0); frontSensorMiddle = analogRead(1); frontSensorRight = analogRead(2); LeftSideSensor = analogRead(3); RightSideSensor = analogRead(4);

if(frontSensorLeft > mid && frontSensorMiddle > mid && frontSensorRight > mid && LeftSideSensor > mid && RightSideSensor > mid)
return true;
else
return false;
}

void forward()
{

int frontSensorLeft = 0; int frontSensorMiddle = 0; int frontSensorRight = 0;

frontSensorLeft = analogRead(0); frontSensorMiddle = analogRead(1); frontSensorRight = analogRead(2);

if(frontSensorMiddle > mid)
{

digitalWrite(motorLeft, HIGH); digitalWrite(motorRight, HIGH);
}

else if(frontSensorLeft > mid && frontSensorRight < mid)
{

digitalWrite(motorLeft, LOW); digitalWrite(motorRight, HIGH);
}

else if(frontSensorLeft < mid && frontSensorRight > mid)
{

digitalWrite(motorLeft, HIGH); digitalWrite(motorRight, LOW);
}
else
{

digitalWrite(motorLeft, HIGH); digitalWrite(motorRight, HIGH);
}
}
void turnLeft()
{

int frontSensorLeft = 0; int frontSensorMiddle = 0; int frontSensorRight = 0;

frontSensorLeft = analogRead(0); frontSensorMiddle = analogRead(1); frontSensorRight = analogRead(2);

digitalWrite(motorLeft, LOW); digitalWrite(motorRight, HIGH);

while(frontSensorLeft > mid || frontSensorMiddle > mid || frontSensorRight > mid); while(frontSensorMiddle < mid);

digitalWrite(motorLeft, LOW); digitalWrite(motorRight, LOW);
}

void turnRight()
{

int frontSensorLeft = 0; int frontSensorMiddle = 0; int frontSensorRight = 0;

frontSensorLeft = analogRead(0); frontSensorMiddle = analogRead(1); frontSensorRight = analogRead(2);

digitalWrite(motorLeft, HIGH); digitalWrite(motorRight, LOW);
while(frontSensorLeft > mid || frontSensorMiddle > mid || frontSensorRight > mid); while(frontSensorMiddle < mid);

digitalWrite(motorLeft, LOW); digitalWrite(motorRight, LOW);
}
The question is:

1. Draw and explain the path of the line follower robot at Diagram 1 according to the programming in Diagram 2.
2. Explain each section of the programming in Diagram 2 according to your understanding.

the diagram 2 is:

here the document of the assignment

Assignment Programming_mpgh.net.rar111 KB · 4 downloads Clean
Posts 12 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?