Skip to content

Commit 17b0dcf

Browse files
stephanie-engStephanie Engnbbrooksclaude
authored
Update deprecated usage of get_package_share without std::filesystem::path (#3703)
* Update deprecated usage of get_package_share * Add include guards for ament/ament_index#104 --------- Co-authored-by: Stephanie Eng <seng@ottomotors.com> Co-authored-by: Nathan Brooks <nathanbrooks@picknik.ai> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6914697 commit 17b0dcf

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

moveit_core/utils/src/robot_model_test_utils.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
/* Author: Bryce Willey */
3636

37+
#include <rclcpp/version.h>
38+
3739
#include <ament_index_cpp/get_package_share_directory.hpp>
3840
#include <boost/algorithm/string_regex.hpp>
3941
#include <filesystem>
@@ -64,10 +66,20 @@ moveit::core::RobotModelPtr loadTestingRobotModel(const std::string& package_nam
6466
const std::string& urdf_relative_path,
6567
const std::string& srdf_relative_path)
6668
{
69+
// For Rolling, L-turtle, and newer
70+
#if RCLCPP_VERSION_GTE(30, 0, 0)
71+
std::filesystem::path urdf_path;
72+
ament_index_cpp::get_package_share_directory(package_name, urdf_path);
73+
urdf_path /= urdf_relative_path;
74+
std::filesystem::path srdf_path;
75+
ament_index_cpp::get_package_share_directory(package_name, srdf_path);
76+
srdf_path /= srdf_relative_path;
77+
#else
6778
const auto urdf_path =
6879
std::filesystem::path(ament_index_cpp::get_package_share_directory(package_name)) / urdf_relative_path;
6980
const auto srdf_path =
7081
std::filesystem::path(ament_index_cpp::get_package_share_directory(package_name)) / srdf_relative_path;
82+
#endif
7183

7284
urdf::ModelInterfaceSharedPtr urdf_model = urdf::parseURDFFile(urdf_path.string());
7385
if (urdf_model == nullptr)
@@ -95,7 +107,13 @@ moveit::core::RobotModelPtr loadTestingRobotModel(const std::string& robot_name)
95107
urdf::ModelInterfaceSharedPtr loadModelInterface(const std::string& robot_name)
96108
{
97109
const std::string package_name = "moveit_resources_" + robot_name + "_description";
110+
// For Rolling, L-turtle, and newer
111+
#if RCLCPP_VERSION_GTE(30, 0, 0)
112+
std::filesystem::path res_path;
113+
ament_index_cpp::get_package_share_directory(package_name, res_path);
114+
#else
98115
std::filesystem::path res_path(ament_index_cpp::get_package_share_directory(package_name));
116+
#endif
99117
std::string urdf_path;
100118
if (robot_name == "pr2")
101119
{
@@ -123,13 +141,25 @@ srdf::ModelSharedPtr loadSRDFModel(const std::string& robot_name)
123141
if (robot_name == "pr2")
124142
{
125143
const std::string package_name = "moveit_resources_" + robot_name + "_description";
144+
// For Rolling, L-turtle, and newer
145+
#if RCLCPP_VERSION_GTE(30, 0, 0)
146+
std::filesystem::path res_path;
147+
ament_index_cpp::get_package_share_directory(package_name, res_path);
148+
#else
126149
std::filesystem::path res_path(ament_index_cpp::get_package_share_directory(package_name));
150+
#endif
127151
srdf_path = (res_path / "srdf/robot.xml").string();
128152
}
129153
else
130154
{
131155
const std::string package_name = "moveit_resources_" + robot_name + "_moveit_config";
156+
// For Rolling, L-turtle, and newer
157+
#if RCLCPP_VERSION_GTE(30, 0, 0)
158+
std::filesystem::path res_path;
159+
ament_index_cpp::get_package_share_directory(package_name, res_path);
160+
#else
132161
std::filesystem::path res_path(ament_index_cpp::get_package_share_directory(package_name));
162+
#endif
133163
srdf_path = (res_path / "config" / (robot_name + ".srdf")).string();
134164
}
135165
srdf_model->initFile(*urdf_model, srdf_path);

moveit_ros/planning/rdf_loader/src/rdf_loader.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
/* Author: Ioan Sucan, Mathias Lüdtke, Dave Coleman */
3636

37+
#include <rclcpp/version.h>
38+
3739
// MoveIt
3840
#include <moveit/rdf_loader/rdf_loader.hpp>
3941
#include <std_msgs/msg/string.hpp>
@@ -217,18 +219,22 @@ bool RDFLoader::loadXmlFileToString(std::string& buffer, const std::string& path
217219
bool RDFLoader::loadPkgFileToString(std::string& buffer, const std::string& package_name,
218220
const std::string& relative_path, const std::vector<std::string>& xacro_args)
219221
{
220-
std::string package_path;
222+
std::filesystem::path path;
221223
try
222224
{
223-
package_path = ament_index_cpp::get_package_share_directory(package_name);
225+
// For Rolling, L-turtle, and newer
226+
#if RCLCPP_VERSION_GTE(30, 0, 0)
227+
ament_index_cpp::get_package_share_directory(package_name, path);
228+
#else
229+
path = ament_index_cpp::get_package_share_directory(package_name);
230+
#endif
224231
}
225232
catch (const ament_index_cpp::PackageNotFoundError& e)
226233
{
227234
RCLCPP_ERROR(getLogger(), "ament_index_cpp: %s", e.what());
228235
return false;
229236
}
230237

231-
std::filesystem::path path(package_path);
232238
path = path / relative_path;
233239

234240
return loadXmlFileToString(buffer, path.string(), xacro_args);

moveit_setup_assistant/moveit_setup_framework/include/moveit_setup_framework/utilities.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#pragma once
3838

39+
#include <rclcpp/version.h>
40+
3941
#include <ament_index_cpp/get_package_prefix.hpp>
4042
#include <ament_index_cpp/get_package_share_directory.hpp>
4143
#include <filesystem>
@@ -52,7 +54,14 @@ inline std::filesystem::path getSharePath(const std::string& package_name)
5254
{
5355
try
5456
{
57+
// For Rolling, L-turtle, and newer
58+
#if RCLCPP_VERSION_GTE(30, 0, 0)
59+
std::filesystem::path path;
60+
ament_index_cpp::get_package_share_directory(package_name, path);
61+
return path;
62+
#else
5563
return std::filesystem::path(ament_index_cpp::get_package_share_directory(package_name));
64+
#endif
5665
}
5766
catch (const std::runtime_error& e)
5867
{

0 commit comments

Comments
 (0)