16 from __future__
import print_function
18 from copy
import deepcopy
20 from nav_msgs.msg
import Odometry
21 from geometry_msgs.msg
import PolygonStamped, Point32
22 from visualization_msgs.msg
import Marker
27 MARKER = np.array([[0, 0.75], [-0.5, -0.25], [0.5, -0.25]])
34 if rospy.has_param(
'~scale_footprint'):
35 scale = rospy.get_param(
'~scale_footprint')
39 print(
'Scale factor should be greater than zero')
45 if rospy.has_param(
'~_scale_label'):
46 scale = rospy.get_param(
'~_scale_label')
50 print(
'Scale factor should be greater than zero')
55 if rospy.get_param(
'~label_x_offset'):
59 self._label_marker.header.frame_id =
'world' 60 self._label_marker.header.stamp = rospy.Time.now()
62 self._label_marker.type = Marker.TEXT_VIEW_FACING
64 self._label_marker.action = Marker.ADD
65 self._label_marker.pose.orientation.x = 0.0
66 self._label_marker.pose.orientation.y = 0.0
67 self._label_marker.pose.orientation.z = 0.0
68 self._label_marker.pose.orientation.w = 1.0
69 self._label_marker.scale.x = 0.0
70 self._label_marker.scale.y = 0.0
72 self._label_marker.color.a = 1.0
73 self._label_marker.color.r = 0.0
74 self._label_marker.color.g = 1.0
75 self._label_marker.color.b = 0.0
80 self.
_footprint_pub = rospy.Publisher(
'footprint', PolygonStamped, queue_size=1)
82 self.
_label_pub = rospy.Publisher(
'label', Marker, queue_size=1)
86 return np.array([[np.cos(alpha), -np.sin(alpha)],
87 [np.sin(alpha), np.cos(alpha)]])
90 x = msg.pose.pose.position.x
91 y = msg.pose.pose.position.y
93 orientation = np.array([msg.pose.pose.orientation.x,
94 msg.pose.pose.orientation.y,
95 msg.pose.pose.orientation.z,
96 msg.pose.pose.orientation.w])
104 for i
in range(new_marker.shape[0]):
105 new_marker[i, :] = np.dot(self.
rot(yaw - np.pi / 2), new_marker[i, :])
106 new_marker[i, 0] += x
107 new_marker[i, 1] += y
110 p.x = new_marker[i, 0]
111 p.y = new_marker[i, 1]
114 new_poly = PolygonStamped()
115 new_poly.header.stamp = rospy.Time.now()
116 new_poly.header.frame_id =
'world' 117 new_poly.polygon.points = points
119 self._footprint_pub.publish(new_poly)
122 self._label_marker.pose.position.x = msg.pose.pose.position.x + self.
_label_x_offset 123 self._label_marker.pose.position.y = msg.pose.pose.position.y
124 self._label_marker.pose.position.z = msg.pose.pose.position.z
128 if __name__ ==
'__main__':
129 print(
'Generate RViz footprint and markers for 2D visualization')
130 rospy.init_node(
'generate_vehicle_footprint')
135 except rospy.ROSInterruptException:
136 print(
'caught exception')