Skip to content

Commit 99bdd41

Browse files
committed
fix: removes vector allocation in getAttachedBodies map override
style: `sample_attached_object` -> `sample_attached_objects`
1 parent 20df675 commit 99bdd41

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

moveit_core/robot_state/src/robot_state.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -1223,12 +1223,8 @@ void RobotState::getAttachedBodies(std::vector<const AttachedBody*>& attached_bo
12231223
void RobotState::getAttachedBodies(std::map<std::string, const AttachedBody*>& attached_bodies) const
12241224
{
12251225
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-
}
1226+
for (const auto& it : attached_body_map_)
1227+
attached_bodies[it.first] = it.second.get();
12321228
}
12331229

12341230
void RobotState::getAttachedBodies(std::vector<const AttachedBody*>& attached_bodies, const JointModelGroup* group) const

moveit_ros/planning/plan_execution/src/plan_execution.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,16 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP
284284
req.group_name = t.getGroupName();
285285
req.pad_environment_collisions = false;
286286
moveit::core::RobotState state = plan.planning_scene->getCurrentState();
287-
std::map<std::string, const moveit::core::AttachedBody*> current_attached_objects, sample_attached_object;
287+
std::map<std::string, const moveit::core::AttachedBody*> current_attached_objects, sample_attached_objects;
288288
state.getAttachedBodies(current_attached_objects);
289289
for (std::size_t i = std::max(path_segment.second - 1, 0); i < wpc; ++i)
290290
{
291291
state = t.getWayPoint(i);
292292
collision_detection::CollisionResult res;
293-
state.getAttachedBodies(sample_attached_object);
293+
state.getAttachedBodies(sample_attached_objects);
294294

295295
// If sample state has attached objects that are not in the current state, remove them from the sample state
296-
for (const auto& [name, object] : sample_attached_object)
296+
for (const auto& [name, object] : sample_attached_objects)
297297
{
298298
if (current_attached_objects.find(name) == current_attached_objects.end())
299299
{
@@ -305,7 +305,7 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP
305305
// If current state has attached objects that are not in the sample state, add them to the sample state
306306
for (const auto& [name, object] : current_attached_objects)
307307
{
308-
if (sample_attached_object.find(name) == sample_attached_object.end())
308+
if (sample_attached_objects.find(name) == sample_attached_objects.end())
309309
{
310310
RCLCPP_DEBUG(logger_, "Attached object '%s' is not in the robot state. Adding it.", name.c_str());
311311
state.attachBody(std::make_unique<moveit::core::AttachedBody>(*object));

0 commit comments

Comments
 (0)