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;
65 double start_s =
66 center_line_s -
68 double end_s =
69 center_line_s +
71 hdmap::MapPathPoint end_point = nearby_path_->GetSmoothPoint(end_s);
72 hdmap::MapPathPoint start_point = nearby_path_->GetSmoothPoint(start_s);
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);
85
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;
98
99
100
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();
115 left_top.SelfRotate(-origin_heading_);
116 left_down.SelfRotate(-origin_heading_);
117 right_top.SelfRotate(-origin_heading_);
118 right_down.SelfRotate(-origin_heading_);
119 start_right.SelfRotate(-origin_heading_);
120 start_left.SelfRotate(-origin_heading_);
121 end_right.SelfRotate(-origin_heading_);
122 end_left.SelfRotate(-origin_heading_);
123
124
125 parking_spot_heading_ = (left_down - left_top).Angle();
126 double end_x = (left_top.x() + right_top.x()) / 2;
127 double end_y = 0.0;
130 end_y = left_top.y() + (left_down.y() - left_top.y()) / 4;
131 } else {
132 end_y = left_top.y() + 3 * (left_down.y() - left_top.y()) / 4;
133 }
134 } else {
136 end_y = left_down.y() + 3 * (left_top.y() - left_down.y()) / 4;
137 } else {
138 end_y = left_down.y() + (left_top.y() - left_down.y()) / 4;
139 }
140 }
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_);
145 } else {
146 open_space_end_pose_.emplace_back(
148 }
149 open_space_end_pose_.emplace_back(0.0);
150
151
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);
160
161
162
163
164 std::vector<Vec2d> left_boundary;
165 std::vector<Vec2d> down_boundary;
166 std::vector<Vec2d> right_boundary;
167 std::vector<Vec2d> up_boundary;
168
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_;
179 end_right.SelfRotate(-origin_heading_);
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);
190 } else {
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_;
200 end_left.SelfRotate(-origin_heading_);
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);
211 }
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);
216
217 return true;
218 }
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