hello ben,
i am preparing for a maze solving competiton with a very difficult problem statement to solve
the problem statement is
i can reach the end point given by just optimizing the mazesolver code given by pololu libs but the problem is how do i make the robot traverse along the exact same path it came from the start point and again reach the start point once it has reached the end point in the exact same path
what i mean is (start point ------endpoint---------back to startpoint)in the exact same path it came by solving the maze
i know that i have to make a function reversing the turn operations that is
s will remain same
R to L
L to R
i tried doing this on 3pi first up by adding this funtion at the second while loop which runs infinitely once the maze is solved,although it reverses the path[i],but it isnt executing the reversed path please suggest me a correct way to achieve this operation
it doesnt execute the reversed path
this is the function i made to reverse the path
void reverse_path()
{ int i;
for (i = path_length-1; i >=0; i++)
{
if(path[i] == 'S')
{
path[i] = 'S';
}
if(path[i] == 'R')
{
path[i] = 'L';
}
if(path[i] == 'L')
{
path[i] = 'R';
}
}}
And this is the void loop in arduino(i do coding using arduino)
void loop()
{
while (0)
{
follow_segment();
// Drive straight a bit. This helps us in case we entered the
// intersection at an angle.
// Note that we are slowing down - this prevents the robot
// from tipping forward too much.
OrangutanMotors::setSpeeds(50, 50);
delay(50);
// These variables record whether the robot has seen a line to the
// left, straight ahead, and right, whil examining the current
// intersection.
unsigned char found_left = 0;
unsigned char found_straight = 0;
unsigned char found_right = 0;
// Now read the sensors and check the intersection type.
unsigned int sensors[5];
robot.readLine(sensors, IR_EMITTERS_ON);
// Check for left and right exits.
if (sensors[0] > 100)
found_left = 1;
if (sensors[4] > 100)
found_right = 1;
// Drive straight a bit more - this is enough to line up our
// wheels with the intersection.
OrangutanMotors::setSpeeds(40, 40);
delay(200);
// Check for a straight exit.
robot.readLine(sensors, IR_EMITTERS_ON);
if (sensors[1] > 200 || sensors[2] > 200 || sensors[3] > 200)
found_straight = 1;
// Check for the ending spot.
// If all three middle sensors are on dark black, we have
// solved the maze.
if (sensors[1] > 600 && sensors[2] > 600 && sensors[3] > 600)
break;
// Intersection identification is complete.
// If the maze has been solved, we can follow the existing
// path. Otherwise, we need to learn the solution.
unsigned char dir = select_turn(found_left, found_straight, found_right);
// Make the turn indicated by the path.
turn(dir);
// Store the intersection in the path variable.
path[path_length] = dir;
path_length++;
// You should check to make sure that the path_length does not
// exceed the bounds of the array. We'll ignore that in this
// example.
// Simplify the learned path.
simplify_path();
// Display the path on the LCD.
display_path();
}
// Solved the maze!
// Now enter an infinite loop - we can re-run the maze as many
// times as we want to.
while (1)
{
// Beep to show that we solved the maze.
OrangutanMotors::setSpeeds(0, 0);
OrangutanBuzzer::play(">>a32");
done = 1;
// Wait for the user to press a button, while displaying
// the solution.
while (!OrangutanPushbuttons::isPressed(BUTTON_B))
{
if (millis() % 2000 < 1000)
{
OrangutanLCD::clear();
OrangutanLCD::print("Solved!");
OrangutanLCD::gotoXY(0, 1);
OrangutanLCD::print("Press B");
}
else
display_path();
delay(30);
}
while (OrangutanPushbuttons::isPressed(BUTTON_B));
delay(1000);
// Re-run the maze. It's not necessary to identify the
// intersections, so this loop is really simple.
int i;
for (i = 0; i < path_length; i++)
{
follow_segment();
// Drive straight while slowing down, as before.
OrangutanMotors::setSpeeds(50, 50);
delay(50);
OrangutanMotors::setSpeeds(40, 40);
delay(200);
// Make a turn according to the instruction stored in
// path[i].
turn(path[i]);
}
follow_segment();
reverse_path();
OrangutanMotors::setSpeeds(80,-80);// reverse after execution of the path then now on to reversing the path so gets aligned to execute the reverse path
for (i = path_length-1; i >=0; i++)
{
// Drive straight while slowing down, as before.
OrangutanMotors::setSpeeds(50, 50);
delay(50);
OrangutanMotors::setSpeeds(40, 40);
delay(200);
// Make a turn according to the instruction stored in
// path[i].
turn(path[i]);
}
follow_segment();
}
}
thanks for any help