Skip to content

Commit e84100a

Browse files
authored
[CM] Add option to avoid shutting down on hardware initial state failure (#2230) (#2251)
1 parent 46daf3f commit e84100a

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

controller_manager/src/controller_manager.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,19 @@ void ControllerManager::init_resource_manager(const std::string & robot_descript
657657
resource_manager_->set_component_state(component, state) ==
658658
hardware_interface::return_type::ERROR)
659659
{
660-
throw std::runtime_error(
661-
fmt::format(
662-
FMT_COMPILE("Failed to set the initial state of the component : {} to {}"),
663-
component.c_str(), state.label()));
660+
if (params_->hardware_components_initial_state.shutdown_on_initial_state_failure)
661+
{
662+
throw std::runtime_error(
663+
fmt::format(
664+
FMT_COMPILE("Failed to set the initial state of the component : {} to {}"),
665+
component.c_str(), state.label()));
666+
}
667+
else
668+
{
669+
RCLCPP_ERROR(
670+
get_logger(), "Failed to set the initial state of the component : '%s' to '%s'",
671+
component.c_str(), state.label().c_str());
672+
}
664673
}
665674
components_to_activate.erase(component);
666675
}
@@ -693,10 +702,19 @@ void ControllerManager::init_resource_manager(const std::string & robot_descript
693702
resource_manager_->set_component_state(component, active_state) ==
694703
hardware_interface::return_type::ERROR)
695704
{
696-
throw std::runtime_error(
697-
fmt::format(
698-
FMT_COMPILE("Failed to set the initial state of the component : {} to {}"),
699-
component.c_str(), active_state.label()));
705+
if (params_->hardware_components_initial_state.shutdown_on_initial_state_failure)
706+
{
707+
throw std::runtime_error(
708+
fmt::format(
709+
FMT_COMPILE("Failed to set the initial state of the component : {} to {}"),
710+
component.c_str(), active_state.label()));
711+
}
712+
else
713+
{
714+
RCLCPP_ERROR(
715+
get_logger(), "Failed to set the initial state of the component : '%s' to '%s'",
716+
component.c_str(), active_state.label().c_str());
717+
}
700718
}
701719
}
702720
robot_description_notification_timer_->cancel();

controller_manager/src/controller_manager_parameters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ controller_manager:
2525
}
2626
}
2727

28+
shutdown_on_initial_state_failure: {
29+
type: bool,
30+
default_value: false,
31+
description: "Specifies whether the controller manager should shut down if setting the desired initial state fails during startup.",
32+
}
33+
2834
defaults:
2935
switch_controller:
3036
strictness: {

doc/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ controller_manager
9494
* A latched topic ``~/activity`` has been added to the controller_manager to publish the activity of the controller_manager, where the change in states of the controllers and the hardware components are published. (`#2006 <https://github.com/ros-controls/ros2_control/pull/2006>`_).
9595
* The controller manager will use a monotonic clock for triggering read-update-write cycles, but when the ``use_sim_time`` parameter is set to true, it will use the ROS Clock for triggering. When monotonic clock is being used, all the hardware components will receive the monotonic time in their read and write method, instead the controllers will always receive the ROS time in their update method irrespective of the clock being used. (`#2046 <https://github.com/ros-controls/ros2_control/pull/2046>`_).
9696
* The default strictness of the ``swtich_controllers`` can now we be chosen using ROS 2 parameters. The default behaviour is still left to ``BEST_EFFORT`` (`#2168 <https://github.com/ros-controls/ros2_control/pull/2168>`_).
97+
* Parameter ``shutdown_on_initial_state_failure`` was added to avoid shutting down on hardware initial state failure (`#2330 <https://github.com/ros-controls/ros2_control/pull/2330>`_).
9798

9899
hardware_interface
99100
******************

0 commit comments

Comments
 (0)