124 {
125
126 size_t time_matched_index = 0;
128 prev_trajectory, replan_reason,
129 &time_matched_index)) {
131 }
132
133
134 if (vehicle_chassis.has_gear_location()) {
139 gear_pos = vehicle_chassis.gear_location();
140 const std::string msg =
141 "gear change from n to d, replan to avoid large station error";
143 *replan_reason = msg;
145 vehicle_state);
146 }
147 gear_pos = vehicle_chassis.gear_location();
148 }
149
150 auto time_matched_point = prev_trajectory->TrajectoryPointAt(
151 static_cast<uint32_t>(time_matched_index));
152
153
155 control_interactive_msg)) {
157 planning_cycle_time, vehicle_state, time_matched_point,
158 control_interactive_msg);
159 }
160
161 size_t position_matched_index = prev_trajectory->QueryNearestPointWithBuffer(
162 {vehicle_state.x(), vehicle_state.y()}, 1.0e-6);
163
164 auto frenet_sd = ComputePositionProjection(
165 vehicle_state.x(), vehicle_state.y(),
166 prev_trajectory->TrajectoryPointAt(
167 static_cast<uint32_t>(position_matched_index)));
168
169
170 if (replan_by_offset) {
171 if (vehicle_chassis.has_parking_brake()) {
172 static bool parking_brake = true;
173 if (parking_brake && !vehicle_chassis.parking_brake()) {
174 parking_brake = vehicle_chassis.parking_brake();
175 const std::string msg =
176 "parking brake off, ego move, replan to avoid large station error";
178 *replan_reason = msg;
180 vehicle_state);
181 }
182 parking_brake = vehicle_chassis.parking_brake();
183 }
184
185 auto lon_diff = time_matched_point.path_point().s() - frenet_sd.first;
186 auto lat_diff = frenet_sd.second;
187 double time_diff =
188 time_matched_point.relative_time() -
189 prev_trajectory
190 ->TrajectoryPointAt(static_cast<uint32_t>(position_matched_index))
191 .relative_time();
192
193 ADEBUG <<
"Control lateral diff: " << lat_diff
194 << ", longitudinal diff: " << lon_diff
195 << ", time diff: " << time_diff;
196
197 if (std::fabs(lat_diff) > FLAGS_replan_lateral_distance_threshold) {
198 const std::string msg = absl::StrCat(
199 "the distance between matched point and actual position is too "
200 "large. Replan is triggered. lat_diff = ",
201 lat_diff);
203 *replan_reason = msg;
205 vehicle_state);
206 }
207
208 if (std::fabs(lon_diff) > FLAGS_replan_longitudinal_distance_threshold) {
209 const std::string msg = absl::StrCat(
210 "the distance between matched point and actual position is too "
211 "large. Replan is triggered. lon_diff = ",
212 lon_diff);
214 *replan_reason = msg;
216 vehicle_state);
217 }
218
219 if (std::fabs(time_diff) > FLAGS_replan_time_threshold) {
220 const std::string msg = absl::StrCat(
221 "the difference between time matched point relative time and "
222 "actual position corresponding relative time is too "
223 "large. Replan is triggered. time_diff = ",
224 time_diff);
226 *replan_reason = msg;
228 vehicle_state);
229 }
230 } else {
231 ADEBUG <<
"replan according to certain amount of "
232 << "lat、lon and time offset is disabled";
233 }
234
235
236 double forward_rel_time =
237 current_timestamp - prev_trajectory->header_time() + planning_cycle_time;
238
239 size_t forward_time_index =
240 prev_trajectory->QueryLowerBoundPoint(forward_rel_time);
241
242 ADEBUG <<
"Position matched index:\t" << position_matched_index;
243 ADEBUG <<
"Time matched index:\t" << time_matched_index;
244
245 auto matched_index = std::min(time_matched_index, position_matched_index);
246
247 std::vector<TrajectoryPoint> stitching_trajectory(
248 prev_trajectory->begin() +
249 std::max(0, static_cast<int>(matched_index - preserved_points_num)),
250 prev_trajectory->begin() + forward_time_index + 1);
251 ADEBUG <<
"stitching_trajectory size: " << stitching_trajectory.size();
252
253 const double zero_s = stitching_trajectory.back().path_point().s();
254 for (auto& tp : stitching_trajectory) {
255 if (!tp.has_path_point()) {
256 *replan_reason = "replan for previous trajectory missed path point";
258 vehicle_state);
259 }
260 tp.set_relative_time(tp.relative_time() + prev_trajectory->header_time() -
261 current_timestamp);
262 tp.mutable_path_point()->set_s(tp.path_point().s() - zero_s);
263 }
264 return stitching_trajectory;
265}
static std::vector< common::TrajectoryPoint > ComputeControlInteractiveStitchingTrajectory(const double planning_cycle_time, const common::VehicleState &vehicle_state, const common::TrajectoryPoint &time_match_point, const control::ControlInteractiveMsg &control_interactive_msg)
static bool need_replan_by_necessary_check(const common::VehicleState &vehicle_state, const double current_timestamp, const PublishableTrajectory *prev_trajectory, std::string *replan_reason, size_t *time_matched_index)
static bool need_replan_by_control_interactive(const double current_timestamp, std::string *replan_reason, const control::ControlInteractiveMsg &control_interactive_msg)