20#include <unordered_map>
35 : monitor_logger_buffer_(common::monitor::MonitorMessageItem::ROUTING) {}
39 AINFO <<
"Use routing topology graph path: " << routing_map_file;
40 navigator_ptr_.reset(
new Navigator(routing_map_file));
49 if (!navigator_ptr_->IsReady()) {
50 AERROR <<
"Navigator is not ready!";
52 "Navigator not ready");
54 AINFO <<
"Routing service is ready.";
55 monitor_logger_buffer_.INFO(
"Routing started");
59std::vector<routing::RoutingRequest> Routing::FillLaneInfoIfMissing(
61 std::vector<routing::RoutingRequest> fixed_requests;
62 std::unordered_map<int, std::vector<LaneWaypoint>>
63 additional_lane_waypoint_map;
65 for (
int i = 0; i < routing_request.waypoint_size(); ++i) {
67 if (lane_waypoint.has_id()) {
74 std::vector<std::shared_ptr<const hdmap::LaneInfo>> lanes;
76 constexpr double kRadius = 0.3;
77 for (
int i = 0; i < 20; ++i) {
78 hdmap_->
GetLanes(point, kRadius + i * kRadius, &lanes);
79 if (lanes.size() > 0) {
84 AERROR <<
"Failed to find nearest lane from map at position: "
85 << point.DebugString();
86 return fixed_requests;
88 for (
size_t j = 0; j < lanes.size(); ++j) {
91 lanes[j]->GetProjection({point.x(), point.y()}, &s, &l);
93 auto waypoint_info = fixed_request.mutable_waypoint(i);
94 waypoint_info->set_id(lanes[j]->
id().
id());
95 waypoint_info->set_s(s);
98 LaneWaypoint new_lane_waypoint(lane_waypoint);
99 new_lane_waypoint.set_id(lanes[j]->
id().
id());
100 new_lane_waypoint.set_s(s);
101 additional_lane_waypoint_map[i].push_back(new_lane_waypoint);
106 fixed_requests.push_back(fixed_request);
109 for (
const auto& m : additional_lane_waypoint_map) {
110 size_t cur_size = fixed_requests.size();
111 for (
size_t i = 0; i < cur_size; ++i) {
113 for (
const auto& lane_waypoint : m.second) {
114 routing::RoutingRequest new_request(fixed_requests[i]);
115 auto waypoint_info = new_request.mutable_waypoint(m.first);
116 waypoint_info->set_id(lane_waypoint.id());
117 waypoint_info->set_s(lane_waypoint.s());
118 fixed_requests.push_back(new_request);
123 for (
const auto& fixed_request : fixed_requests) {
124 ADEBUG <<
"Fixed routing request:" << fixed_request.DebugString();
126 return fixed_requests;
130 const std::shared_ptr<routing::RoutingRequest>& routing_request,
132 if (
nullptr == routing_request) {
133 AWARN <<
"Routing request is empty!";
136 CHECK_NOTNULL(routing_response);
137 AINFO <<
"Get new routing request:" << routing_request->DebugString();
139 const auto& fixed_requests = FillLaneInfoIfMissing(*routing_request);
140 double min_routing_length = std::numeric_limits<double>::max();
141 for (
const auto& fixed_request : fixed_requests) {
143 if (navigator_ptr_->SearchRoute(fixed_request, &routing_response_temp)) {
144 const double routing_length =
146 if (routing_length < min_routing_length) {
147 routing_response->CopyFrom(routing_response_temp);
148 min_routing_length = routing_length;
152 if (min_routing_length < std::numeric_limits<double>::max()) {
153 monitor_logger_buffer_.INFO(
"Routing success!");
157 AERROR <<
"Failed to search route with navigator.";
158 monitor_logger_buffer_.WARN(
"Routing failed! " +
A general class to denote the return status of an API call.
static Status OK()
generate a success status.
static PointENU ToPointENU(const double x, const double y, const double z=0)
static const HDMap * BaseMapPtr()
int GetLanes(const apollo::common::PointENU &point, double distance, std::vector< LaneInfoConstPtr > *lanes) const
get all lanes in certain range
bool Process(const std::shared_ptr< routing::RoutingRequest > &routing_request, routing::RoutingResponse *const routing_response)
std::string Name() const
module name
apollo::common::Status Init()
module initialization function
apollo::common::Status Start()
module start function
std::string RoutingMapFile()
get routing map file path from flags.
std::string BaseMapFile()
get base map file path from flags.
repeated apollo::routing::LaneWaypoint waypoint
optional apollo::routing::Measurement measurement
optional apollo::common::StatusPb status