-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoptitrack_test.py
More file actions
42 lines (32 loc) · 1.51 KB
/
optitrack_test.py
File metadata and controls
42 lines (32 loc) · 1.51 KB
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
import time
from NatNetClient import NatNetClient
from util import quaternion_to_euler
positions = {}
rotations = {}
# This is a callback function that gets connected to the NatNet client. It is called once per rigid body per frame
def receive_rigid_body_frame(id, position, rotation_quaternion):
# Position and rotation received
positions[id] = position
# The rotation is in quaternion. We need to convert it to euler angles
rotx, roty, rotz = quaternion_to_euler(rotation_quaternion)
# Store the roll pitch and yaw angles
rotations[id] = (rotx, roty, rotz)
if __name__ == "__main__":
clientAddress = "192.168.0.247"
optitrackServerAddress = "192.168.0.222"
robot_id = 2
# This will create a new NatNet client
streaming_client = NatNetClient()
streaming_client.set_client_address(clientAddress)
streaming_client.set_server_address(optitrackServerAddress)
streaming_client.set_use_multicast(True)
# Configure the streaming client to call our rigid body handler on the emulator to send data out.
streaming_client.rigid_body_listener = receive_rigid_body_frame
# Start up the streaming client now that the callbacks are set up.
# This will run perpetually, and operate on a separate thread.
is_running = streaming_client.run()
while is_running:
if robot_id in positions:
# last position
print('Last position', positions[robot_id], ' rotation', rotations[robot_id])
time.sleep(.1)