Ask Your Question
0

Problem with single voxel octomap publisher [closed]

asked 2019-07-19 07:14:16 -0500

PabloMV gravatar image

Hi! I'm trying to make a publisher that publish one single octomap voxel. I'm not sure if my code is rigth but i have an error when calling setNodeValue():

#include "ros/ros.h"
#include "octomap_msgs/Octomap.h"
#include "octomap/octomap.h"
#include "octomap/OcTree.h"
#include "octomap_msgs/conversions.h"
class OctomapPub
{
public:
  OctomapPub()
  : nh_(),
  octree_(0.1)
  {
    octo_pub_ = nh_.advertise<octomap_msgs::Octomap>("/octomap/custom", 1000);
    initOctree(octree_);

    octomap::OcTreeKey key = octree_.coordToKey(1.0, 1.0, 1.0);
    updateOctomap(key);
    publishOctomap(octree_);
  }

  void initOctree(octomap::OcTree& octree)
  {
    octree.setOccupancyThres(0.5);
    octree.setProbHit(0.7);
    octree.setProbMiss(0.2);
    octree.setClampingThresMax(0.95);
    octree.setClampingThresMin(0.2);
  }

  void updateOctomap(octomap::OcTreeKey key)
  {
    octree_.setNodeValue(key, octree_.search(key), false);
  }

  void publishOctomap(const octomap::OcTree& octree)
  {
    octomap_msgs::Octomap map;

    if (octomap_msgs::fullMapToMsg(octree, map))
    {
      map.header.frame_id = "base_footprint";
      map.header.stamp = ros::Time::now();

      octo_pub_.publish(map);
      ROS_INFO("OctoMap published. Subscribers: %d", octo_pub_.getNumSubscribers());
    } else {
      ROS_ERROR("Error serializing OctoMap");
    }
  }

private:
  ros::NodeHandle nh_;
  ros::Publisher octo_pub_;
  octomap::OcTree octree_;
};

int main(int argc, char **argv)
{
  ros::init(argc, argv, "OctoMap_publisher");
  ros::NodeHandle nh;
  ros::Rate loop_rate(2);

  OctomapPub octomappub;

  int count = 0;
  while (ros::ok())
  {
    ros::spinOnce();
    loop_rate.sleep();
  }
  return 0;
}

The error it's the following:

/home/pablo/catkin_test/src/pub_example/src/publisher.cpp: In member function ‘void OctomapPub::updateOctomap(octomap::OcTreeKey)’:
/home/pablo/catkin_test/src/pub_example/src/publisher.cpp:33:57: error: no matching function for call to ‘octomap::OcTree::setNodeValue(octomap::OcTreeKey&, octomap::OcTreeNode*, bool)’
     octree_.setNodeValue(key, octree_.search(key), false);
                                                         ^
In file included from /opt/ros/melodic/include/octomap/OccupancyOcTreeBase.h:506:0,
                 from /opt/ros/melodic/include/octomap/OcTree.h:38,
                 from /opt/ros/melodic/include/octomap/octomap.h:37,
                 from /home/pablo/catkin_test/src/pub_example/src/publisher.cpp:3:
/opt/ros/melodic/include/octomap/OccupancyOcTreeBase.hxx:267:9: note: candidate: NODE* octomap::OccupancyOcTreeBase<NODE>::setNodeValue(const octomap::OcTreeKey&, float, bool) [with NODE = octomap::OcTreeNode]
   NODE* OccupancyOcTreeBase<NODE>::setNodeValue(const OcTreeKey& key, float log_odds_value, bool lazy_eval) {
         ^~~~~~~~~~~~~~~~~~~~~~~~~
/opt/ros/melodic/include/octomap/OccupancyOcTreeBase.hxx:267:9: note:   no known conversion for argument 2 from ‘octomap::OcTreeNode*’ to ‘float’
/opt/ros/melodic/include/octomap/OccupancyOcTreeBase.hxx:282:9: note: candidate: NODE* octomap::OccupancyOcTreeBase<NODE>::setNodeValue(const point3d&, float, bool) [with NODE = octomap::OcTreeNode; octomap::point3d = octomath::Vector3]
   NODE* OccupancyOcTreeBase<NODE>::setNodeValue(const point3d& value, float log_odds_value, bool lazy_eval) {
         ^~~~~~~~~~~~~~~~~~~~~~~~~
/opt/ros/melodic/include/octomap/OccupancyOcTreeBase.hxx:282:9: note:   no known conversion for argument 1 from ‘octomap::OcTreeKey’ to ‘const point3d& {aka const octomath::Vector3&}’
/opt/ros/melodic/include/octomap/OccupancyOcTreeBase.hxx:291:9: note: candidate: NODE* octomap::OccupancyOcTreeBase<NODE>::setNodeValue(double, double, double, float, bool) [with NODE = octomap::OcTreeNode]
   NODE* OccupancyOcTreeBase<NODE>::setNodeValue(double x, double y, double z, float log_odds_value, bool lazy_eval) {
         ^~~~~~~~~~~~~~~~~~~~~~~~~
/opt/ros/melodic/include/octomap/OccupancyOcTreeBase.hxx:291:9: note:   candidate expects 5 arguments, 3 provided
pub_example/CMakeFiles/pub_example_nde.dir/build.make:62: recipe for target 'pub_example/CMakeFiles/pub_example_nde.dir/src/publisher.cpp.o' failed
make[2]: *** [pub_example/CMakeFiles/pub_example_nde.dir/src/publisher.cpp.o] Error 1
CMakeFiles/Makefile2 ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by PabloMV
close date 2019-07-29 16:55:51.692053

Comments

1

I think the error is clear octree_.search(key) returns a octomap::OcTreeNode* when your functions argument position is expecting a float

stevemacenski gravatar imagestevemacenski ( 2019-07-19 11:22:27 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2019-07-21 09:40:31 -0500

PabloMV gravatar image

Thanks you're right i didn't notice.

edit flag offensive delete link more

Comments

Awesome, can you mark the answer as correct so that its off the unanswered questions queue?

stevemacenski gravatar imagestevemacenski ( 2019-07-29 15:12:12 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-07-19 07:14:16 -0500

Seen: 25 times

Last updated: Jul 21