From 0a4e65c468951ac0ca124d3c173099f72d5779d7 Mon Sep 17 00:00:00 2001 From: Florent Lamiraux Date: Wed, 27 Nov 2024 08:48:55 +0000 Subject: [PATCH 1/3] Replace deprecated symbols. --- src/urdf-parser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/urdf-parser.cpp b/src/urdf-parser.cpp index 862f462..7330770 100644 --- a/src/urdf-parser.cpp +++ b/src/urdf-parser.cpp @@ -137,7 +137,7 @@ std::string getFilename(const QString& input) { template void toDoubles(const QString& s, ReturnType& vect) { - QStringList nums = s.split(' ', QString::SkipEmptyParts); + QStringList nums = s.split(' ', Qt::SkipEmptyParts); if (ReturnType::num_components != nums.size()) throw std::logic_error("Could not parse " + s.toStdString()); bool ok; @@ -150,7 +150,7 @@ void toDoubles(const QString& s, ReturnType& vect) { template void toFloats(const QString& s, ReturnType& vect) { - QStringList nums = s.split(' ', QString::SkipEmptyParts); + QStringList nums = s.split(' ', Qt::SkipEmptyParts); if (ReturnType::num_components != nums.size()) throw std::logic_error("Could not parse " + s.toStdString()); bool ok; From 09975d8d23e54f1c5e44682bac7bc3d851e8b142 Mon Sep 17 00:00:00 2001 From: Florent Lamiraux Date: Wed, 27 Nov 2024 08:49:37 +0000 Subject: [PATCH 2/3] [urdf] Parse AMENT_PREFIX_PATH when ROS_PACKAGE_PATH is not defined, and add "share/" to each entry to make urdf parsing compatible with ros2. --- include/gepetto/viewer/urdf-parser.h | 4 +++- src/urdf-parser.cpp | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/gepetto/viewer/urdf-parser.h b/include/gepetto/viewer/urdf-parser.h index 79808af..87d419d 100644 --- a/include/gepetto/viewer/urdf-parser.h +++ b/include/gepetto/viewer/urdf-parser.h @@ -18,7 +18,9 @@ namespace urdfParser { /// If input starts with "package://", read ROS_PACKAGE_PATH environment /// variable and return a suitable file, if possible. -/// Returns input on failure (no "package://" or no file found in the packages). +/// If ROS_PACKAGE_PATH is not defined or empty, read AMENT_PREFIX_PATH +/// and add "/share" to each path. +/// Throws on failure (no "package://" or no file found in the packages). std::string getFilename(const std::string& input); /// Create a node from an urdf file diff --git a/src/urdf-parser.cpp b/src/urdf-parser.cpp index 7330770..0336465 100644 --- a/src/urdf-parser.cpp +++ b/src/urdf-parser.cpp @@ -116,12 +116,32 @@ void setShowVisuals(GroupNode* gn, bool visual) { QStringList rosPackagePath() { const QString rosPathVar(qgetenv("ROS_PACKAGE_PATH")); - return rosPathVar.split(':'); + if (rosPathVar.toStdString() != "") + return rosPathVar.split(':'); + const QString amentPrefixPath(qgetenv("AMENT_PREFIX_PATH")); + if (amentPrefixPath.toStdString() != ""){ + QStringList paths(amentPrefixPath.split(':')); + QStringList res; + for (const auto &path : paths) { + res.append(path + QString("/share")); + } + return res; + } + throw std::invalid_argument( + "neither ROS_PACKAGE_PATH nor AMENT_PREFIX_PATH environment variables is " + "defined."); } std::string getFilename(const QString& input) { if (input.startsWith("package://")) { - QStringList rosPaths = rosPackagePath(); + QStringList rosPaths; + try{ + rosPaths = rosPackagePath(); + } catch (const std::invalid_argument& exc){ + throw std::invalid_argument(std::string("Input path: \"") + + input.toStdString() + std::string("\" starts with \"package://\", but ") + + exc.what()); + } for (int i = 0; i < rosPaths.size(); ++i) { QFileInfo fileInfo(rosPaths[i] + '/' + input.right(input.size() - 10)); if (fileInfo.exists() && fileInfo.isFile()) From d0a8ac7ae9bd2e1c3da3f581016e079744bf0659 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 27 Nov 2024 08:53:58 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/urdf-parser.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/urdf-parser.cpp b/src/urdf-parser.cpp index 0336465..ccdffae 100644 --- a/src/urdf-parser.cpp +++ b/src/urdf-parser.cpp @@ -116,31 +116,30 @@ void setShowVisuals(GroupNode* gn, bool visual) { QStringList rosPackagePath() { const QString rosPathVar(qgetenv("ROS_PACKAGE_PATH")); - if (rosPathVar.toStdString() != "") - return rosPathVar.split(':'); + if (rosPathVar.toStdString() != "") return rosPathVar.split(':'); const QString amentPrefixPath(qgetenv("AMENT_PREFIX_PATH")); - if (amentPrefixPath.toStdString() != ""){ + if (amentPrefixPath.toStdString() != "") { QStringList paths(amentPrefixPath.split(':')); QStringList res; - for (const auto &path : paths) { + for (const auto& path : paths) { res.append(path + QString("/share")); } return res; } - throw std::invalid_argument( - "neither ROS_PACKAGE_PATH nor AMENT_PREFIX_PATH environment variables is " - "defined."); + throw std::invalid_argument( + "neither ROS_PACKAGE_PATH nor AMENT_PREFIX_PATH environment variables is " + "defined."); } std::string getFilename(const QString& input) { if (input.startsWith("package://")) { QStringList rosPaths; - try{ + try { rosPaths = rosPackagePath(); - } catch (const std::invalid_argument& exc){ - throw std::invalid_argument(std::string("Input path: \"") + - input.toStdString() + std::string("\" starts with \"package://\", but ") - + exc.what()); + } catch (const std::invalid_argument& exc) { + throw std::invalid_argument( + std::string("Input path: \"") + input.toStdString() + + std::string("\" starts with \"package://\", but ") + exc.what()); } for (int i = 0; i < rosPaths.size(); ++i) { QFileInfo fileInfo(rosPaths[i] + '/' + input.right(input.size() - 10));