@@ -285,27 +285,41 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP
285
285
req.pad_environment_collisions = false ;
286
286
std::vector<const moveit::core::AttachedBody*> attached_bodies;
287
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 (); });
288
+ std::map<std::string, const moveit::core::AttachedBody*> current_attached_objects;
289
+ for (const auto & ab : attached_bodies)
290
+ {
291
+ current_attached_objects[ab->getName ()] = ab;
292
+ }
291
293
moveit::core::RobotState state = plan.planning_scene ->getCurrentState ();
292
294
for (std::size_t i = std::max (path_segment.second - 1 , 0 ); i < wpc; ++i)
293
295
{
294
296
state = t.getWayPoint (i);
295
297
collision_detection::CollisionResult res;
296
298
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)
299
+ std::map<std::string, const moveit::core::AttachedBody*> sample_attached_object;
300
+ for (const auto & ab : attached_bodies)
301
+ {
302
+ sample_attached_object[ab->getName ()] = ab;
303
+ }
304
+ for (const auto & [name, object] : sample_attached_object)
305
+ {
306
+ if (current_attached_objects.find (name) == current_attached_objects.end ())
307
+ {
308
+ RCLCPP_INFO (logger_, " Attached object '%s' is not in the current scene. Removing from robot state" ,
309
+ name.c_str ());
310
+ state.clearAttachedBody (name);
311
+ }
312
+ }
313
+
314
+ for (const auto & [name, object] : current_attached_objects)
301
315
{
302
- if (std::find (current_attached_objects.begin (), current_attached_objects.end (), attached_object) ==
303
- current_attached_objects.end ())
316
+ if (sample_attached_object.find (name) == sample_attached_object.end ())
304
317
{
305
- RCLCPP_INFO (logger_, " Attached object '%s' is not in the current scene " , attached_object .c_str ());
306
- state.clearAttachedBody (attached_object );
318
+ RCLCPP_INFO (logger_, " Attached object '%s' is not in the robot state. Adding it. " , name .c_str ());
319
+ state.attachBody (std::make_unique<moveit::core::AttachedBody>(*object) );
307
320
}
308
321
}
322
+
309
323
if (acm)
310
324
{
311
325
plan.planning_scene ->checkCollision (req, res, state, *acm);
0 commit comments