18 #include "nav2_route/plugins/edge_cost_functions/semantic_scorer.hpp"
24 const nav2::LifecycleNode::SharedPtr node,
25 const std::shared_ptr<tf2_ros::Buffer>,
26 std::shared_ptr<nav2_costmap_2d::CostmapSubscriber>,
27 const std::string & name)
29 RCLCPP_INFO(node->get_logger(),
"Configuring semantic scorer.");
33 nav2::declare_parameter_if_not_declared(
34 node,
getName() +
".semantic_classes", rclcpp::ParameterValue(std::vector<std::string>{}));
35 std::vector<std::string> classes =
36 node->get_parameter(
getName() +
".semantic_classes").as_string_array();
37 for (
auto & cl : classes) {
38 nav2::declare_parameter_if_not_declared(
39 node,
getName() +
"." + cl, rclcpp::ParameterType::PARAMETER_DOUBLE);
40 const double cost = node->get_parameter(
getName() +
"." + cl).as_double();
41 semantic_info_[cl] =
static_cast<float>(cost);
46 nav2::declare_parameter_if_not_declared(
47 node,
getName() +
".semantic_key", rclcpp::ParameterValue(std::string(
"class")));
48 key_ = node->get_parameter(
getName() +
".semantic_key").as_string();
51 nav2::declare_parameter_if_not_declared(
52 node,
getName() +
".weight", rclcpp::ParameterValue(1.0));
53 weight_ =
static_cast<float>(node->get_parameter(
getName() +
".weight").as_double());
58 for (
auto it = mdata.data.cbegin(); it != mdata.data.cend(); ++it) {
59 if (
auto sem = semantic_info_.find(it->first); sem != semantic_info_.end()) {
68 cl = mdata.getValue<std::string>(key_, cl);
69 if (
auto sem = semantic_info_.find(cl); sem != semantic_info_.end()) {
77 const EdgeType & ,
float & cost)
80 Metadata & node_mdata = edge->end->metadata;
81 Metadata & edge_mdata = edge->metadata;
93 cost = weight_ *
score;
104 #include "pluginlib/class_list_macros.hpp"
A plugin interface to score edges during graph search to modify the lowest cost path (e....
Scores an edge based on arbitrary graph semantic data such as set priority/danger levels or regional ...
void metadataValueScorer(Metadata &mdata, float &score)
Scores graph object based on metadata's semantic value at key.
void configure(const nav2::LifecycleNode::SharedPtr node, const std::shared_ptr< tf2_ros::Buffer > tf_buffer, std::shared_ptr< nav2_costmap_2d::CostmapSubscriber > costmap_subscriber, const std::string &name) override
Configure.
std::string getName() override
Get name of the plugin for parameter scope mapping.
void metadataKeyScorer(Metadata &mdata, float &score)
Scores graph object based on metadata's key values.
bool score(const EdgePtr edge, const RouteRequest &route_request, const EdgeType &edge_type, float &cost) override
Main scoring plugin API.
An object representing edges between nodes.
An object to store salient features of the route request including its start and goal node ids,...