Build a updated ROS message with shared_ptr

asked 2016-02-18 01:36:09 -0500

crazymumu gravatar image

updated 2016-02-18 01:55:01 -0500

I want to build a map which is updated in real-time and also is a self-defined ROS message. I declared a shared-ptr like local_map below in global to access coming map. And process in another callback function. I just wondering if there is a better way to that. any suggestion will be appreciated. Thanks.

#include <ros/ros.h>
#include <iostream>
#inlcude ...

class LocalMap

     //hector_navigation::Map is self-defined ROS message
     sub_filter = nh.subscribe<pcl::PointCloud<pcl::PointXYZ> > ("FilteredPoints", 1, &LocalMap::callback,this);
     sub_map = nh.subscribe<hector_navigation::Map>("Local_Map", 1, &LocalMap::callback_map,this);
     map_pub = nh.advertise<hector_navigation::Map>("Local_Map", 1);

    void callback_map(const hector_navigation::Map::ConstPtr& inputMap);
    void callback(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& inputCloud );

    //hector_navigation::MapConstPtr is selfe-defined shared_ptr
    hector_navigation::MapConstPtr local_map;

    ros::NodeHandle nh;
    ros::Subscriber sub_filter;
    ros::Subscriber sub_map;
    ros::Publisher map_pub;

void LocalMap::callback_map(const hector_navigation::Map::ConstPtr& inputMap)
  local_map = inputMap;   

void LocalMap::callback(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& inputCloud )
  hector_navigation::MapConstPtr ptr_map;
  ptr_map = local_map;


   process with ptr_map and inputCloud
   and publish hector_navigation::Map again


int main(int argc, char **argv)
     ros::init(argc, argv, "local_map_node");   
     LocalMap  localproject;   
     return 0;
edit retag flag offensive close merge delete