Autoware.Auto
trajectory_planner_node_base.hpp
Go to the documentation of this file.
1 // Copyright 2020 The Autoware Foundation
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 
18 
19 #ifndef TRAJECTORY_PLANNER_NODE_BASE__TRAJECTORY_PLANNER_NODE_BASE_HPP_
20 #define TRAJECTORY_PLANNER_NODE_BASE__TRAJECTORY_PLANNER_NODE_BASE_HPP_
21 
23 
24 // ROS
25 #include <rclcpp/rclcpp.hpp>
26 #include <rclcpp_action/rclcpp_action.hpp>
27 
28 // Autoware Package
29 #include <autoware_auto_msgs/srv/had_map_service.hpp>
30 #include <autoware_auto_msgs/action/plan_trajectory.hpp>
31 #include <autoware_auto_msgs/msg/route.hpp>
32 #include <common/types.hpp>
33 
34 // external libraries
35 #include <lanelet2_core/LaneletMap.h>
36 #include <memory>
37 #include <string>
38 
39 namespace autoware
40 {
41 namespace trajectory_planner_node_base
42 {
43 
45 
49 
50 enum class PlannerState
51 {
52  IDLE,
53  PLANNING
54 }; // enum class PlannerState
55 
58 class TRAJECTORY_PLANNER_NODE_BASE_PUBLIC TrajectoryPlannerNodeBase : public rclcpp::Node
59 {
60 public:
66  const std::string & node_name,
67  const std::string & action_server_name,
68  const rclcpp::NodeOptions & options);
69 
70 protected:
72  // for relevent map objects for their planner
73  virtual HADMapService::Request create_map_request(const Route & route) = 0;
74 
76  // and status (SUCCESS, FAIL)
77  virtual Trajectory plan_trajectory(
78  const Route & route,
79  const lanelet::LaneletMapPtr & lanelet_map_ptr) = 0;
80 
81 private:
82  using PlanTrajectoryAction = autoware_auto_msgs::action::PlanTrajectory;
83  using GoalHandle = rclcpp_action::ServerGoalHandle<PlanTrajectoryAction>;
84 
85  // ROS Interface
86  rclcpp_action::Server<PlanTrajectoryAction>::SharedPtr m_planner_server;
87  rclcpp::Client<HADMapService>::SharedPtr m_map_client;
88 
89  // callback
90  TRAJECTORY_PLANNER_NODE_BASE_LOCAL rclcpp_action::GoalResponse handle_goal(
91  const rclcpp_action::GoalUUID & uuid,
92  const std::shared_ptr<const PlanTrajectoryAction::Goal> goal);
93  TRAJECTORY_PLANNER_NODE_BASE_LOCAL rclcpp_action::CancelResponse handle_cancel(
94  const std::shared_ptr<GoalHandle> goal_handle);
95  TRAJECTORY_PLANNER_NODE_BASE_LOCAL void handle_accepted(
96  const std::shared_ptr<GoalHandle> goal_handle);
97  void map_response(rclcpp::Client<HADMapService>::SharedFuture future);
98 
99  // \brief Validation of trajectory
100  bool8_t is_trajectory_valid(const Trajectory & trajectory);
101 
102  std::shared_ptr<GoalHandle> m_goal_handle{nullptr};
103 
104  PlannerState m_planner_state;
105  bool8_t is_planning();
106  void start_planning();
107  void stop_planning();
108 };
109 
110 } // namespace trajectory_planner_node_base
111 } // namespace autoware
112 
113 #endif // TRAJECTORY_PLANNER_NODE_BASE__TRAJECTORY_PLANNER_NODE_BASE_HPP_
bool bool8_t
Definition: types.hpp:33
This file includes common type definition.
PlannerState
Definition: trajectory_planner_node_base.hpp:50
autoware_auto_msgs::srv::HADMapService HADMapService
Definition: trajectory_planner_node_base.hpp:46
ROS 2 Wrapper Node for Trajectory Planner.
Definition: trajectory_planner_node_base.hpp:58
autoware_auto_msgs::msg::Trajectory Trajectory
Definition: trajectory_planner_node_base.hpp:48
autoware_auto_msgs::msg::Route Route
Definition: trajectory_planner_node_base.hpp:47
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24