Skip to content

Commit 0e97dcc

Browse files
committed
fix: first attempt of fixing attached objects update during motion execution.
checks that attached objects in the monitored robot matches the one in the planned trajectory. If objects are disappeared in the monitored robot remove also from the trajectory one. TODO add opposite way
1 parent 1794b8e commit 0e97dcc

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

moveit_ros/planning/plan_execution/src/plan_execution.cpp

+26-6
Original file line numberDiff line numberDiff line change
@@ -283,34 +283,54 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP
283283
collision_detection::CollisionRequest req;
284284
req.group_name = t.getGroupName();
285285
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();
286292
for (std::size_t i = std::max(path_segment.second - 1, 0); i < wpc; ++i)
287293
{
294+
state = t.getWayPoint(i);
288295
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+
}
289309
if (acm)
290310
{
291-
plan.planning_scene->checkCollision(req, res, t.getWayPoint(i), *acm);
311+
plan.planning_scene->checkCollision(req, res, state, *acm);
292312
}
293313
else
294314
{
295-
plan.planning_scene->checkCollision(req, res, t.getWayPoint(i));
315+
plan.planning_scene->checkCollision(req, res, state);
296316
}
297317

298-
if (res.collision || !plan.planning_scene->isStateFeasible(t.getWayPoint(i), false))
318+
if (res.collision || !plan.planning_scene->isStateFeasible(state, false))
299319
{
300320
RCLCPP_INFO(logger_, "Trajectory component '%s' is invalid for waypoint %ld out of %ld",
301321
plan.plan_components[path_segment.first].description.c_str(), i, wpc);
302322

303323
// 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);
305325
req.verbose = true;
306326
res.clear();
307327
if (acm)
308328
{
309-
plan.planning_scene->checkCollision(req, res, t.getWayPoint(i), *acm);
329+
plan.planning_scene->checkCollision(req, res, state, *acm);
310330
}
311331
else
312332
{
313-
plan.planning_scene->checkCollision(req, res, t.getWayPoint(i));
333+
plan.planning_scene->checkCollision(req, res, state);
314334
}
315335
return false;
316336
}

0 commit comments

Comments
 (0)