46 {
47
48
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 "
60 "on reference line";
61 return false;
62 }
63
64 double center_line_s = (left_top_s + right_top_s) / 2;
67 hdmap::MapPathPoint end_point = nearby_path_->GetSmoothPoint(end_s);
68 hdmap::MapPathPoint start_point = nearby_path_->GetSmoothPoint(start_s);
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);
81
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;
90
91
92
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();
107 left_top.SelfRotate(-origin_heading_);
108 left_down.SelfRotate(-origin_heading_);
109 right_top.SelfRotate(-origin_heading_);
110 right_down.SelfRotate(-origin_heading_);
111 start_right.SelfRotate(-origin_heading_);
112 start_left.SelfRotate(-origin_heading_);
113 end_right.SelfRotate(-origin_heading_);
114 end_left.SelfRotate(-origin_heading_);
115
116
117 parking_spot_heading_ = (left_down - left_top).Angle();
118 double end_x = (left_top.x() + right_top.x()) / 2;
119 double end_y = 0.0;
122 end_y = left_top.y() + (left_down.y() - left_top.y()) / 4;
123 } else {
124 end_y = left_top.y() + 3 * (left_down.y() - left_top.y()) / 4;
125 }
126 } else {
128 end_y = left_down.y() + 3 * (left_top.y() - left_down.y()) / 4;
129 } else {
130 end_y = left_down.y() + (left_top.y() - left_down.y()) / 4;
131 }
132 }
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_);
137 } else {
139 }
140 open_space_end_pose_.emplace_back(0.0);
141
142
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);
151
152
153
154
155 std::vector<Vec2d> left_boundary;
156 std::vector<Vec2d> down_boundary;
157 std::vector<Vec2d> right_boundary;
158 std::vector<Vec2d> up_boundary;
159
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_;
170 end_right.SelfRotate(-origin_heading_);
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);
181 } else {
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_;
191 end_left.SelfRotate(-origin_heading_);
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);
202 }
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);
207
208 return true;
209 }
void set_x(const double x)
Setter for x component
void SelfRotate(const double angle)
rotate the vector itself by angle.
double x() const
Getter for x component
void set_y(const double y)
Setter for y component
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
optional bool parking_inwards