Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
wait_at_waypoint.cpp
1 // Copyright (c) 2020 Fetullah Atas
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 "nav2_waypoint_follower/plugins/wait_at_waypoint.hpp"
16 
17 #include <string>
18 #include <exception>
19 
20 #include "pluginlib/class_list_macros.hpp"
21 
22 #include "nav2_util/node_utils.hpp"
23 
24 namespace nav2_waypoint_follower
25 {
27 : waypoint_pause_duration_(0),
28  is_enabled_(true)
29 {
30 }
31 
33 {
34 }
35 
37  const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent,
38  const std::string & plugin_name)
39 {
40  auto node = parent.lock();
41  if (!node) {
42  throw std::runtime_error{"Failed to lock node in wait at waypoint plugin!"};
43  }
44  logger_ = node->get_logger();
45  clock_ = node->get_clock();
46  nav2_util::declare_parameter_if_not_declared(
47  node,
48  plugin_name + ".waypoint_pause_duration",
49  rclcpp::ParameterValue(0));
50  nav2_util::declare_parameter_if_not_declared(
51  node,
52  plugin_name + ".enabled",
53  rclcpp::ParameterValue(true));
54  node->get_parameter(
55  plugin_name + ".waypoint_pause_duration",
56  waypoint_pause_duration_);
57  node->get_parameter(
58  plugin_name + ".enabled",
59  is_enabled_);
60  if (waypoint_pause_duration_ == 0) {
61  is_enabled_ = false;
62  RCLCPP_INFO(
63  logger_,
64  "Waypoint pause duration is set to zero, disabling task executor plugin.");
65  } else if (!is_enabled_) {
66  RCLCPP_INFO(
67  logger_, "Waypoint task executor plugin is disabled.");
68  }
69 }
70 
72  const geometry_msgs::msg::PoseStamped & /*curr_pose*/, const int & curr_waypoint_index)
73 {
74  if (!is_enabled_) {
75  return true;
76  }
77  RCLCPP_INFO(
78  logger_, "Arrived at %i'th waypoint, sleeping for %i milliseconds",
79  curr_waypoint_index,
80  waypoint_pause_duration_);
81  clock_->sleep_for(std::chrono::milliseconds(waypoint_pause_duration_));
82  return true;
83 }
84 } // namespace nav2_waypoint_follower
85 PLUGINLIB_EXPORT_CLASS(
Base class for creating a plugin in order to perform a specific task at waypoint arrivals.
Simple plugin based on WaypointTaskExecutor, lets robot to sleep for a specified amount of time at wa...
WaitAtWaypoint()
Construct a new Wait At Waypoint Arrival object.
void initialize(const rclcpp_lifecycle::LifecycleNode::WeakPtr &parent, const std::string &plugin_name)
declares and loads parameters used (waypoint_pause_duration_)
~WaitAtWaypoint()
Destroy the Wait At Waypoint Arrival object.
bool processAtWaypoint(const geometry_msgs::msg::PoseStamped &curr_pose, const int &curr_waypoint_index)
Override this to define the body of your task that you would like to execute once the robot arrived t...