From daa714862ec23e5e1e651b3df3d2668cd9e48ef1 Mon Sep 17 00:00:00 2001 From: Woosik Lee <31552565+WoosikLee2510@users.noreply.github.com> Date: Thu, 9 Jul 2026 22:04:47 -0700 Subject: [PATCH] ros2: pull package path lookup out of shared core into one boundary file --- mins/cmake/ROS1.cmake | 1 + mins/cmake/ROS2.cmake | 1 + mins/src/options/OptionsSimulation.cpp | 13 ++------- mins/src/options/OptionsSystem.cpp | 12 ++------ mins/src/utils/PackagePath.cpp | 38 ++++++++++++++++++++++++++ mins/src/utils/PackagePath.h | 32 ++++++++++++++++++++++ 6 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 mins/src/utils/PackagePath.cpp create mode 100644 mins/src/utils/PackagePath.h diff --git a/mins/cmake/ROS1.cmake b/mins/cmake/ROS1.cmake index 8960daf..3bf2a18 100644 --- a/mins/cmake/ROS1.cmake +++ b/mins/cmake/ROS1.cmake @@ -51,6 +51,7 @@ list(APPEND LIBRARY_SOURCES src/sim/Simulator.cpp src/sim/ConstBsplineSE3.cpp src/sim/SimVisualizer.cpp + src/utils/PackagePath.cpp src/utils/Print_Logger.cpp src/utils/Jabdongsani.cpp src/state/State.cpp diff --git a/mins/cmake/ROS2.cmake b/mins/cmake/ROS2.cmake index f14574b..08297a7 100644 --- a/mins/cmake/ROS2.cmake +++ b/mins/cmake/ROS2.cmake @@ -84,6 +84,7 @@ list(APPEND LIBRARY_SOURCES src/sim/Simulator.cpp src/sim/ConstBsplineSE3.cpp src/sim/Sim2Visualizer.cpp + src/utils/PackagePath.cpp src/utils/Print_Logger.cpp src/utils/Jabdongsani.cpp src/state/State.cpp diff --git a/mins/src/options/OptionsSimulation.cpp b/mins/src/options/OptionsSimulation.cpp index 75bb898..5df7d22 100644 --- a/mins/src/options/OptionsSimulation.cpp +++ b/mins/src/options/OptionsSimulation.cpp @@ -27,13 +27,9 @@ #include "OptionsSimulation.h" #include "OptionsEstimator.h" +#include "utils/PackagePath.h" #include "utils/Print_Logger.h" #include "utils/opencv_yaml_parse.h" -#if ROS_AVAILABLE == 1 -#include -#elif ROS_AVAILABLE == 2 -#include -#endif mins::OptionsSimulation::OptionsSimulation() { est_true = std::make_shared(); } @@ -65,12 +61,7 @@ void mins::OptionsSimulation::load_print(const std::shared_ptr -#elif ROS_AVAILABLE == 2 -#include -#endif void mins::OptionsSystem::load_print(const std::shared_ptr &parser) { if (parser != nullptr) { @@ -46,11 +42,7 @@ void mins::OptionsSystem::load_print(const std::shared_ptr parser->parse_external(f, "sys", "bag_durr", bag_durr); parser->parse_external(f, "sys", "path_gt", path_gt, false); // Replace MINS_DIR if we have it -#if ROS_AVAILABLE == 1 - auto dir = ros::package::getPath("mins"); -#elif ROS_AVAILABLE == 2 - auto dir = ament_index_cpp::get_package_share_directory("mins"); -#endif + auto dir = mins::get_package_path("mins"); path_timing.substr(0, 8) == "MINS_DIR" ? path_timing.replace(0, 8, dir) : std::string(); path_state.substr(0, 8) == "MINS_DIR" ? path_state.replace(0, 8, dir) : std::string(); path_trajectory.substr(0, 8) == "MINS_DIR" ? path_trajectory.replace(0, 8, dir) : std::string(); diff --git a/mins/src/utils/PackagePath.cpp b/mins/src/utils/PackagePath.cpp new file mode 100644 index 0000000..400c563 --- /dev/null +++ b/mins/src/utils/PackagePath.cpp @@ -0,0 +1,38 @@ +/* + * MINS: Efficient and Robust Multisensor-aided Inertial Navigation System + * Copyright (C) 2023 Woosik Lee + * Copyright (C) 2023 Guoquan Huang + * Copyright (C) 2023 MINS Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// This is the only translation unit that touches the ROS package-path API, +// keeping ros::package / ament out of the shared core. +#include "utils/PackagePath.h" +#if ROS_AVAILABLE == 1 +#include +#elif ROS_AVAILABLE == 2 +#include +#endif + +std::string mins::get_package_path(const std::string &pkg) { +#if ROS_AVAILABLE == 1 + return ros::package::getPath(pkg); +#elif ROS_AVAILABLE == 2 + return ament_index_cpp::get_package_share_directory(pkg); +#else + return std::string(); +#endif +} diff --git a/mins/src/utils/PackagePath.h b/mins/src/utils/PackagePath.h new file mode 100644 index 0000000..f59c5ba --- /dev/null +++ b/mins/src/utils/PackagePath.h @@ -0,0 +1,32 @@ +/* + * MINS: Efficient and Robust Multisensor-aided Inertial Navigation System + * Copyright (C) 2023 Woosik Lee + * Copyright (C) 2023 Guoquan Huang + * Copyright (C) 2023 MINS Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef MINS_PACKAGE_PATH_H +#define MINS_PACKAGE_PATH_H + +#include + +namespace mins { +// Resolve an installed package's directory. Defined at the ROS boundary +// (PackagePath.cpp) so the shared core stays free of ros::package / ament. +std::string get_package_path(const std::string &pkg); +} // namespace mins + +#endif // MINS_PACKAGE_PATH_H