-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.py
64 lines (54 loc) · 1.9 KB
/
control.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
#!/usr/bin/env python3
#EV3 is connecting through Wifi with the internet. Then through ssh
from ev3dev.ev3 import * # library for controling ev3
from time import sleep
import sys, termios, tty, os #for keyboard listening
#method for listening for keys
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
#initialising ultrasonic sensor
us = UltrasonicSensor()
# Put the US sensor into distance mode.
us.mode='US-DIST-CM'
units = us.units
#motors initialisation
m = LargeMotor('outB')
a = LargeMotor('outC')
control=''
Sound.play('/home/robot/Beginning.wav').wait()#opening sound
print('Lets begin') #starting script takes few seconds. This just indicates when it is ready.
while control != 'q':
distance = us.value()/10
char = getch()
if char == 'q':
exit(0)
elif char == 'e':
Leds.set_color(Leds.LEFT, Leds.RED)
Leds.set_color(Leds.RIGHT, Leds.RED)
Sound.play('/home/robot/Exterminate.wav').wait()
Leds.set_color(Leds.LEFT, Leds.YELLOW)
Leds.set_color(Leds.RIGHT, Leds.YELLOW)
elif char == 'm':
Sound.play('/home/robot/MustSurvive.wav').wait()
elif char == ' ' and distance < 20:
print(str(distance) + " " + units)
Sound.play('/home/robot/Exterminate.wav').wait()
elif char == 'w':
a.run_timed(time_sp=500, speed_sp=900)
m.run_timed(time_sp=500, speed_sp=910)
elif char == 's':
a.run_timed(time_sp=500, speed_sp=-900)
m.run_timed(time_sp=500, speed_sp=-900)
elif char == 'a':
a.run_timed(time_sp=140, speed_sp=200)
m.run_timed(time_sp=140, speed_sp=-200)
elif char == 'd':
a.run_timed(time_sp=140, speed_sp=-200)
m.run_timed(time_sp=140, speed_sp=200)