Help making a code based on the example 3pi-mazesolver

Hi, we are a group of 3 students who bought Pololu 3pi robot.

We are making a school project using this robot, and we really don’t know how to start a code, based on the 3pi-mazesolver.

The ideia is simple. Instead of the robot study the maze, he already know the maze, and do the turns we want him to do. The maze will have, for example, 3 endings, and for which ending, he must take a different path, he will have a menu included, for the different endings ( that we already know how to do). Problem is, we don’t know much about c++, and we are having problems modifying the original code.

This is the ideia: we create a new array variable ( lab ), that has a predetermined path on it. Then we make the turn(dir) = lab. This way, it would choose the turn we want.

Problem is: We already create the array char lab[] = ( ‘S’, ‘…’, ), that contain the path. We don’t know to = it to the select_turn or turn, to make this happening.

It would be nice if you guys could give us some examples of codes.

Thanks in advance and sorry for the bad English.

Hello.

Making the changes you want to the sample code should be very easy. The code itself is divided into two phases:

  1. Learn the maze and populate the turns array with the appropriate path from start to finish.
  2. Use the turns array to drive the shortest path from start to finish.// This function is called once, from main.c.

You can see this from the simplified program outline provided in section 8.d of the user’s guide:

void maze_solve()
{
    while(1)
    {
        // FIRST MAIN LOOP BODY
        // (when we find the goal, we use break; to get out of this)
    }
     
    // 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 finished the maze.
        // Wait for the user to press a button...
 
        int i;
        for(i=0;i<path_length;i++)
        {
            // SECOND MAIN LOOP BODY
        }
         
        // Follow the last segment up to the finish.
        follow_segment();
 
        // Now we should be at the finish!  Restart the loop.
    }
}

All you need to do is eliminate the first part of program (FIRST MAIN LOOP BODY) and replace it with your own custom turns array before running the second part.

- Ben

void s()
{
	char a[100];
	unsigned int b = 0;

	//  'L' for left
	//  'R' for right
	//  'S' for straight (going straight through an intersection)
	//  'B' for back (U-turn)

	b = 0;

	a[b] = 'R'; b ++;
	a[b] = 'R'; b ++;
	a[b] = 'B'; b ++;
	a[b] = 'L'; b ++;
	a[b] = 'L'; b ++;

	for(int i=0;i<b;i++)
	{
		follow_segment();

		set_motors(50,50);
		delay_ms(50);
		set_motors(40,40);
		delay_ms(200);

		turn(a[i]);
	}
  
	follow_segment();

	set_motors(0,0);
}

Thanks Ben, for the Help. I test the code above and it worked !

We are going to use this code for our school work, and present it at Instituto Superior Técnico, an university in Lisbon, Portugal. All the credits go to you guys at Pololu. Thanks for you help !

I’m glad to hear you were able to get it to work. Good luck with your presentation!

- Ben