lanelet2_route_planning v2.0.0
Loading...
Searching...
No Matches
lanelet2_route_planning.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 <limits>
7#include <map>
8#include <memory>
9#include <mutex>
10#include <string>
11#include <vector>
12
13#include <lanelet2_routing/Route.h>
14#include <tf2_ros/buffer.h>
15#include <tf2_ros/transform_listener.h>
16#include <diagnostic_msgs/msg/diagnostic_array.hpp>
17#include <diagnostic_updater/diagnostic_updater.hpp>
18#include <diagnostic_updater/publisher.hpp>
19#include <lanelet2_map_interface/lanelet2_map_interface.hpp>
20#include <rclcpp/rclcpp.hpp>
21#include <rclcpp_action/rclcpp_action.hpp>
22#include <route_planning_msgs/action/plan_route.hpp>
23#include <route_planning_msgs/msg/route.hpp>
24
26
27template <typename C>
28struct is_vector : std::false_type {};
29
30template <typename T, typename A>
31struct is_vector<std::vector<T, A>> : std::true_type {};
32
33template <typename C>
34inline constexpr bool is_vector_v = is_vector<C>::value;
35
43 double min_frequency = 0.0;
44
48 double max_frequency = std::numeric_limits<double>::infinity();
49
54
58 double max_acceptable_timestamp_delta = std::numeric_limits<double>::infinity();
59};
60
64class Lanelet2RoutePlanning : public rclcpp::Node {
65 public:
70
71 private:
86 template <typename T>
87 void declareAndLoadParameter(const std::string& name,
88 T& param,
89 const std::string& description,
90 const bool add_to_auto_reconfigurable_params = true,
91 const bool is_required = false,
92 const bool read_only = false,
93 const std::optional<double>& from_value = std::nullopt,
94 const std::optional<double>& to_value = std::nullopt,
95 const std::optional<double>& step_value = std::nullopt,
96 const std::string& additional_constraints = "");
97
104 rcl_interfaces::msg::SetParametersResult parametersCallback(const std::vector<rclcpp::Parameter>& parameters);
105
109 void setup();
110
117 bool checkMap(bool handle_update);
118
124 bool buildRoutingGraph();
125
133 void egoDataCallback(const perception_msgs::msg::EgoData::SharedPtr msg);
134
139
142
153 rclcpp_action::GoalResponse actionHandleGoal(const rclcpp_action::GoalUUID& uuid,
154 std::shared_ptr<const route_planning_msgs::action::PlanRoute::Goal> goal);
155
164 rclcpp_action::CancelResponse actionHandleCancel(
165 const std::shared_ptr<rclcpp_action::ServerGoalHandle<route_planning_msgs::action::PlanRoute>> goal_handle);
166
175 const std::shared_ptr<rclcpp_action::ServerGoalHandle<route_planning_msgs::action::PlanRoute>> goal_handle);
176
185 void actionExecute(const std::shared_ptr<rclcpp_action::ServerGoalHandle<route_planning_msgs::action::PlanRoute>> goal_handle);
186
195 bool planRoute(const geometry_msgs::msg::PointStamped& destination,
196 const std::vector<geometry_msgs::msg::PointStamped>& intermediate_destinations = {});
197
204
212
220 void publishHealth(const unsigned char status, const std::string& msg, const rclcpp::Time& now);
221
225 std::vector<std::tuple<std::string, std::function<void(const rclcpp::Parameter&)>>> auto_reconfigurable_params_;
226
230 OnSetParametersCallbackHandle::SharedPtr parameters_callback_;
231
235 rclcpp::Subscription<perception_msgs::msg::EgoData>::SharedPtr subscriber_ego_data_;
236
240 rclcpp::Publisher<route_planning_msgs::msg::Route>::SharedPtr publisher_route_;
241
245 rclcpp::Publisher<route_planning_msgs::msg::Route>::SharedPtr publisher_global_route_;
246
250 rclcpp::TimerBase::SharedPtr publish_timer_;
251
255 rclcpp::TimerBase::SharedPtr global_route_publish_timer_;
256
260 rclcpp_action::Server<route_planning_msgs::action::PlanRoute>::SharedPtr action_server_;
261
265 route_planning_msgs::action::PlanRoute::Feedback::SharedPtr action_feedback_;
266
270 route_planning_msgs::action::PlanRoute::Result::SharedPtr action_result_;
271
275 std::shared_ptr<rclcpp_action::ServerGoalHandle<route_planning_msgs::action::PlanRoute>> action_goal_handle_;
276
280 rclcpp::CallbackGroup::SharedPtr action_callback_group_;
281
285 rclcpp::Time action_start_time_;
286
290 std::unique_ptr<tf2_ros::Buffer> tf_buffer_;
291
295 std::shared_ptr<tf2_ros::TransformListener> tf_listener_;
296
300 perception_msgs::msg::EgoData latest_ego_data_;
301
305 std::unique_ptr<Lanelet2MapInterface> ll2_interface_;
306
310 lanelet::routing::RoutingGraphUPtr routing_graph_;
311
317 geometry_msgs::msg::Point starting_point_;
318
324 geometry_msgs::msg::Point destination_;
325
332 std::vector<geometry_msgs::msg::Point> intermediate_destinations_;
333
337 lanelet::routing::Route latest_route_;
338
345
350
354 route_planning_msgs::msg::Route latest_route_msg_;
355
359 route_planning_msgs::msg::Route latest_full_route_msg_;
360
362 route_planning_msgs::msg::Route latest_global_route_msg_;
363
367 std::vector<Eigen::Vector2d> latest_reference_line_;
368
376
384
388 std::string ll2_map_server_name_ = "lanelet2_map_server";
389
393 double publish_frequency_ = 10.0;
394
399
404
408 double sampling_distance_ = 1.0;
409
414
419
424
429
434
439
444
449
454
459
463 double transform_timeout_ = 0.02;
464
468 std::map<std::string, std::string> health_kv_;
469
473 mutable std::mutex health_kv_mutex_;
474
478 rclcpp::Publisher<diagnostic_msgs::msg::DiagnosticArray>::SharedPtr health_diagnostic_pub_;
479
483 diagnostic_updater::Updater diagnostic_updater_;
484
488 std::unique_ptr<diagnostic_updater::TopicDiagnostic> ego_data_diagnostic_;
489
493 std::unique_ptr<diagnostic_updater::HeaderlessTopicDiagnostic> route_timer_diagnostic_;
494
498 std::unique_ptr<diagnostic_updater::HeaderlessTopicDiagnostic> global_route_timer_diagnostic_;
499
504
509
514};
515
516} // namespace lanelet2_route_planning
double sampling_distance_
Distance between resampled points along route [m] (parameter)
rcl_interfaces::msg::SetParametersResult parametersCallback(const std::vector< rclcpp::Parameter > &parameters)
Handles reconfiguration when a parameter value is changed.
bool has_enriched_route_
Flag indicating that route has been enriched at least once.
geometry_msgs::msg::Point destination_
Destination point in map frame.
void egoDataCallback(const perception_msgs::msg::EgoData::SharedPtr msg)
Callback for EgoData.
std::vector< std::tuple< std::string, std::function< void(const rclcpp::Parameter &)> > > auto_reconfigurable_params_
Auto-reconfigurable parameters for dynamic reconfiguration.
bool is_publishing_route_
Controlling flag for route publication.
double max_drivable_space_radius_
Maximum distance to left/right drivable space bounds, if not otherwise restricted [m] (parameter)
double action_feedback_frequency_
Frequency of action feedback publication [Hz] (parameter)
rclcpp::TimerBase::SharedPtr publish_timer_
Timer for publishing the enriched route.
double required_traveled_distance_proportion_
Proportion of route length that must have been traveled before considering destination reached [0....
void buildGlobalRouteMessage()
Builds a global ROS route message from the latest planned lanelet route.
double sampling_max_lateral_error_global_
Maximum lateral error of the adaptively sampled global reference line [m] (parameter)
rclcpp::Publisher< diagnostic_msgs::msg::DiagnosticArray >::SharedPtr health_diagnostic_pub_
Health diagnostic publisher.
double enrich_route_behind_ego_distance_
Distance behind ego position where global route is enriched with more information [m] (negative=unlim...
double route_overshoot_distance_
Overshoot route by this distance behind destination [m] (parameter)
void setup()
Sets up subscribers, publishers, etc. to configure the node.
rclcpp_action::GoalResponse actionHandleGoal(const rclcpp_action::GoalUUID &uuid, std::shared_ptr< const route_planning_msgs::action::PlanRoute::Goal > goal)
Action goal callback: processes a route planning request.
std::map< std::string, std::string > health_kv_
Health key-value pairs for diagnostic message.
std::string ll2_map_server_name_
Name of lanelet2_map_server node (parameter)
route_planning_msgs::action::PlanRoute::Result::SharedPtr action_result_
Latest action result.
double publish_frequency_global_
Frequency of global route publication [Hz] (parameter)
std::unique_ptr< diagnostic_updater::HeaderlessTopicDiagnostic > global_route_timer_diagnostic_
Diagnostic to auto-diagnose global route timer frequency.
TopicDiagnosticConfig global_route_timer_diagnostic_config_
Configuration for auto-diagnosed global route timer.
bool buildRoutingGraph()
Builds the lanelet2 routing graph based on the current map.
diagnostic_updater::Updater diagnostic_updater_
Diagnostic updater for monitoring topic frequencies and timestamps.
rclcpp::Publisher< route_planning_msgs::msg::Route >::SharedPtr publisher_route_
Publisher for enriched route.
route_planning_msgs::action::PlanRoute::Feedback::SharedPtr action_feedback_
Latest action feedback.
double destination_distance_threshold_
Distance to destination where destination is considered reached [m] (parameter)
std::unique_ptr< diagnostic_updater::HeaderlessTopicDiagnostic > route_timer_diagnostic_
Diagnostic to auto-diagnose route timer frequency.
std::shared_ptr< tf2_ros::TransformListener > tf_listener_
Transform listener.
double publish_frequency_
Frequency of route publication [Hz] (parameter)
double enrich_route_ahead_ego_distance_
Distance ahead of ego position where global route is enriched with more information [m] (negative=unl...
std::unique_ptr< tf2_ros::Buffer > tf_buffer_
Transform buffer.
lanelet::routing::Route latest_route_
Latest planned lanelet route.
bool checkMap(bool handle_update)
Checks if map is loaded and handles map updates.
rclcpp::TimerBase::SharedPtr global_route_publish_timer_
Timer for publishing the global route.
geometry_msgs::msg::Point starting_point_
Starting point in map frame.
rclcpp::Subscription< perception_msgs::msg::EgoData >::SharedPtr subscriber_ego_data_
Subscriber for ego data.
void globalRoutePublishTimerCallback()
Callback to periodically publish the adaptively sampled global route.
route_planning_msgs::msg::Route latest_route_msg_
Latest route message to publish.
std::unique_ptr< diagnostic_updater::TopicDiagnostic > ego_data_diagnostic_
Diagnostic to auto-diagnose ego data topic.
std::vector< geometry_msgs::msg::Point > intermediate_destinations_
Intermediate points in map frame.
route_planning_msgs::msg::Route latest_global_route_msg_
Latest adaptively sampled non-enriched global route.
int max_num_threads_
Maximum number of threads for parallel processing (0=max available) (parameter)
lanelet::routing::RoutingGraphUPtr routing_graph_
Lanelet routing graph for current map.
double route_undershoot_distance_
Undershoot route by this distance before ego position [m] (parameter)
void publishHealth(const unsigned char status, const std::string &msg, const rclcpp::Time &now)
Publishes health diagnostic.
void buildEnrichedRouteMessage()
Builds an enriched ROS route message from the latest planned lanelet route.
TopicDiagnosticConfig route_timer_diagnostic_config_
Configuration for auto-diagnosed route timer.
std::vector< std::vector< int > > latest_suggested_turn_signal_distance_ahead_by_route_element_by_lane_element_
Latest suggested turn signal distance ahead by route element by lane element.
void actionHandleAccepted(const std::shared_ptr< rclcpp_action::ServerGoalHandle< route_planning_msgs::action::PlanRoute > > goal_handle)
Action accepted callback: starts action execution.
std::shared_ptr< rclcpp_action::ServerGoalHandle< route_planning_msgs::action::PlanRoute > > action_goal_handle_
Latest action goal handle.
std::vector< Eigen::Vector2d > latest_reference_line_
Latest complete dense reference line in the map frame.
perception_msgs::msg::EgoData latest_ego_data_
Latest ego data in map frame.
bool project_destination_to_reference_line_
Whether to project destination to reference line (parameter)
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.
void publishTimerCallback()
Callback to periodically publish the route.
OnSetParametersCallbackHandle::SharedPtr parameters_callback_
Callback handle for dynamic parameter reconfiguration.
rclcpp_action::CancelResponse actionHandleCancel(const std::shared_ptr< rclcpp_action::ServerGoalHandle< route_planning_msgs::action::PlanRoute > > goal_handle)
Action cancel callback: cancels a running action.
rclcpp::CallbackGroup::SharedPtr action_callback_group_
Callback group for action server.
bool planRoute(const geometry_msgs::msg::PointStamped &destination, const std::vector< geometry_msgs::msg::PointStamped > &intermediate_destinations={})
Plans a lanelet route to the destination.
rclcpp::Time action_start_time_
Latest action start time to compute action duration.
TopicDiagnosticConfig ego_data_diagnostic_config_
Configuration for auto-diagnosed ego data topic.
std::vector< size_t > latest_lanelet_idx_by_reference_line_point_idx_
Latest mapping between global route reference line and lanelet indices.
rclcpp_action::Server< route_planning_msgs::action::PlanRoute >::SharedPtr action_server_
Action server.
void actionExecute(const std::shared_ptr< rclcpp_action::ServerGoalHandle< route_planning_msgs::action::PlanRoute > > goal_handle)
Action execution: continually publishes route progress.
rclcpp::Publisher< route_planning_msgs::msg::Route >::SharedPtr publisher_global_route_
Publisher for the adaptively sampled global route.
route_planning_msgs::msg::Route latest_full_route_msg_
Latest complete minimal route used internally for progress tracking.
double transform_timeout_
How long to wait for a transform to be available [s] (parameter)
std::unique_ptr< Lanelet2MapInterface > ll2_interface_
Lanelet2 map interface.
std::mutex health_kv_mutex_
Mutex protecting health key-value pairs across threads.
Configuration parameters for topic diagnostics.
double max_acceptable_timestamp_delta
Maximum acceptable difference between message timestamp and receipt time (in seconds)
double min_acceptable_timestamp_delta
Minimum acceptable difference between message timestamp and receipt time (in seconds)