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.
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.
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.
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.
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.
To ensure that our calculations are correct,
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.
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.