Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
RoutingGraphAccessor.hpp
Go to the documentation of this file.
1#pragma once
2
3/*
4 * Copyright (C) 2022 LEIDOS.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7 * use this file except in compliance with the License. You may obtain a copy of
8 * the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15 * License for the specific language governing permissions and limitations under
16 * the License.
17 */
18
19
20#include <lanelet2_routing/RoutingGraph.h>
21#include <lanelet2_routing/internal/Graph.h>
22
23
33
34 public:
35
44 autoware_lanelet2_msgs::msg::RoutingGraph routingGraphToMsg(const std::string& participant) {
45
46
47 autoware_lanelet2_msgs::msg::RoutingGraph msg; // output message
48
49 // Assign base fields
50 msg.num_unique_routing_cost_ids = this->graph_->numRoutingCosts();
51 msg.participant_type = participant;
52
53 // Get the underlying graph
54 // Type will be boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VertexInfo, EdgeInfo>
55 // As version of lanelet2 used when writing this function
56 auto underlying_graph = this->graph_->get();
57
58 // Iterate over all vertices in the graph
59 boost::graph_traits<lanelet::routing::internal::GraphType>::vertex_iterator vi, vi_end;
60
61 for(boost::tie(vi, vi_end) = boost::vertices(underlying_graph); vi != vi_end; ++vi) {
62
63 autoware_lanelet2_msgs::msg::RoutingGraphVertexAndEdges vertex_and_edges;
64
65 lanelet::routing::internal::GraphType::vertex_descriptor source = *vi;
66
67 // Iterate over all outgoing edges for this vertex
68 boost::graph_traits<lanelet::routing::internal::GraphType>::out_edge_iterator ei, ei_end;
69 for(boost::tie(ei, ei_end) = boost::out_edges(source, underlying_graph); ei != ei_end; ++ei) {
70
71 lanelet::routing::internal::GraphType::edge_descriptor edge = *ei;
72 lanelet::routing::internal::GraphType::vertex_descriptor target = boost::target(edge, underlying_graph);
73
74
75 // Populate the edge info in the message
76 vertex_and_edges.lanelet_or_area_ids.push_back(underlying_graph[target].laneletOrArea.id());
77
78 vertex_and_edges.edge_routing_costs.push_back(underlying_graph[edge].routingCost);
79 vertex_and_edges.edge_routing_cost_source_ids.push_back(underlying_graph[edge].costId);
80
81 uint8_t relation = 0;
82 switch(underlying_graph[edge].relation) {
83 case lanelet::routing::RelationType::Successor:
84 relation = autoware_lanelet2_msgs::msg::RoutingGraphVertexAndEdges::RELATION_SUCCESSOR; break;
86 relation = autoware_lanelet2_msgs::msg::RoutingGraphVertexAndEdges::RELATION_LEFT; break;
88 relation = autoware_lanelet2_msgs::msg::RoutingGraphVertexAndEdges::RELATION_RIGHT; break;
89 case lanelet::routing::RelationType::AdjacentLeft:
90 relation = autoware_lanelet2_msgs::msg::RoutingGraphVertexAndEdges::RELATION_ADJACENT_LEFT; break;
91 case lanelet::routing::RelationType::AdjacentRight:
92 relation = autoware_lanelet2_msgs::msg::RoutingGraphVertexAndEdges::RELATION_ADJACENT_RIGHT; break;
93 case lanelet::routing::RelationType::Conflicting:
94 relation = autoware_lanelet2_msgs::msg::RoutingGraphVertexAndEdges::RELATION_CONFLICTING; break;
95 case lanelet::routing::RelationType::Area:
96 relation = autoware_lanelet2_msgs::msg::RoutingGraphVertexAndEdges::RELATION_AREA; break;
97 default: // None relation will be default
98 relation = autoware_lanelet2_msgs::msg::RoutingGraphVertexAndEdges::RELATION_NONE; break;
99 }
100
101 vertex_and_edges.edge_relations.push_back(relation);
102
103 }
104
105 vertex_and_edges.lanelet_or_area = underlying_graph[source].laneletOrArea.id();
106
107 // Assign core vertext to the correct array in the ros message based on its type
108 if (underlying_graph[source].laneletOrArea.isLanelet()) { // Lanelet
109 msg.lanelet_vertices.push_back(vertex_and_edges);
110
111 } else { // Area
112 msg.area_vertices.push_back(vertex_and_edges);
113 }
114
115 }
116
117 return msg;
118 }
119};
120
This class serves as a method of exposing the internal protected members of the lanelet2 RoutingGraph...
autoware_lanelet2_msgs::msg::RoutingGraph routingGraphToMsg(const std::string &participant)
Returns a ROS message version of this RoutingGraph. This is done by accessing protected data members ...