Ask Your Question

Creating a CollisionObject from a mesh in Kinetic

asked 2018-11-30 04:51:27 -0500

Pulkit123 gravatar image

Hi I am using ROS Kinetic. I am trying to add a custom defined mesh as collision object. Below is my code but in RViz no object is being shown. The code shows no error . Please give me suggestions as what to do?

#include <ros/ros.h>
#include <geometry_msgs/Pose.h>
#include <geometric_shapes/shape_operations.h>
#include "geometric_shapes/mesh_operations.h"
#include "geometric_shapes/shape_operations.h"

// MoveIt!
#include <moveit_msgs/PlanningScene.h>
#include <moveit_msgs/AttachedCollisionObject.h>
#include <geometric_shapes/solid_primitive_dims.h>

int main(int argc, char** argv)
  ros::init(argc, argv, "move_group_tutorial");
  ros::AsyncSpinner spinner(1);
  ros::NodeHandle node_handle;
  ros::Publisher pub_planning_scene_diff_;

  /* First put an object into the scene*/
  /* Advertise the collision object message publisher*/
  ros::Publisher collision_object_publisher = node_handle.advertise<moveit_msgs::CollisionObject>("collision_object", 10000);
  while (collision_object_publisher.getNumSubscribers() < 1)
    ros::WallDuration sleep_t(0.5);
  /* Define the object message */
  moveit_msgs::CollisionObject co;
  /* The header must contain a valid TF frame */
  co.header.frame_id = "world";
  co.header.stamp = ros::Time::now();

  // to remove an object
   /* The id of the object */ = "box";
  co.operation = moveit_msgs::CollisionObject::REMOVE;
  std::cout << "object removed" << "\n";

  // add a mesh
  co.operation = moveit_msgs::CollisionObject::ADD;

  shapes::Mesh*  c_mesh = shapes::createMeshFromResource("package://coro_description/meshes/visual/link0.dae");
  shapes::ShapeMsg mesh_msg;
  shapes::constructMsgFromShape(c_mesh, mesh_msg);
  shape_msgs::Mesh mesh_custom = boost::get<shape_msgs::Mesh>(mesh_msg);

  co.mesh_poses[0].position.x = 2.0;
  co.mesh_poses[0].position.y = 2.0;
  co.mesh_poses[0].position.z = 1.0;
edit retag flag offensive close merge delete


have you tried with planning_scene_interface? Also see this.

aPonza gravatar image aPonza  ( 2018-12-05 06:13:16 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-10-15 22:46:12 -0500

AndyZe gravatar image

updated 2021-10-16 20:07:34 -0500

I see a couple things wrong with the code here.

Redundant includes (minor issue)

#include <geometric_shapes/shape_operations.h>
#include "geometric_shapes/shape_operations.h"

Pushing the mesh into element 1 rather than element 0:

co.meshes.resize(1);  // There is now 1 element
co.meshes.push_back(mesh_custom); // There are now 2 elements
co.mesh_poses[0].position.x = 2.0; // This corresponds to the wrong element

Also, the color of the mesh isn't defined. Maybe it doesn't show up because it's transparent by default.

Other than that, I would use rostopic info and rostopic echo to make sure you're publishing to a topic that has a subscriber.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-11-30 04:51:27 -0500

Seen: 322 times

Last updated: Oct 16