ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How can I stop the Moveit planning execution when there is a collsion between the robot and the object in the scene?

asked 2021-03-29 00:34:19 -0500

Astronaut gravatar image

Hi

I have successfully introduced collision objects in the Moveit planning scene. The collision objects are real objects detected with a ZED camera and they are in the Moveit simulation as can see from this code and RVIZ screenshot. Here the collision objects code

using namespace sensor_msgs;
using namespace std;

void chatterCallback(const darknet_ros_3d_msgs::BoundingBoxes3d& boxes)
{ 

 int counter_id = 0;
 const std::string PLANNING_GROUP = "crane_control";    
 moveit::planning_interface::PlanningSceneInterface planning_scene_interface;
 std::vector<std::string> object_ids;
 moveit_msgs::CollisionObject collision_object;
 collision_object.header.frame_id = "world";
 collision_object.id = "BOX_";
 std::vector<moveit_msgs::CollisionObject> collision_objects;

          for(auto bb : boxes.bounding_boxes)
                    {

                                  shape_msgs::SolidPrimitive primitive;
                                  primitive.type = primitive.BOX;
                                  primitive.dimensions.resize(3);
                                  string str= to_string(counter_id++);

                                  //Pose
                                  geometry_msgs::Pose box_pose;
                                  box_pose.position.x = abs ((bb.xmax + bb.xmin)/2);
                                  box_pose.position.y = abs ((bb.ymax + bb.ymin)/2);
                                  box_pose.position.z = abs ((bb.zmax + bb.zmin)/2)-10;
                                  box_pose.orientation.x = 0; 
                                  box_pose.orientation.y = 0;   
                                  box_pose.orientation.z = 0;
                                  box_pose.orientation.w = 1.0;

                                  //Dimension
                                  primitive.dimensions[0] = abs (bb.xmax - bb.xmin);
                                  primitive.dimensions[1] = abs (bb.ymax - bb.ymin);
                                  primitive.dimensions[2] = abs (bb.zmax - bb.zmin); 

                                  //Collision objects                                                                                                                               
                                  collision_object.primitives.push_back(primitive);
                                  collision_object.primitive_poses.push_back(box_pose);                                                                   
                                  collision_objects.push_back(collision_object); 
                                  sleep(0.5);                                                        

                            }
                                 collision_object.operation = collision_object.REMOVE; 
                                 object_ids.push_back(collision_object.id);
                                 planning_scene_interface.removeCollisionObjects(object_ids); 
                                 sleep(0.3); 
                                 collision_object.operation = collision_object.ADD;
                                 planning_scene_interface.applyCollisionObjects(collision_objects);

 }

int main(int argc,  char** argv)

{
  ros::init(argc, argv, "cpp_subscriber");
  ros::NodeHandle n;
  ros::Subscriber sub = n.subscribe("/darknet_ros_3d/bounding_boxes", 5, chatterCallback);
  ros::spin();  

}

Here can see the collision object with RVIZ RVIZ

So, now first I would like to give the robot a path-goal from point A to B and then when is in the collision with the object just to stop. Any Help?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-03-29 00:54:02 -0500

fvd gravatar image

I'm not sure I understood your pipeline completely (what's a "path-goal"?), but:

  1. If you set a pose goal and requested a motion plan, your path will not be in collision that are currently in the scene.
  2. If you are requesting a cartesian path, the current interface returns the up to the first collision.
  3. If you are detecting collision objects while moving, IIRC the Replanning checkbox in the Motion Planning plugin is supposed to keep checking the trajectory for collisions and replan when it finds a collision in the remaining path. You could take a look at and change this functionality to just stop.
  4. If "path-goal" means that you already have a trajectory and you want to check it for collisions in your current scene, you can use the isPathValid functions in the PlanningScene API.
edit flag offensive delete link more

Comments

2

And a general comment: you might want to move the initialisation of the PlanningSceneInterface and related infrastructure to somewhere outside the callback. The code as-is leads to (potentially) high-frequency creation and destruction of objects with a high cost to that creation and destruction. That's far from optimal, and will likely influence application performance quite a bit.

gvdhoorn gravatar image gvdhoorn  ( 2021-03-29 01:19:08 -0500 )edit

"Path-goal " , sorry I mean navigate the robot from a point A to B. In my case the tower crane (the load is moving from point A to B and in that way I want to introduce the collision object and make the robot(tower crane) stop. Hope now more clear

Astronaut gravatar image Astronaut  ( 2021-03-29 01:36:11 -0500 )edit

Like where to move the initialization of the PlanningSceneInterface and related infrastructure to somewhere outside the callback? Then what will be in the callback?

Astronaut gravatar image Astronaut  ( 2021-03-29 01:39:19 -0500 )edit

It's not clear to me at what time you add the collision object to the scene. If it's before the planning starts, then you should be fine. If it's during movement (during execution of the trajectory) then you need to take some extra care.

fvd gravatar image fvd  ( 2021-03-29 01:41:01 -0500 )edit

It's during movement. So how to proceed in this case? Which of your 4 statements can be used ?

Astronaut gravatar image Astronaut  ( 2021-03-29 01:50:33 -0500 )edit

Mainly 3. I haven't looked at that part of the code in detail, but I know that your use case was the intention behind it. Have a look at plan_execution.cpp and the replanning flag.

You could also use 4 to check for collisions when you detect new collision objects, and stop the execution yourself.

fvd gravatar image fvd  ( 2021-03-29 02:13:26 -0500 )edit

It's here. Watch out that you're not looking at outdated tutorials (you linked to Kinetic). Also please accept this answer so it's out of the queue.

fvd gravatar image fvd  ( 2021-03-29 06:29:43 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-03-29 00:34:19 -0500

Seen: 684 times

Last updated: Mar 29 '21