@@ -283,17 +283,20 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP
283
283
collision_detection::CollisionRequest req;
284
284
req.group_name = t.getGroupName ();
285
285
req.pad_environment_collisions = false ;
286
- moveit::core::RobotState state = plan.planning_scene ->getCurrentState ();
286
+ moveit::core::RobotState start_state = plan.planning_scene ->getCurrentState ();
287
287
std::map<std::string, const moveit::core::AttachedBody*> current_attached_objects, waypoint_attached_objects;
288
- state.getAttachedBodies (current_attached_objects);
289
- waypoint_attached_objects = plan_components_attached_objects_[path_segment.first ];
288
+ start_state.getAttachedBodies (current_attached_objects);
289
+ if (plan_components_attached_objects_.size () > static_cast <size_t >(path_segment.first ))
290
+ waypoint_attached_objects = plan_components_attached_objects_[path_segment.first ];
291
+ moveit::core::RobotState waypoint_state (start_state);
290
292
for (std::size_t i = std::max (path_segment.second - 1 , 0 ); i < wpc; ++i)
291
293
{
292
294
collision_detection::CollisionResult res;
293
- state = t.getWayPoint (i);
295
+ waypoint_attached_objects.clear (); // clear out the last waypoints attached objects
296
+ waypoint_state = t.getWayPoint (i);
294
297
if (plan_components_attached_objects_[path_segment.first ].empty ())
295
298
{
296
- state .getAttachedBodies (waypoint_attached_objects);
299
+ waypoint_state .getAttachedBodies (waypoint_attached_objects);
297
300
}
298
301
299
302
// If sample state has attached objects that are not in the current state, remove them from the sample state
@@ -302,7 +305,7 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP
302
305
if (current_attached_objects.find (name) == current_attached_objects.end ())
303
306
{
304
307
RCLCPP_DEBUG (logger_, " Attached object '%s' is not in the current scene. Removing it." , name.c_str ());
305
- state .clearAttachedBody (name);
308
+ waypoint_state .clearAttachedBody (name);
306
309
}
307
310
}
308
311
@@ -312,35 +315,35 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP
312
315
if (waypoint_attached_objects.find (name) == waypoint_attached_objects.end ())
313
316
{
314
317
RCLCPP_DEBUG (logger_, " Attached object '%s' is not in the robot state. Adding it." , name.c_str ());
315
- state .attachBody (std::make_unique<moveit::core::AttachedBody>(*object));
318
+ waypoint_state .attachBody (std::make_unique<moveit::core::AttachedBody>(*object));
316
319
}
317
320
}
318
321
319
322
if (acm)
320
323
{
321
- plan.planning_scene ->checkCollision (req, res, state , *acm);
324
+ plan.planning_scene ->checkCollision (req, res, waypoint_state , *acm);
322
325
}
323
326
else
324
327
{
325
- plan.planning_scene ->checkCollision (req, res, state );
328
+ plan.planning_scene ->checkCollision (req, res, waypoint_state );
326
329
}
327
330
328
- if (res.collision || !plan.planning_scene ->isStateFeasible (state , false ))
331
+ if (res.collision || !plan.planning_scene ->isStateFeasible (waypoint_state , false ))
329
332
{
330
333
RCLCPP_INFO (logger_, " Trajectory component '%s' is invalid for waypoint %ld out of %ld" ,
331
334
plan.plan_components [path_segment.first ].description .c_str (), i, wpc);
332
335
333
336
// call the same functions again, in verbose mode, to show what issues have been detected
334
- plan.planning_scene ->isStateFeasible (state , true );
337
+ plan.planning_scene ->isStateFeasible (waypoint_state , true );
335
338
req.verbose = true ;
336
339
res.clear ();
337
340
if (acm)
338
341
{
339
- plan.planning_scene ->checkCollision (req, res, state , *acm);
342
+ plan.planning_scene ->checkCollision (req, res, waypoint_state , *acm);
340
343
}
341
344
else
342
345
{
343
- plan.planning_scene ->checkCollision (req, res, state );
346
+ plan.planning_scene ->checkCollision (req, res, waypoint_state );
344
347
}
345
348
return false ;
346
349
}
@@ -469,7 +472,7 @@ moveit_msgs::msg::MoveItErrorCodes plan_execution::PlanExecution::executeAndMoni
469
472
{
470
473
const auto & trajectory = component.trajectory ;
471
474
std::map<std::string, const moveit::core::AttachedBody*> trajectory_attached_objects;
472
- if (trajectory)
475
+ if (trajectory && trajectory-> getWayPointCount () > 0 )
473
476
{
474
477
std::map<std::string, const moveit::core::AttachedBody*> attached_objects;
475
478
trajectory->getWayPoint (0 ).getAttachedBodies (trajectory_attached_objects);
@@ -483,7 +486,8 @@ moveit_msgs::msg::MoveItErrorCodes plan_execution::PlanExecution::executeAndMoni
483
486
}
484
487
}
485
488
}
486
- plan_components_attached_objects_.push_back (trajectory_attached_objects);
489
+ if (!trajectory_attached_objects.empty ())
490
+ plan_components_attached_objects_.push_back (trajectory_attached_objects);
487
491
}
488
492
489
493
while (rclcpp::ok () && !execution_complete_ && !path_became_invalid_)
0 commit comments