Inverted simplified maze Code and Video!

I was running my 3pi and I came across an idea, but something I have seen before, what about running the maze backwards.
What I mean is, starting the maze run normally and when it gets to the end have it go back to the start using the simplified path it stored(but inverted)…Taking the fastest way back…

Does anyone know what the code would look like???
I tired inverting the stored path but that didnt work to well…

-Mike

1 Like

Hi Mike,

You need to think of a way to take a path of lefts, rights and forwards, and converts them into the inverted path. To start you off, once you reach the end you should do a 180 degree turn. Once you know the proper path to go, the code to travel the path will be exactly the same as what you have now.

Please share what you find out!

- Ryan

For those of you who have read this thread I have finished the inverted simplified path. I myself haven’t seen a 3pi that does this yet so here’s my code and my video…
please feel free to ask any questions in case I forgot something…

Code

// This code is for the inverted section only!!!!
char temp[100] = "";

                int ii, jj;
		for(ii = 0, jj = path_length-1; ii<=path_length; ii++, jj--) 
		{
			temp[ii] = path[jj];
			if(temp[ii]== 'L') temp[ii] = 'R';
			else if (temp[ii] == 'R') temp[ii] = 'L';
			}
		
		int i;
		for(i=0;i<path_length;i++)
		
		{
			// SECOND MAIN LOOP   
			follow_segment(100);
		
			set_motors(50,50);
			delay_ms(50);
			set_motors(40,40);
			delay_ms(40);

		turn(temp[i]);
		
		}
			
		// Follow the last part to the finish.
		follow_segment(100);
		
			while(1);

*** Video****(on youtube.com, under ‘Inverted 3pi maze solver’)

please tell me what you think!!!

1 Like

Cool. Nice video, and good explanations of what is happening. In your video you say something like “any maze will do.” Doesn’t your maze need to be non-looped and gridded to work? A maze with loops is a nice challenge for someone who wants to learn about more advanced data structures and algorithms.

By the way, if you want your code to be easier for people on the forum to read and reuse, I recommend, while posting it, to select it and click the code button above the post input box.

- Ryan

I’m glad to see you were able to get the inverted maze solver working! Thanks for sharing your code and the video. As Ryan said, however, a left-hand-on-the-wall strategy can fail in a looped maze, because you can get stuck in the loop. You need a different, more advanced algorithm that tracks your actual position (typically in terms of the grid spacing of the maze) to solve a looped maze. The 3pi is capable of doing this, but it’s a much more complicated undertaking.

The video cuts out right before the robot actually reaches the start of the maze. Did the 3pi make it all the way to the start and stop there, or did it mess up right at the end (beginning?)?

- Ben

To answer both Ryan and Ben’s questions…

Ryan:
yes, It must be a gridded maze, non-looped! Thank you for pointing that out.

Ben:
It did make it to the end however, I have it stop when it reaches a ‘white surface’ and ‘reset’ and ready for the next maze(the maze could be different)… since I only had two of the 6 sections of my maze and no white surface for it to stop.