**Gyro sensor and geometric figures**¶

## Preparing For This Tutorial:¶

The LEGO Mindstorm EV3 Robot that coincides with this tutorial comes from building specific sections found in the LEGO Mindstorm Education Core Set building instructions. You will need to build the main body for the robot (I’ll refer to as the Base Unit), plus gyro sensor.

Time constraints:

starting from 45 min - single lesson

## Exercise¶

Create a program that will make the robot run around the circumference of: an equilateral triangle, a square,a pentagon and other polygons.

## Theory¶

There are three special names given to triangles that tell how many sides (or angles) are equal.

Equilateral Triangle - three equal sides, three equal angles, always 60°

Isosceles Triangle - two equal sides, two equal angles

Scalene Triangle - no equal sides, no equal angles

In any triangle the three angles always add to 180°.

**Two Angles are Supplementary** when they add up to 180 degrees. Notice
that together they make a straight angle.

These two angles (150° and 30°) are **Supplementary Angles,** because
they add up to 180°:

**A polygon is regular** when all angles are equal and all sides are
equal (otherwise it is “irregular”).

This is a regular pentagon (a 5-sided polygon).

The **Exterior Angle** is the angle between any side of a shape, and a
line extended from the next side.

The Interior Angle and Exterior Angle are measured from the same line,
so they **add up to 180°** (they are supplementary).

## Short help on programming¶

**Commands/functions needed for the exercise**

Commands necessary to move

```
#!/usr/bin/env python3
from ev3dev2.motor import MoveTank, OUTPUT_B, OUTPUT_C
tank_pair=MoveTank(OUTPUT_B,OUTPUT_C)
tank_pair.on_for_rotations(20,20,1)
tank_pair.on(-20,20)
stank_pair.off()
```

Import necessary library and create a new instance of the class and assigns this object to the local variable gy

```
#!/usr/bin/env python3
from ev3dev2.sensor.lego import GyroSensor
gy = GyroSensor()
```

Set mode of gyro sensor

```
#!/usr/bin/env python3
gy.mode = 'GYRO-ANG'
Read the value from gyro sensor
gy.value()
```

**Example solution**

#Create a program to make the robot move straight and then turn 90 degrees.

# Import of necessary libraries

```
#!/usr/bin/env python3
from ev3dev2.motor import LargeMotor, MoveTank, OUTPUT_B, OUTPUT_C
from ev3dev2.sensor.lego import GyroSensor
from time import sleep
#Connect two large motors to port B and port C
tank_pair=MoveTank(OUTPUT_B,OUTPUT_C)
#Plug a gyro sensor into any sensor port
gy = GyroSensor()
#Set mode of gyro sensor
gy.mode = 'GYRO-ANG'
#read the value from gyro sensor
start_angle=gy.value()
angle=0
tank_pair.on_for_rotations(20,20,2)
#do the loop while condition is true
while angle-start_angle<90:
angle=gy.value()
#you are able to see the results on the screen
print(str(angle))
tank_pair.on(-20,20)
tank_pair.off()
```

**Museum at night**