This repository was archived by the owner on Apr 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ugv.py
More file actions
83 lines (67 loc) · 2.05 KB
/
test_ugv.py
File metadata and controls
83 lines (67 loc) · 2.05 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
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
import serial
import json
import time
PORT = '/dev/ttyTHS1'
BAUD = 115200
def send_cmd(ser, data):
cmd = (json.dumps(data) + '\n').encode('utf-8')
for byte in cmd:
ser.write(bytes([byte]))
time.sleep(0.001)
def main():
print(f"Connecting to {PORT} at {BAUD} baud...")
ser = serial.Serial(PORT, BAUD, timeout=2, rtscts=False, xonxoff=False)
ser.reset_input_buffer()
ser.reset_output_buffer()
print("Connected!\n")
# Test 1: LED lights on (IO4=base light, IO5=head light)
print("Test 1: LED lights ON")
send_cmd(ser, {"T": 132, "IO4": 255, "IO5": 255})
time.sleep(2)
# Test 2: LED lights off
print("Test 2: LED lights OFF")
send_cmd(ser, {"T": 132, "IO4": 0, "IO5": 0})
time.sleep(1)
# Test 3: Move forward (negative = forward based on your test)
print("Test 3: Move FORWARD for 2 seconds")
send_cmd(ser, {"T": 1, "L": -0.5, "R": -0.5})
time.sleep(2)
# Stop
print("Stopping...")
send_cmd(ser, {"T": 1, "L": 0, "R": 0})
time.sleep(1)
# Test 4: Move backward
print("Test 4: Move BACKWARD for 2 seconds")
send_cmd(ser, {"T": 1, "L": 0.5, "R": 0.5})
time.sleep(2)
# Stop
print("Stopping...")
send_cmd(ser, {"T": 1, "L": 0, "R": 0})
time.sleep(1)
# Test 5: Turn left
print("Test 5: Turn LEFT for 1 second")
send_cmd(ser, {"T": 1, "L": 0.5, "R": -0.5})
time.sleep(1)
# Stop
print("Stopping...")
send_cmd(ser, {"T": 1, "L": 0, "R": 0})
time.sleep(1)
# Test 6: Turn right
print("Test 6: Turn RIGHT for 1 second")
send_cmd(ser, {"T": 1, "L": -0.5, "R": 0.5})
time.sleep(1)
# Stop
print("Stopping...")
send_cmd(ser, {"T": 1, "L": 0, "R": 0})
time.sleep(1)
# Test 7: LED flash
print("Test 7: LED flash 3 times")
for i in range(3):
send_cmd(ser, {"T": 132, "IO4": 255, "IO5": 255})
time.sleep(0.3)
send_cmd(ser, {"T": 132, "IO4": 0, "IO5": 0})
time.sleep(0.3)
print("\nAll tests done!")
ser.close()
if __name__ == "__main__":
main()