Nav2 Navigation Stack - lyrical  lyrical
ROS 2 Navigation Stack
dynamic_edges_scorer.hpp
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 #ifndef NAV2_ROUTE__PLUGINS__EDGE_COST_FUNCTIONS__DYNAMIC_EDGES_SCORER_HPP_
16 #define NAV2_ROUTE__PLUGINS__EDGE_COST_FUNCTIONS__DYNAMIC_EDGES_SCORER_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <unordered_map>
21 #include <set>
22 
23 #include "nav2_ros_common/lifecycle_node.hpp"
24 #include "nav2_route/interfaces/edge_cost_function.hpp"
25 #include "nav2_msgs/srv/dynamic_edges.hpp"
26 #include "nav2_ros_common/node_utils.hpp"
27 #include "nav2_ros_common/service_server.hpp"
28 #include "nav2_ros_common/tf2_factories.hpp"
29 
30 namespace nav2_route
31 {
32 
39 {
40 public:
44  DynamicEdgesScorer() = default;
45 
49  virtual ~DynamicEdgesScorer() = default;
50 
54  void configure(
55  const nav2::LifecycleNode::SharedPtr node,
56  const nav2::TransformBuffer::SharedPtr tf_buffer,
57  std::shared_ptr<nav2_costmap_2d::CostmapSubscriber> costmap_subscriber,
58  const std::string & name) override;
59 
67  bool score(
68  const EdgePtr edge, const RouteRequest & route_request,
69  const EdgeType & edge_type, float & cost) override;
70 
75  std::string getName() override;
76 
82  void closedEdgesCb(
83  const std::shared_ptr<rmw_request_id_t> request_header,
84  const std::shared_ptr<nav2_msgs::srv::DynamicEdges::Request> request,
85  std::shared_ptr<nav2_msgs::srv::DynamicEdges::Response> response);
86 
87 protected:
88  rclcpp::Logger logger_{rclcpp::get_logger("DynamicEdgesScorer")};
89  std::string name_;
90  std::set<unsigned int> closed_edges_;
91  std::unordered_map<unsigned int, float> dynamic_penalties_;
92  nav2::ServiceServer<nav2_msgs::srv::DynamicEdges>::SharedPtr service_;
93 };
94 
95 } // namespace nav2_route
96 
97 #endif // NAV2_ROUTE__PLUGINS__EDGE_COST_FUNCTIONS__DYNAMIC_EDGES_SCORER_HPP_
Rejects edges that are in the closed set of edges for navigation to prevent routes from containing pa...
virtual ~DynamicEdgesScorer()=default
destructor
void configure(const nav2::LifecycleNode::SharedPtr node, const nav2::TransformBuffer::SharedPtr tf_buffer, std::shared_ptr< nav2_costmap_2d::CostmapSubscriber > costmap_subscriber, const std::string &name) override
Configure.
void closedEdgesCb(const std::shared_ptr< rmw_request_id_t > request_header, const std::shared_ptr< nav2_msgs::srv::DynamicEdges::Request > request, std::shared_ptr< nav2_msgs::srv::DynamicEdges::Response > response)
Service callback to process edge changes.
bool score(const EdgePtr edge, const RouteRequest &route_request, const EdgeType &edge_type, float &cost) override
Main scoring plugin API.
std::string getName() override
Get name of the plugin for parameter scope mapping.
DynamicEdgesScorer()=default
Constructor.
A plugin interface to score edges during graph search to modify the lowest cost path (e....
An object representing edges between nodes.
Definition: types.hpp:134
An object to store salient features of the route request including its start and goal node ids,...
Definition: types.hpp:224