Skip to content

Commit

Permalink
First attempt to deactivate hardware from read/write return value
Browse files Browse the repository at this point in the history
This is the first step to deactivate a hw component when writing to that
component stops working (e.g. because of some interpreter program stopped
running).

The idea is that a hw component can go back to "configured", where the
communication is working, but commanding the robot is not possible
  • Loading branch information
fmauch committed May 15, 2023
1 parent 5065d0c commit 23dd762
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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,
INACTIVE = 2,
};

} // namespace hardware_interface
Expand Down
25 changes: 23 additions & 2 deletions hardware_interface/src/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,12 +1072,26 @@ HardwareReadWriteStatus ResourceManager::read(
{
for (auto & component : components)
{
if (component.read(time, period) != return_type::OK)
auto ret_val = component.read(time, period);
if (ret_val == 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());
}
else if (ret_val == return_type::INACTIVE)
{
using lifecycle_msgs::msg::State;
rclcpp_lifecycle::State state(State::PRIMARY_STATE_INACTIVE, lifecycle_state_names::INACTIVE);
set_component_state(component.get_name(), state);
}
// If desired: automatic re-activation. We could add a flag for this...
//else
//{
//using lifecycle_msgs::msg::State;
//rclcpp_lifecycle::State state(State::PRIMARY_STATE_ACTIVE, lifecycle_state_names::ACTIVE);
//set_component_state(component.get_name(), state);
//}
}
};

Expand All @@ -1100,12 +1114,19 @@ HardwareReadWriteStatus ResourceManager::write(
{
for (auto & component : components)
{
if (component.write(time, period) != return_type::OK)
auto ret_val = component.write(time, period);
if (ret_val == 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());
}
else if (ret_val == return_type::INACTIVE)
{
using lifecycle_msgs::msg::State;
rclcpp_lifecycle::State state(State::PRIMARY_STATE_INACTIVE, lifecycle_state_names::INACTIVE);
set_component_state(component.get_name(), state);
}
}
};

Expand Down

0 comments on commit 23dd762

Please sign in to comment.