15 #ifndef NAV2_ROUTE__ROUTE_SERVER_HPP_
16 #define NAV2_ROUTE__ROUTE_SERVER_HPP_
22 #include <unordered_map>
25 #include "nav2_ros_common/lifecycle_node.hpp"
26 #include "nav2_ros_common/tf2_factories.hpp"
27 #include "nav2_ros_common/simple_action_server.hpp"
28 #include "nav2_ros_common/node_utils.hpp"
29 #include "nav2_util/robot_utils.hpp"
30 #include "nav2_ros_common/service_server.hpp"
31 #include "nav2_msgs/action/compute_route.hpp"
32 #include "nav2_msgs/action/compute_and_track_route.hpp"
33 #include "nav2_msgs/msg/route.hpp"
34 #include "nav2_msgs/msg/route_node.hpp"
35 #include "nav2_msgs/srv/set_route_graph.hpp"
36 #include "nav2_core/route_exceptions.hpp"
37 #include "visualization_msgs/msg/marker_array.hpp"
39 #include "nav2_route/types.hpp"
40 #include "nav2_route/utils.hpp"
41 #include "nav2_route/graph_loader.hpp"
42 #include "nav2_route/route_planner.hpp"
43 #include "nav2_route/path_converter.hpp"
44 #include "nav2_route/route_tracker.hpp"
45 #include "nav2_route/goal_intent_extractor.hpp"
57 using ComputeRoute = nav2_msgs::action::ComputeRoute;
58 using ComputeRouteGoal = ComputeRoute::Goal;
59 using ComputeRouteResult = ComputeRoute::Result;
62 using ComputeAndTrackRoute = nav2_msgs::action::ComputeAndTrackRoute;
63 using ComputeAndTrackRouteGoal = ComputeAndTrackRoute::Goal;
64 using ComputeAndTrackRouteFeedback = ComputeAndTrackRoute::Feedback;
65 using ComputeAndTrackRouteResult = ComputeAndTrackRoute::Result;
72 explicit RouteServer(
const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
84 nav2::CallbackReturn
on_configure(
const rclcpp_lifecycle::State & state)
override;
91 nav2::CallbackReturn
on_activate(
const rclcpp_lifecycle::State & state)
override;
98 nav2::CallbackReturn
on_deactivate(
const rclcpp_lifecycle::State & state)
override;
105 nav2::CallbackReturn
on_cleanup(
const rclcpp_lifecycle::State & state)
override;
112 nav2::CallbackReturn
on_shutdown(
const rclcpp_lifecycle::State & state)
override;
118 void computeAndTrackRoute();
137 template<
typename GoalT>
139 const std::shared_ptr<const GoalT> goal,
146 template<
typename ActionT>
148 typename nav2::SimpleActionServer<ActionT>::SharedPtr & action_server);
162 template<
typename ActionT>
163 bool isRequestValid(
typename nav2::SimpleActionServer<ActionT>::SharedPtr & action_server);
173 std::shared_ptr<ComputeRoute::Result> result,
175 const nav_msgs::msg::Path & path,
176 const rclcpp::Duration & planning_duration);
186 std::shared_ptr<ComputeAndTrackRoute::Result>,
188 const nav_msgs::msg::Path & ,
189 const rclcpp::Duration & );
198 const std::shared_ptr<rmw_request_id_t>,
199 const std::shared_ptr<nav2_msgs::srv::SetRouteGraph::Request> request,
200 std::shared_ptr<nav2_msgs::srv::SetRouteGraph::Response> response);
213 template<
typename GoalT>
214 void exceptionWarning(
const std::shared_ptr<const GoalT> goal,
const std::exception & ex);
216 typename ComputeRouteServer::SharedPtr compute_route_server_;
217 typename ComputeAndTrackRouteServer::SharedPtr compute_and_track_route_server_;
220 nav2::TransformBuffer::SharedPtr tf_;
221 nav2::TransformListener::SharedPtr transform_listener_;
224 nav2::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr
225 graph_vis_publisher_;
228 nav2::Publisher<nav2_msgs::msg::Route>::SharedPtr route_publisher_;
231 nav2::ServiceServer<nav2_msgs::srv::SetRouteGraph>::SharedPtr set_graph_service_;
234 std::shared_ptr<GraphLoader> graph_loader_;
235 std::shared_ptr<RoutePlanner> route_planner_;
236 std::shared_ptr<RouteTracker> route_tracker_;
237 std::shared_ptr<PathConverter> path_converter_;
238 std::shared_ptr<GoalIntentExtractor> goal_intent_extractor_;
240 std::shared_ptr<nav2_costmap_2d::CostmapSubscriber> costmap_subscriber_;
244 GraphToIDMap id_to_graph_map_;
245 std::string route_frame_, base_frame_;
246 double max_planning_time_;
A lifecycle node wrapper to enable common Nav2 needs such as manipulating parameters.
An action server wrapper to make applications simpler using Actions.
An action server implements a Navigation Route-Graph planner to compliment free-space planning in the...
void computeRoute()
Main route action server callbacks for computing and tracking a route.
~RouteServer()=default
A destructor for nav2_route::RouteServer.
void setRouteGraph(const std::shared_ptr< rmw_request_id_t >, const std::shared_ptr< nav2_msgs::srv::SetRouteGraph::Request > request, std::shared_ptr< nav2_msgs::srv::SetRouteGraph::Response > response)
The service callback to set a new route graph.
rclcpp::Duration findPlanningDuration(const rclcpp::Time &start_time)
Find the planning duration of the request and log warnings.
void publishRoute(const Route &route)
Publish the route msg.
Route findRoute(const std::shared_ptr< const GoalT > goal, ReroutingState &rerouting_info)
Compute a route to the goal, incorporating rerouting information.
nav2::CallbackReturn on_configure(const rclcpp_lifecycle::State &state) override
Configure member variables and initializes planner.
nav2::CallbackReturn on_activate(const rclcpp_lifecycle::State &state) override
Activate member variables.
bool isRequestValid(typename nav2::SimpleActionServer< ActionT >::SharedPtr &action_server)
Find the routing request is valid (action server OK and not cancelled)
RouteServer(const rclcpp::NodeOptions &options=rclcpp::NodeOptions())
A constructor for nav2_route::RouteServer.
void exceptionWarning(const std::shared_ptr< const GoalT > goal, const std::exception &ex)
Log exception warnings, templated by action message type.
nav2::CallbackReturn on_cleanup(const rclcpp_lifecycle::State &state) override
Reset member variables.
nav2::CallbackReturn on_deactivate(const rclcpp_lifecycle::State &state) override
Deactivate member variables.
nav2::CallbackReturn on_shutdown(const rclcpp_lifecycle::State &state) override
Called when in shutdown state.
void populateActionResult(std::shared_ptr< ComputeRoute::Result > result, const Route &route, const nav_msgs::msg::Path &path, const rclcpp::Duration &planning_duration)
Populate result for compute route action.
void processRouteRequest(typename nav2::SimpleActionServer< ActionT >::SharedPtr &action_server)
Main processing called by both action server callbacks to centralize the great deal of shared code be...
State shared to objects to communicate important rerouting data to avoid rerouting over blocked edges...
An ordered set of nodes and edges corresponding to the planned route.