-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
104 lines (90 loc) · 2.95 KB
/
main.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
"""
Jonne Klockars 2023
HUMEA Lab
Sonic Move Biodata Sonata main function.
"""
import argparse
import logging
from pathlib import Path
import sys
# https://dearpygui.readthedocs.io/en/latest/
import dearpygui.dearpygui as dpg
# https://osc4py3.readthedocs.io/en/latest/
from osc4py3 import oscbuildparse
from osc4py3.as_eventloop import *
import dashboard as db
def osc(server_ip, server_port, client_ip, client_port):
"""Sets up Open Sound Control messaging between a server
and a client.
"""
logging.basicConfig(
format='%(asctime)s - %(processName)s - %(name)s'
' - %(levelname)s - %(message)s', level=logging.WARNING
)
logger = logging.getLogger('logger')
osc_startup(logger=logger)
osc_udp_server(server_ip, server_port, 'OSC_server')
osc_udp_client(client_ip, client_port, 'OSC_client')
def osc_handler(acc, tot_acc, gyr, rot, mag, ori, mtw2_id):
print(acc, tot_acc, gyr, rot, mag, ori, mtw2_id)
def main():
"""
Arguments
---------
server_ip : str
IP address of Open Sound Control server.
server_port : int
Open Sound Control port.
client_ip : str
IP address of Open Sound Control client.
client_port : int
Open Sound Control client port.
device : str
'dongle' or 'station' Xsens main device. Default is 'station'.
path : str
File path for saving log files. Recommendation is to create a
folder just for the logs.
"""
parser = argparse.ArgumentParser()
parser.add_argument(
'--server_ip', '-si', type=str, default='127.0.0.1',
help='OSC server IP.'
)
parser.add_argument(
'--server_port', '-sp', type=int, default=50005,
help='OSC server port.'
)
parser.add_argument(
'--client_ip', '-ci', type=str, default='127.0.0.1',
help='OSC client IP.'
)
parser.add_argument(
'--client_port', '-cp', type=int, default=50005,
help='OSC client port.'
)
parser.add_argument(
'--device', '-d', type=str, default='station',
help='Xsens main device: "dongle" or "station".'
)
parser.add_argument(
'--path', '-p', type=str, default=r'C:\Users\wksadmin\Downloads\lokit',
help='File path for saving log files.'
)
args = parser.parse_args()
try:
osc(args.server_ip, args.server_port, args.client_ip, args.client_port)
except Exception as e:
print(f'{e}./n Open Sound Control setup failed. Aborting.')
sys.exit(1)
try:
dashboard = db.Dashboard(args.device, Path(args.path))
except Exception as e:
print(f'{e}./n Dashboard setup failed. Aborting.')
sys.exit(1)
dpg.setup_dearpygui()
dpg.maximize_viewport()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
if __name__ == '__main__':
main()