Robotics StackExchange | Archived questions

How to use octomap to get obstacle information

Hi,

I am using octomapserver to get occupancy grid of my environment. It provides me the message in octomap_msgs/Octomap type through /octomapbinary topic. I can visualize it in rviz and it works well.

I want to get information about detected obstacles, like their coordinates or distances from my robot in the map. I think I should use castRay function for it, however I am not sure how to use it.

How should I get information about obstacles/occupied cells using outputs of Octomap?

my trying is:

void Map::occMapCallback(const octomap_msgs::Octomap& msg){
   octree = new octomap::OcTree(msg.resolution);    
   std::stringstream datastream;
   if (msg.data.size() > 0){
       datastream.write((const char*) &msg.data[0], msg.data.size());
       octree->readBinaryData(datastream);
   }
}

void Map::rayCasting(const geometry_msgs::Point& point){
   octomap::point3d origin(point.x, point.y, point.z);
   // raycasting in the x-direction
   octomap::point3d d_x(1.f, 0.f, 0.f);
   octomap::point3d end;
   bool occupied_x = octree->castRay(origin, d_x, end, true, 20);
}

This code compiles but crashes.

Asked by koraykoca on 2022-07-24 02:29:47 UTC

Comments

Answers