@@ -215,61 +215,60 @@ def _publish_cmd_vel_new(self, event):
215215
216216 self .robot_interface .publish_cmd_vel (self .cmd_vel )
217217
218- def _publish_trajectory_tracking_pt (self , t , robot_states , planners ):
218+ def _publish_trajectory_tracking_pt (self , t , robot_states , planner ):
219219 msg = MultiDOFJointTrajectory ()
220220 msg .header .stamp = rospy .Time .now ()
221221
222- for planner in planners :
223- # Get base reference if available
224- if planner .has_base_ref :
225- p , v = planner .getBaseTrackingPoint (t , robot_states )
226- if p is not None :
227- msg .joint_names .append ("base" )
228- pt_msg = MultiDOFJointTrajectoryPoint ()
229- transform = Transform ()
230- transform .translation .x = p [0 ]
231- transform .translation .y = p [1 ]
232- transform .translation .z = 0.25 # Display height
233- quat = tf .quaternion_from_euler (0 , 0 , p [2 ])
234- transform .rotation .x = quat [0 ]
235- transform .rotation .y = quat [1 ]
236- transform .rotation .z = quat [2 ]
237- transform .rotation .w = quat [3 ]
238- pt_msg .transforms .append (transform )
239- if v is not None :
240- velocity = Twist ()
241- velocity .linear .x = v [0 ]
242- velocity .linear .y = v [1 ]
243- velocity .angular .z = v [2 ]
244- pt_msg .velocities .append (velocity )
245- msg .points .append (pt_msg )
246-
247- # Get EE reference if available
248- if planner .has_ee_ref :
249- p , v = planner .getEETrackingPoint (t , robot_states )
250- if p is not None :
251- msg .joint_names .append ("EE" )
252- pt_msg = MultiDOFJointTrajectoryPoint ()
253- transform = Transform ()
254- transform .translation .x = p [0 ]
255- transform .translation .y = p [1 ]
256- transform .translation .z = p [2 ]
257- quat = tf .quaternion_from_euler (* p [3 :])
258- transform .rotation .x = quat [0 ]
259- transform .rotation .y = quat [1 ]
260- transform .rotation .z = quat [2 ]
261- transform .rotation .w = quat [3 ]
262- pt_msg .transforms .append (transform )
263- if v is not None :
264- velocity = Twist ()
265- velocity .linear .x = v [0 ]
266- velocity .linear .y = v [1 ]
267- velocity .linear .z = v [2 ]
268- velocity .angular .x = v [3 ] if len (v ) > 3 else 0
269- velocity .angular .y = v [4 ] if len (v ) > 4 else 0
270- velocity .angular .z = v [5 ] if len (v ) > 5 else 0
271- pt_msg .velocities .append (velocity )
272- msg .points .append (pt_msg )
222+ # Get base reference if available
223+ if planner .has_base_ref :
224+ p , v = planner .getBaseTrackingPoint (t , robot_states )
225+ if p is not None :
226+ msg .joint_names .append ("base" )
227+ pt_msg = MultiDOFJointTrajectoryPoint ()
228+ transform = Transform ()
229+ transform .translation .x = p [0 ]
230+ transform .translation .y = p [1 ]
231+ transform .translation .z = 0.25 # Display height
232+ quat = tf .quaternion_from_euler (0 , 0 , p [2 ])
233+ transform .rotation .x = quat [0 ]
234+ transform .rotation .y = quat [1 ]
235+ transform .rotation .z = quat [2 ]
236+ transform .rotation .w = quat [3 ]
237+ pt_msg .transforms .append (transform )
238+ if v is not None :
239+ velocity = Twist ()
240+ velocity .linear .x = v [0 ]
241+ velocity .linear .y = v [1 ]
242+ velocity .angular .z = v [2 ]
243+ pt_msg .velocities .append (velocity )
244+ msg .points .append (pt_msg )
245+
246+ # Get EE reference if available
247+ if planner .has_ee_ref :
248+ p , v = planner .getEETrackingPoint (t , robot_states )
249+ if p is not None :
250+ msg .joint_names .append ("EE" )
251+ pt_msg = MultiDOFJointTrajectoryPoint ()
252+ transform = Transform ()
253+ transform .translation .x = p [0 ]
254+ transform .translation .y = p [1 ]
255+ transform .translation .z = p [2 ]
256+ quat = tf .quaternion_from_euler (* p [3 :])
257+ transform .rotation .x = quat [0 ]
258+ transform .rotation .y = quat [1 ]
259+ transform .rotation .z = quat [2 ]
260+ transform .rotation .w = quat [3 ]
261+ pt_msg .transforms .append (transform )
262+ if v is not None :
263+ velocity = Twist ()
264+ velocity .linear .x = v [0 ]
265+ velocity .linear .y = v [1 ]
266+ velocity .linear .z = v [2 ]
267+ velocity .angular .x = v [3 ] if len (v ) > 3 else 0
268+ velocity .angular .y = v [4 ] if len (v ) > 4 else 0
269+ velocity .angular .z = v [5 ] if len (v ) > 5 else 0
270+ pt_msg .velocities .append (velocity )
271+ msg .points .append (pt_msg )
273272
274273 if len (msg .points ) > 0 :
275274 self .tracking_point_pub .publish (msg )
@@ -361,51 +360,49 @@ def _publish_planner_data(self, event):
361360 marker_plan .lifetime = rospy .Duration .from_sec (0.1 )
362361 self .plan_visualization_pub .publish (marker_plan )
363362
364- curr_planners = self .sot .getPlanners (2 )
365- colors = [[1 , 0 , 0 ], [0 , 1 , 0 ]]
366- for pid , planner in enumerate (curr_planners ):
367- # Visualize current base waypoint/path if available
368- if planner .has_base_ref :
369- if planner .ref_type == RefType .WAYPOINT :
370- quat = tf .quaternion_from_euler (0 , 0 , planner .base_target [2 ])
371- pose_msg = PoseStamped ()
372- pose_msg .header .stamp = rospy .Time ()
373- pose_msg .pose .position = Point (* planner .base_target [:2 ], 0.25 )
374- pose_msg .pose .orientation = Quaternion (* list (quat ))
375- self .pose_plan_visualization_pub .publish (pose_msg )
376- elif planner .ref_type == RefType .PATH :
377- marker_plan = self ._make_marker (
378- Marker .POINTS ,
379- pid ,
380- rgba = colors [pid ] + [1 ],
381- scale = [0.1 , 0.1 , 0.1 ],
382- )
383- marker_plan .points = [
384- Point (* pt [:2 ], 0 ) for pt in planner .base_plan ["p" ]
385- ]
386- marker_plan .lifetime = rospy .Duration .from_sec (0.1 )
387- self .current_plan_visualization_pub .publish (marker_plan )
388-
389- # Visualize current EE waypoint/path if available
390- if planner .has_ee_ref :
391- if planner .ref_type == RefType .WAYPOINT :
392- quat = tf .quaternion_from_euler (* planner .ee_target [3 :])
393- pose_msg = PoseStamped ()
394- pose_msg .header .frame_id = "world"
395- pose_msg .header .stamp = rospy .Time ()
396- pose_msg .pose .position = Point (* planner .ee_target [:3 ])
397- pose_msg .pose .orientation = Quaternion (* list (quat ))
398- self .pose_plan_visualization_pub .publish (pose_msg )
399- elif planner .ref_type == RefType .PATH :
400- marker_plan = self ._make_marker (
401- Marker .POINTS ,
402- pid + 100 ,
403- rgba = colors [pid ] + [1 ],
404- scale = [0.1 , 0.1 , 0.1 ],
405- )
406- marker_plan .points = [Point (* pt [:3 ]) for pt in planner .ee_plan ["p" ]]
407- marker_plan .lifetime = rospy .Duration .from_sec (0.1 )
408- self .current_plan_visualization_pub .publish (marker_plan )
363+ planner = self .sot .getPlanner ()
364+ # Visualize current base waypoint/path if available
365+ if planner .has_base_ref :
366+ if planner .ref_type == RefType .WAYPOINT :
367+ quat = tf .quaternion_from_euler (0 , 0 , planner .base_target [2 ])
368+ pose_msg = PoseStamped ()
369+ pose_msg .header .stamp = rospy .Time ()
370+ pose_msg .pose .position = Point (* planner .base_target [:2 ], 0.25 )
371+ pose_msg .pose .orientation = Quaternion (* list (quat ))
372+ self .pose_plan_visualization_pub .publish (pose_msg )
373+ elif planner .ref_type == RefType .PATH :
374+ marker_plan = self ._make_marker (
375+ Marker .POINTS ,
376+ 0 ,
377+ rgba = [1 , 0 , 0 , 1 ],
378+ scale = [0.1 , 0.1 , 0.1 ],
379+ )
380+ marker_plan .points = [
381+ Point (* pt [:2 ], 0 ) for pt in planner .base_plan ["p" ]
382+ ]
383+ marker_plan .lifetime = rospy .Duration .from_sec (0.1 )
384+ self .current_plan_visualization_pub .publish (marker_plan )
385+
386+ # Visualize current EE waypoint/path if available
387+ if planner .has_ee_ref :
388+ if planner .ref_type == RefType .WAYPOINT :
389+ quat = tf .quaternion_from_euler (* planner .ee_target [3 :])
390+ pose_msg = PoseStamped ()
391+ pose_msg .header .frame_id = "world"
392+ pose_msg .header .stamp = rospy .Time ()
393+ pose_msg .pose .position = Point (* planner .ee_target [:3 ])
394+ pose_msg .pose .orientation = Quaternion (* list (quat ))
395+ self .pose_plan_visualization_pub .publish (pose_msg )
396+ elif planner .ref_type == RefType .PATH :
397+ marker_plan = self ._make_marker (
398+ Marker .POINTS ,
399+ 100 ,
400+ rgba = [0 , 1 , 0 , 1 ],
401+ scale = [0.1 , 0.1 , 0.1 ],
402+ )
403+ marker_plan .points = [Point (* pt [:3 ]) for pt in planner .ee_plan ["p" ]]
404+ marker_plan .lifetime = rospy .Duration .from_sec (0.1 )
405+ self .current_plan_visualization_pub .publish (marker_plan )
409406
410407 self .sot_lock .release ()
411408
@@ -520,9 +517,6 @@ def run(self):
520517 t0 = t
521518 self .sot .started = True
522519
523- sot_num_plans = self .ctrl_config .get ("task_num" , None )
524- if sot_num_plans is None :
525- sot_num_plans = 1 if self .ctrl_config ["type" ][:2 ] == "ST" else 2
526520 while not self .ctrl_c :
527521 t = rospy .Time .now ().to_sec ()
528522
@@ -558,10 +552,8 @@ def run(self):
558552 # if the robot is very close to the goal, stop the robot
559553 # Check if any active planner is close to finish
560554 self .sot_lock .acquire ()
561- active_planners = self .sot .getPlanners (num_planners = sot_num_plans )
562- close_to_goal = False
563- for planner in active_planners :
564- close_to_goal = close_to_goal or planner .closeToFinish ()
555+ planner = self .sot .getPlanner ()
556+ close_to_goal = planner .closeToFinish ()
565557 self .sot_lock .release ()
566558 if close_to_goal :
567559 print ("Close to goal. Braking" )
@@ -597,11 +589,11 @@ def run(self):
597589
598590 # publish data
599591 self ._publish_mpc_data (self .controller )
600- # Get active planners for visualization
592+ # Get active planner for visualization
601593 self .sot_lock .acquire ()
602- active_planners = self .sot .getPlanners ( num_planners = sot_num_plans )
594+ active_planner = self .sot .getPlanner ( )
603595 self .sot_lock .release ()
604- self ._publish_trajectory_tracking_pt (t - t0 , robot_states , active_planners )
596+ self ._publish_trajectory_tracking_pt (t - t0 , robot_states , active_planner )
605597
606598 # Update Task Manager
607599 # Convert to pose arrays in world frame
0 commit comments