@@ -52,6 +52,76 @@ def __init__(self, goal_x, goal_y, map_frame, robot_name, follow_robot=False, pu
5252 self .timer = self .create_timer (1.0 , self .publish_once )
5353 self .get_logger ().info (f"Publishing path to goal ({ goal_x } , { goal_y } ) once" )
5454
55+ def to_viz_msg_follow (self , action , marker_ns ):
56+ points = []
57+ for p in action .path .poses :
58+ pt = Point ()
59+ pt .x = p .pose .position .x
60+ pt .y = p .pose .position .y
61+ pt .z = p .pose .position .z
62+ points .append (pt )
63+ m = Marker ()
64+ m .header .frame_id = self .map_frame
65+ m .header .stamp = gtm ()
66+ m .ns = marker_ns
67+ m .id = 0
68+ m .type = m .LINE_STRIP
69+ m .action = m .ADD
70+ m .pose .orientation .w = 1.0
71+ m .scale .x = 0.2
72+ m .scale .y = 0.2
73+ m .color .a = 1.0
74+ m .color .r = 0.0
75+ m .color .g = 1.0
76+ m .color .b = 0.0
77+ m .points = points
78+
79+ start = Marker ()
80+ start .header .frame_id = self .map_frame
81+ start .header .stamp = gtm ()
82+ start .ns = marker_ns
83+ start .id = 1
84+ start .type = m .SPHERE
85+ start .action = m .ADD
86+ start .pose .orientation .w = 1.0
87+ start .scale .x = 0.4
88+ start .scale .y = 0.4
89+ start .scale .z = 0.4
90+ start .color .a = 0.5
91+ start .color .r = 1.0
92+ start .color .g = 0.0
93+ start .color .b = 0.0
94+ start .pose .position .x = points [0 ].x
95+ start .pose .position .y = points [0 ].y
96+ start .pose .position .z = points [0 ].z
97+
98+ end = Marker ()
99+ end .header .frame_id = self .map_frame
100+ end .header .stamp = gtm ()
101+ end .ns = marker_ns
102+ end .id = 2
103+ end .type = m .SPHERE
104+ end .action = m .ADD
105+ end .pose .orientation .w = 1.0
106+ end .scale .x = 0.4
107+ end .scale .y = 0.4
108+ end .scale .z = 0.4
109+ end .color .a = 0.5
110+ end .color .r = 0.0
111+ end .color .g = 0.0
112+ end .color .b = 1.0
113+ end .pose .position .x = points [- 1 ].x
114+ end .pose .position .y = points [- 1 ].y
115+ end .pose .position .z = points [- 1 ].z
116+
117+ return [m , start , end ]
118+
119+
120+ def to_viz_msg (self , action , marker_ns ):
121+ ma = MarkerArray ()
122+ for ix , a in enumerate (action .actions ):
123+ ma .markers += self .to_viz_msg_follow (a , marker_ns + f"/{ ix } " )
124+ return ma
55125
56126
57127 def generate_waypoints (self , start_x , start_y , start_yaw , num_waypoints = 10 ):
@@ -71,7 +141,7 @@ def publish_path(self):
71141 """Publish path from current robot pose to goal"""
72142 try :
73143 # Get current robot pose
74- robot_pose , robot_yaw = get_tf_pose (self .tf_buffer , self .map_frame , self .robot_frame )
144+ robot_pose , ( roll , pitch , robot_yaw ) = get_tf_pose (self .tf_buffer , self .map_frame , self .robot_frame , get_euler = True )
75145
76146 # Generate waypoints
77147 if self .follow_robot :
@@ -117,7 +187,8 @@ def publish_path(self):
117187 msg .actions .append (action_msg )
118188
119189 self .publisher .publish (msg )
120- self .viz_publisher .publish (to_viz_msg (msg , self .robot_name ))
190+ # self.viz_publisher.publish(to_viz_msg(msg, self.robot_name)) # somehow throw an error about the msg type, it has a '_' before the actual msg name
191+ self .viz_publisher .publish (self .to_viz_msg (msg , self .robot_name ))
121192 self .get_logger ().info (f"Published path with { len (waypoints )} waypoints" )
122193
123194 except Exception as e :
@@ -162,4 +233,4 @@ def main():
162233
163234
164235if __name__ == "__main__" :
165- main ()
236+ main ()
0 commit comments