summaryrefslogtreecommitdiff
path: root/robot/problems/introduction/gyrosquare/naloga08_gyroSquare.py
blob: ec0dd2fd0fa7c3ebc3c30d1d6bfacefaa8f6eef6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python
# coding=utf-8

print ("""
Naloga 8:
   Robot naj prevozi kvadrat s stranico 20 cm; pri tem naj si pomaga z ziroskopom.
""")
import sys
sys.path.append('/home/user/codeq')
import time
from ev3dev import *
from mindstorms_widgets import mindstorms_widgets

robot = mindstorms_widgets()
robot.connect_motor( 'left' )
robot.connect_motor( 'right' )
robot.connect_sensor( 'gyro' )

robot.gyro_set_mode( 'angle' )
robot.reset_gyro()

power = 20
def forward_and_turnRight(power, angle):
    robot.move_steering( 'on_for_seconds', direction=0, power=power, seconds=2 )
    robot.move_tank( 'on', lr_power=[power,-power] )
    while robot.gyro_sensor_measure( 'angle' ) < angle:
        pass    
    robot.move_tank( 'off' )

forward_and_turnRight(power,  89)
forward_and_turnRight(power, 179)
forward_and_turnRight(power, 269)
forward_and_turnRight(power, 359)