@@ -283,34 +283,54 @@ 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
+ std::vector<const moveit::core::AttachedBody*> attached_bodies;
287
+ plan.planning_scene ->getCurrentState ().getAttachedBodies (attached_bodies);
288
+ std::vector<std::string> current_attached_objects;
289
+ std::transform (attached_bodies.begin (), attached_bodies.end (), current_attached_objects.begin (),
290
+ [](const moveit::core::AttachedBody* ab) { return ab->getName (); });
291
+ moveit::core::RobotState state = plan.planning_scene ->getCurrentState ();
286
292
for (std::size_t i = std::max (path_segment.second - 1 , 0 ); i < wpc; ++i)
287
293
{
294
+ state = t.getWayPoint (i);
288
295
collision_detection::CollisionResult res;
296
+ state.getAttachedBodies (attached_bodies);
297
+ std::vector<std::string> sample_attached_object;
298
+ std::transform (attached_bodies.begin (), attached_bodies.end (), sample_attached_object.begin (),
299
+ [](const moveit::core::AttachedBody* ab) { return ab->getName (); });
300
+ for (const auto & attached_object : sample_attached_object)
301
+ {
302
+ if (std::find (current_attached_objects.begin (), current_attached_objects.end (), attached_object) ==
303
+ current_attached_objects.end ())
304
+ {
305
+ RCLCPP_INFO (logger_, " Attached object '%s' is not in the current scene" , attached_object.c_str ());
306
+ state.clearAttachedBody (attached_object);
307
+ }
308
+ }
289
309
if (acm)
290
310
{
291
- plan.planning_scene ->checkCollision (req, res, t. getWayPoint (i) , *acm);
311
+ plan.planning_scene ->checkCollision (req, res, state , *acm);
292
312
}
293
313
else
294
314
{
295
- plan.planning_scene ->checkCollision (req, res, t. getWayPoint (i) );
315
+ plan.planning_scene ->checkCollision (req, res, state );
296
316
}
297
317
298
- if (res.collision || !plan.planning_scene ->isStateFeasible (t. getWayPoint (i) , false ))
318
+ if (res.collision || !plan.planning_scene ->isStateFeasible (state , false ))
299
319
{
300
320
RCLCPP_INFO (logger_, " Trajectory component '%s' is invalid for waypoint %ld out of %ld" ,
301
321
plan.plan_components [path_segment.first ].description .c_str (), i, wpc);
302
322
303
323
// call the same functions again, in verbose mode, to show what issues have been detected
304
- plan.planning_scene ->isStateFeasible (t. getWayPoint (i) , true );
324
+ plan.planning_scene ->isStateFeasible (state , true );
305
325
req.verbose = true ;
306
326
res.clear ();
307
327
if (acm)
308
328
{
309
- plan.planning_scene ->checkCollision (req, res, t. getWayPoint (i) , *acm);
329
+ plan.planning_scene ->checkCollision (req, res, state , *acm);
310
330
}
311
331
else
312
332
{
313
- plan.planning_scene ->checkCollision (req, res, t. getWayPoint (i) );
333
+ plan.planning_scene ->checkCollision (req, res, state );
314
334
}
315
335
return false ;
316
336
}
0 commit comments