# 3pi video (turns)

This messages was originally sent to Ben

I have a 3pi robot and Ive been messing with it for a little while now. Ive seen a lot of the 3pi videos and overheard you say that you were one of the designers/creators of this wonderful robot… but I have just one question, in the maze solving video I noticed the turns it makes on the second run (simplified maze) the turns are so smooth and quick… Ive tried adjusting the motor settings and code but mine isn’t so smooth… What does your code look like… any help would be greatly appreciated.
Thanks
Mike

Hi, Mike.

Getting the turns to work like that was somewhat tricky. My in-place turns involve setting the motors to opposite-but-equal speeds, while my smooth turns involve setting one motor to zero (or maybe reverse at some slow speed) while the other motor keeps running. In my code I wrote functions called things like:

turn_right_in_place()
turn_right_smooth()
turn_left_in_place()
turn_right_smooth()
turn_around()

They use simple timing to achieve the turns, and I honed them by trial-and-error. Once I was confident that they would turn the robot the desired amount, I just called them from my code when an intersection was reached.

The big problem with the smooth turns is that if you call it too late, the robot will be off the line after the turn. You really have to start it the instant the robot detects the intersection. This is why I only use them once the robot has learned the course. While the 3pi is learning the course, I use a conservative strategy of really exploring the intersection to determine what the possible paths are. Once I have fully explored the maze and determined the optimal path, I can use that information to make quicker decisions when I’ve reached an intersection.

More specifically, when I’m learning the maze, I always drive straight through an intersection so I can tell whether it has left, straight, and right paths available. When I’m solving the maze after it has been learned, I don’t need to characterize the intersections anymore. I know that if I’m making a right at the next intersection, I can start my turn the instant any of my outer sensors sees anything. Ultimately, I have two different functions: one for driving the course as I learn it and one for driving a specific path on a course.

If you want to drive a maze quickly and with smooth turns, you have to be willing to spend a lot of time tweaking the various parameters until you get something that works well reliably. I spent an entire evening tuning the one you saw in that video!

- Ben

Ben,
Thanks for all your help. I changed mine a little differently than you said but with the same idea…but, I finally got it right!!! by messing around and tweaking the turns and timing here and there. It looks a lot better when its solving and learning too!!!

----For any one who wants to see my code here is it—
keep in mind I have my max speed set at 100, because that’s what works with the maze I built… so it might require different settings

``````void turn(char dir)
{
switch(dir)
{
case 'L':
// Turn left.
set_motors(-40,100);
delay_ms(208);
play_note(G(5), 200, 15);

break;

case 'R':
// Turn right.
set_motors(100,-40);
delay_ms(208);
play_note(A(5), 200, 15);

break;
case 'B':
// Turn around.
set_motors(80,-80);
delay_ms(420);
play(">b32>>c32");

break;
case 'S':
// Don't do anything!
play_note(D(5), 200, 15);

break;
}
}

// end: **
..............................................
// wheels with the intersection. in maze_solve.c
//Set this for both loops!! or the turns wont be accurate in the second loop
set_motors(40,40);
delay_ms(40);

//int max = (100) other speeds might require different settings
``````

I’m glad to hear you got it working! Thanks for sharing your code. Are you trying to make a maze-solver for a competition, or are you just working on it as a fun personal challenge?

- Ben

Im using it for my capstone project for class in Electronic engineering… I have a video of it on youtube, under Capstone robot…
Ive made many additions to it, since the video, but I just want to perfect it! In a previous thread I asked people about (inverting the simplified maze) meaning after the learning phase, start from the finish and go to the start using the stored simplified phase… and thats what im working on now, and I almost have it but it spins out right before its reaches the starting point… Ill be posting that code as well because Ive never seen a 3pi attempt that.

also Ive turned many of my colleges and friends to your company and they have all asked about a facebook page… you guys should start one!!! just a thought

We appreciate the good word of mouth, and thank you for the suggestion about Facebook. It sounds like you’re making some great progress modifying the stock maze-solving code into something much better! Our hope when we released it as an example was that people would do just that.

If you need some help debugging your project, you could post a video showing where and how it’s messing up along with the relevant portions of your code, and I could give you some input.

When you do have a final video of your maze-solver, please post it!

- Ben

what is the main factor of maze that deside above value in smooth turn. is it width of tape or parallel distance ?

in one compitition i got 3 tries i will use 1 st for learning
2nd normal with safe turn and last for smooth , how should i change those values with safe value in program

PS
what is battery value at which i should change battery.

PS+1
why in every video of maze robot slows a bit when it passes intersection he is not going to turn there ?

I’m not completely sure I understand what you’re asking here. What do you mean by parallel distance?

The faster and fancier you get, the more likely your robot is to mess up. Safe values are ones that lead to a slightly slower run with significantly increased reliability. You should get your robot running reliably and make those values your safe values, then try to push it some. My safe approach is to have the robot turn in place rather than make smooth turns.

That depends on whether you’re using alkaline or NiMH cells. I’d consider changing alkalines when you get near 5.4V and NiMHs when you get around 4.3V. Those are just rough estimates, though. Most importantly, don’t program your 3pi when the batteries are low.

It’s easier to charactize intersections if you drive through them slowly. Once I know the solution, I don’t bother slowing down at intersections where I’m not turning.

- Ben