Nav2 Navigation Stack - humble  humble
ROS 2 Navigation Stack
rerouting_service.cpp
1 // Copyright (c) 2025, Open Navigation LLC
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 
15 
16 #include <memory>
17 #include <string>
18 
19 #include "nav2_route/plugins/route_operations/rerouting_service.hpp"
20 
21 namespace nav2_route
22 {
23 
25  const rclcpp_lifecycle::LifecycleNode::SharedPtr node,
26  std::shared_ptr<nav2_costmap_2d::CostmapSubscriber>/* costmap_subscriber */,
27  const std::string & name)
28 {
29  RCLCPP_INFO(node->get_logger(), "Configuring Rerouting service operation.");
30  name_ = name;
31  logger_ = node->get_logger();
32  reroute_.store(false);
33  service_ = node->create_service<std_srvs::srv::Trigger>(
34  std::string(node->get_name()) + "/" + getName() + "/reroute",
35  std::bind(
37  std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
38 }
39 
41  const std::shared_ptr<rmw_request_id_t>,
42  const std::shared_ptr<std_srvs::srv::Trigger::Request>/*request*/,
43  std::shared_ptr<std_srvs::srv::Trigger::Response> response)
44 {
45  RCLCPP_INFO(logger_, "A reroute has been requested!");
46  reroute_.store(true);
47  response->success = true;
48 }
49 
51  NodePtr /*node*/,
52  EdgePtr /*edge_entered*/,
53  EdgePtr /*edge_exited*/,
54  const Route & /*route*/,
55  const geometry_msgs::msg::PoseStamped & /*curr_pose*/,
56  const Metadata * /*mdata*/)
57 {
58  OperationResult result;
59  if (reroute_.load()) {
60  reroute_.store(false);
61  result.reroute = true;
62  return result;
63  }
64 
65  return result;
66 }
67 
68 } // namespace nav2_route
69 
70 #include "pluginlib/class_list_macros.hpp"
A route operation to process requests from an external server for rerouting.
void serviceCb(const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< std_srvs::srv::Trigger::Request > request, std::shared_ptr< std_srvs::srv::Trigger::Response > response)
Service callback to trigger a reroute externally.
void configure(const rclcpp_lifecycle::LifecycleNode::SharedPtr node, std::shared_ptr< nav2_costmap_2d::CostmapSubscriber > costmap_subscriber, const std::string &name) override
Configure.
OperationResult perform(NodePtr node, EdgePtr edge_entered, EdgePtr edge_exited, const Route &route, const geometry_msgs::msg::PoseStamped &curr_pose, const Metadata *mdata=nullptr) override
The main speed limit operation to adjust the maximum speed of the vehicle.
std::string getName() override
Get name of the plugin for parameter scope mapping.
A plugin interface to perform an operation while tracking the route such as triggered from the graph ...
An object representing edges between nodes.
Definition: types.hpp:134
An object to store arbitrary metadata regarding nodes from the graph file.
Definition: types.hpp:35
An object to store the nodes in the graph file.
Definition: types.hpp:183
a struct to hold return from an operation
An ordered set of nodes and edges corresponding to the planned route.
Definition: types.hpp:211