Skip to content

Commit 20df675

Browse files
committed
feat: adds getAttachedBodies override that returns a map instead of a vector
1 parent b94e50b commit 20df675

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

moveit_core/robot_state/include/moveit/robot_state/robot_state.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,9 @@ class RobotState
15191519
/** \brief Get all bodies attached to the model corresponding to this state */
15201520
void getAttachedBodies(std::vector<const AttachedBody*>& attached_bodies) const;
15211521

1522+
/** \brief Get all bodies attached to the model corresponding to this state */
1523+
void getAttachedBodies(std::map<std::string, const AttachedBody*>& attached_bodies) const;
1524+
15221525
/** \brief Get all bodies attached to a particular group the model corresponding to this state */
15231526
void getAttachedBodies(std::vector<const AttachedBody*>& attached_bodies, const JointModelGroup* group) const;
15241527

moveit_core/robot_state/src/robot_state.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,17 @@ void RobotState::getAttachedBodies(std::vector<const AttachedBody*>& attached_bo
12201220
attached_bodies.push_back(it.second.get());
12211221
}
12221222

1223+
void RobotState::getAttachedBodies(std::map<std::string, const AttachedBody*>& attached_bodies) const
1224+
{
1225+
attached_bodies.clear();
1226+
std::vector<const AttachedBody*> bodies;
1227+
getAttachedBodies(bodies);
1228+
for (const auto& b : bodies)
1229+
{
1230+
attached_bodies[b->getName()] = b;
1231+
}
1232+
}
1233+
12231234
void RobotState::getAttachedBodies(std::vector<const AttachedBody*>& attached_bodies, const JointModelGroup* group) const
12241235
{
12251236
attached_bodies.clear();

moveit_ros/planning/plan_execution/src/plan_execution.cpp

+3-13
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,14 @@ 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-
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-
297286
moveit::core::RobotState state = plan.planning_scene->getCurrentState();
298-
std::map<std::string, const moveit::core::AttachedBody*> current_attached_objects = getAttachedObjects(state);
287+
std::map<std::string, const moveit::core::AttachedBody*> current_attached_objects, sample_attached_object;
288+
state.getAttachedBodies(current_attached_objects);
299289
for (std::size_t i = std::max(path_segment.second - 1, 0); i < wpc; ++i)
300290
{
301291
state = t.getWayPoint(i);
302292
collision_detection::CollisionResult res;
303-
std::map<std::string, const moveit::core::AttachedBody*> sample_attached_object = getAttachedObjects(state);
293+
state.getAttachedBodies(sample_attached_object);
304294

305295
// If sample state has attached objects that are not in the current state, remove them from the sample state
306296
for (const auto& [name, object] : sample_attached_object)

0 commit comments

Comments
 (0)