49 Vec2d left_top = target_parking_spot_->polygon().points().at(3);
50 Vec2d left_down = target_parking_spot_->polygon().points().at(0);
51 Vec2d right_top = target_parking_spot_->polygon().points().at(2);
52 Vec2d right_down = target_parking_spot_->polygon().points().at(1);
53 double left_top_s = 0.0;
54 double left_top_l = 0.0;
55 double right_top_s = 0.0;
56 double right_top_l = 0.0;
57 if (!(nearby_path_->GetProjection(left_top, &left_top_s, &left_top_l) &&
58 nearby_path_->GetProjection(right_top, &right_top_s, &right_top_l))) {
59 AERROR <<
"fail to get parking spot points' projections "
64 double center_line_s = (left_top_s + right_top_s) / 2;
73 double start_left_width = nearby_path_->GetRoadLeftWidth(start_s);
74 double start_right_width = nearby_path_->GetRoadRightWidth(start_s);
75 double end_left_width = nearby_path_->GetRoadLeftWidth(end_s);
76 double end_right_width = nearby_path_->GetRoadRightWidth(end_s);
77 double start_right_vec_cos = std::cos(start_point.
heading() - M_PI / 2);
78 double start_right_vec_sin = std::sin(start_point.
heading() - M_PI / 2);
79 double start_left_vec_cos = std::cos(start_point.
heading() + M_PI / 2);
80 double start_left_vec_sin = std::sin(start_point.
heading() + M_PI / 2);
81 double end_right_vec_cos = std::cos(end_point.
heading() - M_PI / 2);
82 double end_right_vec_sin = std::sin(end_point.
heading() - M_PI / 2);
83 double end_left_vec_cos = std::cos(end_point.
heading() + M_PI / 2);
84 double end_left_vec_sin = std::sin(end_point.
heading() + M_PI / 2);
86 Vec2d start_right =
Vec2d(start_right_width * start_right_vec_cos,
87 start_right_width * start_right_vec_sin);
88 start_right = start_right + start_point;
89 Vec2d start_left =
Vec2d(start_left_width * start_left_vec_cos,
90 start_left_width * start_left_vec_sin);
91 start_left = start_left + start_point;
92 Vec2d end_right =
Vec2d(end_right_width * end_right_vec_cos,
93 end_right_width * end_right_vec_sin);
94 end_right = end_right + end_point;
95 Vec2d end_left =
Vec2d(end_left_width * end_left_vec_cos,
96 end_left_width * end_left_vec_sin);
97 end_left = end_left + end_point;
101 origin_heading_ = nearby_path_->GetSmoothPoint(center_line_s).heading();
102 origin_point_.
set_x(left_top.
x());
103 origin_point_.
set_y(left_top.
y());
104 left_top -= origin_point_;
105 left_down -= origin_point_;
106 right_top -= origin_point_;
107 right_down -= origin_point_;
108 start_right -= origin_point_;
109 start_left -= origin_point_;
110 end_right -= origin_point_;
111 end_left -= origin_point_;
112 AINFO <<
"left_down x " << left_down.
x();
113 AINFO <<
"right_down x " << right_down.
x();
114 AINFO <<
"left_top x " << left_top.
x();
125 parking_spot_heading_ = (left_down - left_top).Angle();
126 double end_x = (left_top.
x() + right_top.
x()) / 2;
130 end_y = left_top.
y() + (left_down.
y() - left_top.
y()) / 4;
132 end_y = left_top.
y() + 3 * (left_down.
y() - left_top.
y()) / 4;
136 end_y = left_down.
y() + 3 * (left_top.
y() - left_down.
y()) / 4;
138 end_y = left_down.
y() + (left_top.
y() - left_down.
y()) / 4;
141 open_space_end_pose_.emplace_back(end_x);
142 open_space_end_pose_.emplace_back(end_y);
144 open_space_end_pose_.emplace_back(parking_spot_heading_);
146 open_space_end_pose_.emplace_back(
149 open_space_end_pose_.emplace_back(0.0);
152 double x_min = std::min({start_left.
x(), start_right.
x()});
153 double x_max = std::max({end_left.
x(), end_right.
x()});
154 double y_min = std::min({left_down.
y(), start_right.
y(), start_left.
y()});
155 double y_max = std::max({left_down.
y(), start_right.
y(), start_left.
y()});
156 ROI_xy_boundary_.emplace_back(x_min);
157 ROI_xy_boundary_.emplace_back(x_max);
158 ROI_xy_boundary_.emplace_back(y_min);
159 ROI_xy_boundary_.emplace_back(y_max);
164 std::vector<Vec2d> left_boundary;
165 std::vector<Vec2d> down_boundary;
166 std::vector<Vec2d> right_boundary;
167 std::vector<Vec2d> up_boundary;
169 if (left_top_l < 0) {
170 start_right.
set_x(-left_top_l * start_right_vec_cos);
171 start_right.
set_y(-left_top_l * start_right_vec_sin);
172 start_right = start_right + start_point;
173 end_right.
set_x(-left_top_l * end_right_vec_cos);
174 end_right.
set_y(-left_top_l * end_right_vec_sin);
175 end_right = end_right + end_point;
176 start_right -= origin_point_;
177 end_right -= origin_point_;
180 left_boundary.push_back(start_right);
181 left_boundary.push_back(left_top);
182 left_boundary.push_back(left_down);
183 down_boundary.push_back(left_down);
184 down_boundary.push_back(right_down);
185 right_boundary.push_back(right_down);
186 right_boundary.push_back(right_top);
187 right_boundary.push_back(end_right);
188 up_boundary.push_back(end_left);
189 up_boundary.push_back(start_left);
191 start_left.
set_x(left_top_l * start_left_vec_cos);
192 start_left.
set_y(left_top_l * start_left_vec_sin);
193 start_left = start_left + start_point;
194 end_left.
set_x(left_top_l * end_left_vec_cos);
195 end_left.
set_y(left_top_l * end_left_vec_sin);
196 end_left = end_left + end_point;
197 start_left -= origin_point_;
198 end_left -= origin_point_;
201 left_boundary.push_back(end_left);
202 left_boundary.push_back(left_top);
203 left_boundary.push_back(left_down);
204 down_boundary.push_back(left_down);
205 down_boundary.push_back(right_down);
206 right_boundary.push_back(right_down);
207 right_boundary.push_back(right_top);
208 right_boundary.push_back(start_left);
209 up_boundary.push_back(start_right);
210 up_boundary.push_back(end_right);
212 ROI_parking_boundary_.emplace_back(left_boundary);
213 ROI_parking_boundary_.emplace_back(down_boundary);
214 ROI_parking_boundary_.emplace_back(right_boundary);
215 ROI_parking_boundary_.emplace_back(up_boundary);
223 Vec2d left_top = target_parking_spot_->polygon().points().at(3);
224 Vec2d left_down = target_parking_spot_->polygon().points().at(0);
225 Vec2d right_top = target_parking_spot_->polygon().points().at(2);
226 Vec2d right_down = target_parking_spot_->polygon().points().at(1);
227 double left_top_s = 0.0;
228 double left_top_l = 0.0;
229 double right_top_s = 0.0;
230 double right_top_l = 0.0;
231 if (!(nearby_path_->GetProjection(left_top, &left_top_s, &left_top_l) &&
232 nearby_path_->GetProjection(right_top, &right_top_s, &right_top_l))) {
233 AERROR <<
"fail to get parking spot points' projections "
238 double center_line_s = (left_top_s + right_top_s) / 2;
247 double start_left_width = nearby_path_->GetRoadLeftWidth(start_s);
248 double start_right_width = nearby_path_->GetRoadRightWidth(start_s);
249 double end_left_width = nearby_path_->GetRoadLeftWidth(end_s);
250 double end_right_width = nearby_path_->GetRoadRightWidth(end_s);
252 double start_right_vec_cos = std::cos(start_point.
heading() - M_PI / 2);
253 double start_right_vec_sin = std::sin(start_point.
heading() - M_PI / 2);
254 double start_left_vec_cos = std::cos(start_point.
heading() + M_PI / 2);
255 double start_left_vec_sin = std::sin(start_point.
heading() + M_PI / 2);
256 double end_right_vec_cos = std::cos(end_point.
heading() - M_PI / 2);
257 double end_right_vec_sin = std::sin(end_point.
heading() - M_PI / 2);
258 double end_left_vec_cos = std::cos(end_point.
heading() + M_PI / 2);
259 double end_left_vec_sin = std::sin(end_point.
heading() + M_PI / 2);
261 Vec2d start_right =
Vec2d(start_right_width * start_right_vec_cos,
262 start_right_width * start_right_vec_sin);
263 start_right = start_right + start_point;
264 Vec2d start_left =
Vec2d(start_left_width * start_left_vec_cos,
265 start_left_width * start_left_vec_sin);
266 start_left = start_left + start_point;
267 Vec2d end_right =
Vec2d(end_right_width * end_right_vec_cos,
268 end_right_width * end_right_vec_sin);
269 end_right = end_right + end_point;
270 Vec2d end_left =
Vec2d(end_left_width * end_left_vec_cos,
271 end_left_width * end_left_vec_sin);
272 end_left = end_left + end_point;
275 double heading = (left_down - left_top).Angle();
276 double x = (left_top.
x() + right_top.
x()) / 2;
279 y = left_top.
y() + (-left_top.
y() + left_down.
y()) / 4;
281 y = left_down.
y() + 3 * (left_top.
y() - left_down.
y()) / 4;
283 open_space_end_pose_.emplace_back(x);
284 open_space_end_pose_.emplace_back(y);
285 open_space_end_pose_.emplace_back(heading);
286 open_space_end_pose_.emplace_back(0.0);
289 double x_min = std::min({start_left.
x(), start_right.
x()});
290 double x_max = std::max({end_left.
x(), end_right.
x()});
291 double y_min = std::min({left_down.
y(), start_right.
y(), start_left.
y()});
292 double y_max = std::max({left_down.
y(), start_right.
y(), start_left.
y()});
293 ROI_xy_boundary_.emplace_back(x_min);
294 ROI_xy_boundary_.emplace_back(x_max);
295 ROI_xy_boundary_.emplace_back(y_min);
296 ROI_xy_boundary_.emplace_back(y_max);
301 std::vector<Vec2d> left_boundary;
302 std::vector<Vec2d> down_boundary;
303 std::vector<Vec2d> right_boundary;
304 std::vector<Vec2d> up_boundary;
306 if (left_top_l < 0) {
307 start_right.
set_x(-left_top_l * start_right_vec_cos);
308 start_right.
set_y(-left_top_l * start_right_vec_sin);
309 start_right = start_right + start_point;
310 end_right.
set_x(-left_top_l * end_right_vec_cos);
311 end_right.
set_y(-left_top_l * end_right_vec_sin);
312 end_right = end_right + end_point;
313 left_boundary.push_back(start_right);
314 left_boundary.push_back(left_top);
315 left_boundary.push_back(left_down);
316 down_boundary.push_back(left_down);
317 down_boundary.push_back(right_down);
318 right_boundary.push_back(right_down);
319 right_boundary.push_back(right_top);
320 right_boundary.push_back(end_right);
321 up_boundary.push_back(end_left);
322 up_boundary.push_back(start_left);
324 start_left.
set_x(left_top_l * start_left_vec_cos);
325 start_left.
set_y(left_top_l * start_left_vec_sin);
326 start_left = start_left + start_point;
327 end_left.
set_x(left_top_l * end_left_vec_cos);
328 end_left.
set_y(left_top_l * end_left_vec_sin);
329 end_left = end_left + end_point;
330 left_boundary.push_back(end_left);
331 left_boundary.push_back(left_top);
332 left_boundary.push_back(left_down);
333 down_boundary.push_back(left_down);
334 down_boundary.push_back(right_down);
335 right_boundary.push_back(right_down);
336 right_boundary.push_back(right_top);
337 right_boundary.push_back(start_left);
338 up_boundary.push_back(start_right);
339 up_boundary.push_back(end_right);
341 No_rotate_ROI_parking_boundary_.emplace_back(left_boundary);
342 No_rotate_ROI_parking_boundary_.emplace_back(down_boundary);
343 No_rotate_ROI_parking_boundary_.emplace_back(right_boundary);
344 No_rotate_ROI_parking_boundary_.emplace_back(up_boundary);
391 bool LoadMap(
const std::string& lane_id,
const std::string& parking_id) {
392 std::cout << lane_id << std::endl;
393 std::cout << parking_id << std::endl;
396 nearby_lane_id.set_id(lane_id);
398 target_lane_id.set_id(parking_id);
399 auto nearby_lane = map_ptr->GetLaneById(nearby_lane_id);
400 if (nearby_lane ==
nullptr) {
401 std::cout <<
"No such lane found " << lane_id << std::endl;
404 std::cout <<
"the lane found is " << nearby_lane->
id().id() << std::endl;
407 nearby_lane->accumulate_s().front(),
408 nearby_lane->accumulate_s().back());
409 std::vector<LaneSegment> segments_vector;
410 segments_vector.push_back(nearby_lanesegment);
411 nearby_path_ = std::unique_ptr<Path>(
new Path(segments_vector));
412 const auto& parking_space_overlaps = nearby_path_->parking_space_overlaps();
413 if (parking_space_overlaps.empty()) {
414 std::cout <<
"No parking overlaps found on the lane requested"
418 for (
const auto parking_overlap : parking_space_overlaps) {
419 if (parking_overlap.object_id != parking_id) {
420 target_parking_spot_ = map_ptr->GetParkingSpaceById(target_lane_id);
421 std::cout <<
"parking_overlap.object_id is "
422 << target_lane_id.
id() << std::endl;
425 if (target_parking_spot_ ==
nullptr) {
426 std::cout <<
"No such parking spot found " << parking_id << std::endl;
429 parking_spot_box_ = target_parking_spot_->polygon();