An advanced but understandable description of how to program the mindstorm robot to move in a regular n-gon like pentagon, hexagon etc. (Yes, we know math). We have also included notes on the used formulas. A must see for each of you who would like to master the robot movements.

**#24**- 09 Jun 2013
- 8:35

### Hexagon

- CaRMetal software is needed to open the file;

### Draw.rbt

- download the NXT-G source code of the program.

### Pentagon

- CaRMetal software is needed to open the file;

### Square

- CaRMetal software is needed to open the file;

### English

I guess that all of you have tried to make the robot to move in а square at some point. Today I would like to show you how to make the robot move in regular n-gon, like pentagon or hexagon.

At first the program looks really simple. You make the robot move in straight line, then turn and this is repeated n times. Actually the program is simple. The only tricky part is when you have to calculate the turn the robot should make. To show you how you can reach a formula with which you can calculate this turn, I will use a free program, called CaRMetal. Let’s take a look at what we know about regular n-gons. The first thing is that they have n equal sides and n equal angles. The second is the fact that they can be inscribed in a circle. For instance, if we take a look at this hexagon and we connect the opposite vertices of the hexagon we will see that the three lines will intersect in one point. This point is the center of the hexagon as well as the center of the circle around the hexagon. If we take a look at this six triangles, we will see that they are equal. Also thеsе angles, here, are equal. In our case they are 60 degrees, but if we have a n-gon, they will be 360/n. Now let’s take a look at this triangle, here. The sum of the three angles will be 180 degrees. So the sum of the two angles, here, will be 180 minus this angle, here, or 180-360/n.

Next is the fact that this angle, here, is equal to this angle, here. So actually the whole angle of the regular n-gon is 180-360/n. But the robot should make the supplementary angle of this angle. So actually the robot will make 180-180-360/n, which is equal to 360/n. At the end we reach the fact that the robot should turn at 360/n. For the purpose of our lesson we will use the well known base construction of our competition robot. I have attached a whiteboard marker at the back of the robot. First let’s measure the distance between the tires. You should measure the distance between the two pivot point of the tyres. In our case, this is 11 cm. I have download a program with one move block, which makes the two Motors move forward for 1 rotation at 75% power. Let’s execute this program.

Now, I will measure the distance the robot has gone and it is 17 cm. Now after we have measured the distance, between the tyres and the centimeters per rotation let’s get back to our formula. The distance between the tires was 11 centimeters and the centimeters per rotation were 17. So in our case the formula would look like this. Now using that formula let's calculate what is the turn for a square. So n will be 4. And we will have: (1/4 multiplied by 2 multiplied by 11 multiplied by 'pi') divided 17 Let's implement that formula in NXT-G. I have created a new constant which is called 'pi' and it's a number type. And it's value is 3.14 and also I have a new variable which is called "Turn" and again it's a number type. First I will take a Math block and I will divide 1 by 4 the result I will multiply by 2.

Then again I will multiply by 11, now I will take a Constant block and the result I will multiply by 'pi'.

So connect the two blocks and chose multiplication. Now the result i should divide by 17.

Now we have reached the number of rotations we should do. Unfortunately the Move block and the Motor block accept only seconds and degrees. So I will need to multiply the result by 360. And now the result I will store in a new variable which will be called "Turn".

Now let's take a Loop block which will execute itself four times.

Inside we will have a Move block for lets say two rotations. I will make the power to let's say 40, because I will execute the program on a white board. And it is pretty slippy.

And the robot is not that accurate at high power. Then I will take a Motor block chose Motor C, chose degrees, take the Turn variable.

And I will connect the Turn variable to duration. I forgot to make the power of the turn 40. Okey, so now I have the program ready let's download and try it. Now let's execute the program.

As you can see the figure that the robot is drawing is way different from a square. And that is mainly because of these arcs. In the next tutorial I will show you how you can connect the consecutive sides of the figure.