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

stl mesh does not become visible in Rviz

asked 2020-04-30 04:16:04 -0500

BrandDebiel gravatar image

updated 2020-05-01 10:57:53 -0500

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;


collision_object_hBeam.meshes.push_back(mesh);
collision_object_hBeam.mesh_poses.push_back(hBeamPose);
collision_objects.push_back(collision_object_hBeam);

//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";
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-05-01 10:27:05 -0500

gvdhoorn gravatar image

updated 2020-05-01 10:27:31 -0500

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.

edit flag offensive delete link more

Comments

Thanks again for helping me out!!

BrandDebiel gravatar image BrandDebiel  ( 2020-05-01 10:49:20 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2020-04-30 04:16:04 -0500

Seen: 934 times

Last updated: May 01 '20