-
Notifications
You must be signed in to change notification settings - Fork 0
/
ro.py
130 lines (107 loc) · 2.75 KB
/
ro.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# GPIO
import RPi.GPIO as _g
# Keyboard input
import curses as _c
# time utilities
import time as _t
# configuration
from config import configuration as _conf
# servo motor for camera
from RoPiServo import RoPiServo
# motor for movements
from RoPiMotor import RoPiMotor
# leds
from RoPiLED import RoPiLED
# screen
#from RoPiScreen import RoPiScreen
# distance sensors
from RoPiDistance import RoPiDistance
# tracking sensors
from RoPiTrack import RoPiTrack
# start engines
if _conf['DEVEL_LOG'] : print("Starting engines...")
led = RoPiLED()
#screen = RoPiScreen()
distance = RoPiDistance(led)
track = RoPiTrack()
motor = RoPiMotor(distance, track)
servo = RoPiServo()
if _conf['DEVEL_LOG'] : print("Engines started!")
# capture commands from input
_s = _c.initscr()
_c.noecho()
_c.cbreak()
_s.keypad(True)
_s.nodelay(True)
# start infinite loop...
if _conf['DEVEL_LOG'] : print("Capturing input...")
started = _t.time()
try:
while True:
# capture input
_k = _s.getch()
if _conf['DEVEL_LOG'] : print("Captured key: ", _k)
# pause/quit
if _k == ord('p'):
break
# autonomus guide
elif _k == ord('u'):
motor.autonomous()
# cam reset
elif _k == ord('r'):
servo.reset()
# cam up
elif _k == _c.KEY_UP:
servo.up()
# cam down
elif _k == _c.KEY_DOWN:
servo.down()
# cam right
elif _k == _c.KEY_RIGHT:
servo.right()
# cam left
elif _k == _c.KEY_LEFT:
servo.left()
# wheels forward
elif _k == ord('w'):
motor.forward()
# wheels backward
elif _k == ord("s"):
motor.backward()
# wheels left
elif _k == ord("a"):
motor.forwardleft()
# wheels right
elif _k == ord("d"):
motor.forwardright()
# wheels left backward
elif _k == ord("z"):
motor.backwardleft()
# wheels right backward
elif _k == ord("x"):
motor.backwardright()
# clean old actions if no action in CLEAN_ACTION_TIME_SPAN
elif _k == -1 :
now = _t.time()
if _conf['DEVEL_LOG'] : print("Nothing in time: ", now)
if now - started > _conf['CLEAN_ACTION_TIME_SPAN'] :
if _conf['DEVEL_LOG'] : print("Clean old queued actions...")
motor.cleanQueues()
led.allOff()
started = _t.time()
# capture interruption
except KeyboardInterrupt:
pass
# exit cycle
finally:
_c.nocbreak()
_s.keypad(0)
_c.echo()
_c.endwin()
# clean
servo.terminate()
motor.terminate()
#screen.terminate()
distance.terminate()
track.terminate()
_g.cleanup()