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

issue 815 hardware interface add return value #933

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ class ControllerManager : public rclcpp::Node
CONTROLLER_MANAGER_PUBLIC
void manage_switch();

CONTROLLER_MANAGER_LOCAL
std::vector<std::string> controllers_to_skip;

/// Deactivate chosen controllers from real-time controller list.
/**
* Deactivate controllers with names \p controllers_to_deactivate from list \p rt_controller_list.
Expand Down
25 changes: 22 additions & 3 deletions controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1970,8 +1970,8 @@ void ControllerManager::set_hardware_component_state_srv_cb(
// the ternary operator is needed because label in State constructor cannot be an empty string
request->target_state.label.empty() ? "-" : request->target_state.label);
response->ok =
(resource_manager_->set_component_state(request->name, target_state) ==
hardware_interface::return_type::OK);
(resource_manager_->set_component_state(request->name, target_state) !=
hardware_interface::return_type::ERROR);
hw_components_info = resource_manager_->get_components_status();
response->state.id = hw_components_info[request->name].state.id();
response->state.label = hw_components_info[request->name].state.label();
Expand Down Expand Up @@ -2002,6 +2002,7 @@ std::vector<std::string> ControllerManager::get_controller_names()
void ControllerManager::read(const rclcpp::Time & time, const rclcpp::Duration & period)
{
auto [ok, failed_hardware_names] = resource_manager_->read(time, period);
controllers_to_skip.clear();

if (!ok)
{
Expand All @@ -2018,6 +2019,16 @@ void ControllerManager::read(const rclcpp::Time & time, const rclcpp::Duration &
deactivate_controllers(rt_controller_list, stop_request);
// TODO(destogl): do auto-start of broadcasters
}
else if (failed_hardware_names.size() > 0)
{
// Status is ok but some hardware is not ok (SKIPPED)
// Determine controllers to skip
for (const auto & hardware_name : failed_hardware_names)
{
auto controllers = resource_manager_->get_cached_controllers_to_hardware(hardware_name);
controllers_to_skip.insert(controllers_to_skip.end(), controllers.begin(), controllers.end());
}
}
Comment on lines +2022 to +2031
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is needed here. Hardware interface is not failed. The issue here is that we are calling read and write from HW interfaces constantly, and in some cases we skip it (when not inactive or active). But then the controllers cannot run at all since they don't have interfaces to connect to – so I doubt that we have to do anything with them here.

}

controller_interface::return_type ControllerManager::update(
Expand Down Expand Up @@ -2048,7 +2059,15 @@ controller_interface::return_type ControllerManager::update(
update_loop_counter_, controller_go ? "True" : "False",
loaded_controller.info.name.c_str());

if (controller_go)
bool controller_skip =
(std::find(
controllers_to_skip.begin(), controllers_to_skip.end(), loaded_controller.info.name) !=
controllers_to_skip.end());
RCLCPP_DEBUG(
get_logger(), "Skip ?: controller_skip: '%s' controller_name: '%s'",
controller_skip ? "True" : "False", loaded_controller.info.name.c_str());

if (!controller_skip && controller_go)
{
auto controller_ret = loaded_controller.c->update(
time, (controller_update_factor != 1u)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum class return_type : std::uint8_t
{
OK = 0,
ERROR = 1,
SKIPPED = 2,
};

} // namespace hardware_interface
Expand Down
8 changes: 6 additions & 2 deletions hardware_interface/src/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,9 +1261,13 @@ HardwareReadWriteStatus ResourceManager::read(
{
if (component.read(time, period) != return_type::OK)
Copy link
Member

Choose a reason for hiding this comment

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

Why not simply change this?

Suggested change
if (component.read(time, period) != return_type::OK)
if (component.read(time, period) == return_type::ERROR)

{
read_write_status.ok = false;
read_write_status.failed_hardware_names.push_back(component.get_name());
resource_storage_->remove_all_hardware_interfaces_from_available_list(component.get_name());
if (component.read(time, period) == return_type::ERROR)
{
read_write_status.ok = false;
resource_storage_->remove_all_hardware_interfaces_from_available_list(
component.get_name());
}
}
}
};
Expand Down
Loading