Adding objects to the planning scene

To start adding an object, we need to have a planning scene; this is only possible when MoveIt! is running, so the first step is to start Gazebo, MoveIt!, the controllers, and RViz. Since the planning scene only exists in MoveIt!, RViz is required to be able to visualize objects contained in it. In order to launch all of the required modules, we need to run the following commands:

    $ roslaunch rosbook_arm_gazebo rosbook_arm_empty_world.launch
    $ roslaunch rosbook_arm_moveit_config moveit_rviz.launch config:=true  

The snippet of code then starts by instantiating the planning scene interface object, which can be used to perform actions on the planning scene itself:

moveit::planning_interface::PlanningSceneInterfacecurrent_scene; 

The next step is to create the collision object message that we want to send through the planning scene interface. The first thing we need to provide for the collision object is a name, which will uniquely identify this object and will allow us to perform actions on it, such as removing it from the scene once we're done with it:

moveit_msgs::CollisionObject box; 
 
box.id = "rosbook_box"; 

The next step is to provide the properties of the object itself. This is done through a solid primitive message, which specifies the type of object we are creating, and depending on the type of object, it also specifies its properties. In our case, we are simply creating a box, which essentially has three dimensions:

shape_msgs::SolidPrimitive primitive; 
primitive.type = primitive.BOX; 
primitive.dimensions.resize(3); 
primitive.dimensions[0] = 0.2; 
primitive.dimensions[1] = 0.2; 
primitive.dimensions[2] = 0.2; 

To continue, we need to provide the pose of the box in the planning scene. Since we want to produce a possible collision scenario, we have placed the box close to our robotic arm. The pose itself is specified with a pose message from the standard geometry messages package:

geometry_msgs::Pose pose; 
pose.orientation.w = 1.0; 
pose.position.x = 0.7; 
pose.position.y = -0.5; 
pose.position.z = 1.0; 

We then add the primitive and the pose to the message and specify that the operation we want to perform is to add it to the planning scene:

box.primitives.push_back(primitive); 
box.primitive_poses.push_back(pose); 
box.operation = box.ADD; 

Finally, we add the collision object to a vector of collision object messages and call the addCollisionObjects method from the planning scene interface. This will take care of sending the required messages through the appropriate topics, in order to ensure that the object is created in the current planning scene:

std::vector<moveit_msgs::CollisionObject>collision_objects; 
collision_objects.push_back(box); 
 
current_scene.addCollisionObjects(collision_objects); 

We can test this snippet by running the following command in a terminal, as said earlier. Since the object is added to the planning scene, it is important to have the RViz visualization running; otherwise, the reader won't be able to see the object:

    $ rosrun rosbook_arm_snippets move_group_add_object  

The result can be seen in the following figure as a simple, green, squared box in between the arm's goal and the current position of the arm:

Scene collision object in RViz
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.8.82