5 from tf2_msgs.msg
import TFMessage
6 from gazebo_msgs.msg
import LinkStates
7 from geometry_msgs.msg
import TransformStamped
15 for i
in range(len(linkStates.name)):
16 if linkStates.name[i] == gazebo_frame_id:
17 p = linkStates.pose[i]
22 roslog.warn(
"Gazebo link state \"" + gazebo_frame_id +
"\" not found, cannot generate ground truth.")
26 t.header.frame_id = frame_id
27 t.header.stamp = rospy.Time.now()
29 t.child_frame_id = child_frame_id
31 t.transform.translation.x = p.position.x
32 t.transform.translation.y = p.position.y
33 t.transform.translation.z = p.position.z
35 t.transform.rotation.x = p.orientation.x
36 t.transform.rotation.y = p.orientation.y
37 t.transform.rotation.z = p.orientation.z
38 t.transform.rotation.w = p.orientation.w
40 tf_pub.publish(TFMessage([t]))
42 if __name__ ==
'__main__':
43 rospy.init_node(
'generate_gazebo_ground_truth', disable_signals=
True)
45 frame_id = rospy.get_param(
'~frame_id',
'world')
46 child_frame_id = rospy.get_param(
'~child_frame_id',
'base_link_gt')
47 gazebo_frame_id = rospy.get_param(
'~gazebo_frame_id',
'base_link')
49 gazebo_sub = rospy.Subscriber(
'/gazebo/link_states', LinkStates, callBack)
51 tf_pub = rospy.Publisher(
'/tf', TFMessage, queue_size=10)