-
Notifications
You must be signed in to change notification settings - Fork 1
/
outstream_shadowsuit.py
112 lines (84 loc) · 3.12 KB
/
outstream_shadowsuit.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
105
106
107
108
109
110
111
112
#
# outstream_shadowsuit.py
#
# streams a single shadow suit to LSL
# to do: update for multiple shadow suits
#
# Robert Twomey | Clarke Center UCSD | November 2018
import sys
from MotionSDK import *
from pylsl import StreamInfo, StreamOutlet
PortConfigurable = 32076
doPrint = False
def shadow_client(host, port, lsl_outlet):
client = Client(host, port)
sys.stdout.write("Creating Shadow client...")
sys.stdout.flush()
sys.stdout.write("connected to %s:%d\n" % (host, port))
sys.stdout.flush()
if PortConfigurable == port:
# xml_string = \
# "<?xml version=\"1.0\"?>" \
# "<configurable>" \
# "<preview><Gq/></preview><sensor><a/></sensor>" \
# "</configurable>"
# this data string is copied from the ShadowStream.cs Unity example,
# it is what is used for their rigged skeleton in Unity.
xml_string = \
"<?xml version=\"1.0\"?>" \
"<configurable inactive=\"1\">" \
"<Lq/> <!-- Local quaternion. -->" \
"<c/> <!-- Position contraint with unit weight. Shadow plugin only. -->" \
"</cofnigurable>"
if client.writeData(xml_string):
sys.stdout.write("Sent active channel definition to Configurable service...\n")
sys.stdout.flush()
if client.waitForData():
sys.stdout.write("Streaming shadow data...")
sys.stdout.flush()
while True:
data = client.readData()
if None == data:
continue
new_sample = []
container = Format.Configurable(data)
for key in container:
line = "data({}) = (".format(key)
for i in range(container[key].size()):
element = container[key].value(i)
new_sample.append(element)
if i > 0:
line += ", "
line += "{}".format(element)
line += ")"
if doPrint:
print(line)
lsl_outlet.push_sample(new_sample)
else:
print("Client not configured properly...exiting.")
def main(argv):
# Set the default host name parameter. The SDK is socket based so any
# networked Motion Service is available.
host = ""
if len(argv) > 1:
host = argv[1]
sys.stdout.write("\n=== outstream_shadowsuit.py ===\n\n")
sys.stdout.flush()
# Setup outlet stream infos
mocap_channels = 32
sample_size = 8
sys.stdout.write("Creating LSL outlets...")
sys.stdout.flush()
stream_info_mocap = StreamInfo('ShadowSuit', 'MOCAP', mocap_channels * sample_size, 200)
channels = stream_info_mocap.desc().append_child("channels")
channel_list = ["lq0", "lq1", "lq2", "lq3",
"c0", "c1", "c2", "c3"]
for c in channel_list:
channels.append_child(c)
# Create outlets
outlet_mocap = StreamOutlet(stream_info_mocap)
sys.stdout.write("created.\n")
sys.stdout.flush()
shadow_client(host, PortConfigurable, outlet_mocap)
if __name__ == "__main__":
sys.exit(main(sys.argv))