-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_prediction.py
48 lines (34 loc) · 1.11 KB
/
send_prediction.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
import serial
from pythonosc import udp_client
serialport = "/dev/cu.usbmodem143402"
ser = serial.Serial(serialport, 115200)
"""Small example OSC server
This program listens to several addresses, and prints some information about
received packets.
"""
import argparse
import math
from pythonosc import dispatcher
from pythonosc import osc_server
def write_pred_serial(unused_addr, arg1, arg2,arg3):
print(arg1,arg2,arg3)
ser.flush()
if arg1<arg2 and arg1<arg3:
ser.write(b"0:")
elif arg2<arg3 and arg2<arg1:
ser.write(b"1:")
else:
ser.write(b"2:")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip",
default="127.0.0.1", help="The ip to listen on")
parser.add_argument("--port",
type=int, default=12000, help="The port to listen on")
args = parser.parse_args()
dispatcher = dispatcher.Dispatcher()
dispatcher.map("/wek/outputs",write_pred_serial)
server = osc_server.ThreadingOSCUDPServer(
(args.ip, args.port), dispatcher)
print("Serving on {}".format(server.server_address))
server.serve_forever()