Skip to content

Commit 6a0f0f2

Browse files
committed
Added default path for route if not specified
1 parent 8afb57b commit 6a0f0f2

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

maps_managers/easynav_routes_maps_manager/src/easynav_routes_maps_manager/RoutesMapsManager.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ void RoutesMapsManager::on_initialize()
7474

7575
map_path_.clear();
7676
if (package_name.empty() && map_path_file.empty()) {
77-
// Accepted: we will use a default in-memory route in load_routes_from_yaml().
77+
// No path configured: default to /tmp so that save_routes still works.
78+
map_path_ = "/tmp/routes.yaml";
7879
RCLCPP_INFO(
7980
node->get_logger(),
80-
"[%s] No package or map_path_file specified, using default in-memory route",
81-
plugin_name.c_str());
81+
"[%s] No package or map_path_file specified, routes will be saved to %s",
82+
plugin_name.c_str(), map_path_.c_str());
8283
} else if (!map_path_file.empty() && map_path_file[0] == '/') {
8384
// Absolute path: ignore package_name.
8485
map_path_ = map_path_file;
@@ -161,11 +162,16 @@ void RoutesMapsManager::on_initialize()
161162
out << YAML::EndMap;
162163

163164
std::ofstream file(map_path_);
165+
if (!file.is_open()) {
166+
response->success = false;
167+
response->message = "Could not open file for writing: " + map_path_;
168+
return;
169+
}
164170
file << out.c_str();
165171
file.close();
166172

167173
response->success = true;
168-
response->message = "Routes saved";
174+
response->message = "Routes saved to " + map_path_;
169175
} catch (const std::exception & e) {
170176
response->success = false;
171177
response->message = e.what();

0 commit comments

Comments
 (0)