Skip to content

Commit

Permalink
Add states for a better state transition
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Jun 13, 2024
1 parent 7854c7c commit 1ddcda5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
if (info_.is_async)
{
bool trigger_status = true;
if (next_trigger_ == TriggerType::WRITE)
{
RCLCPP_WARN(
rclcpp::get_logger("SystemInterface"),
"Trigger read called while write async handler call is still pending for hardware "
"interface : '%s'. Skipping read cycle and will wait for a write cycle!",
info_.name.c_str());
return return_type::OK;
}
if (write_async_handler_->is_trigger_cycle_in_progress())
{
RCLCPP_WARN(
Expand All @@ -210,6 +219,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
info_.name.c_str());
return return_type::OK;
}
next_trigger_ = TriggerType::WRITE;
}
else
{
Expand Down Expand Up @@ -246,6 +256,15 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
if (info_.is_async)
{
bool trigger_status = true;
if (next_trigger_ == TriggerType::READ)
{
RCLCPP_WARN(
rclcpp::get_logger("ActuatorInterface"),
"Trigger write called while read async handler call is still pending for hardware "
"interface : '%s'. Skipping write cycle and will wait for a read cycle!",
info_.name.c_str());
return return_type::OK;
}
if (read_async_handler_->is_trigger_cycle_in_progress())
{
RCLCPP_WARN(
Expand All @@ -265,6 +284,7 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
info_.name.c_str());
return return_type::OK;
}
next_trigger_ = TriggerType::READ;
}
else
{
Expand Down Expand Up @@ -313,6 +333,13 @@ class ActuatorInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNod
rclcpp_lifecycle::State lifecycle_state_;
std::unique_ptr<realtime_tools::AsyncFunctionHandler<return_type>> read_async_handler_;
std::unique_ptr<realtime_tools::AsyncFunctionHandler<return_type>> write_async_handler_;

private:
enum class TriggerType
{
READ,
WRITE
} next_trigger_ = TriggerType::READ;
};

} // namespace hardware_interface
Expand Down
27 changes: 27 additions & 0 deletions hardware_interface/include/hardware_interface/system_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
if (info_.is_async)
{
bool trigger_status = true;
if (next_trigger_ == TriggerType::WRITE)
{
RCLCPP_WARN(
rclcpp::get_logger("SystemInterface"),
"Trigger read called while write async handler call is still pending for hardware "
"interface : '%s'. Skipping read cycle and will wait for a write cycle!",
info_.name.c_str());
return return_type::OK;
}
if (write_async_handler_->is_trigger_cycle_in_progress())
{
RCLCPP_WARN(
Expand All @@ -200,6 +209,7 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
info_.name.c_str());
return return_type::OK;
}
next_trigger_ = TriggerType::WRITE;
}
else
{
Expand Down Expand Up @@ -236,6 +246,15 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
if (info_.is_async)
{
bool trigger_status = true;
if (next_trigger_ == TriggerType::READ)
{
RCLCPP_WARN(
rclcpp::get_logger("SystemInterface"),
"Trigger write called while read async handler call is still pending for hardware "
"interface : '%s'. Skipping write cycle and will wait for a read cycle!",
info_.name.c_str());
return return_type::OK;
}
if (read_async_handler_->is_trigger_cycle_in_progress())
{
RCLCPP_WARN(
Expand All @@ -255,6 +274,7 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
info_.name.c_str());
return return_type::OK;
}
next_trigger_ = TriggerType::READ;
}
else
{
Expand Down Expand Up @@ -303,6 +323,13 @@ class SystemInterface : public rclcpp_lifecycle::node_interfaces::LifecycleNodeI
rclcpp_lifecycle::State lifecycle_state_;
std::unique_ptr<realtime_tools::AsyncFunctionHandler<return_type>> read_async_handler_;
std::unique_ptr<realtime_tools::AsyncFunctionHandler<return_type>> write_async_handler_;

private:
enum class TriggerType
{
READ,
WRITE
} next_trigger_ = TriggerType::READ;
};

} // namespace hardware_interface
Expand Down

0 comments on commit 1ddcda5

Please sign in to comment.