Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit ec9c9e4

Browse files
committed
Maps Manager read and write PCD files, also by topic works
1 parent e65c22e commit ec9c9e4

3 files changed

Lines changed: 34 additions & 16 deletions

File tree

easynav_pointcloud_common/src/easynav_pointcloud_common/PointCloudData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ PointCloudData::load_from_file(const std::string & path)
186186
void
187187
PointCloudData::show(const std::string & comment) const
188188
{
189-
std::cerr << ":: PointCloudData values :: \n";
189+
std::cerr << ":: PointCloudData Values :: \n";
190190
std::cerr << "Comment: " << comment << "\n";
191191
std::cerr << "width: " << width_ << "\n";
192192
std::cerr << "height: " << height_ << "\n";

easynav_pointcloud_maps_manager/src/easynav_pointcloud_maps_manager/PointCloudMapsManager.cpp

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
159177
void
160178
PointCloudMapsManager::update(NavState & nav_state)
161179
{
162-
163180
dynamic_map_.deep_copy(static_map_);
164181

165182
if (nav_state.has("points")) {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
maps_manager_node:
22
ros__parameters:
3-
use_sim_time: true
3+
use_sim_time: false
44
map_types: [PointCloudData]
55
PointCloudData:
66
plugin: easynav_pointcloud_maps_manager/PointCloudMapsManager
77
map_topic_in: /map_builder/cloud_filtered
8-
map_path_file: /home/juanscelyg/ws/easynav_ws/src/easynav_outdoor_testcase/maps/map.pcd
8+
package_name: easynav_outdoor_testcase
9+
map_path_file: maps/pointcloud_map.pcd
910

0 commit comments

Comments
 (0)