Apollo 10.0
自动驾驶开放平台
common.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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
19namespace apollo {
20namespace planning {
21namespace util {
22
24
25/*
26 * @brief: build virtual obstacle of stop wall, and add STOP decision
27 */
28int BuildStopDecision(const std::string& stop_wall_id, const double stop_line_s,
29 const double stop_distance,
30 const StopReasonCode& stop_reason_code,
31 const std::vector<std::string>& wait_for_obstacles,
32 const std::string& decision_tag, Frame* const frame,
33 ReferenceLineInfo* const reference_line_info,
34 double stop_wall_width) {
35 CHECK_NOTNULL(frame);
36 CHECK_NOTNULL(reference_line_info);
37
38 // check
39 const auto& reference_line = reference_line_info->reference_line();
40 if (!WithinBound(0.0, reference_line.Length(), stop_line_s)) {
41 AERROR << "stop_line_s[" << stop_line_s << "] is not on reference line";
42 return 0;
43 }
44
45 // create virtual stop wall
46 const auto* obstacle =
47 frame->CreateStopObstacle(reference_line_info, stop_wall_id,
48 stop_line_s, stop_wall_width);
49 if (!obstacle) {
50 AERROR << "Failed to create obstacle [" << stop_wall_id << "]";
51 return -1;
52 }
53 const Obstacle* stop_wall = reference_line_info->AddObstacle(obstacle);
54 if (!stop_wall) {
55 AERROR << "Failed to add obstacle[" << stop_wall_id << "]";
56 return -1;
57 }
58
59 // build stop decision
60 const double stop_s = stop_line_s - stop_distance;
61 const auto& stop_point = reference_line.GetReferencePoint(stop_s);
62 const double stop_heading =
63 reference_line.GetReferencePoint(stop_s).heading();
64
65 ObjectDecisionType stop;
66 auto* stop_decision = stop.mutable_stop();
67 stop_decision->set_reason_code(stop_reason_code);
68 stop_decision->set_distance_s(-stop_distance);
69 stop_decision->set_stop_heading(stop_heading);
70 stop_decision->mutable_stop_point()->set_x(stop_point.x());
71 stop_decision->mutable_stop_point()->set_y(stop_point.y());
72 stop_decision->mutable_stop_point()->set_z(0.0);
73
74 for (size_t i = 0; i < wait_for_obstacles.size(); ++i) {
75 stop_decision->add_wait_for_obstacle(wait_for_obstacles[i]);
76 }
77
78 auto* path_decision = reference_line_info->path_decision();
79 path_decision->AddLongitudinalDecision(decision_tag, stop_wall->Id(), stop);
80
81 return 0;
82}
83
84int BuildStopDecision(const std::string& stop_wall_id,
85 const std::string& lane_id, const double lane_s,
86 const double stop_distance,
87 const StopReasonCode& stop_reason_code,
88 const std::vector<std::string>& wait_for_obstacles,
89 const std::string& decision_tag, Frame* const frame,
90 ReferenceLineInfo* const reference_line_info) {
91 CHECK_NOTNULL(frame);
92 CHECK_NOTNULL(reference_line_info);
93
94 const auto& reference_line = reference_line_info->reference_line();
95
96 // create virtual stop wall
97 const auto* obstacle =
98 frame->CreateStopObstacle(stop_wall_id, lane_id, lane_s);
99 if (!obstacle) {
100 AERROR << "Failed to create obstacle [" << stop_wall_id << "]";
101 return -1;
102 }
103
104 const Obstacle* stop_wall = reference_line_info->AddObstacle(obstacle);
105 if (!stop_wall) {
106 AERROR << "Failed to create obstacle for: " << stop_wall_id;
107 return -1;
108 }
109
110 const auto& stop_wall_box = stop_wall->PerceptionBoundingBox();
111 if (!reference_line.IsOnLane(stop_wall_box.center())) {
112 ADEBUG << "stop point is not on lane. SKIP STOP decision";
113 return 0;
114 }
115
116 // build stop decision
117 auto stop_point = reference_line.GetReferencePoint(
118 stop_wall->PerceptionSLBoundary().start_s() - stop_distance);
119
120 ObjectDecisionType stop;
121 auto* stop_decision = stop.mutable_stop();
122 stop_decision->set_reason_code(stop_reason_code);
123 stop_decision->set_distance_s(-stop_distance);
124 stop_decision->set_stop_heading(stop_point.heading());
125 stop_decision->mutable_stop_point()->set_x(stop_point.x());
126 stop_decision->mutable_stop_point()->set_y(stop_point.y());
127 stop_decision->mutable_stop_point()->set_z(0.0);
128
129 auto* path_decision = reference_line_info->path_decision();
130 path_decision->AddLongitudinalDecision(decision_tag, stop_wall->Id(), stop);
131
132 return 0;
133}
134
135} // namespace util
136} // namespace planning
137} // namespace apollo
Frame holds all data for one planning cycle.
Definition frame.h:62
const Obstacle * CreateStopObstacle(ReferenceLineInfo *const reference_line_info, const std::string &obstacle_id, const double obstacle_s, double stop_wall_width=4.0)
: create static virtual object with lane width, mainly used for virtual stop wall
Definition frame.cc:214
This is the class that associates an Obstacle with its path properties.
Definition obstacle.h:62
const std::string & Id() const
Definition obstacle.h:75
const SLBoundary & PerceptionSLBoundary() const
Definition obstacle.cc:694
const common::math::Box2d & PerceptionBoundingBox() const
Definition obstacle.h:90
bool AddLongitudinalDecision(const std::string &tag, const std::string &object_id, const ObjectDecisionType &decision)
ReferenceLineInfo holds all data for one reference line.
const ReferenceLine & reference_line() const
Obstacle * AddObstacle(const Obstacle *obstacle)
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
bool WithinBound(T start, T end, T value)
Definition util.h:62
int BuildStopDecision(const std::string &stop_wall_id, const double stop_line_s, const double stop_distance, const StopReasonCode &stop_reason_code, const std::vector< std::string > &wait_for_obstacles, const std::string &decision_tag, Frame *const frame, ReferenceLineInfo *const reference_line_info, double stop_wall_width)
Definition common.cc:28
class register implement
Definition arena_queue.h:37