@@ -55,39 +55,55 @@ PointCloudMapsManager::on_initialize()
5555 auto node = get_node ();
5656 const auto & plugin_name = get_plugin_name ();
5757
58- std::string map_path_file, map_topic_in;
58+ std::string package_name, map_path_file, map_topic_in;
59+ node->declare_parameter (plugin_name + " .package_name" , package_name);
5960 node->declare_parameter (plugin_name + " .map_path_file" , map_path_file);
6061 node->declare_parameter (plugin_name + " .map_topic_in" , map_topic_in);
6162
63+ node->get_parameter (plugin_name + " .package_name" , package_name);
6264 node->get_parameter (plugin_name + " .map_path_file" , map_path_file);
6365 node->get_parameter (plugin_name + " .map_topic_in" , map_topic_in);
6466
65- std::cerr << " :: PARAMETERS :: \n " ;
66- std::cerr << " Map path file: " << map_path_file << " \n " ;
67- std::cerr << " map topic in name: " << map_topic_in << " \n " ;
67+ RCLCPP_INFO (get_node ()->get_logger (),
68+ " PointCloud : ..:: PARAMETERS ::.." );
6869
69- if (map_path_file != " " ) {
70- map_path_ = map_path_file;
70+ if (package_name != " " && map_path_file != " " ) {
71+ std::string pkgpath;
72+ try {
73+ pkgpath = ament_index_cpp::get_package_share_directory (package_name);
74+ RCLCPP_INFO (get_node ()->get_logger (),
75+ " PointCloud : Package name = %s" , package_name.c_str ());
76+ map_path_ = pkgpath + " /" + map_path_file;
77+ RCLCPP_INFO (get_node ()->get_logger (),
78+ " PointCloud : Map path file = %s" , map_path_.c_str ());
79+ } catch (ament_index_cpp::PackageNotFoundError & ex) {
80+ return std::unexpected (" Package " + package_name + " not found. Error: " + ex.what ());
81+ }
7182
7283 if (!static_map_.load_from_file (map_path_)) {
7384 return std::unexpected (" File [" + map_path_ + " ] not found" );
7485 } else {
7586 RCLCPP_INFO (get_node ()->get_logger (),
76- " PointCloudMapsManager : Map loaded from file" );
87+ " PointCloud : Map loaded from file" );
7788 dynamic_map_.deep_copy (static_map_);
7889 }
7990 } else {
80- map_path_ = " map .pcd" ;
91+ map_path_ = " pointcloud_map .pcd" ;
8192 RCLCPP_INFO (get_node ()->get_logger (),
82- " PointCloudMapsManager: Map path file to save: %s" , map_path_.c_str ());
93+ " PointCloud : Path Map file to save = ./ %s" , map_path_.c_str ());
8394 }
8495
8596 std::string topic_name;
8697 if (map_topic_in != " " ) {
8798 topic_name = map_topic_in;
99+ RCLCPP_INFO (get_node ()->get_logger (),
100+ " PointCloud : Map topic in name = %s" , topic_name.c_str ());
88101 } else {
89102 topic_name = node->get_name () + std::string (" /" ) + plugin_name + " /topic_in" ;
103+ RCLCPP_INFO (get_node ()->get_logger (),
104+ " PointCloud : Input Topic by default" );
90105 }
106+
91107
92108 static_map_pub_ = node->create_publisher <sensor_msgs::msg::PointCloud2>(
93109 node->get_name () + std::string (" /" ) + plugin_name + " /static_map" ,
@@ -101,7 +117,7 @@ PointCloudMapsManager::on_initialize()
101117 [this ](sensor_msgs::msg::PointCloud2::UniquePtr msg) {
102118
103119 RCLCPP_INFO (get_node ()->get_logger (),
104- " PointCloudMapsManager : topic_callback: reading map " );
120+ " PointCloud : topic_callback : Reading Map " );
105121 static_map_.from_point_cloud (*msg);
106122
107123 static_map_.to_point_cloud (static_map_msg_);
@@ -118,12 +134,14 @@ PointCloudMapsManager::on_initialize()
118134 std::shared_ptr<std_srvs::srv::Trigger::Response> response)
119135 {
120136 (void )request;
137+
121138 if (!static_map_.save_to_file (map_path_)) {
122139 response->success = false ;
123- response->message = " Failed to save map to: " + map_path_;
140+ response->message = " PointCloud : Failed to save map to: " + map_path_;
124141 } else {
142+ static_map_.show (" Data to be saved" );
125143 response->success = true ;
126- response->message = " Map successfully saved to: " + map_path_;
144+ response->message = " PointCloud : Map successfully saved to: " + map_path_;
127145 }
128146 });
129147
@@ -159,7 +177,6 @@ PointCloudMapsManager::set_dynamic_map(const PointCloudData & new_map)
159177void
160178PointCloudMapsManager::update (NavState & nav_state)
161179{
162-
163180 dynamic_map_.deep_copy (static_map_);
164181
165182 if (nav_state.has (" points" )) {
0 commit comments