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

Catch pluginlib exceptions #229

Merged
Merged
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
25 changes: 21 additions & 4 deletions gazebo_ros2_control/src/gazebo_ros2_control_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,24 @@ void GazeboRosControlPlugin::Load(gazebo::physics::ModelPtr parent, sdf::Element

for (unsigned int i = 0; i < control_hardware_info.size(); i++) {
std::string robot_hw_sim_type_str_ = control_hardware_info[i].hardware_plugin_name;
auto gazeboSystem = std::unique_ptr<gazebo_ros2_control::GazeboSystemInterface>(
impl_->robot_hw_sim_loader_->createUnmanagedInstance(robot_hw_sim_type_str_));

rclcpp::Node::SharedPtr node_ros2 = std::dynamic_pointer_cast<rclcpp::Node>(impl_->model_nh_);
RCLCPP_DEBUG(
impl_->model_nh_->get_logger(), "Load hardware interface %s ...",
robot_hw_sim_type_str_.c_str());
std::unique_ptr<gazebo_ros2_control::GazeboSystemInterface> gazeboSystem;
try {
gazeboSystem = std::unique_ptr<gazebo_ros2_control::GazeboSystemInterface>(
impl_->robot_hw_sim_loader_->createUnmanagedInstance(robot_hw_sim_type_str_));
} catch (pluginlib::PluginlibException & ex) {
RCLCPP_ERROR(
impl_->model_nh_->get_logger(), "The plugin failed to load for some reason. Error: %s\n",
ex.what());
continue;
}
rclcpp::Node::SharedPtr node_ros2 = std::dynamic_pointer_cast<rclcpp::Node>(
impl_->model_nh_);
RCLCPP_DEBUG(
impl_->model_nh_->get_logger(), "Loaded hardware interface %s!",
robot_hw_sim_type_str_.c_str());
if (!gazeboSystem->initSim(
node_ros2,
impl_->parent_model_,
Expand All @@ -302,6 +316,9 @@ void GazeboRosControlPlugin::Load(gazebo::physics::ModelPtr parent, sdf::Element
impl_->model_nh_->get_logger(), "Could not initialize robot simulation interface");
return;
}
RCLCPP_DEBUG(
impl_->model_nh_->get_logger(), "Initialized robot simulation interface %s!",
robot_hw_sim_type_str_.c_str());

resource_manager_->import_component(std::move(gazeboSystem), control_hardware_info[i]);

Expand Down