Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
wait.cpp
1 // Copyright (c) 2019 Samsung Research America
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <chrono>
16 #include <memory>
17 
18 #include "nav2_behaviors/plugins/wait.hpp"
19 
20 namespace nav2_behaviors
21 {
22 
24 : TimedBehavior<WaitAction>(),
25  feedback_(std::make_shared<WaitAction::Feedback>())
26 {
27 }
28 
29 Wait::~Wait() = default;
30 
31 ResultStatus Wait::onRun(const std::shared_ptr<const WaitAction::Goal> command)
32 {
33  wait_end_ = node_.lock()->now() + rclcpp::Duration(command->time);
34  return ResultStatus{Status::SUCCEEDED, 0, ""};
35 }
36 
38 {
39  auto current_point = node_.lock()->now();
40  auto time_left = wait_end_ - current_point;
41 
42  feedback_->time_left = time_left;
43  action_server_->publish_feedback(feedback_);
44 
45  if (time_left.nanoseconds() > 0) {
46  return ResultStatus{Status::RUNNING, 0, ""};
47  } else {
48  return ResultStatus{Status::SUCCEEDED, 0, ""};
49  }
50 }
51 
52 } // namespace nav2_behaviors
53 
54 #include "pluginlib/class_list_macros.hpp"
55 PLUGINLIB_EXPORT_CLASS(nav2_behaviors::Wait, nav2_core::Behavior)
An action server behavior for waiting a fixed duration.
Definition: wait.hpp:34
ResultStatus onCycleUpdate() override
Loop function to run behavior.
Definition: wait.cpp:37
ResultStatus onRun(const std::shared_ptr< const WaitActionGoal > command) override
Initialization to run behavior.
Definition: wait.cpp:31
Wait()
A constructor for nav2_behaviors::Wait.
Definition: wait.cpp:23
Abstract interface for behaviors to adhere to with pluginlib.
Definition: behavior.hpp:42