-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconbot.py
89 lines (71 loc) · 2.07 KB
/
conbot.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
85
86
87
88
89
#!/usr/bin/env python3
# so that script can be run from Brickman
import subprocess
import termios, tty, sys
from ev3dev.ev3 import *
# attach large motors to ports B and C, medium motor to port A
motor_left = LargeMotor('outC')
motor_right = LargeMotor('outB')
motor_a = MediumMotor('outA')
#==============================================
print("\n============To the order!============\n\n\n\n============LOG============\n")
#==============================================
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
tty.setcbreak(fd)
ch = sys.stdin.read(1)
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
def cabezaderecha():
motor_a.run_forever(speed_sp=450)
def cabezaizquierda():
motor_a.run_forever(speed_sp=-450)
def marchaimp():
subprocess.call(['python3', 'marchaImperial'])
#==============================================
def fire():
motor_a.run_timed(time_sp=3000, speed_sp=600)
#==============================================
def forward():
motor_left.run_forever(speed_sp=450)
motor_right.run_forever(speed_sp=450)
#==============================================
def back():
motor_left.run_forever(speed_sp=-450)
motor_right.run_forever(speed_sp=-450)
#==============================================
def left():
motor_left.run_forever(speed_sp=-450)
motor_right.run_forever(speed_sp=450)
#==============================================
def right():
motor_left.run_forever(speed_sp=450)
motor_right.run_forever(speed_sp=-450)
#==============================================
def stop():
motor_left.run_forever(speed_sp=0)
motor_right.run_forever(speed_sp=0)
motor_a.run_forever(speed_sp=0)
#==============================================
while True:
k = getch()
print(k)
if k == 'm':
marchaimp()
if k == 'g':
cabezaderecha()
if k == 'h':
cabezaizquierda()
if k == 's':
forward()
if k == 'w':
back()
if k == 'd':
right()
if k == 'a':
left()
if k == ' ':
stop()
if k == 'q':
exit()