Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URDF Loader Exceptions and Fix Infinite While-Loop when URDF file isn't in a ROS Package #2032

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,16 @@ void StartScreenWidget::onPackagePathChanged(const QString& /*path*/)

void StartScreenWidget::onUrdfPathChanged(const QString& path)
{
setup_step_.loadURDFFile(path.toStdString(), urdf_file_->getArgs().toStdString());
urdf_file_->setArgsEnabled(setup_step_.isXacroFile());
try
{
setup_step_.loadURDFFile(path.toStdString(), urdf_file_->getArgs().toStdString());
urdf_file_->setArgsEnabled(setup_step_.isXacroFile());
}
catch (const std::runtime_error& e)
{
RCLCPP_ERROR(setup_step_.getLogger(), "Error Loading URDF Path. %s", e.what());
QMessageBox::warning(this, "Error Loading URDF Path", QString(e.what()));
}
}

bool StartScreenWidget::loadPackageSettings(bool show_warnings)
Expand Down Expand Up @@ -343,8 +351,8 @@ bool StartScreenWidget::loadExistingFiles()
}
catch (const std::runtime_error& e)
{
RCLCPP_ERROR(setup_step_.getLogger(), "Error Loading SRDF. %s", e.what());
QMessageBox::warning(this, "Error Loading SRDF", QString(e.what()));
RCLCPP_ERROR(setup_step_.getLogger(), "%s", e.what());
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#pragma once

#include <ament_index_cpp/get_package_prefix.hpp>
#include <ament_index_cpp/get_package_share_directory.hpp>
#include <filesystem>
#include <string>
Expand All @@ -49,7 +50,14 @@ namespace moveit_setup
*/
inline std::filesystem::path getSharePath(const std::string& package_name)
{
return std::filesystem::path(ament_index_cpp::get_package_share_directory(package_name));
try
{
return std::filesystem::path(ament_index_cpp::get_package_share_directory(package_name));
}
catch (const std::runtime_error& e)
{
return std::filesystem::path();
}
}

/**
Expand Down
24 changes: 13 additions & 11 deletions moveit_setup_assistant/moveit_setup_framework/src/urdf_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,15 @@ void URDFConfig::setPackageName()
urdf_pkg_name_ = "";
urdf_pkg_relative_path_ = urdf_path_; // just the absolute path
}
else
// Check that ROS can find the package
const std::filesystem::path robot_desc_pkg_path = getSharePath(urdf_pkg_name_);
chancecardona marked this conversation as resolved.
Show resolved Hide resolved

if (robot_desc_pkg_path.empty())
{
// Check that ROS can find the package
const std::filesystem::path robot_desc_pkg_path = getSharePath(urdf_pkg_name_);

if (robot_desc_pkg_path.empty())
{
RCLCPP_WARN(*logger_,
"Package Not Found In ROS Workspace. ROS was unable to find the package name '%s'"
" within the ROS workspace. This may cause issues later.",
urdf_pkg_name_.c_str());
}
RCLCPP_WARN(*logger_,
"Package Not Found In ROS Workspace. ROS was unable to find the package name '%s'"
" within the ROS workspace. This may cause issues later.",
chancecardona marked this conversation as resolved.
Show resolved Hide resolved
urdf_pkg_name_.c_str());
}
}

Expand All @@ -134,6 +131,11 @@ void URDFConfig::load()
throw std::runtime_error("URDF/COLLADA file not found: " + urdf_path_.string());
}

if (urdf_pkg_name_.empty())
{
throw std::runtime_error("URDF/COLLADA package not found for file path: " + urdf_path_.string());
}

if (urdf_string_.empty() && rdf_loader::RDFLoader::isXacroFile(urdf_path_))
{
throw std::runtime_error("Running xacro failed.\nPlease check console for errors.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ bool extractPackageNameFromPath(const std::filesystem::path& path, std::string&
}

// truncate path step by step and check if it contains a package.xml
while (!sub_path.empty())
// This runs until the path is either empty "" or at the root "/" or "C:\\"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch! great find

while (!sub_path.empty() && sub_path != sub_path.root_path())
{
if (std::filesystem::is_regular_file(sub_path / "package.xml"))
{
Expand Down