diff --git a/moveit_core/utils/src/robot_model_test_utils.cpp b/moveit_core/utils/src/robot_model_test_utils.cpp index eea311fbec..b858a3d23a 100644 --- a/moveit_core/utils/src/robot_model_test_utils.cpp +++ b/moveit_core/utils/src/robot_model_test_utils.cpp @@ -34,6 +34,8 @@ /* Author: Bryce Willey */ +#include + #include #include #include @@ -64,10 +66,20 @@ moveit::core::RobotModelPtr loadTestingRobotModel(const std::string& package_nam const std::string& urdf_relative_path, const std::string& srdf_relative_path) { +// For Rolling, L-turtle, and newer +#if RCLCPP_VERSION_GTE(30, 0, 0) + std::filesystem::path urdf_path; + ament_index_cpp::get_package_share_directory(package_name, urdf_path); + urdf_path /= urdf_relative_path; + std::filesystem::path srdf_path; + ament_index_cpp::get_package_share_directory(package_name, srdf_path); + srdf_path /= srdf_relative_path; +#else const auto urdf_path = std::filesystem::path(ament_index_cpp::get_package_share_directory(package_name)) / urdf_relative_path; const auto srdf_path = std::filesystem::path(ament_index_cpp::get_package_share_directory(package_name)) / srdf_relative_path; +#endif urdf::ModelInterfaceSharedPtr urdf_model = urdf::parseURDFFile(urdf_path.string()); if (urdf_model == nullptr) @@ -95,7 +107,13 @@ moveit::core::RobotModelPtr loadTestingRobotModel(const std::string& robot_name) urdf::ModelInterfaceSharedPtr loadModelInterface(const std::string& robot_name) { const std::string package_name = "moveit_resources_" + robot_name + "_description"; +// For Rolling, L-turtle, and newer +#if RCLCPP_VERSION_GTE(30, 0, 0) + std::filesystem::path res_path; + ament_index_cpp::get_package_share_directory(package_name, res_path); +#else std::filesystem::path res_path(ament_index_cpp::get_package_share_directory(package_name)); +#endif std::string urdf_path; if (robot_name == "pr2") { @@ -123,13 +141,25 @@ srdf::ModelSharedPtr loadSRDFModel(const std::string& robot_name) if (robot_name == "pr2") { const std::string package_name = "moveit_resources_" + robot_name + "_description"; +// For Rolling, L-turtle, and newer +#if RCLCPP_VERSION_GTE(30, 0, 0) + std::filesystem::path res_path; + ament_index_cpp::get_package_share_directory(package_name, res_path); +#else std::filesystem::path res_path(ament_index_cpp::get_package_share_directory(package_name)); +#endif srdf_path = (res_path / "srdf/robot.xml").string(); } else { const std::string package_name = "moveit_resources_" + robot_name + "_moveit_config"; +// For Rolling, L-turtle, and newer +#if RCLCPP_VERSION_GTE(30, 0, 0) + std::filesystem::path res_path; + ament_index_cpp::get_package_share_directory(package_name, res_path); +#else std::filesystem::path res_path(ament_index_cpp::get_package_share_directory(package_name)); +#endif srdf_path = (res_path / "config" / (robot_name + ".srdf")).string(); } srdf_model->initFile(*urdf_model, srdf_path); diff --git a/moveit_ros/planning/rdf_loader/src/rdf_loader.cpp b/moveit_ros/planning/rdf_loader/src/rdf_loader.cpp index de43e05744..db0957e96f 100644 --- a/moveit_ros/planning/rdf_loader/src/rdf_loader.cpp +++ b/moveit_ros/planning/rdf_loader/src/rdf_loader.cpp @@ -34,6 +34,8 @@ /* Author: Ioan Sucan, Mathias Lüdtke, Dave Coleman */ +#include + // MoveIt #include #include @@ -217,10 +219,15 @@ bool RDFLoader::loadXmlFileToString(std::string& buffer, const std::string& path bool RDFLoader::loadPkgFileToString(std::string& buffer, const std::string& package_name, const std::string& relative_path, const std::vector& xacro_args) { - std::string package_path; + std::filesystem::path path; try { - package_path = ament_index_cpp::get_package_share_directory(package_name); +// For Rolling, L-turtle, and newer +#if RCLCPP_VERSION_GTE(30, 0, 0) + ament_index_cpp::get_package_share_directory(package_name, path); +#else + path = ament_index_cpp::get_package_share_directory(package_name); +#endif } catch (const ament_index_cpp::PackageNotFoundError& e) { @@ -228,7 +235,6 @@ bool RDFLoader::loadPkgFileToString(std::string& buffer, const std::string& pack return false; } - std::filesystem::path path(package_path); path = path / relative_path; return loadXmlFileToString(buffer, path.string(), xacro_args); diff --git a/moveit_setup_assistant/moveit_setup_framework/include/moveit_setup_framework/utilities.hpp b/moveit_setup_assistant/moveit_setup_framework/include/moveit_setup_framework/utilities.hpp index ace3237c6b..6cc6967965 100644 --- a/moveit_setup_assistant/moveit_setup_framework/include/moveit_setup_framework/utilities.hpp +++ b/moveit_setup_assistant/moveit_setup_framework/include/moveit_setup_framework/utilities.hpp @@ -36,6 +36,8 @@ #pragma once +#include + #include #include #include @@ -52,7 +54,14 @@ inline std::filesystem::path getSharePath(const std::string& package_name) { try { +// For Rolling, L-turtle, and newer +#if RCLCPP_VERSION_GTE(30, 0, 0) + std::filesystem::path path; + ament_index_cpp::get_package_share_directory(package_name, path); + return path; +#else return std::filesystem::path(ament_index_cpp::get_package_share_directory(package_name)); +#endif } catch (const std::runtime_error& e) {