@@ -665,6 +665,7 @@ class ResourceStorage
665665 {
666666 auto interfaces = hardware.export_state_interfaces ();
667667 const auto interface_names = add_state_interfaces (interfaces);
668+ hardware_info_map_[hardware.get_name ()].state_interfaces = interface_names;
668669
669670 RCLCPP_WARN_EXPRESSION (
670671 get_logger (), interface_names.empty (),
@@ -1304,6 +1305,22 @@ class ResourceStorage
13041305 init_systems (systems_);
13051306 }
13061307
1308+ bool is_hardware_command_interface (const std::string & interface_name) const
1309+ {
1310+ // Check if the interface is a command interface of any hardware component
1311+ for (const auto & [hw_name, hw_info] : hardware_info_map_)
1312+ {
1313+ const auto & command_interfaces = hw_info.command_interfaces ;
1314+ if (
1315+ std::find (command_interfaces.begin (), command_interfaces.end (), interface_name) !=
1316+ command_interfaces.end ())
1317+ {
1318+ return true ;
1319+ }
1320+ }
1321+ return false ;
1322+ }
1323+
13071324 void clear ()
13081325 {
13091326 actuators_.clear ();
@@ -2020,20 +2037,30 @@ bool ResourceManager::prepare_command_mode_switch(
20202037 // Check if interfaces are available
20212038 std::stringstream ss_not_available;
20222039 ss_not_available << " Not available: " << std::endl << " [" << std::endl;
2023- auto check_available = [&](const std::vector<std::string> & list_to_check)
2040+ auto check_available =
2041+ [&](const std::vector<std::string> & list_to_check, bool check_only_if_cmd_itf_available)
20242042 {
20252043 bool all_available = true ;
20262044 for (const auto & interface : list_to_check)
20272045 {
2046+ // / When the hardware goes is in error, the command interfaces are made unavailable to avoid
2047+ // / starting any interfaces, so for the stop interfaces we will have to check if the
2048+ // / interfaces belong to the hardware when they are unavailable to avoid deactivation
20282049 if (!command_interface_is_available (interface))
20292050 {
2051+ if (
2052+ !check_only_if_cmd_itf_available &&
2053+ resource_storage_->is_hardware_command_interface (interface))
2054+ {
2055+ continue ;
2056+ }
20302057 all_available = false ;
20312058 ss_not_available << " " << interface << std::endl;
20322059 }
20332060 }
20342061 return all_available;
20352062 };
2036- if (!(check_available (start_interfaces) && check_available (stop_interfaces)))
2063+ if (!(check_available (start_interfaces, true ) && check_available (stop_interfaces, false )))
20372064 {
20382065 ss_not_available << " ]" << std::endl;
20392066 RCLCPP_ERROR (
0 commit comments