14 #include "nav2_waypoint_follower/plugins/input_at_waypoint.hpp"
19 #include "pluginlib/class_list_macros.hpp"
21 #include "nav2_ros_common/node_utils.hpp"
22 #include "nav2_ros_common/rate.hpp"
24 namespace nav2_waypoint_follower
27 using std::placeholders::_1;
30 : input_received_(false),
41 const nav2::LifecycleNode::WeakPtr & parent,
42 const std::string & plugin_name)
44 auto node = parent.lock();
47 throw std::runtime_error{
"Failed to lock node in input at waypoint plugin!"};
51 logger_ = node->get_logger();
52 clock_ = node->get_clock();
55 std::string input_topic;
56 is_enabled_ = node->declare_or_get_parameter(
57 plugin_name +
".enabled",
true);
58 input_topic = node->declare_or_get_parameter(
59 plugin_name +
".input_topic", std::string(
"input_at_waypoint/input"));
60 timeout = node->declare_or_get_parameter(
61 plugin_name +
".timeout", 10.0);
62 timeout_ = rclcpp::Duration(timeout, 0.0);
65 logger_,
"InputAtWaypoint: Subscribing to input topic %s.", input_topic.c_str());
66 subscription_ = node->create_subscription<std_msgs::msg::Empty>(
72 std::lock_guard<std::mutex> lock(mutex_);
73 input_received_ =
true;
77 const geometry_msgs::msg::PoseStamped & ,
78 const int & curr_waypoint_index)
84 input_received_ =
false;
86 auto node = node_.lock();
88 RCLCPP_ERROR(logger_,
"Failed to lock node in input at waypoint plugin.");
92 rclcpp::Time start = clock_->now();
94 bool input_received =
false;
95 while (clock_->now() - start < timeout_) {
97 std::lock_guard<std::mutex> lock(mutex_);
98 input_received = input_received_;
101 if (input_received) {
109 logger_,
"Unable to get external input at wp %i. Moving on.", curr_waypoint_index);
115 PLUGINLIB_EXPORT_CLASS(
A sim-time-aware rate for Nav2 loops.
Base class for creating a plugin in order to perform a specific task at waypoint arrivals.