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;
69 double start_left_width = nearby_path_->GetRoadLeftWidth(start_s);
70 double start_right_width = nearby_path_->GetRoadRightWidth(start_s);
71 double end_left_width = nearby_path_->GetRoadLeftWidth(end_s);
72 double end_right_width = nearby_path_->GetRoadRightWidth(end_s);
73 double start_right_vec_cos = std::cos(start_point.
heading() - M_PI / 2);
74 double start_right_vec_sin = std::sin(start_point.
heading() - M_PI / 2);
75 double start_left_vec_cos = std::cos(start_point.
heading() + M_PI / 2);
76 double start_left_vec_sin = std::sin(start_point.
heading() + M_PI / 2);
77 double end_right_vec_cos = std::cos(end_point.
heading() - M_PI / 2);
78 double end_right_vec_sin = std::sin(end_point.
heading() - M_PI / 2);
79 double end_left_vec_cos = std::cos(end_point.
heading() + M_PI / 2);
80 double end_left_vec_sin = std::sin(end_point.
heading() + M_PI / 2);
82 Vec2d start_right =
Vec2d(start_right_width * start_right_vec_cos, start_right_width * start_right_vec_sin);
83 start_right = start_right + start_point;
84 Vec2d start_left =
Vec2d(start_left_width * start_left_vec_cos, start_left_width * start_left_vec_sin);
85 start_left = start_left + start_point;
86 Vec2d end_right =
Vec2d(end_right_width * end_right_vec_cos, end_right_width * end_right_vec_sin);
87 end_right = end_right + end_point;
88 Vec2d end_left =
Vec2d(end_left_width * end_left_vec_cos, end_left_width * end_left_vec_sin);
89 end_left = end_left + end_point;
93 origin_heading_ = nearby_path_->GetSmoothPoint(center_line_s).heading();
94 origin_point_.
set_x(left_top.
x());
95 origin_point_.
set_y(left_top.
y());
96 left_top -= origin_point_;
97 left_down -= origin_point_;
98 right_top -= origin_point_;
99 right_down -= origin_point_;
100 start_right -= origin_point_;
101 start_left -= origin_point_;
102 end_right -= origin_point_;
103 end_left -= origin_point_;
104 AINFO <<
"left_down x " << left_down.
x();
105 AINFO <<
"right_down x " << right_down.
x();
106 AINFO <<
"left_top x " << left_top.
x();
117 parking_spot_heading_ = (left_down - left_top).Angle();
118 double end_x = (left_top.
x() + right_top.
x()) / 2;
122 end_y = left_top.
y() + (left_down.
y() - left_top.
y()) / 4;
124 end_y = left_top.
y() + 3 * (left_down.
y() - left_top.
y()) / 4;
128 end_y = left_down.
y() + 3 * (left_top.
y() - left_down.
y()) / 4;
130 end_y = left_down.
y() + (left_top.
y() - left_down.
y()) / 4;
133 open_space_end_pose_.emplace_back(end_x);
134 open_space_end_pose_.emplace_back(end_y);
136 open_space_end_pose_.emplace_back(parking_spot_heading_);
140 open_space_end_pose_.emplace_back(0.0);
143 double x_min = std::min({start_left.
x(), start_right.
x()});
144 double x_max = std::max({end_left.
x(), end_right.
x()});
145 double y_min = std::min({left_down.
y(), start_right.
y(), start_left.
y()});
146 double y_max = std::max({left_down.
y(), start_right.
y(), start_left.
y()});
147 ROI_xy_boundary_.emplace_back(x_min);
148 ROI_xy_boundary_.emplace_back(x_max);
149 ROI_xy_boundary_.emplace_back(y_min);
150 ROI_xy_boundary_.emplace_back(y_max);
155 std::vector<Vec2d> left_boundary;
156 std::vector<Vec2d> down_boundary;
157 std::vector<Vec2d> right_boundary;
158 std::vector<Vec2d> up_boundary;
160 if (left_top_l < 0) {
161 start_right.
set_x(-left_top_l * start_right_vec_cos);
162 start_right.
set_y(-left_top_l * start_right_vec_sin);
163 start_right = start_right + start_point;
164 end_right.
set_x(-left_top_l * end_right_vec_cos);
165 end_right.
set_y(-left_top_l * end_right_vec_sin);
166 end_right = end_right + end_point;
167 start_right -= origin_point_;
168 end_right -= origin_point_;
171 left_boundary.push_back(start_right);
172 left_boundary.push_back(left_top);
173 left_boundary.push_back(left_down);
174 down_boundary.push_back(left_down);
175 down_boundary.push_back(right_down);
176 right_boundary.push_back(right_down);
177 right_boundary.push_back(right_top);
178 right_boundary.push_back(end_right);
179 up_boundary.push_back(end_left);
180 up_boundary.push_back(start_left);
182 start_left.
set_x(left_top_l * start_left_vec_cos);
183 start_left.
set_y(left_top_l * start_left_vec_sin);
184 start_left = start_left + start_point;
185 end_left.
set_x(left_top_l * end_left_vec_cos);
186 end_left.
set_y(left_top_l * end_left_vec_sin);
187 end_left = end_left + end_point;
188 start_left -= origin_point_;
189 end_left -= origin_point_;
192 left_boundary.push_back(end_left);
193 left_boundary.push_back(left_top);
194 left_boundary.push_back(left_down);
195 down_boundary.push_back(left_down);
196 down_boundary.push_back(right_down);
197 right_boundary.push_back(right_down);
198 right_boundary.push_back(right_top);
199 right_boundary.push_back(start_left);
200 up_boundary.push_back(start_right);
201 up_boundary.push_back(end_right);
203 ROI_parking_boundary_.emplace_back(left_boundary);
204 ROI_parking_boundary_.emplace_back(down_boundary);
205 ROI_parking_boundary_.emplace_back(right_boundary);
206 ROI_parking_boundary_.emplace_back(up_boundary);
214 Vec2d left_top = target_parking_spot_->polygon().points().at(3);
215 Vec2d left_down = target_parking_spot_->polygon().points().at(0);
216 Vec2d right_top = target_parking_spot_->polygon().points().at(2);
217 Vec2d right_down = target_parking_spot_->polygon().points().at(1);
218 double left_top_s = 0.0;
219 double left_top_l = 0.0;
220 double right_top_s = 0.0;
221 double right_top_l = 0.0;
222 if (!(nearby_path_->GetProjection(left_top, &left_top_s, &left_top_l)
223 && nearby_path_->GetProjection(right_top, &right_top_s, &right_top_l))) {
224 AERROR <<
"fail to get parking spot points' projections "
229 double center_line_s = (left_top_s + right_top_s) / 2;
234 double start_left_width = nearby_path_->GetRoadLeftWidth(start_s);
235 double start_right_width = nearby_path_->GetRoadRightWidth(start_s);
236 double end_left_width = nearby_path_->GetRoadLeftWidth(end_s);
237 double end_right_width = nearby_path_->GetRoadRightWidth(end_s);
239 double start_right_vec_cos = std::cos(start_point.
heading() - M_PI / 2);
240 double start_right_vec_sin = std::sin(start_point.
heading() - M_PI / 2);
241 double start_left_vec_cos = std::cos(start_point.
heading() + M_PI / 2);
242 double start_left_vec_sin = std::sin(start_point.
heading() + M_PI / 2);
243 double end_right_vec_cos = std::cos(end_point.
heading() - M_PI / 2);
244 double end_right_vec_sin = std::sin(end_point.
heading() - M_PI / 2);
245 double end_left_vec_cos = std::cos(end_point.
heading() + M_PI / 2);
246 double end_left_vec_sin = std::sin(end_point.
heading() + M_PI / 2);
248 Vec2d start_right =
Vec2d(start_right_width * start_right_vec_cos, start_right_width * start_right_vec_sin);
249 start_right = start_right + start_point;
250 Vec2d start_left =
Vec2d(start_left_width * start_left_vec_cos, start_left_width * start_left_vec_sin);
251 start_left = start_left + start_point;
252 Vec2d end_right =
Vec2d(end_right_width * end_right_vec_cos, end_right_width * end_right_vec_sin);
253 end_right = end_right + end_point;
254 Vec2d end_left =
Vec2d(end_left_width * end_left_vec_cos, end_left_width * end_left_vec_sin);
255 end_left = end_left + end_point;
258 double heading = (left_down - left_top).Angle();
259 double x = (left_top.
x() + right_top.
x()) / 2;
262 y = left_top.
y() + (-left_top.
y() + left_down.
y()) / 4;
264 y = left_down.
y() + 3 * (left_top.
y() - left_down.
y()) / 4;
266 open_space_end_pose_.emplace_back(x);
267 open_space_end_pose_.emplace_back(y);
268 open_space_end_pose_.emplace_back(heading);
269 open_space_end_pose_.emplace_back(0.0);
272 double x_min = std::min({start_left.
x(), start_right.
x()});
273 double x_max = std::max({end_left.
x(), end_right.
x()});
274 double y_min = std::min({left_down.
y(), start_right.
y(), start_left.
y()});
275 double y_max = std::max({left_down.
y(), start_right.
y(), start_left.
y()});
276 ROI_xy_boundary_.emplace_back(x_min);
277 ROI_xy_boundary_.emplace_back(x_max);
278 ROI_xy_boundary_.emplace_back(y_min);
279 ROI_xy_boundary_.emplace_back(y_max);
284 std::vector<Vec2d> left_boundary;
285 std::vector<Vec2d> down_boundary;
286 std::vector<Vec2d> right_boundary;
287 std::vector<Vec2d> up_boundary;
289 if (left_top_l < 0) {
290 start_right.
set_x(-left_top_l * start_right_vec_cos);
291 start_right.
set_y(-left_top_l * start_right_vec_sin);
292 start_right = start_right + start_point;
293 end_right.
set_x(-left_top_l * end_right_vec_cos);
294 end_right.
set_y(-left_top_l * end_right_vec_sin);
295 end_right = end_right + end_point;
296 left_boundary.push_back(start_right);
297 left_boundary.push_back(left_top);
298 left_boundary.push_back(left_down);
299 down_boundary.push_back(left_down);
300 down_boundary.push_back(right_down);
301 right_boundary.push_back(right_down);
302 right_boundary.push_back(right_top);
303 right_boundary.push_back(end_right);
304 up_boundary.push_back(end_left);
305 up_boundary.push_back(start_left);
307 start_left.
set_x(left_top_l * start_left_vec_cos);
308 start_left.
set_y(left_top_l * start_left_vec_sin);
309 start_left = start_left + start_point;
310 end_left.
set_x(left_top_l * end_left_vec_cos);
311 end_left.
set_y(left_top_l * end_left_vec_sin);
312 end_left = end_left + end_point;
313 left_boundary.push_back(end_left);
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(start_left);
321 up_boundary.push_back(start_right);
322 up_boundary.push_back(end_right);
324 No_rotate_ROI_parking_boundary_.emplace_back(left_boundary);
325 No_rotate_ROI_parking_boundary_.emplace_back(down_boundary);
326 No_rotate_ROI_parking_boundary_.emplace_back(right_boundary);
327 No_rotate_ROI_parking_boundary_.emplace_back(up_boundary);
368 bool LoadMap(
const std::string& lane_id,
const std::string& parking_id) {
369 std::cout << lane_id << std::endl;
370 std::cout << parking_id << std::endl;
373 nearby_lane_id.set_id(lane_id);
375 target_lane_id.set_id(parking_id);
376 auto nearby_lane = map_ptr->GetLaneById(nearby_lane_id);
377 if (nearby_lane ==
nullptr) {
378 std::cout <<
"No such lane found " << lane_id << std::endl;
381 std::cout <<
"the lane found is " << nearby_lane->
id().id() << std::endl;
383 =
LaneSegment(nearby_lane, nearby_lane->accumulate_s().front(), nearby_lane->accumulate_s().back());
384 std::vector<LaneSegment> segments_vector;
385 segments_vector.push_back(nearby_lanesegment);
386 nearby_path_ = std::unique_ptr<Path>(
new Path(segments_vector));
387 const auto& parking_space_overlaps = nearby_path_->parking_space_overlaps();
388 if (parking_space_overlaps.empty()) {
389 std::cout <<
"No parking overlaps found on the lane requested" << std::endl;
392 for (
const auto parking_overlap : parking_space_overlaps) {
393 if (parking_overlap.object_id != parking_id) {
394 target_parking_spot_ = map_ptr->GetParkingSpaceById(target_lane_id);
395 std::cout <<
"parking_overlap.object_id is " << target_lane_id.
id() << std::endl;
398 if (target_parking_spot_ ==
nullptr) {
399 std::cout <<
"No such parking spot found " << parking_id << std::endl;
402 parking_spot_box_ = target_parking_spot_->polygon();