Apollo 10.0
自动驾驶开放平台
open_space_pre_stop_decider.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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
22
23#include <memory>
24#include <string>
25#include <vector>
26
31
32namespace apollo {
33namespace planning {
34
40
42 const std::string& config_dir, const std::string& name,
43 const std::shared_ptr<DependencyInjector>& injector) {
44 if (!Decider::Init(config_dir, name, injector)) {
45 return false;
46 }
47 // Load the config this task.
48 bool res = Decider::LoadConfig<OpenSpacePreStopDeciderConfig>(&config_);
49 AINFO << "Load config:" << config_.DebugString();
50 return res;
51}
52
53Status OpenSpacePreStopDecider::Process(
54 Frame* frame, ReferenceLineInfo* reference_line_info) {
55 CHECK_NOTNULL(frame);
56 CHECK_NOTNULL(reference_line_info);
57 double target_s = 0.0;
58 const auto& stop_type = config_.stop_type();
59 switch (stop_type) {
61 if (!CheckParkingSpotPreStop(frame, reference_line_info, &target_s)) {
62 const std::string msg = "Checking parking spot pre stop fails";
63 AERROR << msg;
64 return Status(ErrorCode::PLANNING_ERROR, msg);
65 }
66 SetParkingSpotStopFence(target_s, frame, reference_line_info);
67 break;
69 if (!CheckPullOverPreStop(frame, reference_line_info, &target_s)) {
70 const std::string msg = "Checking pull over pre stop fails";
71 AERROR << msg;
72 return Status(ErrorCode::PLANNING_ERROR, msg);
73 }
74 SetPullOverStopFence(target_s, frame, reference_line_info);
75 break;
76 default:
77 const std::string msg = "This stop type not implemented";
78 AERROR << msg;
79 return Status(ErrorCode::PLANNING_ERROR, msg);
80 }
81 return Status::OK();
82}
83
84bool OpenSpacePreStopDecider::CheckPullOverPreStop(
85 Frame* const frame, ReferenceLineInfo* const reference_line_info,
86 double* target_s) {
87 *target_s = 0.0;
88 const auto& pull_over_status =
89 injector_->planning_context()->planning_status().pull_over();
90 if (pull_over_status.has_position() && pull_over_status.position().has_x() &&
91 pull_over_status.position().has_y()) {
92 common::SLPoint pull_over_sl;
93 const auto& reference_line = reference_line_info->reference_line();
94 reference_line.XYToSL(pull_over_status.position(), &pull_over_sl);
95 *target_s = pull_over_sl.s();
96 }
97 return true;
98}
99
100bool OpenSpacePreStopDecider::CheckParkingSpotPreStop(
101 Frame* const frame, ReferenceLineInfo* const reference_line_info,
102 double* target_s) {
103 const auto& target_parking_spot_id =
104 frame->open_space_info().target_parking_spot_id();
105 const auto& nearby_path = reference_line_info->reference_line().map_path();
106 if (target_parking_spot_id.empty()) {
107 AERROR << "no target parking spot id found when setting pre stop fence";
108 return false;
109 }
110
111 double target_area_center_s = 0.0;
112 bool target_area_found = false;
113 const auto& parking_space_overlaps = nearby_path.parking_space_overlaps();
114 ParkingSpaceInfoConstPtr target_parking_spot_ptr;
115 const hdmap::HDMap* hdmap = hdmap::HDMapUtil::BaseMapPtr();
116 for (const auto& parking_overlap : parking_space_overlaps) {
117 if (parking_overlap.object_id == target_parking_spot_id) {
118 // TODO(Jinyun) parking overlap s are wrong on map, not usable
119 // target_area_center_s =
120 // (parking_overlap.start_s + parking_overlap.end_s) / 2.0;
121 hdmap::Id id;
122 id.set_id(parking_overlap.object_id);
123 target_parking_spot_ptr = hdmap->GetParkingSpaceById(id);
124 Vec2d left_bottom_point =
125 target_parking_spot_ptr->polygon().points().at(0);
126 Vec2d right_bottom_point =
127 target_parking_spot_ptr->polygon().points().at(1);
128 Vec2d right_up_point = target_parking_spot_ptr->polygon().points().at(2);
129 Vec2d left_up_point = target_parking_spot_ptr->polygon().points().at(3);
130 Vec2d center_point = (left_bottom_point + right_bottom_point +
131 right_up_point + left_up_point) /
132 4.0;
133 double center_l;
134 nearby_path.GetNearestPoint(center_point, &target_area_center_s,
135 &center_l);
136 target_area_found = true;
137 }
138 }
139
140 if (!target_area_found) {
141 AERROR << "no target parking spot found on reference line";
142 return false;
143 }
144 *target_s = target_area_center_s;
145 return true;
146}
147
148void OpenSpacePreStopDecider::SetParkingSpotStopFence(
149 const double target_s, Frame* const frame,
150 ReferenceLineInfo* const reference_line_info) {
151 const auto& nearby_path = reference_line_info->reference_line().map_path();
152 const double adc_front_edge_s = reference_line_info->AdcSlBoundary().end_s();
153 const double front_edge_to_center = common::VehicleConfigHelper::Instance()
154 ->GetConfig()
155 .vehicle_param()
156 .front_edge_to_center();
157 double ego_s = adc_front_edge_s - front_edge_to_center;
158 const VehicleState& vehicle_state = frame->vehicle_state();
159 double stop_line_s = 0.0;
160 double stop_distance_to_target = config_.stop_distance_to_target();
161 double static_linear_velocity_epsilon = 1.0e-2;
162 static constexpr double kStopBuffer = 0.2;
163 CHECK_GE(stop_distance_to_target, 1.0e-8);
164 stop_line_s =
165 target_s + front_edge_to_center + config_.stop_buffer_to_target();
166 const std::string stop_wall_id = OPEN_SPACE_STOP_ID;
167 std::vector<std::string> wait_for_obstacles;
168 frame->mutable_open_space_info()->set_open_space_pre_stop_fence_s(
169 stop_line_s);
170 util::BuildStopDecision(stop_wall_id, stop_line_s, 0.0,
171 StopReasonCode::STOP_REASON_PRE_OPEN_SPACE_STOP,
172 wait_for_obstacles, "OpenSpacePreStopDecider", frame,
173 reference_line_info);
174}
175
176void OpenSpacePreStopDecider::SetPullOverStopFence(
177 const double target_s, Frame* const frame,
178 ReferenceLineInfo* const reference_line_info) {
179 const auto& nearby_path = reference_line_info->reference_line().map_path();
180 const double adc_front_edge_s = reference_line_info->AdcSlBoundary().end_s();
181 const VehicleState& vehicle_state = frame->vehicle_state();
182 double stop_line_s = 0.0;
183 double stop_distance_to_target = config_.stop_distance_to_target();
184 double static_linear_velocity_epsilon = 1.0e-2;
185 CHECK_GE(stop_distance_to_target, 1.0e-8);
186 double target_vehicle_offset = target_s - adc_front_edge_s;
187 if (target_vehicle_offset > stop_distance_to_target) {
188 stop_line_s = target_s - stop_distance_to_target;
189 } else {
190 if (!frame->open_space_info().pre_stop_rightaway_flag()) {
191 // TODO(Jinyun) Use constant comfortable deacceleration rather than
192 // distance by config to set stop fence
193 stop_line_s = adc_front_edge_s + config_.rightaway_stop_distance();
194 if (std::abs(vehicle_state.linear_velocity()) <
195 static_linear_velocity_epsilon) {
196 stop_line_s = adc_front_edge_s;
197 }
198 *(frame->mutable_open_space_info()->mutable_pre_stop_rightaway_point()) =
199 nearby_path.GetSmoothPoint(stop_line_s);
200 frame->mutable_open_space_info()->set_pre_stop_rightaway_flag(true);
201 } else {
202 double stop_point_s = 0.0;
203 double stop_point_l = 0.0;
204 nearby_path.GetNearestPoint(
205 frame->open_space_info().pre_stop_rightaway_point(), &stop_point_s,
206 &stop_point_l);
207 stop_line_s = stop_point_s;
208 }
209 }
210
211 const std::string stop_wall_id = OPEN_SPACE_STOP_ID;
212 std::vector<std::string> wait_for_obstacles;
213 frame->mutable_open_space_info()->set_open_space_pre_stop_fence_s(
214 stop_line_s);
215 util::BuildStopDecision(stop_wall_id, stop_line_s, 0.0,
216 StopReasonCode::STOP_REASON_PRE_OPEN_SPACE_STOP,
217 wait_for_obstacles, "OpenSpacePreStopDecider", frame,
218 reference_line_info);
219}
220} // namespace planning
221} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
static const HDMap * BaseMapPtr()
Frame holds all data for one planning cycle.
Definition frame.h:62
bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
ReferenceLineInfo holds all data for one reference line.
std::shared_ptr< DependencyInjector > injector_
Definition task.h:59
virtual bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector)
Definition task.cc:40
Planning module main class.
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
std::shared_ptr< const ParkingSpaceInfo > ParkingSpaceInfoConstPtr
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