16 from __future__
import print_function
21 from copy
import deepcopy
22 from nav_msgs.msg
import Odometry
23 from geometry_msgs.msg
import PolygonStamped, Point32
25 from gazebo_msgs.srv
import GetWorldProperties, GetModelProperties
32 get_world_props =
None 34 get_model_props =
None 36 marker = np.array([[0, 0.75], [-0.5, -0.25], [0.5, -0.25]])
39 return np.array([[np.cos(alpha), -np.sin(alpha)],
40 [np.sin(alpha), np.cos(alpha)]])
44 if name
not in vehicle_pub:
46 x = msg.pose.pose.position.x
47 y = msg.pose.pose.position.y
49 orientation = np.array([msg.pose.pose.orientation.x,
50 msg.pose.pose.orientation.y,
51 msg.pose.pose.orientation.z,
52 msg.pose.pose.orientation.w])
56 new_marker = deepcopy(marker)
58 for i
in range(new_marker.shape[0]):
59 new_marker[i, :] = np.dot(
rot(yaw-np.pi/2), new_marker[i, :])
64 p.x = new_marker[i, 0]
65 p.y = new_marker[i, 1]
68 new_poly = PolygonStamped()
69 new_poly.header.stamp = rospy.Time.now()
70 new_poly.header.frame_id =
'world' 71 new_poly.polygon.points = points
73 vehicle_pub[name].publish(new_poly)
76 return [t
for t, _
in rosgraph.Master(
'/{}/'.format(name)).getPublishedTopics(
'')
if not t.startswith(
'/rosout')
and name
in t]
81 msg_class, _, _ = rostopic.get_topic_class(t)
82 if msg_class == Odometry:
83 odom_topic_sub = rospy.Subscriber(
88 """Call list of models in the Gazebo simulation and filter out the 91 global get_world_props
92 if get_world_props
is None:
95 rospy.wait_for_service(
'/gazebo/get_world_properties', timeout=2)
96 get_world_props = rospy.ServiceProxy(
'/gazebo/get_world_properties',
98 except rospy.ROSException:
99 print(
'/gazebo/get_world_properties service is unavailable')
101 global get_model_props
102 if get_model_props
is None:
105 rospy.wait_for_service(
'/gazebo/get_model_properties')
106 get_model_props = rospy.ServiceProxy(
'/gazebo/get_model_properties',
108 except rospy.ROSException:
109 print(
'/gazebo/get_model_properties service is unavailable')
114 for model
in msg.model_names:
116 if not model_properties.is_static
and \
117 rospy.has_param(
'/{}/robot_description'.format(model))
and \
118 model
not in vehicle_pub:
120 vehicle_pub[model] = rospy.Publisher(
'/{}/footprint'.format(model),
123 except rospy.ServiceException
as e:
124 print(
'Service call failed: {}'.format(e))
127 update_timer = rospy.Timer(rospy.Duration(10), update_vehicle_list)
129 if __name__ ==
'__main__':
130 print(
'Start publishing vehicle footprints to RViz')
131 rospy.init_node(
'publish_footprints')
136 except rospy.ROSInterruptException:
137 print(
'caught exception')