-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuart_steer_test.py
More file actions
53 lines (39 loc) · 1.6 KB
/
Copy pathuart_steer_test.py
File metadata and controls
53 lines (39 loc) · 1.6 KB
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
import threading
import donkeycar as dk
from parts.uart_backup import UART_backup_driver
from parts.health_check import HealthCheck
RATE_HZ = 50
class ManualSteering:
"""Read steering from stdin in a background thread; UART loop keeps running."""
def __init__(self):
self.steer = 0.0
self._lock = threading.Lock()
threading.Thread(target=self._input_loop, daemon=True).start()
def _input_loop(self):
print("Enter steer (-1 to 1), press Enter to update:")
while True:
try:
val = float(input("> "))
val = max(-1.0, min(1.0, val))
with self._lock:
self.steer = val
print(f" -> steering {val} (UART {int(127.5 * (val + 1))})")
except ValueError:
print(" invalid — enter a number between -1 and 1")
def run(self):
with self._lock:
return self.steer, 0, "RTK FIXED"
if __name__ == "__main__":
V = dk.vehicle.Vehicle()
heartbeat = HealthCheck("192.168.12.25", 6000)
V.add(heartbeat, inputs=[], outputs=["safety/heartbeat"])
V.add(ManualSteering(), inputs=[], outputs=["controls/steering", "controls/throttle", "fix"], threaded=False)
uart = UART_backup_driver("/dev/ttyACM2", quiet=True)
V.add(
uart,
inputs=["controls/throttle", "controls/steering", "safety/heartbeat", "fix"],
outputs=["steer_actual", "throttle_actual"],
threaded=False,
)
print(f"Manual steering test at {RATE_HZ} Hz — type a value and press Enter, Ctrl+C to stop")
V.start(rate_hz=RATE_HZ)