moveit icon indicating copy to clipboard operation
moveit copied to clipboard

PlanningSceneInterface::clearScene()

Open v4hn opened this issue 3 years ago • 3 comments

The best reliable way I know for user nodes to remove all objects from the planning scene is this:

   moveit::planning_interface::PlanningSceneInterface psi;
   moveit_msgs::PlanningScene rm;
   rm.is_diff = true;
   rm.robot_state.is_diff = true;
   rm.robot_state.attached_collision_objects.resize(1);
   rm.robot_state.attached_collision_objects[0].object.operation = moveit_msgs::CollisionObject::REMOVE;
   rm.world.collision_objects.resize(1);
   rm.world.collision_objects[0].operation = moveit_msgs::CollisionObject::REMOVE;
   psi.applyPlanningScene(rm);

I would propose to simplify this to

   moveit::planning_interface::PlanningSceneInterface psi;
   psi.clearScene();

Opinions? Additions? Alternatives?

v4hn avatar Jul 09 '21 21:07 v4hn

I am all for this - in fact, it already exists in Python and the function should be linked if a C++ implementation is added.

felixvd avatar Jul 12 '21 05:07 felixvd

PlanningScene has a removeAllCollisionObjects() method. Doesn't that work in this case? The planning_interface does not work with MoveItCpp I believe, but then the PlanningScene can be accessed through the PlanninSceneMonitor. So removeAllCollisionObjects() works for both MoveGroupInterface and MoveItCpp.

pvanlaar avatar Jul 15 '21 18:07 pvanlaar

PlanningScene has a removeAllCollisionObjects() method. Doesn't that work in this case?

Using the MGI/PSI you usually interact with the PlanningScene of a move_group ROS node. You don't have access to this method of the C++ PlanningScene class from outside the node and the PSM does not help with that.

For MoveItCpp I agree though.

v4hn avatar Jul 19 '21 20:07 v4hn

Hi, I am new to open source contributing if this issue still exists, I would like to work on it.

If yes, then can the simple steps stated below be included in the PSI to create a function in PSI and then just psi.clearScene()

Would that be a viable solution?

The best reliable way I know for user nodes to remove all objects from the planning scene is this:

   moveit::planning_interface::PlanningSceneInterface psi;
   moveit_msgs::PlanningScene rm;
   rm.is_diff = true;
   rm.robot_state.is_diff = true;
   rm.robot_state.attached_collision_objects.resize(1);
   rm.robot_state.attached_collision_objects[0].object.operation = moveit_msgs::CollisionObject::REMOVE;
   rm.world.collision_objects.resize(1);
   rm.world.collision_objects[0].operation = moveit_msgs::CollisionObject::REMOVE;
   psi.applyPlanningScene(rm);

aaryanmurgunde avatar Oct 20 '23 14:10 aaryanmurgunde

@aaryanmurgunde, you are very welcome to work on this. Concrete TODOs:

  • [ ] Wrap the listed code snippet into a new function in PlanningSceneInterface::clear().
  • [ ] Optionally use that function also in python code as suggested here
  • [ ] Test everything. Ideally, provide a new unit test for it.

rhaschke avatar Oct 20 '23 14:10 rhaschke

@aaryanmurgunde, you are very welcome to work on this. Concrete TODOs:

  • [x] Wrap the listed code snippet into a new function in PlanningSceneInterface::clear().
  • [ ] Optionally use that function also in python code as suggested here
  • [x] Test everything. Ideally, provide a new unit test for it.

@rhaschke I'm not sure about the wrapper for python if you could help me understand that then I can build for the same as well.

Thank You : )

aaryanmurgunde avatar Oct 21 '23 10:10 aaryanmurgunde

Just use the newly implemented function in python, i.e. call self._psi.clear(). This requires clear to be exposed by the python wrapper of PlanningSceneInterface.

rhaschke avatar Oct 21 '23 12:10 rhaschke

@rhaschke For the python wrapper file wrapper_python_planning_scene_interface.cpp on line L112 adding

+  bool clearPython()
+  {
+    return clear();
+  }

and on line L126

+ planning_scene_class.def("clear", &PlanningSceneInterfaceWrapper::clearPython);

and in the planning_scene_interface.py on line L171

# replace 
- self.remove_attached_object()
- self.remove_world_object()

# with
+ self._psi.clear()

Any other changes that need to made ?

aaryanmurgunde avatar Oct 23 '23 12:10 aaryanmurgunde

I suffices to define the wrapper like this (no need to define clearPython()):

- planning_scene_class.def("clear", &PlanningSceneInterfaceWrapper::clearPython);
+ planning_scene_class.def("clear", &PlanningSceneInterfaceWrapper::clear);

rhaschke avatar Oct 23 '23 12:10 rhaschke

  • [x] Wrap the listed code snippet into a new function in PlanningSceneInterface::clear().
  • [x] Optionally use that function also in python code as suggested here
  • [x] Test everything. Ideally, provide a new unit test for it.

Done! pushed a commit for that as well.

Thank you so much for helping me out @rhaschke. It has been a big learning curve, I'm now much more prepared to work more on fixing issues and contributing to Open Source.

aaryanmurgunde avatar Oct 23 '23 12:10 aaryanmurgunde

Let's Close this issue then @rhaschke ?

aaryanmurgunde avatar Oct 25 '23 10:10 aaryanmurgunde

This issue will be closed via #2764.

rhaschke avatar Oct 25 '23 11:10 rhaschke