How to Make Your Mindstorms NXT Robot Turn

The Problem

You have a shiny new LEGO Mindstorms NXT robotics kit, built the first robot (the “tribot”)… and then find yourself banging your head against the wall trying to figure out how to make the darned thing turn.

The software package that comes with the LEGO Mindstorms NXT robotics kit has a “move” box that allows you to select forwards, backwards, steering, etc. At first glance, this appears to be the perfect intuitive tool with all the bells and whistles.

However, when you set the steering to turn left or right, the value for the “duration” box makes you pause. You choose “degrees”, and put in (say) 90° to turn the robot to the left or right… but the robot refuses to obey.

The Oversight

At first glance, that line of thinking seems natural. If you want the robot to turn 90°, you tell it to turn 90°. But… that’s not the way it works in real life.

We humans have learned through practice how to turn our bodies through a complicated process of moving our legs, arms, etc. while staying balanced. We take in information about our position through our eyes and inner ears (where balance is sensed) to help us out. The brain has developed neural pathways (mental shortcuts) so strong that the process is completely automatic. We literally give no thought to the process. We just do it.

A robot doesn’t have the marvelous array of biological machinery that we humans have. Because there are no sensors giving it information about the world around it, the “tribot” has absolutely no idea of where it is in space. When it begins to turn the wheels, it cannot tell where it was when it started turning, how far to turn, or when to stop.

Hope

Fortunately, it does have one sensor. Each motor can tell how far it has turned. Therefore, we can tell the robot how far to turn each wheel, and the software will take care of the picky details. So, to make the robot turn, we just need to figure out how far to turn the wheels. For that, we’ll need some simple geometry and a calculator. In fact, the only required math is multiplication and division.

Here are the steps, which will be detailed below.

  1. Determine how far each wheel must travel on the ground.
  2. Turn that number into the number of rotations for each wheel.
  3. Verify with a simple experiment

Step One

First, we need to determine how far each wheel must travel. To keep things simple, we’ll turn the robot in place by turning the wheels the same distance in opposite directions. In this case each wheel will travel along the red circle. To do a complete turn, the top wheel “B” will end up in its starting location. The bottom wheel “C” will also end up in its original place.

So, how far does each wheel travel? If you remember basic geometry, the circle’s circumference is the diameter times π. So, carefully measure the distance from the middle of one wheel to the middle of the other. It will be easiest if you use a metric ruler, and read the number of millimetres. For the robot in the picture, that distance is 117mm. Your robot may be slightly different, but pretty close. The circumference of the circle is 117mm × π ≅ 378mm.

Thus, to turn the robot in place, each wheel must travel 378mm to around the circle one time.

turn-1.jpg

Step Two

Now that we know how far each wheel must travel, we need to know how many times each wheel must turn to travel the 378mm around the circle.

The wheel is also a circle, and the diameter of that circle is conveniently printed on the side of the tire. I see the following on the side of each tire:

© LEGO Group 56×26

The 56 means that the tire is 56mm in diameter. The 26 means that the tire is 26mm wide. (It’s useful to double-check by measuring.) Therefore, each time the tire makes one complete rotation, it travels 56mm × π ≅ 176mm across the ground. (We’re assuming there’s no slippage or other real-world factors that will mess things up slightly.)

So, if the tire moves the robot 176mm every time it turns, to travel 378mm the tire must turn 378mm ÷ 176mm ≅ 2.15 times. We’ve been rounding things off for convenience so far, so this is not quite right. Do the math on your calculator again, but don’t round off. You should get approximately 2.09 rotations.

Step Three

To ensure that our calculations are correct,

  1. Create a new program and put a single move box on it.
  2. Set the steering all the way to one side. Left or right won’t matter other than it will determine whether the robot turns clockwise or counterclockwise. For the experiment, this doesn’t matter.
  3. Set Duration for 2.09 rotations.
  4. You may need to turn the power down so it can stop more accurately. Try 50.
  5. Run the program. The robot should turn all the way around one time. If it turns around correctly, congratulations! If not, do not worry. The NXT software has some bugs in it, which the next part will address. Edit: As explained in the Acknowledgements below, the original full explanation in the NXTasy forums is no longer available. Please ask your questions in the new MindBoards forums.

Conclusion

This long exercise for something simple is to show the thinking process that is required for figuring out how to make the robot turn.

You can use this process to determine how far to turn. For example, to make the robot turn left or right, it will only need to turn one fourth of a circle; 90°. Divide your answer by four.

Acknowledgements

Brian and Richard were very helpful and generous on the NXTasy forums. You may see the thread here. It contains a lot of helpful information. These notes are merely a partial summary of what transpired there. Edit: The original NXTasy forums sadly have disappeared, which is highly disappointing. The forums had a vibrant and helpful community of NXT enthusiasts. A replacement site is here, and you can find the new forums here.

This entry was posted in CNC & Robotics, Micro & Hardware and tagged , , , , , , . Bookmark the permalink.

16 Responses to How to Make Your Mindstorms NXT Robot Turn

  1. Hassan says:

    Hey man thanks its useful concerning extremely accurate turns.

  2. Mi St says:

    Thank you, bro!

  3. Eric says:

    Thanks! I was getting tired of banging my head.

  4. When I get tired of banging my head against the wall, I try shooting myself in the foot for variety. j/k

  5. bob says:

    thanks

  6. Zul says:

    hello ,Mr james. i would like to make a robot.I use nxt. I would like to know how to set in mindstorm to give instruction to my robot automaticly make u turn if cannot turn left or right?

  7. faleye kenny says:

    how do you build a tribot i mean the building guide

  8. faleye kenny says:

    That wasrealy helpful

  9. Tom says:

    Where is part 2? It looks like 2.09 doesn’t work for me :(

  10. Jan says:

    Thank you! I’m taking a series of 4 online robotics classes and the turning was driving me crazy! I have successfully programmed a 360 degree turn My Block and a Rectangle My Block with your help.

  11. @Tom: Part 2 has languished unfinished, I’m sorry to say. All of the information that I was going to write was on the link to the NXTasy forums, so I felt no pressure to make a formal write-up. However, to my disappointment the forms disappeared in the intervening time.

    @Jan: I’m glad it helped. It drove us crazy too. :)

  12. I amended the post to include a link to the new MindBoards forum, which hopefully will be as useful as the only NXTasy site.

  13. N8 says:

    Thank you! It is nice to know that there was more to the story. Thanks for sharing your knowledge. I will go pull the sharp stick out of my eye and relax.

  14. Rae xin says:

    Now I know to do a 180 degree turn.

  15. Pingback: Making Your Robot Turn More Accurately | StudiesLab

Leave a Reply