14 #include "nav2_waypoint_follower/plugins/input_at_waypoint.hpp"
19 #include "pluginlib/class_list_macros.hpp"
21 #include "nav2_util/node_utils.hpp"
23 namespace nav2_waypoint_follower
26 using std::placeholders::_1;
29 : input_received_(false),
40 const rclcpp_lifecycle::LifecycleNode::WeakPtr & parent,
41 const std::string & plugin_name)
43 auto node = parent.lock();
46 throw std::runtime_error{
"Failed to lock node in input at waypoint plugin!"};
49 logger_ = node->get_logger();
50 clock_ = node->get_clock();
53 std::string input_topic;
54 nav2_util::declare_parameter_if_not_declared(
55 node, plugin_name +
".timeout",
56 rclcpp::ParameterValue(10.0));
57 nav2_util::declare_parameter_if_not_declared(
58 node, plugin_name +
".enabled",
59 rclcpp::ParameterValue(
true));
60 nav2_util::declare_parameter_if_not_declared(
61 node, plugin_name +
".input_topic",
62 rclcpp::ParameterValue(
"input_at_waypoint/input"));
63 timeout = node->get_parameter(plugin_name +
".timeout").as_double();
64 node->get_parameter(plugin_name +
".enabled", is_enabled_);
65 node->get_parameter(plugin_name +
".input_topic", input_topic);
67 timeout_ = rclcpp::Duration(timeout, 0.0);
70 logger_,
"InputAtWaypoint: Subscribing to input topic %s.", input_topic.c_str());
71 subscription_ = node->create_subscription<std_msgs::msg::Empty>(
77 std::lock_guard<std::mutex> lock(mutex_);
78 input_received_ =
true;
82 const geometry_msgs::msg::PoseStamped & ,
83 const int & curr_waypoint_index)
89 input_received_ =
false;
91 rclcpp::Time start = clock_->now();
93 bool input_received =
false;
94 while (clock_->now() - start < timeout_) {
96 std::lock_guard<std::mutex> lock(mutex_);
97 input_received = input_received_;
100 if (input_received) {
108 logger_,
"Unable to get external input at wp %i. Moving on.", curr_waypoint_index);
114 PLUGINLIB_EXPORT_CLASS(
Base class for creating a plugin in order to perform a specific task at waypoint arrivals.