Apollo 11.0
自动驾驶开放平台
open_space_fallback_decider_park.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22
23namespace apollo {
24namespace planning {
30
32 const std::string& config_dir, const std::string& name,
33 const std::shared_ptr<DependencyInjector>& injector) {
34 if (!Decider::Init(config_dir, name, injector)) {
35 return false;
36 }
37 // Load the config this task.
38 if (!Decider::LoadConfig<OpenSpaceFallBackDeciderParkConfig>(&config_)) {
39 AERROR << "Failed to load config file";
40 return false;
41 } else {
42 open_space_fallback_collision_distance_ =
44 return true;
45 }
46}
47
48bool OpenSpaceFallbackDeciderPark::QuardraticFormulaLowerSolution(const double a,
49 const double b,
50 const double c,
51 double* sol) {
52 // quardratic formula: ax^2 + bx + c = 0, return lower solution
53 // TODO(QiL): use const from common::math
54 const double kEpsilon = 1e-6;
55 *sol = 0.0;
56 if (std::abs(a) < kEpsilon) {
57 return false;
58 }
59
60 double tmp = b * b - 4 * a * c;
61 if (tmp < kEpsilon) {
62 return false;
63 }
64 double sol1 = (-b + std::sqrt(tmp)) / (2.0 * a);
65 double sol2 = (-b - std::sqrt(tmp)) / (2.0 * a);
66
67 *sol = std::abs(std::min(sol1, sol2));
68 ADEBUG << "QuardraticFormulaLowerSolution finished with sol: " << *sol
69 << "sol1: " << sol1 << ", sol2: " << sol2 << "a: " << a << "b: " << b
70 << "c: " << c;
71 return true;
72}
73
74Status OpenSpaceFallbackDeciderPark::Process(Frame* frame) {
75 AINFO << "frame->open_space_info().chosen_partitioned_trajectory(): " <<
76 frame->open_space_info().chosen_partitioned_trajectory().first.size();
77 AINFO << "frame->open_space_info().optimizer_trajectory_data(): " <<
78 frame->open_space_info().optimizer_trajectory_data().size();
79
80 std::vector<std::vector<common::math::Box2d>> predicted_bounding_rectangles;
81 std::vector<Obstacle*> static_obstacles;
82 int first_collision_index = 0;
83 int fallback_start_index = 0;
84 // mayaochang add
85 bool is_collision_with_static_obstacle = false;
86 bool is_collision_with_dynamic_obstacle = false;
87
88 // only predicted dynamic obstacle
90 Vec2d(frame->vehicle_state().x(), frame->vehicle_state().y()),
91 frame->obstacles(),
92 predicted_bounding_rectangles,
94 config_.collision_check_range());
95 // get the static obstacles
97 Vec2d(frame->vehicle_state().x(), frame->vehicle_state().y()),
98 frame->obstacles(),
99 static_obstacles,
100 config_.collision_check_range());
101 ADEBUG << "Numbers of obstsacles are: " << frame->obstacles().size();
102 ADEBUG << "Numbers of predicted bounding rectangles of dynamic obstacle are: "
103 << predicted_bounding_rectangles[0].size()
104 << " and : " << predicted_bounding_rectangles.size()
105 << "Numbers of static obstsacles are:" << static_obstacles.size();
106
107 if (frame->open_space_info().chosen_partitioned_trajectory().first.empty()) {
108 AERROR << "No trajectory is generated for fallback";
109
110 // set relative time
111 static constexpr double relative_stop_time = 0.1;
112
113 auto fallback_tra_pair =
115 mutable_chosen_partitioned_trajectory();
116 fallback_tra_pair->first.clear();
117 auto current_speed = injector_->vehicle_state()->
118 vehicle_state().linear_velocity();
119 AINFO << "open_space_fallback_collision_distance_: " << open_space_fallback_collision_distance_;
120 double stop_deceleration_for_static_collision =
121 std::max(std::min(-1 * current_speed * current_speed /
122 (2 * (open_space_fallback_collision_distance_ - 1e-12)),
123 -0.2),
124 -4.0);
125 AINFO << "stop_deceleration_for_static_collision: " << stop_deceleration_for_static_collision;
126 TrajGearPair fallback_trajectory_pair_candidate;
127 fallback_trajectory_pair_candidate.second =
128 frame_->local_view().chassis->gear_location();
129 CalculateFallbackTrajectory(fallback_trajectory_pair_candidate,
130 stop_deceleration_for_static_collision,
131 relative_stop_time, fallback_tra_pair);
132 open_space_fallback_collision_distance_ = std::max (1e-6,
133 open_space_fallback_collision_distance_ - fabs(fallback_tra_pair->first[1].path_point().s()));
134 AINFO << "open_space_fallback_collision_ditance_: " << open_space_fallback_collision_distance_;
135 // check if the fallback trajectory has collision with obstacle
136 TrajGearPair fallback_trajectory =
139 fallback_trajectory, predicted_bounding_rectangles,
140 static_obstacles, &fallback_start_index, &first_collision_index,
141 is_collision_with_static_obstacle,
142 is_collision_with_dynamic_obstacle,
144 AINFO << " fallback trajectory still has collision with obstacles";
145 // stop vehicle with max deceleration
146 CalculateFallbackTrajectory(fallback_trajectory, -4.0,
147 relative_stop_time, fallback_tra_pair);
148 }
149 return Status::OK();
150 }
151
152 // set collision distance with static collision
153 open_space_fallback_collision_distance_ =
155
157 frame->open_space_info().chosen_partitioned_trajectory(),
158 predicted_bounding_rectangles, static_obstacles,
159 &fallback_start_index, &first_collision_index,
160 is_collision_with_static_obstacle,
161 is_collision_with_dynamic_obstacle,
163 AINFO << "trajectory still has collision with obstacles";
164 // generate fallback trajectory base on current partition trajectory
165 // vehicle speed is decreased to zero inside safety distance
166 TrajGearPair fallback_trajectory_pair_candidate =
167 frame->open_space_info().chosen_partitioned_trajectory();
168 // auto* ptr_fallback_trajectory_pair =
169 // frame_->mutable_open_space_info()->mutable_fallback_trajectory();
170 const auto future_collision_point =
171 fallback_trajectory_pair_candidate.first[first_collision_index];
172
173 // Fallback starts from current location but with vehicle velocity
174 auto fallback_start_point =
175 fallback_trajectory_pair_candidate.first[fallback_start_index];
176 const auto& vehicle_state = injector_->vehicle_state()->vehicle_state();
177
178 // TODO(QiL): move 1.0 to configs
179 double stop_distance =
180 fallback_trajectory_pair_candidate.second == canbus::Chassis::GEAR_DRIVE
181 ? std::max(future_collision_point.path_point().s() -
182 fallback_start_point.path_point().s() - config_.distance_to_obs(),
183 0.0)
184 : std::min(future_collision_point.path_point().s() -
185 fallback_start_point.path_point().s() + config_.distance_to_obs(),
186 0.0);
187
188 ADEBUG << "stop distance : " << stop_distance;
189
190 const auto& vehicle_param =
191 common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param();
192 const double max_adc_stop_speed =
193 vehicle_param.max_abs_speed_when_stopped();
194
195 // static collision action
196 if (is_collision_with_static_obstacle) {
197 AINFO << "collision with static obstacle";
198
200 mutable_optimizer_trajectory_data()->clear();
202 mutable_path_planning_trajectory_result()->clear();
204 mutable_interpolated_trajectory_result()->clear();
206 mutable_partitioned_trajectories()->clear();
208 mutable_chosen_partitioned_trajectory()->first.clear();
209
210 // set the collision distance with static collision and relative time
211 const auto& open_space_fallback_collision_distance =
213 static constexpr double relative_stop_time = 0.1;
214
215 double relative_time = 0.0;
216 double current_s_distance = 0.0;
217 auto fallback_tra_pair =
219 mutable_chosen_partitioned_trajectory();
220 fallback_tra_pair->first.clear();
221 double stop_deceleration_for_static_collision = 0;
222
223 auto current_speed = vehicle_state.linear_velocity();
224 AINFO << "open_space_fallback_collision_distance: "
225 << open_space_fallback_collision_distance
226 << "stop_distance: " << stop_distance;
227 if (open_space_fallback_collision_distance > std::abs(stop_distance)) {
228 AINFO << "The collision distance with static obstacle is too small, "
229 "distance is :"
230 << stop_distance << "!";
231
232 stop_deceleration_for_static_collision = -4.0;
233 } else {
234 AINFO << "The collision distance with static obstacle is large, stop "
235 "with set distance is :"
236 << open_space_fallback_collision_distance << "!";
237 // generate stop deceleration
238 stop_deceleration_for_static_collision =
239 std::max(-1 * current_speed * current_speed /
240 (2 * (open_space_fallback_collision_distance - 1e-6)),
241 -4.0);
242 AINFO << "current_speed: " << current_speed
243 << "open_space_fallback_collision_distance: "
244 << open_space_fallback_collision_distance;
245 }
246 AINFO << "stop deceleration for static collision is : "
247 << stop_deceleration_for_static_collision
248 << "relative_stop_time: " << relative_stop_time;
249 if (config_.is_use_trajectory_pose()) {
250 CalculateFallbackTrajectoryWithTrajectoryPose(
251 fallback_trajectory_pair_candidate,
252 fallback_start_point, future_collision_point, stop_distance,
253 relative_stop_time, fallback_tra_pair);
254 } else {
255 CalculateFallbackTrajectory(fallback_trajectory_pair_candidate,
256 open_space_fallback_collision_distance,
257 relative_stop_time, fallback_tra_pair);
258 }
259 AINFO << "fallback trajectory has collision with obstacles";
260 // check if the fallback trajectory has collision with obstacle
261 TrajGearPair fallback_trajectory =
263 AINFO << "fallback trajectory has collision with obstacles";
265 fallback_trajectory, predicted_bounding_rectangles,
266 static_obstacles, &fallback_start_index, &first_collision_index,
267 is_collision_with_static_obstacle,
268 is_collision_with_dynamic_obstacle,
270 AINFO << " fallback trajectory still has collision with obstacles";
271 // stop vehicle with max deceleration
272 CalculateFallbackTrajectory(fallback_trajectory, -4.0,
273 relative_stop_time, fallback_tra_pair);
274 }
275 }
276
277 // dynamic collision action
278 if (is_collision_with_dynamic_obstacle) {
279 auto fallback_tra_pair =
281 mutable_chosen_partitioned_trajectory();
282 fallback_tra_pair->first.clear();
283
284 fallback_start_point.set_v(vehicle_state.linear_velocity());
285
287 future_collision_point;
288
289 // min stop distance: (max_acc)
290 double min_stop_distance =
291 0.5 * fallback_start_point.v() * fallback_start_point.v() / 4.0;
292
293 // const auto& vehicle_config =
294 // common::VehicleConfigHelper::Instance()->GetConfig();
295 const double vehicle_max_acc = 4.0; // vehicle_config.max_acceleration();
296 const double vehicle_max_dec =
297 -4.0; // vehicle_config.max_deceleration();
298
299 double stop_deceleration = 0.0;
300
301 if (fallback_trajectory_pair_candidate.second ==
303 stop_deceleration =
304 std::min(fallback_start_point.v() * fallback_start_point.v() /
305 (2.0 * (stop_distance + 1e-6)),
306 vehicle_max_acc);
307 stop_distance = std::min(-1 * min_stop_distance, stop_distance);
308 } else {
309 stop_deceleration =
310 std::max(-fallback_start_point.v() * fallback_start_point.v() /
311 (2.0 * (stop_distance + 1e-6)),
312 vehicle_max_dec);
313 stop_distance = std::max(min_stop_distance, stop_distance);
314 }
315
316 AINFO << "stop_deceleration: " << stop_deceleration;
317
318 // Search stop index in chosen trajectory by distance
319 int stop_index = fallback_start_index;
320
321 for (int i = fallback_start_index;
322 i < fallback_trajectory_pair_candidate.first.NumOfPoints(); ++i) {
323 if (std::abs(
324 fallback_trajectory_pair_candidate.first[i].path_point().s()) >=
325 std::abs(fallback_start_point.path_point().s() + stop_distance)) {
326 stop_index = i;
327 break;
328 }
329 }
330
331 AINFO << "stop index before is: " << stop_index
332 << "; fallback_start index before is: " << fallback_start_index;
333
334 for (int i = 0; i < fallback_start_index; ++i) {
335 fallback_trajectory_pair_candidate.first[i].set_v(
336 fallback_start_point.v());
337 fallback_trajectory_pair_candidate.first[i].set_a(stop_deceleration);
338 }
339
340 // TODO(QiL): refine the logic and remove redundant code, change 0.5 to
341 // from loading optimizer configs
342
343 // If stop_index == fallback_start_index;
344 if (fallback_start_index >= stop_index) {
345 // 1. Set fallback start speed to 0, acceleration to max acceleration.
346 AINFO << "Stop distance within safety buffer, stop now!";
347 fallback_start_point.set_v(0.0);
348 fallback_start_point.set_a(0.0);
349 fallback_trajectory_pair_candidate.first[stop_index].set_v(0.0);
350 fallback_trajectory_pair_candidate.first[stop_index].set_a(0.0);
351
352 // 2. Trim all trajectory points after stop index
353 fallback_trajectory_pair_candidate.first.erase(
354 fallback_trajectory_pair_candidate.first.begin() + stop_index + 1,
355 fallback_trajectory_pair_candidate.first.end());
356
357 // 3. AppendTrajectoryPoint with same location but zero velocity
358 for (int i = 0; i < 20; ++i) {
359 common::TrajectoryPoint trajectory_point(
360 fallback_trajectory_pair_candidate.first[stop_index]);
361 trajectory_point.set_relative_time(
362 i * 0.5 + 0.5 +
363 fallback_trajectory_pair_candidate.first[stop_index]
364 .relative_time());
365 fallback_trajectory_pair_candidate.first.AppendTrajectoryPoint(
366 trajectory_point);
367 }
368
370 fallback_trajectory_pair_candidate;
371
372 return Status::OK();
373 }
374
375 AINFO << "before change, size : "
376 << fallback_trajectory_pair_candidate.first.size()
377 << ", first index information : "
378 << fallback_trajectory_pair_candidate.first[0].DebugString()
379 << ", second index information : "
380 << fallback_trajectory_pair_candidate.first[1].DebugString();
381
382 // If stop_index > fallback_start_index
383
384 for (int i = fallback_start_index; i <= stop_index; ++i) {
385 double new_relative_time = 0.0;
386 double temp_v = 0.0;
387 double c =
388 -2.0 * fallback_trajectory_pair_candidate.first[i].path_point().s();
389
390 if (QuardraticFormulaLowerSolution(stop_deceleration,
391 2.0 * fallback_start_point.v(), c,
392 &new_relative_time) &&
393 std::abs(
394 fallback_trajectory_pair_candidate.first[i].path_point().s()) <=
395 std::abs(stop_distance)) {
396 ADEBUG << "new_relative_time" << new_relative_time;
397 temp_v =
398 fallback_start_point.v() + stop_deceleration * new_relative_time;
399 // speed limit
400 if (std::abs(temp_v) < 1.0) {
401 fallback_trajectory_pair_candidate.first[i].set_v(temp_v);
402 } else {
403 fallback_trajectory_pair_candidate.first[i].set_v(
404 temp_v / std::abs(temp_v) * 1.0);
405 }
406 fallback_trajectory_pair_candidate.first[i].set_a(stop_deceleration);
407
408 fallback_trajectory_pair_candidate.first[i].set_relative_time(
409 new_relative_time);
410 } else {
411 if (i != 0) {
412 fallback_trajectory_pair_candidate.first[i]
413 .mutable_path_point()
414 ->CopyFrom(fallback_trajectory_pair_candidate.first[i - 1]
415 .path_point());
416 fallback_trajectory_pair_candidate.first[i].set_v(0.0);
417 fallback_trajectory_pair_candidate.first[i].set_a(0.0);
418 fallback_trajectory_pair_candidate.first[i].set_relative_time(
419 fallback_trajectory_pair_candidate.first[i - 1]
420 .relative_time() +
421 0.5);
422 } else {
423 fallback_trajectory_pair_candidate.first[i].set_v(0.0);
424 fallback_trajectory_pair_candidate.first[i].set_a(0.0);
425 }
426 }
427 }
428
429 ADEBUG << "fallback start point after changes: "
430 << fallback_start_point.DebugString();
431
432 ADEBUG << "stop index: " << stop_index;
433 ADEBUG << "fallback start index: " << fallback_start_index;
434
435 // 2. Erase afterwards
436 fallback_trajectory_pair_candidate.first.erase(
437 fallback_trajectory_pair_candidate.first.begin() + stop_index + 1,
438 fallback_trajectory_pair_candidate.first.end());
439
440 // 3. AppendTrajectoryPoint with same location but zero velocity
441 for (int i = 0; i < 20; ++i) {
442 common::TrajectoryPoint trajectory_point(
443 fallback_trajectory_pair_candidate.first[stop_index]);
444 trajectory_point.set_relative_time(
445 i * 0.5 + 0.5 +
446 fallback_trajectory_pair_candidate.first[stop_index]
447 .relative_time());
448 fallback_trajectory_pair_candidate.first.AppendTrajectoryPoint(
449 trajectory_point);
450 }
452 mutable_chosen_partitioned_trajectory()) =
453 fallback_trajectory_pair_candidate;
454 }
455 }
456 return Status::OK();
457}
458
459bool OpenSpaceFallbackDeciderPark::IsCollisionFreeEgoBox() {
460 // prediction time resolution: FLAGS_trajectory_time_resolution
461 const auto& vehicle_state = frame_->vehicle_state();
462 double x = vehicle_state.x();
463 double y = vehicle_state.y();
464 double heading = vehicle_state.heading();
465
466 const auto& vehicle_config =
467 common::VehicleConfigHelper::Instance()->GetConfig();
468 double ego_length = vehicle_config.vehicle_param().length();
469 double ego_width = vehicle_config.vehicle_param().width();
470 Box2d ego_box({x, y}, heading, ego_length, ego_width);
471 Polygon2d ego_polygon = Polygon2d(ego_box);
472
473 for (const Obstacle* obstacle : frame_->obstacles()) {
474 if (obstacle->IsVirtual() || !obstacle->IsStatic() ||
475 obstacle->Perception().width() < 0.2 ||
476 obstacle->Perception().length() < 0.2) {
477 continue;
478 }
479 Polygon2d obstacle_polygon = obstacle->PerceptionPolygon();
480 if (ego_polygon.HasOverlap(obstacle_polygon)) {
481 return false;
482 }
483 }
484 return true;
485}
486
487void OpenSpaceFallbackDeciderPark::CalculateFallbackTrajectory(
488 const TrajGearPair& ChosenPartitionedTrajectory, const double& deceleration,
489 const double& relative_time_interval, TrajGearPair* traj_gear_pair) {
490 // clear the trajectory
491 traj_gear_pair->first.clear();
492 // get the vehicle current speed
493 double current_speed = fabs(frame_->vehicle_state().linear_velocity());
494 double pre_speed = current_speed;
495 double decelerate = fabs(deceleration);
496
497 double current_s_distance = 0;
498 double relative_time = 0;
499 const auto& vehicle_config =
500 common::VehicleConfigHelper::Instance()->GetConfig();
501
502 // if the current gear is Reverse,Current heading Should be + M_PI when
503 // calculate the position
504 double moving_heading = frame_->vehicle_state().heading();
505 int alpha =
506 frame_->local_view().chassis->gear_location()
507 == canbus::Chassis::GEAR_DRIVE ? 1 : -1;
508
509 while (pre_speed >
510 vehicle_config.vehicle_param().max_abs_speed_when_stopped()) {
511 TrajectoryPoint point;
512 static constexpr double kSpeedEpsilon = 1e-9;
513
514 point.mutable_path_point()->set_x(frame_->vehicle_state().x() +
515 current_s_distance * alpha *
516 std::cos(moving_heading));
517 point.mutable_path_point()->set_y(frame_->vehicle_state().y() +
518 current_s_distance * alpha *
519 std::sin(moving_heading));
520 point.mutable_path_point()->set_theta(frame_->vehicle_state().heading());
521 point.mutable_path_point()->set_s(current_s_distance * alpha);
522 point.mutable_path_point()->set_kappa(0.0);
523 point.set_relative_time(relative_time);
524 point.set_v(current_speed* alpha);
525 point.set_a(decelerate* -1 * alpha);
526 traj_gear_pair->first.emplace_back(point);
527 relative_time += relative_time_interval;
528 pre_speed = current_speed;
529 current_speed -= relative_time_interval * decelerate;
530 current_s_distance +=
531 (pre_speed + current_speed) / 2 * relative_time_interval;
532 if (pre_speed < kSpeedEpsilon) break;
533 }
534 traj_gear_pair->second = frame_->local_view().chassis->gear_location();
535 if (traj_gear_pair->first.empty()) {
536 for (int i = 0; i < 20; i++) {
537 TrajectoryPoint point;
538 point.mutable_path_point()->set_x(frame_->vehicle_state().x());
539 point.mutable_path_point()->set_y(frame_->vehicle_state().y());
540 point.mutable_path_point()->set_theta(frame_->vehicle_state().heading());
541 point.mutable_path_point()->set_s(0);
542 point.mutable_path_point()->set_kappa(0.0);
543 point.set_relative_time(relative_time);
544 point.set_v(0);
545 point.set_a(-1.0 * alpha);
546 traj_gear_pair->first.emplace_back(point);
547 relative_time += relative_time_interval;
548 }
549 traj_gear_pair->second = frame_->local_view().chassis->gear_location();
550 }
551}
552
553void OpenSpaceFallbackDeciderPark::CalculateFallbackTrajectoryWithTrajectoryPose(
554 const TrajGearPair& ChosenPartitionedTrajectory, const TrajectoryPoint start_point, const TrajectoryPoint collision_point, const double& stop_distance,
555 const double& relative_time_interval, TrajGearPair* traj_gear_pair) {
556 static int count = 0;
557 AINFO << "stop_distance:" << stop_distance;
558 if (std::fabs(stop_distance) >= 1e-3) {
559 count ++;
560 int alpha = stop_distance < 0 ? -1 : 1;
561 double v_max = 0.5;
562 double t = std::fabs(stop_distance) / v_max * 2;
563 double a = v_max / t;
564 Vec2d unit_vec(collision_point.path_point().x() - start_point.path_point().x(), collision_point.path_point().y() - start_point.path_point().y());
565 Vec2d start_vec(start_point.path_point().x(), start_point.path_point().y());
566 unit_vec.Normalize();
567 for (double relative_t = 0; relative_t < t; relative_t += relative_time_interval){
568 TrajectoryPoint point;
569 double point_v, point_a, point_s;
570 point_v = a * (t - relative_t);
571 point_a = -1 * a;
572 point_s = std::fabs(stop_distance) - 0.5 * point_v * (t - relative_t);
573 Vec2d point_vec = start_vec + unit_vec * point_s;
574 point.mutable_path_point()->set_x(point_vec.x());
575 point.mutable_path_point()->set_y(point_vec.y());
576 point.mutable_path_point()->set_theta(start_point.path_point().theta());
577 point.mutable_path_point()->set_s(point_s * alpha);
578 point.mutable_path_point()->set_kappa(0.0);
579 point.set_relative_time(relative_t - 0.1 * count);
580 point.set_v(point_v * alpha);
581 point.set_a(point_a * alpha);
582 AINFO << "point: " << point.DebugString();
583 traj_gear_pair->first.emplace_back(point);
584 }
585 TrajectoryPoint point;
586 Vec2d point_vec = start_vec + unit_vec * std::fabs(stop_distance);
587 point.mutable_path_point()->set_x(point_vec.x());
588 point.mutable_path_point()->set_y(point_vec.y());
589 point.mutable_path_point()->set_theta(start_point.path_point().theta());
590 point.mutable_path_point()->set_s(stop_distance);
591 point.mutable_path_point()->set_kappa(0.0);
592 point.set_relative_time(t - 0.1 * count);
593 point.set_v(0);
594 point.set_a(0);
595 AINFO << "point: " << point.DebugString();
596 traj_gear_pair->first.emplace_back(point);
597 traj_gear_pair->second = ChosenPartitionedTrajectory.second;
598 }
599 if (traj_gear_pair->first.empty()) {
600 double relative_time = 0;
601 int alpha =
602 frame_->local_view().chassis->gear_location()
603 == canbus::Chassis::GEAR_DRIVE ? 1 : -1;
604 for (int i = 0; i < 20; i++) {
605 TrajectoryPoint point;
606 point.mutable_path_point()->set_x(frame_->vehicle_state().x());
607 point.mutable_path_point()->set_y(frame_->vehicle_state().y());
608 point.mutable_path_point()->set_theta(frame_->vehicle_state().heading());
609 point.mutable_path_point()->set_s(0);
610 point.mutable_path_point()->set_kappa(0.0);
611 point.set_relative_time(relative_time);
612 point.set_v(0);
613 point.set_a(-1.0 * alpha);
614 traj_gear_pair->first.emplace_back(point);
615 relative_time += relative_time_interval;
616 }
617 traj_gear_pair->second = frame_->local_view().chassis->gear_location();
618 }
619}
620
621} // namespace planning
622} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
The class of polygon in 2-D.
Definition polygon2d.h:42
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
const OpenSpaceInfo & open_space_info() const
Definition frame.h:167
const LocalView & local_view() const
Definition frame.h:163
const common::VehicleState & vehicle_state() const
Definition frame.cc:83
OpenSpaceInfo * mutable_open_space_info()
Definition frame.h:169
bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
static bool IsCollisionFreeTrajectory(const TrajGearPair &trajectory_gear_pair, const std::vector< std::vector< common::math::Box2d > > &predicted_bounding_rectangles, const std::vector< Obstacle * > &static_obstacles, int *current_index, int *first_collision_index, bool &is_collision_with_static_obstacle, bool &is_collision_with_dynamic_obstacle, const double &collilsion_time_buffer)
static void BuildPredictedEnvironment(const common::math::Vec2d ego_pos, const std::vector< const Obstacle * > &obstacles, std::vector< std::vector< common::math::Box2d > > &predicted_bounding_rectangles, const double &time_period, const double &build_range)
static void BuildStaticObstacleEnvironment(const common::math::Vec2d ego_pos, const std::vector< const Obstacle * > &obstacles, std::vector< Obstacle * > &static_obstacles, const double &build_range)
common::TrajectoryPoint * mutable_future_collision_point()
const TrajGearPair & chosen_partitioned_trajectory() const
TrajGearPair * mutable_fallback_trajectory()
std::shared_ptr< DependencyInjector > injector_
Definition task.h:59
virtual bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector)
Definition task.cc:40
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
std::pair< DiscretizedTrajectory, canbus::Chassis::GearPosition > TrajGearPair
class register implement
Definition arena_queue.h:37
Definition future.h:29
std::shared_ptr< canbus::Chassis > chassis
Definition local_view.h:42