4 connect to Oculus Prime Server Application 5 poll server for odometry data 6 broadcast tranform between base_link and odom frames 9 from math
import radians, sin, cos
11 from nav_msgs.msg
import Odometry
12 import oculusprimesocket
24 global before, pos, now
25 now = rospy.Time.now() - rospy.Duration(rospy.get_param(
'~odom_lag', default_lag))
27 dt = (now-before).to_sec()
30 distance = float(s[2])/1000
31 delta_x = distance * cos(pos[2])
32 delta_y = distance * sin(pos[2])
33 delta_th = radians(float(s[3]))
39 odom_quat = tf.transformations.quaternion_from_euler(0, 0, pos[2])
40 br.sendTransform((pos[0], pos[1], 0), odom_quat, now,
"base_link",
"odom")
48 odom.header.stamp = now
49 odom.header.frame_id =
"odom" 52 odom.pose.pose.position.x = pos[0]
53 odom.pose.pose.position.y = pos[1]
54 odom.pose.pose.position.z = 0.0
55 odom.pose.pose.orientation.x = odom_quat[0]
56 odom.pose.pose.orientation.y = odom_quat[1]
57 odom.pose.pose.orientation.z = odom_quat[2]
58 odom.pose.pose.orientation.w = odom_quat[3]
59 odom.pose.covariance= [0.000001, 0, 0, 0, 0, 0,
60 0, 0.000001, 0, 0, 0, 0,
61 0, 0, 0.000001, 0, 0, 0,
62 0, 0, 0, 0.000001, 0, 0,
63 0, 0, 0, 0, 0.000001, 0,
64 0, 0, 0, 0, 0, 0.000001]
67 odom.child_frame_id =
"base_link" 68 odom.twist.twist.linear.x = distance / dt
69 odom.twist.twist.linear.y = 0
70 odom.twist.twist.linear.z = 0
71 odom.twist.twist.angular.x = 0
72 odom.twist.twist.angular.y = 0
73 odom.twist.twist.angular.z = delta_th / dt
76 odom_pub.publish(odom)
88 rospy.init_node(
'odom_tf', anonymous=
False)
89 before = rospy.Time.now()
91 odom_pub = rospy.Publisher(
'odom', Odometry, queue_size=10)
92 rospy.on_shutdown(cleanup)
99 while not rospy.is_shutdown():
def replyBufferSearch(pattern)