-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomms_emulation.py
executable file
·50 lines (44 loc) · 1.32 KB
/
comms_emulation.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
# idk chief, this seems sus. Please check.
from utilities.comms import Server
# from socket import gethostbyname
from random import random
ip = "localhost" # "172.6.0.116" # gethostbyname("soji.local")
s = Server(ip, 9160)
def grab_routine():
c2c = s.rx(conn)
s.tx("received", conn)
# Zero out Arm
# arm.move([90, 20, 0, 50])
print(f"Initial C2C: {c2c}")
while abs(c2c) > 25:
print(f"{addr}: C2C = {c2c}")
spin = "left" if c2c < 25 else "right" if c2c > 25 else "center"
print(spin)
c2c = s.rx(conn)
s.tx("received", conn)
s.rx(conn)
s.tx("grabbed", conn)
print("Grab Routine Success.")
addr = None
while True:
try:
print("Connecting...")
conn, addr = s.connect()
addr = addr[0]
print(f"CONNECTED: {addr}")
while conn:
position, center = s.rx(conn)
print(f"{addr}: Position = {position}, Center = {center}")
if center:
print("center active")
s.tx("received", conn)
try:
grab_routine()
except Exception as e:
print(e)
continue
else:
s.tx(random(), conn)
except Exception as e:
print(f"[ERROR] {addr}: {e}")
continue