Apollo 10.0
自动驾驶开放平台
node_creator.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include <algorithm>
20#include <cmath>
21
22namespace apollo {
23namespace routing {
24namespace node_creator {
25
26namespace {
27
28using ::google::protobuf::RepeatedPtrField;
29
33
34bool IsAllowedOut(const LaneBoundaryType& type) {
37 return true;
38 }
39 return false;
40}
41
42double GetLengthbyRate(double cur_s, double cur_total_length,
43 double target_length) {
44 double new_length = cur_s / cur_total_length * target_length;
45 return std::min(new_length, target_length);
46}
47
48double GetLaneLength(const Lane& lane) {
49 double length = 0.0;
50 for (const auto& segment : lane.central_curve().segment()) {
51 length += segment.length();
52 }
53 return length;
54}
55
56void AddOutBoundary(const LaneBoundary& bound, double lane_length,
57 RepeatedPtrField<CurveRange>* const out_range) {
58 for (int i = 0; i < bound.boundary_type_size(); ++i) {
59 if (!IsAllowedOut(bound.boundary_type(i))) {
60 continue;
61 }
62 CurveRange* range = out_range->Add();
63 range->mutable_start()->set_s(GetLengthbyRate(bound.boundary_type(i).s(),
64 bound.length(), lane_length));
65 if (i != bound.boundary_type_size() - 1) {
66 range->mutable_end()->set_s(GetLengthbyRate(
67 bound.boundary_type(i + 1).s(), bound.length(), lane_length));
68 } else {
69 range->mutable_end()->set_s(lane_length);
70 }
71 }
72}
73
74void InitNodeInfo(const Lane& lane, const std::string& road_id,
75 Node* const node) {
76 double lane_length = GetLaneLength(lane);
77 node->set_lane_id(lane.id().id());
78 node->set_road_id(road_id);
79 AddOutBoundary(lane.left_boundary(), lane_length, node->mutable_left_out());
80 AddOutBoundary(lane.right_boundary(), lane_length, node->mutable_right_out());
81 node->set_length(lane_length);
82 node->mutable_central_curve()->CopyFrom(lane.central_curve());
83 node->set_is_virtual(true);
84 if (!lane.has_junction_id() ||
85 lane.left_neighbor_forward_lane_id_size() > 0 ||
86 lane.right_neighbor_forward_lane_id_size() > 0) {
87 node->set_is_virtual(false);
88 }
89}
90
91void InitNodeCost(const Lane& lane, const RoutingConfig& routing_config,
92 Node* const node) {
93 double lane_length = GetLaneLength(lane);
94 double speed_limit =
95 lane.has_speed_limit() ? lane.speed_limit() : routing_config.base_speed();
96 double ratio = speed_limit >= routing_config.base_speed()
97 ? std::sqrt(routing_config.base_speed() / speed_limit)
98 : 1.0;
99 double cost = lane_length * ratio;
100 if (lane.has_turn()) {
101 if (lane.turn() == Lane::LEFT_TURN) {
102 cost += routing_config.left_turn_penalty();
103 } else if (lane.turn() == Lane::RIGHT_TURN) {
104 cost += routing_config.right_turn_penalty();
105 } else if (lane.turn() == Lane::U_TURN) {
106 cost += routing_config.uturn_penalty();
107 }
108 }
109 node->set_cost(cost);
110}
111
112} // namespace
113
114void GetPbNode(const hdmap::Lane& lane, const std::string& road_id,
115 const RoutingConfig& routingconfig, Node* const node) {
116 InitNodeInfo(lane, road_id, node);
117 InitNodeCost(lane, routingconfig, node);
118}
119
120} // namespace node_creator
121} // namespace routing
122} // namespace apollo
void GetPbNode(const hdmap::Lane &lane, const std::string &road_id, const RoutingConfig &routingconfig, Node *const node)
class register implement
Definition arena_queue.h:37
repeated LaneBoundaryType boundary_type