lanelet2_route_planning v2.0.0
Loading...
Searching...
No Matches
plan_route_action_client.hpp
Go to the documentation of this file.
1// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include <memory>
7#include <optional>
8#include <string>
9#include <utility>
10#include <vector>
11
12#include <geometry_msgs/msg/point_stamped.hpp>
13#include <geometry_msgs/msg/pose_stamped.hpp>
14#include <lanelet2_map_interface/lanelet2_map_interface.hpp>
15#include <rclcpp/rclcpp.hpp>
16#include <rclcpp_action/rclcpp_action.hpp>
17#include <route_planning_msgs/action/plan_route.hpp>
18
20
21template <typename C>
22struct is_vector : std::false_type {};
23
24template <typename T, typename A>
25struct is_vector<std::vector<T, A>> : std::true_type {};
26
27template <typename C>
28inline constexpr bool is_vector_v = is_vector<C>::value;
29
33class PlanRouteActionClient : public rclcpp::Node {
34 using PlanRoute = route_planning_msgs::action::PlanRoute;
35 using GoalHandlePlanRoute = rclcpp_action::ClientGoalHandle<PlanRoute>;
36
37 public:
42
43 private:
58 template <typename T>
59 void declareAndLoadParameter(const std::string& name,
60 T& param,
61 const std::string& description,
62 const bool add_to_auto_reconfigurable_params = true,
63 const bool is_required = false,
64 const bool read_only = false,
65 const std::optional<double>& from_value = std::nullopt,
66 const std::optional<double>& to_value = std::nullopt,
67 const std::optional<double>& step_value = std::nullopt,
68 const std::string& additional_constraints = "");
69
76 rcl_interfaces::msg::SetParametersResult parametersCallback(const std::vector<rclcpp::Parameter>& parameters);
77
81 void setup();
82
88 void goalPoseCallback(const geometry_msgs::msg::PoseStamped::SharedPtr msg);
89
97
101 void planToNextWaypoint();
102
107
114 void sendGoal(const geometry_msgs::msg::PoseStamped::SharedPtr msg,
115 const std::vector<geometry_msgs::msg::PointStamped>& intermediate_destinations = {});
116
122 void goalResponseCallback(const GoalHandlePlanRoute::SharedPtr& goal_handle);
123
130 void feedbackCallback(GoalHandlePlanRoute::SharedPtr goal_handle, const std::shared_ptr<const PlanRoute::Feedback> feedback);
131
137 void resultCallback(const GoalHandlePlanRoute::WrappedResult& result);
138
142 std::vector<std::tuple<std::string, std::function<void(const rclcpp::Parameter&)>>> auto_reconfigurable_params_;
143
147 OnSetParametersCallbackHandle::SharedPtr parameters_callback_;
148
152 rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr goal_pose_subscriber_;
153
157 rclcpp_action::Client<PlanRoute>::SharedPtr action_client_;
158
162 std::shared_future<GoalHandlePlanRoute::SharedPtr> goal_handle_future_;
163
167 rclcpp::TimerBase::SharedPtr auto_planning_timer_;
168
172 std::unique_ptr<Lanelet2MapInterface> ll2_interface_;
173
177 std::vector<std::pair<double, double>> waypoints_;
178
182 std::vector<double> waypoint_wait_times_;
183
188
193
198
203
208
212 std::string ll2_map_server_name_ = "ll2_map_server";
213
219 std::vector<std::string> waypoints_param_;
220
225
232
236 bool cancel_route_ = false;
237};
238
239} // namespace plan_route_action_client
size_t next_waypoint_idx_
Index of next waypoint to follow.
double active_waypoint_wait_time_s_
Wait time of the active waypoint [s].
std::shared_future< GoalHandlePlanRoute::SharedPtr > goal_handle_future_
Goal handle.
std::vector< double > waypoint_wait_times_
Wait time for each waypoint [s]; negative values mark intermediate destinations.
bool has_active_waypoint_
Whether the active goal belongs to the waypoint list.
void planToRandomDestination()
Plans to a random destination.
rclcpp_action::ClientGoalHandle< PlanRoute > GoalHandlePlanRoute
void goalPoseCallback(const geometry_msgs::msg::PoseStamped::SharedPtr msg)
Callback for goal pose (most likely received from RViz)
void resultCallback(const GoalHandlePlanRoute::WrappedResult &result)
Callback for result from the action server.
bool cancel_route_
Flag to cancel the route planning action (parameter)
double auto_planning_resume_time_s_
Earliest wall-clock time at which automatic planning may continue.
rcl_interfaces::msg::SetParametersResult parametersCallback(const std::vector< rclcpp::Parameter > &parameters)
Handles reconfiguration when a parameter value is changed.
bool enable_continuous_planning_
Whether to continuously plan a new route (parameter)
std::vector< std::pair< double, double > > waypoints_
WGS84 waypoints to endlessly follow.
rclcpp::TimerBase::SharedPtr auto_planning_timer_
Timer to automatically plan route, e.g., if waypoints are given.
rclcpp_action::Client< PlanRoute >::SharedPtr action_client_
Action client.
void sendGoal(const geometry_msgs::msg::PoseStamped::SharedPtr msg, const std::vector< geometry_msgs::msg::PointStamped > &intermediate_destinations={})
Sends a goal to the action server.
std::string ll2_map_server_name_
Name of lanelet2_map_server node (parameter)
void autoPlanningTimerCallback()
Callback for automatically planning a route, e.g., if waypoints are given.
bool has_completed_one_goal_
Whether one goal has been completed (succeeded or failed)
OnSetParametersCallbackHandle::SharedPtr parameters_callback_
Callback handle for dynamic parameter reconfiguration.
void goalResponseCallback(const GoalHandlePlanRoute::SharedPtr &goal_handle)
Callback for goal response from the action server.
std::vector< std::string > waypoints_param_
WGS84 waypoints to endlessly follow (parameter)
void feedbackCallback(GoalHandlePlanRoute::SharedPtr goal_handle, const std::shared_ptr< const PlanRoute::Feedback > feedback)
Callback for feedback from the action server.
bool enable_random_destination_
Whether to plan a route to a random destination (parameter)
void setup()
Sets up subscribers, publishers, etc. to configure the node.
rclcpp::Subscription< geometry_msgs::msg::PoseStamped >::SharedPtr goal_pose_subscriber_
Subscriber for goal pose.
void declareAndLoadParameter(const std::string &name, T &param, const std::string &description, const bool add_to_auto_reconfigurable_params=true, const bool is_required=false, const bool read_only=false, const std::optional< double > &from_value=std::nullopt, const std::optional< double > &to_value=std::nullopt, const std::optional< double > &step_value=std::nullopt, const std::string &additional_constraints="")
Declares and loads a ROS parameter.
std::vector< std::tuple< std::string, std::function< void(const rclcpp::Parameter &)> > > auto_reconfigurable_params_
Auto-reconfigurable parameters for dynamic reconfiguration.
std::unique_ptr< Lanelet2MapInterface > ll2_interface_
Lanelet2 map interface.