Skip to content

Commit 6f72824

Browse files
committed
MPS: fixup processCollisionObject
- Declare CollisionObject argument as constant: Internally the argument is temporarily modified, but for a caller it is effectively const. - Correctly restore the old operation mode - Fixup check in unit test
1 parent 3ec69fb commit 6f72824

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

core/include/moveit/task_constructor/stages/modify_planning_scene.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class ModifyPlanningScene : public PropagatingEitherWay
150150
protected:
151151
// apply stored modifications to scene
152152
std::pair<InterfaceState, SubTrajectory> apply(const InterfaceState& from, bool invert);
153-
void processCollisionObject(planning_scene::PlanningScene& scene, moveit_msgs::CollisionObject& object, bool invert);
153+
void processCollisionObject(planning_scene::PlanningScene& scene, const moveit_msgs::CollisionObject& object,
154+
bool invert);
154155
void attachObjects(planning_scene::PlanningScene& scene, const std::pair<std::string, std::pair<Names, bool>>& pair,
155156
bool invert);
156157
void allowCollisions(planning_scene::PlanningScene& scene, const CollisionMatrixPairs& pairs, bool invert);

core/python/test/rostest_mps.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,14 @@ def DISABLED_test_bw_add_object(self):
9595
self.psi.remove_world_object("block") # restore original state
9696

9797
s = self.task.solutions[0].toMsg()
98-
for ps in [s.start_scene] + [s.sub_trajectory[i].scene_diff for i in [0, 1]]:
99-
objects = [o.id for o in ps.world.collision_objects]
100-
self.assertTrue(objects == ["block", "box"])
98+
99+
# block shouldn't be in start scene
100+
objects = [o.id for o in s.start_scene.world.collision_objects]
101+
self.assertTrue(objects == ["box"])
102+
103+
# only addObject(block) should add it
104+
objects = [o.id for o in s.sub_trajectory[1].scene_diff.world.collision_objects]
105+
self.assertTrue(objects == ["block", "box"])
101106

102107
def DISABLED_test_bw_remove_object(self):
103108
mps = stages.ModifyPlanningScene("removeObject(box) backwards")

core/src/stages/modify_planning_scene.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,19 @@ std::pair<InterfaceState, SubTrajectory> ModifyPlanningScene::apply(const Interf
149149
}
150150

151151
void ModifyPlanningScene::processCollisionObject(planning_scene::PlanningScene& scene,
152-
moveit_msgs::CollisionObject& object, bool invert) {
153-
auto op = object.operation;
152+
const moveit_msgs::CollisionObject& object, bool invert) {
153+
const auto op = object.operation;
154154
if (invert) {
155155
if (op == moveit_msgs::CollisionObject::ADD)
156-
op = moveit_msgs::CollisionObject::REMOVE;
156+
// (temporarily) change operation to REMOVE to revert adding the object
157+
const_cast<moveit_msgs::CollisionObject&>(object).operation = moveit_msgs::CollisionObject::REMOVE;
157158
else if (op == moveit_msgs::CollisionObject::REMOVE)
158159
throw std::runtime_error("cannot apply removeObject() backwards");
159160
}
160161

161162
scene.processCollisionObjectMsg(object);
162-
object.operation = op;
163+
// restore previous operation (for next call)
164+
const_cast<moveit_msgs::CollisionObject&>(object).operation = op;
163165
}
164166
} // namespace stages
165167
} // namespace task_constructor

0 commit comments

Comments
 (0)