gazebo_ground_truth.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rospy
3 import tf
4 
5 from tf2_msgs.msg import TFMessage
6 from gazebo_msgs.msg import LinkStates
7 from geometry_msgs.msg import TransformStamped
8 
9 target_frame_id = ""
10 
11 def callBack(linkStates):
12  global delta, first
13 
14  found = False
15  for i in range(len(linkStates.name)):
16  if linkStates.name[i] == gazebo_frame_id:
17  p = linkStates.pose[i]
18  found = True
19  break
20 
21  if not found:
22  roslog.warn("Gazebo link state \"" + gazebo_frame_id +"\" not found, cannot generate ground truth.")
23  return
24 
25  t = TransformStamped()
26  t.header.frame_id = frame_id
27  t.header.stamp = rospy.Time.now()
28 
29  t.child_frame_id = child_frame_id
30 
31  t.transform.translation.x = p.position.x
32  t.transform.translation.y = p.position.y
33  t.transform.translation.z = p.position.z
34 
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
39 
40  tf_pub.publish(TFMessage([t]))
41 
42 if __name__ == '__main__':
43  rospy.init_node('generate_gazebo_ground_truth', disable_signals=True)
44 
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')
48 
49  gazebo_sub = rospy.Subscriber('/gazebo/link_states', LinkStates, callBack)
50 
51  tf_pub = rospy.Publisher('/tf', TFMessage, queue_size=10)
53 
54  rospy.spin()
def callBack(linkStates)


rtabmap_ros
Author(s): Mathieu Labbe
autogenerated on Tue Jan 24 2023 04:04:40