21 std::filesystem::path path(path_string);
22 if (path_string.empty())
return path;
23 if (!path.has_root_path()) {
24 const char* ros_home_ptr = std::getenv(
"ROS_HOME");
25 if (ros_home_ptr !=
nullptr && !std::string(ros_home_ptr).empty()) {
26 path = std::filesystem::path(std::string(ros_home_ptr));
28 const char* home_dir = std::getenv(
"HOME");
29 if (home_dir !=
nullptr && !std::string(home_dir).empty()) {
30 path = std::filesystem::path(std::string(home_dir) +
"/.ros");
32 path = std::filesystem::current_path();
35 path.append(path_string);
37 path = path.lexically_normal();
42 : parent_node_(&parent_node),
43 map_filepath_(std::string(
".lanelet2_map_interface/") + std::string(parent_node.get_fully_qualified_name()) +
"/map.osm"),
44 map_server_name_(map_server_name) {
45 rcl_interfaces::msg::ParameterDescriptor param_desc;
46 param_desc.description =
"Local filepath to where map from map server is written to (relative to $ROS_HOME)";
49 }
catch (
const rclcpp::exceptions::ParameterAlreadyDeclaredException& ex) {
50 RCLCPP_WARN(
parent_node_->get_logger(),
"Parameter 'map_filepath' already declared: %s", ex.what());
72 auto parameters_future =
73 parameter_client_->get_parameters({
"map_frame_id",
"map_contents",
"origin_lat",
"origin_lon"},
92 RCLCPP_INFO_STREAM(
parent_node_->get_logger(),
"Parameter '" << p.get_name() <<
"' changed, reloading map");
98 auto result = future.get();
99 for (
auto& parameter : result) {
107 RCLCPP_ERROR_STREAM(
parent_node_->get_logger(),
"Parameter 'map_frame_id_' is empty");
111 RCLCPP_ERROR_STREAM(
parent_node_->get_logger(),
"Parameter 'map_filepath_' is empty");
115 RCLCPP_ERROR_STREAM(
parent_node_->get_logger(),
"Parameter 'map_contents_' is empty");
118 if (
origin_lat_ == std::numeric_limits<double>::quiet_NaN()) {
119 RCLCPP_WARN_STREAM(
parent_node_->get_logger(),
"Parameter 'origin_lat_' is not set");
122 if (
origin_lon_ == std::numeric_limits<double>::quiet_NaN()) {
123 RCLCPP_WARN_STREAM(
parent_node_->get_logger(),
"Parameter 'origin_lon_' is not set");
146 if (param.get_name() ==
"map_frame_id") {
149 if (param.get_name() ==
"map_contents") {
152 if (param.get_name() ==
"origin_lat") {
155 if (param.get_name() ==
"origin_lon") {
168 if (!std::filesystem::exists(map_directory)) {
169 if (!std::filesystem::create_directories(map_directory)) {
170 RCLCPP_ERROR_STREAM(
parent_node_->get_logger(),
"Failed to create directory '" << map_directory <<
"'");
176 std::ofstream map_file;
188 }
catch (
const std::exception& exc) {
std::shared_ptr< lanelet::Projector > getProjectorPtr()
Returns the projector used to interpret the loaded map coordinates.
void serviceParamsCallback(std::shared_future< std::vector< rclcpp::Parameter > > future)
Handles the asynchronous response of an initial parameter fetch.
bool validateParams()
Validates that the required map parameters are available and usable.
Lanelet2MapInterface(rclcpp::Node &parent_node, std::string map_server_name)
Creates a client-side interface for retrieving Lanelet2 map parameters from a map server node.
std::string map_frame_id_
lanelet::LaneletMapPtr getNonConstMapPtr()
Returns the currently loaded mutable Lanelet2 map.
bool loadMap()
Loads and parses the map from the currently cached parameters.
rclcpp::Node * parent_node_
std::shared_ptr< rclcpp::AsyncParametersClient > parameter_client_
void updateParamsCallback(const rclcpp::Parameter &p)
Reacts to a single parameter event from the map server.
lanelet::LaneletMapPtr mapPtr_
std::shared_ptr< rclcpp::ParameterCallbackHandle > origin_lon_callback_handle_
void findMapServer()
Checks for the configured map server and, once available, requests initial parameters and installs su...
std::string map_contents_
std::shared_ptr< rclcpp::ParameterCallbackHandle > origin_lat_callback_handle_
std::shared_ptr< lanelet::Projector > utmProjectorPtr_
std::string map_filepath_
void updateMapParam(rclcpp::Parameter param)
Updates one cached map parameter from a value received from the map server.
std::shared_ptr< rclcpp::ParameterCallbackHandle > contents_callback_handle_
std::shared_ptr< rclcpp::ParameterCallbackHandle > frame_id_callback_handle_
std::shared_ptr< rclcpp::ParameterEventHandler > parameter_sub_
std::string map_server_name_
rclcpp::TimerBase::SharedPtr startup_timer_
lanelet::LaneletMapConstPtr getMapPtr()
Returns the currently loaded immutable Lanelet2 map.
std::filesystem::path resolveFilepath(const std::string &path_string)
Resolves a relative string filepath.