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

use ros clock for wait #3782

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nav2_behaviors/include/nav2_behaviors/plugins/wait.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Wait : public TimedBehavior<WaitAction>
CostmapInfoType getResourceInfo() override {return CostmapInfoType::LOCAL;}

protected:
std::chrono::time_point<std::chrono::steady_clock> wait_end_;
rclcpp::Time wait_end_;
WaitAction::Feedback::SharedPtr feedback_;
};

Expand Down
12 changes: 5 additions & 7 deletions nav2_behaviors/plugins/wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,19 @@ Wait::~Wait() = default;

ResultStatus Wait::onRun(const std::shared_ptr<const WaitAction::Goal> command)
{
wait_end_ = std::chrono::steady_clock::now() +
rclcpp::Duration(command->time).to_chrono<std::chrono::nanoseconds>();
wait_end_ = node_.lock()->now() + rclcpp::Duration(command->time);
return ResultStatus{Status::SUCCEEDED};
}

ResultStatus Wait::onCycleUpdate()
{
auto current_point = std::chrono::steady_clock::now();
auto time_left =
std::chrono::duration_cast<std::chrono::nanoseconds>(wait_end_ - current_point).count();
auto current_point = node_.lock()->now();
auto time_left = wait_end_ - current_point;

feedback_->time_left = rclcpp::Duration(rclcpp::Duration::from_nanoseconds(time_left));
feedback_->time_left = time_left;
action_server_->publish_feedback(feedback_);

if (time_left > 0) {
if (time_left.nanoseconds() > 0) {
return ResultStatus{Status::RUNNING};
} else {
return ResultStatus{Status::SUCCEEDED};
Expand Down