Skip to content

Commit

Permalink
use current trigger time from AsyncFunctionHandler to calculate the r…
Browse files Browse the repository at this point in the history
…ight periodicity
  • Loading branch information
saikishor committed Nov 17, 2024
1 parent e873706 commit 1a57fdf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct ControllerUpdateStatus
bool ok = true;
return_type result = return_type::OK;
std::optional<std::chrono::nanoseconds> execution_time = std::nullopt;
std::optional<rclcpp::Duration> period = std::nullopt;
};

/**
Expand Down
6 changes: 6 additions & 0 deletions controller_interface/src/controller_interface_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ ControllerUpdateStatus ControllerInterfaceBase::trigger_update(
trigger_stats_.total_triggers++;
if (is_async())
{
const rclcpp::Time & last_trigger_time = async_handler_->get_current_callback_time();
const auto result = async_handler_->trigger_async_callback(time, period);
if (!result.first)
{
Expand All @@ -182,6 +183,10 @@ ControllerUpdateStatus ControllerInterfaceBase::trigger_update(
{
status.execution_time = execution_time;
}
if (last_trigger_time.get_clock_type() != RCL_CLOCK_UNINITIALIZED)
{
status.period = time - last_trigger_time;
}
}
else
{
Expand All @@ -190,6 +195,7 @@ ControllerUpdateStatus ControllerInterfaceBase::trigger_update(
status.result = update(time, period);
status.execution_time = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::steady_clock::now() - start_time);
status.period = period;
}
return status;
}
Expand Down

0 comments on commit 1a57fdf

Please sign in to comment.