forked from ori-drs/ivr_robotics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial.py
84 lines (63 loc) · 2.26 KB
/
tutorial.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Some simple open loop scripts
import ev3dev.ev3 as ev3
import time
import utilities as util
def operateWheelsBasic():
print("spin the wheels")
motor =ev3.LargeMotor('outA')
motor.connected
# run_time takes milliseconds
motor.run_timed(speed_sp=720, time_sp=500)
time.sleep(1)
motor.run_timed(speed_sp=-720, time_sp=500)
print('sleeping for 1 second')
time.sleep(1)
def makeLightSwitch():
print ("turn on LED w switch")
print ("for 10 seconds")
t_start = util.timestamp_now()
ts = ev3.TouchSensor(ev3.INPUT_1)
while True:
ev3.Leds.set_color(ev3.Leds.LEFT, (ev3.Leds.GREEN, ev3.Leds.RED)[ts.value()])
t_now = util.timestamp_now()
if (t_now - t_start > 10E3):
print ("finishing")
break
print ("turning off light")
print (" ")
ev3.Leds.set_color(ev3.Leds.LEFT, (ev3.Leds.GREEN, ev3.Leds.RED)[0])
def makeLightAndMotorSwitch():
print ("drive forward and back")
print ("using switches")
print ("for 30 seconds")
motor = ev3.LargeMotor('outA')
motor.connected
t_start = util.timestamp_now()
ts = ev3.TouchSensor()
ts2 = ev3.TouchSensor(ev3.INPUT_2)
while True:
ev3.Leds.set_color(ev3.Leds.LEFT, (ev3.Leds.GREEN, ev3.Leds.RED)[ts.value()])
ev3.Leds.set_color(ev3.Leds.RIGHT, (ev3.Leds.GREEN, ev3.Leds.RED)[ts2.value()])
if (ts.value()):
motor.run_timed(speed_sp=720, time_sp=50)
elif (ts2.value()):
motor.run_timed(speed_sp=-720, time_sp=50)
t_now = util.timestamp_now()
if (t_now - t_start > 30E3):
print ("im done")
break
print ("turning off light, done")
ev3.Leds.set_color(ev3.Leds.LEFT, (ev3.Leds.GREEN, ev3.Leds.RED)[0])
def recordUltraSonic():
print("Record readings from ultrasonic")
print("Will print after back button is pressed")
btn = ev3.Button()
sonar = ev3.UltrasonicSensor(ev3.INPUT_1)
sonar.connected
sonar.mode = 'US-DIST-CM' # will return value in mm
readings = ""
readings_file = open('results.txt', 'w')
while not btn.backspace:
readings = readings + str(sonar.value()) + '\n'
readings_file.write(readings)
readings_file.close() # Will write to a text file in a column