forked from rail-berkeley/oculus_reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualize_oculus_transforms.py
More file actions
46 lines (35 loc) · 1.25 KB
/
visualize_oculus_transforms.py
File metadata and controls
46 lines (35 loc) · 1.25 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
43
44
45
46
from reader import OculusReader
from tf.transformations import quaternion_from_matrix
import rospy
import tf2_ros
import geometry_msgs.msg
def publish_transform(transform, name):
translation = transform[:3, 3]
br = tf2_ros.TransformBroadcaster()
t = geometry_msgs.msg.TransformStamped()
t.header.stamp = rospy.Time.now()
t.header.frame_id = 'world'
t.child_frame_id = name
t.transform.translation.x = translation[0]
t.transform.translation.y = translation[1]
t.transform.translation.z = translation[2]
quat = quaternion_from_matrix(transform)
t.transform.rotation.x = quat[0]
t.transform.rotation.y = quat[1]
t.transform.rotation.z = quat[2]
t.transform.rotation.w = quat[3]
br.sendTransform(t)
def main():
oculus_reader = OculusReader()
rospy.init_node('oculus_reader')
while not rospy.is_shutdown():
rospy.sleep(1)
transformations, buttons = oculus_reader.get_transformations_and_buttons()
if 'r' not in transformations:
continue
right_controller_pose = transformations['r']
publish_transform(right_controller_pose, 'oculus')
print('transformations', transformations)
print('buttons', buttons)
if __name__ == '__main__':
main()