@@ -283,39 +283,41 @@ 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::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
- }
286
+ auto getAttachedObjects = [](const moveit::core::RobotState& state) {
287
+ std::vector<const moveit::core::AttachedBody*> attached_bodies;
288
+ state.getAttachedBodies (attached_bodies);
289
+ std::map<std::string, const moveit::core::AttachedBody*> attached_objects;
290
+ for (const auto & ab : attached_bodies)
291
+ {
292
+ attached_objects[ab->getName ()] = ab;
293
+ }
294
+ return attached_objects;
295
+ };
296
+
293
297
moveit::core::RobotState state = plan.planning_scene ->getCurrentState ();
298
+ std::map<std::string, const moveit::core::AttachedBody*> current_attached_objects = getAttachedObjects (state);
294
299
for (std::size_t i = std::max (path_segment.second - 1 , 0 ); i < wpc; ++i)
295
300
{
296
301
state = t.getWayPoint (i);
297
302
collision_detection::CollisionResult res;
298
- state.getAttachedBodies (attached_bodies);
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
- }
303
+ std::map<std::string, const moveit::core::AttachedBody*> sample_attached_object = getAttachedObjects (state);
304
+
305
+ // If sample state has attached objects that are not in the current state, remove them from the sample state
304
306
for (const auto & [name, object] : sample_attached_object)
305
307
{
306
308
if (current_attached_objects.find (name) == current_attached_objects.end ())
307
309
{
308
- RCLCPP_INFO (logger_, " Attached object '%s' is not in the current scene. Removing from robot state" ,
309
- name.c_str ());
310
+ RCLCPP_DEBUG (logger_, " Attached object '%s' is not in the current scene. Removing it." , name.c_str ());
310
311
state.clearAttachedBody (name);
311
312
}
312
313
}
313
314
315
+ // If current state has attached objects that are not in the sample state, add them to the sample state
314
316
for (const auto & [name, object] : current_attached_objects)
315
317
{
316
318
if (sample_attached_object.find (name) == sample_attached_object.end ())
317
319
{
318
- RCLCPP_INFO (logger_, " Attached object '%s' is not in the robot state. Adding it." , name.c_str ());
320
+ RCLCPP_DEBUG (logger_, " Attached object '%s' is not in the robot state. Adding it." , name.c_str ());
319
321
state.attachBody (std::make_unique<moveit::core::AttachedBody>(*object));
320
322
}
321
323
}
0 commit comments