Skip to content

Commit ce9b1d2

Browse files
committed
fix: adds first draft of on the fly attached object checks
1 parent 0e97dcc commit ce9b1d2

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

moveit_ros/planning/plan_execution/src/plan_execution.cpp

+25-11
Original file line numberDiff line numberDiff line change
@@ -285,27 +285,41 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP
285285
req.pad_environment_collisions = false;
286286
std::vector<const moveit::core::AttachedBody*> attached_bodies;
287287
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+
}
291293
moveit::core::RobotState state = plan.planning_scene->getCurrentState();
292294
for (std::size_t i = std::max(path_segment.second - 1, 0); i < wpc; ++i)
293295
{
294296
state = t.getWayPoint(i);
295297
collision_detection::CollisionResult res;
296298
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)
301315
{
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())
304317
{
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));
307320
}
308321
}
322+
309323
if (acm)
310324
{
311325
plan.planning_scene->checkCollision(req, res, state, *acm);

0 commit comments

Comments
 (0)