Rosanswers logo

With the code below I try to get a collision object into Rviz. For some reason the stl mesh is not showing in the 3D viewer. However the object I am trying to insert is based on the exact same stl which I have attached to the robot as an end-effector. I have no problems getting the end-effector visible on the robot.

In the piece of code below I try to create a collision object from an stl and add it to the collision objects vector. This vector already contains objects that are based on primitives. These primitives are visible except the stl based object. When importing the stl in the Rviz gui it works perfectly, so I guess the stl file seems to be fine.

//Add STL object to world
ROS_INFO("Load mesh file...");
Eigen::Vector3d vectorScale(1, 1, 1);
moveit_msgs::CollisionObject collision_object_hBeam;
collision_object_hBeam.header.frame_id = move_group.getPlanningFrame(); //Added this line to get the code working
collision_object_hBeam.id = "hBeam";

std::string packagePath = ros::package::getPath("moveit_tutorials");
ROS_INFO("PackagePath: %s", packagePath.c_str());

shapes::Mesh *meshObject = shapes::createMeshFromResource(
          "file:///home/dvdv/ws_robotplatform/src/moveit_tutorials/markerTool.stl", vectorScale);

shape_msgs::Mesh mesh;
shapes::ShapeMsg meshMessage;
shapes::constructMsgFromShape(meshObject, meshMessage);
mesh = boost::get<shape_msgs::Mesh>(meshMessage);

geometry_msgs::Pose hBeamPose;
hBeamPose.orientation.w = 1;
hBeamPose.orientation.x = 0;
hBeamPose.orientation.y = 0;
hBeamPose.orientation.z = 0;
hBeamPose.position.x = 1.0;
hBeamPose.position.y = 1.0;
hBeamPose.position.z = 1.0;


//Add objects to world ROS_INFO_NAMED("tutorial", "Add an object into the world"); planning_scene_interface.addCollisionObjects(collision_objects);

EDIT: I noticed I also get an error message, when I do not add the mesh the error does not come up. So I am sure it has something to do with it:

[ERROR] [1588345900.710790122]: Unknown frame:

EDIT: Code should look like this in order for it to work:

moveit_msgs::CollisionObject collision_object_hBeam;
collision_object_hBeam.header.frame_id = move_group.getPlanningFrame(); //This line was missing in the code snippet above
collision_object_hBeam.id = "hBeam";

Originally posted by BrandDebiel on ROS Answers with karma: 47 on 2020-04-30

Post score: 0


1 Answer 1


Rosanswers logo

It's likely you've forgotten to populate the header.frame_id of the moveit_msgs::CollisionObject.

The frame_id is used by MoveIt/RViz to figure out where your mesh should be attached/visualised.

You'll need to set it to the name of one of the TF frames already present in your TF tree.

Originally posted by gvdhoorn with karma: 86574 on 2020-05-01

This answer was ACCEPTED on the original site

Post score: 0

Original comments

Comment by BrandDebiel on 2020-05-01:
Thanks again for helping me out!!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.