Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
university
music_proj
Commits
78c0182d
Commit
78c0182d
authored
Aug 07, 2019
by
Kamal Nasser
Browse files
idk it works now
parent
4e1dc513
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
32 deletions
+49
-32
rtscs_param_receivers/optitrack_param_receiver/optitrack_packet_receiver.py
...ers/optitrack_param_receiver/optitrack_packet_receiver.py
+1
-1
setup_utils/measurement_util.py
setup_utils/measurement_util.py
+10
-12
socket-server/server_udp.py
socket-server/server_udp.py
+38
-19
No files found.
rtscs_param_receivers/optitrack_param_receiver/optitrack_packet_receiver.py
View file @
78c0182d
...
...
@@ -4,7 +4,7 @@ import optirx as rx
DEFAULT_MULTICAST_ADDRESS
=
'239.255.42.99'
DEFAULT_DATA_PORT
=
1511
DEFAULT_NATNETSDK_VERSION
=
(
2
,
8
,
0
,
0
)
DEFAULT_NATNETSDK_VERSION
=
(
2
,
9
,
0
,
0
)
class
OptitrackPacketReceiver
(
threading
.
Thread
):
...
...
setup_utils/measurement_util.py
View file @
78c0182d
...
...
@@ -26,32 +26,30 @@ if __name__ == '__main__':
optritrack_packet_recv
.
start
()
while
True
:
packet
=
optritrack_packet_recv
.
get_last_packet
()
#print packet
#
print packet
rh
=
optirx_utils
.
get_first_rigid_body
(
packet
)
if
rh
is
not
None
:
# mul by -1 to fix flipped coordinates if not fully compatible Motive calibration square
rh_position
=
rh
.
position
#rh_position = map(lambda coordinate: -1 * coordinate, rh.position)
rh_position
=
list
(
rh
.
position
)
rh_position
[
0
]
=
-
rh_position
[
0
]
# rh_position = map(lambda coordinate: -1 * coordinate, rh.position)
rh_roll
=
math
.
degrees
(
optirx_utils
.
orientation2radians
(
rh
.
orientation
)[
0
])
currentNumbers
=
list
(
rh_position
)
+
[
rh_roll
]
currentNumbers
=
rh_position
+
[
rh_roll
]
for
method
in
[
"min"
,
"max"
]:
for
idx
,
value
in
enumerate
(
currentNumbers
,
start
=
0
):
totalNumbers
[
method
][
idx
]
=
fns
[
method
](
totalNumbers
[
method
][
idx
],
value
)
print
'
\n
'
*
20
#
print tabulate([totalNumbers["min"], totalNumbers["max"], currentNumbers], headers=["x", "y", "z", "roll"])
print
tabulate
([
totalNumbers
[
"min"
],
totalNumbers
[
"max"
],
currentNumbers
],
headers
=
[
"x"
,
"y"
,
"z"
,
"roll"
])
print
"""
AXIS_RANGES = {
'x': (%0.3f, %0.3f),
'y': (%0.3f, %0.3f),
'z': (%0.3f, %0.3f),
'rh_roll': (-180, 180)
}"""
%
(
totalNumbers
[
"min"
][
0
],
totalNumbers
[
"max"
][
0
],
totalNumbers
[
"min"
][
1
],
totalNumbers
[
"max"
][
1
],
totalNumbers
[
"min"
][
2
],
totalNumbers
[
"max"
][
2
],
totalNumbers
[
"min"
][
3
],
totalNumbers
[
"max"
][
3
]
)
'roll': (-180, 180)
}"""
%
(
totalNumbers
[
"min"
][
0
],
totalNumbers
[
"max"
][
0
],
totalNumbers
[
"min"
][
1
],
totalNumbers
[
"max"
][
1
],
totalNumbers
[
"min"
][
2
],
totalNumbers
[
"max"
][
2
])
time
.
sleep
(
0.05
)
socket-server/server_udp.py
View file @
78c0182d
...
...
@@ -3,31 +3,30 @@ import optirx_utils
import
eventlet
import
math
from
oscpy.client
import
OSCClient
from
utils
import
clip_value
,
remap_range
,
round_to_precision
from
utils
import
clip_value
,
remap_range
import
json
eventlet
.
monkey_patch
()
eventlet
.
monkey_patch
(
all
=
True
)
UDP_IP
=
"1
92.168.43.186
"
UDP_IP
=
"1
27.0.0.1
"
UDP_PORT
=
5000
max_udp_client
=
OSCClient
(
UDP_IP
,
UDP_PORT
)
def
send_udp
(
message
):
max_udp_client
.
send_message
(
"/"
,
message
)
DEFAULT_NOTE_DURATION_PRECISION
=
0.125
# rh roll implemented for future use
AXIS_RANGES
=
{
'x'
:
(
-
1.286
,
0.
863
),
'y'
:
(
-
1.
1
32
,
1.059
),
'z'
:
(
-
0.979
,
0.
803
),
'x'
:
(
-
0.941
,
0.
972
),
'y'
:
(
-
1.3
1
2
,
0.768
),
'z'
:
(
-
1.356
,
0.
779
),
'roll'
:
(
-
180
,
180
)
}
MAP_RANGES
=
{
'x'
:
(
75
,
17
0
),
'y'
:
(
0
,
1
00
),
'x'
:
(
0
,
22
0
),
'y'
:
(
0
,
1
),
'z'
:
(
-
55
,
0
),
'roll'
:
(
0
,
1
)
'roll'
:
(
1
,
400
)
}
def
get_zero_bounding_rect
():
...
...
@@ -45,6 +44,7 @@ def get_zero_bounding_rect():
length
=
axis_length
(
axis
)
midpoint
=
axis_midpoint
(
axis
)
offset
=
length
*
0.1
print
"axis=%s offset=%f length=%f"
%
(
axis
,
offset
,
length
)
offsets
[
axis
]
=
(
midpoint
-
offset
,
midpoint
+
offset
)
return
offsets
...
...
@@ -91,8 +91,9 @@ def transform_params(position, roll):
return
transformed_params
def
zero_range_params
(
p
):
#print p
if
inside_zero_rect
(
p
):
print
'inside'
#
print 'inside'
return
[
0
,
0
,
0
]
return
p
...
...
@@ -107,18 +108,21 @@ def get_rtscs_params_body(rh):
# mul by -1 to fix flipped coordinates if not fully compatible Motive calibration square
rh_position
=
list
(
rh
.
position
)
# map(lambda coordinate: -1 * coordinate, rh.position)
# Convert right hand convention to left hand convention for Motive 1.73+ used with CS-200
#
rh_position[0] = -rh_position[0]
rh_position
[
0
]
=
-
rh_position
[
0
]
# For convenience convert roll angle from radians to degrees
rh_roll
=
math
.
degrees
(
optirx_utils
.
orientation2radians
(
rh
.
orientation
)[
0
])
rh_position
=
zero_range_params
(
rh_position
)
print
(
rh_position
)
#
print(
inside_zero_rect(rh_position), rh_position, rh_roll
)
return
transform_params
(
rh_position
,
rh_roll
)
udp_msg_to_send
=
None
def
get_optirx_data
():
dsock
=
rx
.
mkdatasock
(
ip_address
=
"127.0.0.1"
,
multicast_address
=
'239.255.42.99'
,
port
=
1511
)
natnetsdk_version
=
(
2
,
8
,
0
,
0
)
natnetsdk_version
=
(
2
,
9
,
0
,
0
)
while
True
:
data
=
dsock
.
recv
(
rx
.
MAX_PACKETSIZE
)
# parse packet and store it locally
...
...
@@ -130,15 +134,30 @@ def get_optirx_data():
if
rh
is
not
None
:
params
=
get_rtscs_params_body
(
rh
)
if
params
!=
(
0
,
0
,
0
,
0
):
print
(
params
)
#
print(params)
msg
=
[
json
.
dumps
({
'tempo'
:
params
[
0
],
'tempo'
:
round
(
params
[
1
],
2
),
'senda'
:
params
[
1
],
'mastervol'
:
params
[
2
],
})]
send_udp
(
msg
)
global
udp_msg_to_send
udp_msg_to_send
=
msg
#print(msg)
eventlet
.
sleep
(
0.1
)
#eventlet.sleep(0.1)
def
send_udp_interval
():
while
True
:
global
udp_msg_to_send
if
udp_msg_to_send
!=
None
:
print
"sending %s"
%
udp_msg_to_send
send_udp
(
udp_msg_to_send
)
udp_msg_to_send
=
None
eventlet
.
sleep
(
0.05
)
eventlet
.
spawn
(
send_udp_interval
)
t_data
=
eventlet
.
spawn
(
get_optirx_data
)
t_data
.
wait
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment