6 from geometry_msgs.msg
import Point, Pose, Quaternion, PoseStamped
7 from tf.transformations
import euler_from_quaternion, quaternion_from_euler, quaternion_matrix, quaternion_from_matrix, quaternion_multiply
8 from nav_msgs.msg
import Odometry
11 rtabmap_original_odom_topic =
"/rtabmap/ugv_odom" 13 rtabmap_odom_topic =
"/rtabmap/odom" 15 target_frame_id =
"/ugv_base_link" 16 source_frame_id =
"/ugv_odom" 20 odom_original = Odometry()
24 odom_original = odom_msg
28 if __name__ ==
'__main__':
29 rospy.init_node(
'visual_odom_frame_transformer')
34 rtabmap_odom_pub = rospy.Publisher(rtabmap_odom_topic, Odometry, queue_size=1)
37 rospy.Subscriber(rtabmap_original_odom_topic, Odometry, odomCallback)
39 listener.waitForTransform(target_frame_id, source_frame_id, rospy.Time(), rospy.Duration(100.0))
41 rate = rospy.Rate(10.0)
42 while not rospy.is_shutdown():
44 (trans,rot) = listener.lookupTransform(target_frame_id, source_frame_id, rospy.Time(0))
49 odom_x = odom_original.pose.pose.position.x
50 odom_y = odom_original.pose.pose.position.y
51 odom_z = odom_original.pose.pose.position.z
52 odom_rx = odom_original.pose.pose.orientation.x
53 odom_ry = odom_original.pose.pose.orientation.y
54 odom_rz = odom_original.pose.pose.orientation.z
55 odom_rw = odom_original.pose.pose.orientation.w
58 R_L = quaternion_matrix([rot[0],rot[1],rot[2],rot[3]])
62 R_L = np.linalg.inv(R_L)
65 R_I = quaternion_matrix([odom_rx, odom_ry, odom_rz, odom_rw])
73 quat = quaternion_from_matrix(R_F)
76 odom.header.stamp = odom_original.header.stamp
77 odom.header.frame_id = source_frame_id
78 odom.child_frame_id = target_frame_id
79 odom.pose.pose = Pose(Point(R_F[0][3],R_F[1][3],R_F[2][3]),Quaternion(quat[0],quat[1],quat[2],quat[3]))
82 rtabmap_odom_pub.publish(odom)