26#include "absl/strings/str_cat.h"
47 const std::string& config_dir,
const std::string& name,
48 const std::shared_ptr<DependencyInjector>& injector) {
53 bool res = Task::LoadConfig<OpenSpaceTrajectoryPartitionConfig>(&config_);
60 vehicle_box_iou_threshold_to_midpoint_ =
62 linear_velocity_threshold_on_ego_ =
65 common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param();
66 ego_length_ = vehicle_param_.
length();
67 ego_width_ = vehicle_param_.
width();
70 AINFO << config_.DebugString();
75 auto* current_gear_status =
78 current_gear_status->gear_shift_period_finished =
true;
79 current_gear_status->gear_shift_period_started =
true;
80 current_gear_status->gear_shift_period_time = 0.0;
81 current_gear_status->gear_shift_start_time = 0.0;
85Status OpenSpaceTrajectoryPartition::Process() {
88 const auto& stitched_trajectory_result =
91 auto* interpolated_trajectory_result_ptr =
92 open_space_info_ptr->mutable_interpolated_trajectory_result();
94 InterpolateTrajectory(stitched_trajectory_result,
95 interpolated_trajectory_result_ptr);
97 auto* partitioned_trajectories =
98 open_space_info_ptr->mutable_partitioned_trajectories();
100 PartitionTrajectory(*interpolated_trajectory_result_ptr,
101 partitioned_trajectories);
103 const auto& open_space_status =
104 injector_->planning_context()->planning_status().open_space();
105 if (!open_space_status.position_init() &&
107 auto* open_space_status =
injector_->planning_context()
108 ->mutable_planning_status()
109 ->mutable_open_space();
110 open_space_status->set_position_init(
true);
111 auto* chosen_partitioned_trajectory =
112 open_space_info_ptr->mutable_chosen_partitioned_trajectory();
113 auto* mutable_trajectory =
114 open_space_info_ptr->mutable_stitched_trajectory_result();
115 AdjustRelativeTimeAndS(open_space_info.partitioned_trajectories(), 0, 0,
116 mutable_trajectory, chosen_partitioned_trajectory);
117 current_trajectory_index_ = 0;
118 fail_search_fallback_ =
false;
124 size_t trajectories_size = partitioned_trajectories->size();
126 current_trajectory_index_ =
127 std::min<size_t>(trajectories_size - 1, current_trajectory_index_);
128 size_t current_trajectory_point_index = 0;
129 bool flag_change_to_next =
false;
135 partitioned_trajectories->at(current_trajectory_index_).second;
136 const auto& cur_trajectory =
137 partitioned_trajectories->at(current_trajectory_index_).first;
138 size_t trajectory_size = cur_trajectory.size();
139 CHECK_GT(trajectory_size, 0U);
140 flag_change_to_next = CheckReachTrajectoryEnd(
141 cur_trajectory, gear, trajectories_size, ¤t_trajectory_point_index);
142 AINFO <<
"current_trajectory_index_" << current_trajectory_index_ <<
","
143 << current_trajectory_point_index <<
"time index" << last_index_
144 <<
"flag_change_to_next" << flag_change_to_next;
145 auto* chosen_partitioned_trajectory =
146 open_space_info_ptr->mutable_chosen_partitioned_trajectory();
148 auto chosen_trajectory = &(chosen_partitioned_trajectory->first);
150 if (InsertGearShiftTrajectory(flag_change_to_next,
151 current_trajectory_index_,
152 open_space_info.partitioned_trajectories(),
153 chosen_partitioned_trajectory) &&
154 chosen_partitioned_trajectory->first.size() != 0) {
155 chosen_trajectory = &(chosen_partitioned_trajectory->first);
156 ADEBUG <<
"After InsertGearShiftTrajectory [" << chosen_trajectory->size()
163 std::priority_queue<std::pair<size_t, double>,
164 std::vector<std::pair<size_t, double>>, comp_>
166 AINFO <<
"ego:" << std::fixed << ego_x_ <<
"," << ego_y_ <<
","
167 << vehicle_moving_direction_;
168 for (
size_t j = 0; j < trajectory_size; ++j) {
169 const TrajectoryPoint& trajectory_point = cur_trajectory.at(j);
170 const PathPoint& path_point = trajectory_point.path_point();
171 const double path_point_x = path_point.x();
172 const double path_point_y = path_point.y();
173 const double path_point_theta = path_point.theta();
174 const Vec2d tracking_vector(path_point_x - ego_x_, path_point_y - ego_y_);
175 const double distance = tracking_vector.Length();
177 const double traj_point_moving_direction =
184 traj_point_moving_direction - vehicle_moving_direction_));
189 if (distance < distance_search_range_ &&
190 heading_search_difference < heading_search_range_) {
192 Box2d path_point_box({path_point_x, path_point_y}, path_point_theta,
193 ego_length_, ego_width_);
194 Vec2d shift_vec{shift_distance_ * std::cos(path_point_theta),
195 shift_distance_ * std::sin(path_point_theta)};
196 path_point_box.Shift(shift_vec);
198 Polygon2d(ego_box_).ComputeIoU(Polygon2d(path_point_box));
199 closest_point.emplace(j, iou_ratio);
203 if (closest_point.empty() || fail_search_fallback_) {
204 fail_search_fallback_ =
true;
206 auto fallback_tra_pair =
208 GenerateStopTrajectory(&fallback_tra_pair->first, -4.0);
210 const std::string msg =
211 "Fail to find nearest trajectory point to follow stop to fallback "
216 current_trajectory_point_index = closest_point.top().first;
217 if (!flag_change_to_next) {
219 size_t time_match_index;
220 double now_time = Clock::Instance()->NowInSeconds();
221 auto& traj = partitioned_trajectories->at(current_trajectory_index_).first;
222 if (last_index_ != -1) {
223 veh_rel_time = traj[last_index_].relative_time() + now_time - last_time_;
224 AINFO << std::fixed << now_time <<
"," << last_time_;
225 time_match_index = traj.QueryLowerBoundPoint(veh_rel_time);
227 time_match_index = current_trajectory_point_index;
228 last_index_ = time_match_index;
229 last_time_ = now_time;
232 AINFO <<
"time_match_index" << time_match_index <<
"pos match index"
233 << current_trajectory_point_index;
234 AINFO <<
"TRAJ CLOSEST" << std::fixed
235 << traj.at(current_trajectory_point_index).path_point().x() <<
","
236 << traj.at(current_trajectory_point_index).path_point().y();
237 if (std::abs(traj[time_match_index].path_point().s() -
238 traj.at(current_trajectory_point_index).path_point().s()) <
240 current_trajectory_point_index = time_match_index;
242 AINFO <<
"reset speed because matched point too far";
243 last_index_ = current_trajectory_point_index;
244 last_time_ = now_time;
249 auto* mutable_trajectory =
250 open_space_info_ptr->mutable_stitched_trajectory_result();
251 AdjustRelativeTimeAndS(open_space_info.partitioned_trajectories(),
252 current_trajectory_index_,
253 current_trajectory_point_index, mutable_trajectory,
254 chosen_partitioned_trajectory);
258void OpenSpaceTrajectoryPartition::InterpolateTrajectory(
259 const DiscretizedTrajectory& stitched_trajectory_result,
260 DiscretizedTrajectory* interpolated_trajectory) {
261 if (FLAGS_use_iterative_anchoring_smoother) {
262 *interpolated_trajectory = stitched_trajectory_result;
265 interpolated_trajectory->clear();
267 CHECK_GT(stitched_trajectory_result.size(), 0U);
268 CHECK_GT(interpolated_pieces_num, 0U);
269 size_t trajectory_to_be_partitioned_intervals_num =
270 stitched_trajectory_result.size() - 1;
271 size_t interpolated_points_num = interpolated_pieces_num - 1;
272 for (
size_t i = 0; i < trajectory_to_be_partitioned_intervals_num; ++i) {
273 double relative_time_interval =
274 (stitched_trajectory_result.at(i + 1).relative_time() -
275 stitched_trajectory_result.at(i).relative_time()) /
276 static_cast<double>(interpolated_pieces_num);
277 interpolated_trajectory->push_back(stitched_trajectory_result.at(i));
278 for (
size_t j = 0; j < interpolated_points_num; ++j) {
279 double relative_time =
280 stitched_trajectory_result.at(i).relative_time() +
281 (
static_cast<double>(j) + 1.0) * relative_time_interval;
282 interpolated_trajectory->emplace_back(
284 stitched_trajectory_result.at(i),
285 stitched_trajectory_result.at(i + 1), relative_time));
288 interpolated_trajectory->push_back(stitched_trajectory_result.back());
291void OpenSpaceTrajectoryPartition::UpdateVehicleInfo() {
293 ego_theta_ = vehicle_state.heading();
294 ego_x_ = vehicle_state.x();
295 ego_y_ = vehicle_state.y();
296 ego_v_ = vehicle_state.linear_velocity();
297 ego_gear_ = vehicle_state.gear();
298 Box2d box({ego_x_, ego_y_}, ego_theta_, ego_length_, ego_width_);
299 ego_box_ = std::move(box);
300 Vec2d ego_shift_vec{shift_distance_ * std::cos(ego_theta_),
301 shift_distance_ * std::sin(ego_theta_)};
302 ego_box_.Shift(ego_shift_vec);
303 vehicle_moving_direction_ =
309bool OpenSpaceTrajectoryPartition::EncodeTrajectory(
310 const DiscretizedTrajectory& trajectory, std::string*
const encoding) {
311 if (trajectory.empty()) {
312 AERROR <<
"Fail to encode trajectory because it is empty";
315 static constexpr double encoding_origin_x = 58700.0;
316 static constexpr double encoding_origin_y = 4141000.0;
317 const auto& init_path_point = trajectory.front().path_point();
318 const auto& last_path_point = trajectory.back().path_point();
320 const int init_point_x =
321 static_cast<int>((init_path_point.x() - encoding_origin_x) * 1000.0);
322 const int init_point_y =
323 static_cast<int>((init_path_point.y() - encoding_origin_y) * 1000.0);
324 const int init_point_heading =
325 static_cast<int>(init_path_point.theta() * 10000.0);
326 const int last_point_x =
327 static_cast<int>((last_path_point.x() - encoding_origin_x) * 1000.0);
328 const int last_point_y =
329 static_cast<int>((last_path_point.y() - encoding_origin_y) * 1000.0);
330 const int last_point_heading =
331 static_cast<int>(last_path_point.theta() * 10000.0);
333 *encoding = absl::StrCat(
335 init_point_x,
"_", init_point_y,
"_", init_point_heading,
"/",
337 last_point_x,
"_", last_point_y,
"_", last_point_heading);
341bool OpenSpaceTrajectoryPartition::CheckTrajTraversed(
342 const std::string& trajectory_encoding_to_check) {
343 const auto& open_space_status =
344 injector_->planning_context()->planning_status().open_space();
345 const int index_history_size =
346 open_space_status.partitioned_trajectories_index_history_size();
348 if (index_history_size <= 1) {
351 for (
int i = 0; i < index_history_size - 1; i++) {
352 const auto& index_history =
353 open_space_status.partitioned_trajectories_index_history(i);
354 if (index_history == trajectory_encoding_to_check) {
361void OpenSpaceTrajectoryPartition::UpdateTrajHistory(
362 const std::string& chosen_trajectory_encoding) {
363 auto* open_space_status =
injector_->planning_context()
364 ->mutable_planning_status()
365 ->mutable_open_space();
367 const auto& trajectory_history =
371 .partitioned_trajectories_index_history();
372 if (trajectory_history.empty()) {
373 open_space_status->add_partitioned_trajectories_index_history(
374 chosen_trajectory_encoding);
377 if (*(trajectory_history.rbegin()) == chosen_trajectory_encoding) {
380 open_space_status->add_partitioned_trajectories_index_history(
381 chosen_trajectory_encoding);
384void OpenSpaceTrajectoryPartition::PartitionTrajectory(
385 const DiscretizedTrajectory& raw_trajectory,
386 std::vector<TrajGearPair>* partitioned_trajectories) {
387 CHECK_NOTNULL(partitioned_trajectories);
389 size_t horizon = raw_trajectory.size();
391 partitioned_trajectories->clear();
392 partitioned_trajectories->emplace_back();
393 TrajGearPair* current_trajectory_gear = &(partitioned_trajectories->back());
395 auto* trajectory = &(current_trajectory_gear->first);
396 auto* gear = &(current_trajectory_gear->second);
399 const auto& first_path_point = raw_trajectory.front().path_point();
400 const auto& second_path_point = raw_trajectory[1].path_point();
401 const auto& last_path_point = raw_trajectory.back().path_point();
402 double heading_angle = first_path_point.theta();
403 const Vec2d init_tracking_vector(
404 second_path_point.x() - first_path_point.x(),
405 second_path_point.y() - first_path_point.y());
406 double tracking_angle = init_tracking_vector.Angle();
407 if (first_path_point.x() == second_path_point.x() &&
408 first_path_point.y() == second_path_point.y() &&
409 first_path_point.x() == last_path_point.x() &&
410 first_path_point.y() == last_path_point.y()) {
411 *gear =
injector_->vehicle_state()->vehicle_state().gear();
417 : canbus::Chassis::GEAR_REVERSE;
419 AINFO <<
"First trajectory segment gear: " << std::to_string(*gear);
422 Vec2d last_pos_vec(first_path_point.x(), first_path_point.y());
423 double distance_s = 0.0;
424 bool is_trajectory_last_point =
false;
426 for (
size_t i = 0; i < horizon - 1; ++i) {
427 const TrajectoryPoint& trajectory_point = raw_trajectory.at(i);
428 const TrajectoryPoint& next_trajectory_point = raw_trajectory.at(i + 1);
429 const TrajectoryPoint& last_trajectory_point = raw_trajectory.back();
432 heading_angle = trajectory_point.path_point().theta();
435 if (next_trajectory_point.path_point().x() ==
436 trajectory_point.path_point().x() &&
437 next_trajectory_point.path_point().y() ==
438 trajectory_point.path_point().y() &&
439 last_trajectory_point.path_point().x() ==
440 trajectory_point.path_point().x() &&
441 last_trajectory_point.path_point().y() ==
442 trajectory_point.path_point().y()) {
443 AINFO <<
"Current trajectory point is same, set the gear with current gear!";
444 cur_gear =
injector_->vehicle_state()->vehicle_state().gear();
446 const Vec2d tracking_vector(next_trajectory_point.path_point().x() -
447 trajectory_point.path_point().x(),
448 next_trajectory_point.path_point().y() -
449 trajectory_point.path_point().y());
450 tracking_angle = tracking_vector.Angle();
452 tracking_angle - heading_angle)) < (M_PI_2)
454 : canbus::Chassis::GEAR_REVERSE;
456 AINFO <<
"cur_gear: " << std::to_string(cur_gear);
458 if (cur_gear != *gear) {
459 is_trajectory_last_point =
true;
460 LoadTrajectoryPoint(trajectory_point, is_trajectory_last_point, *gear,
461 &last_pos_vec, &distance_s, trajectory);
462 partitioned_trajectories->emplace_back();
463 current_trajectory_gear = &(partitioned_trajectories->back());
464 current_trajectory_gear->second = cur_gear;
466 is_trajectory_last_point =
false;
469 trajectory = &(current_trajectory_gear->first);
470 gear = &(current_trajectory_gear->second);
472 LoadTrajectoryPoint(trajectory_point, is_trajectory_last_point, *gear,
473 &last_pos_vec, &distance_s, trajectory);
475 is_trajectory_last_point =
true;
476 const TrajectoryPoint& last_trajectory_point = raw_trajectory.back();
477 LoadTrajectoryPoint(last_trajectory_point, is_trajectory_last_point, *gear,
478 &last_pos_vec, &distance_s, trajectory);
481void OpenSpaceTrajectoryPartition::LoadTrajectoryPoint(
482 const TrajectoryPoint& trajectory_point,
483 const bool is_trajectory_last_point,
485 double* distance_s, DiscretizedTrajectory* current_trajectory) {
486 current_trajectory->emplace_back();
487 TrajectoryPoint* point = &(current_trajectory->back());
488 point->set_relative_time(trajectory_point.relative_time());
489 point->mutable_path_point()->set_x(trajectory_point.path_point().x());
490 point->mutable_path_point()->set_y(trajectory_point.path_point().y());
491 point->mutable_path_point()->set_theta(trajectory_point.path_point().theta());
492 point->set_v(trajectory_point.v());
493 point->mutable_path_point()->set_s(*distance_s);
494 Vec2d cur_pos_vec(trajectory_point.path_point().x(),
495 trajectory_point.path_point().y());
497 (cur_pos_vec.DistanceTo(*last_pos_vec));
498 *last_pos_vec = cur_pos_vec;
499 point->mutable_path_point()->set_kappa((is_trajectory_last_point ? -1 : 1) *
500 std::
tan(trajectory_point.steer()) /
502 point->set_a(trajectory_point.a());
505bool OpenSpaceTrajectoryPartition::CheckReachTrajectoryEnd(
506 const DiscretizedTrajectory& trajectory,
508 size_t* current_trajectory_point_index) {
510 const TrajectoryPoint& trajectory_end_point = trajectory.back();
511 const size_t trajectory_size = trajectory.size();
512 const PathPoint& path_end_point = trajectory_end_point.path_point();
513 const double path_end_point_x = path_end_point.x();
514 const double path_end_point_y = path_end_point.y();
515 const Vec2d tracking_vector(ego_x_ - path_end_point_x,
516 ego_y_ - path_end_point_y);
517 const double path_end_point_theta = path_end_point.theta();
518 const double included_angle =
520 const double distance_to_trajs_end =
521 std::sqrt((path_end_point_x - ego_x_) * (path_end_point_x - ego_x_) +
522 (path_end_point_y - ego_y_) * (path_end_point_y - ego_y_));
523 const double lateral_offset =
524 std::abs(distance_to_trajs_end * std::sin(included_angle));
525 const double longitudinal_offset =
526 std::abs(distance_to_trajs_end * std::cos(included_angle));
527 const double traj_end_point_moving_direction =
530 : path_end_point_theta;
532 const double heading_search_to_trajs_end = std::abs(
NormalizeAngle(
533 traj_end_point_moving_direction - vehicle_moving_direction_));
536 double end_point_iou_ratio = 0.0;
537 if (lateral_offset < lateral_offset_to_midpoint_ &&
538 longitudinal_offset < longitudinal_offset_to_midpoint_ &&
539 heading_search_to_trajs_end < heading_offset_to_midpoint_ &&
540 std::abs(ego_v_) < linear_velocity_threshold_on_ego_) {
542 Box2d path_end_point_box({path_end_point_x, path_end_point_y},
543 path_end_point_theta, ego_length_, ego_width_);
544 Vec2d shift_vec{shift_distance_ * std::cos(path_end_point_theta),
545 shift_distance_ * std::sin(path_end_point_theta)};
546 path_end_point_box.Shift(shift_vec);
547 end_point_iou_ratio =
548 Polygon2d(ego_box_).ComputeIoU(Polygon2d(path_end_point_box));
550 if (end_point_iou_ratio > vehicle_box_iou_threshold_to_midpoint_) {
551 if (current_trajectory_index_ + 1 >= trajectories_size) {
552 current_trajectory_index_ = trajectories_size - 1;
553 *current_trajectory_point_index = trajectory_size - 1;
555 current_trajectory_index_ += 1;
556 *current_trajectory_point_index = 0;
558 AINFO <<
"Reach the end of a trajectory, switching to next one";
563 AINFO <<
"Vehicle did not reach end of a trajectory with conditions for "
564 "lateral distance_check: "
565 << (lateral_offset < lateral_offset_to_midpoint_)
566 <<
" and actual lateral distance: " << lateral_offset
567 <<
"; longitudinal distance_check: "
568 << (longitudinal_offset < longitudinal_offset_to_midpoint_)
569 <<
" and actual longitudinal distance: " << longitudinal_offset
570 <<
"; heading_check: "
571 << (heading_search_to_trajs_end < heading_offset_to_midpoint_)
572 <<
" with actual heading: " << heading_search_to_trajs_end
573 <<
"; velocity_check: "
574 << (std::abs(ego_v_) < linear_velocity_threshold_on_ego_)
575 <<
" with actual linear velocity: " << ego_v_ <<
"; iou_check: "
576 << (end_point_iou_ratio > vehicle_box_iou_threshold_to_midpoint_)
577 <<
" with actual iou: " << end_point_iou_ratio;
581bool OpenSpaceTrajectoryPartition::UseFailSafeSearch(
582 const std::vector<TrajGearPair>& partitioned_trajectories,
583 const std::vector<std::string>& trajectories_encodings,
584 size_t* current_trajectory_index,
size_t* current_trajectory_point_index) {
585 AERROR <<
"Trajectory partition fail, using failsafe search";
586 const size_t trajectories_size = partitioned_trajectories.size();
587 std::priority_queue<std::pair<std::pair<size_t, size_t>,
double>,
588 std::vector<std::pair<std::pair<size_t, size_t>,
double>>,
590 failsafe_closest_point_on_trajs;
591 for (
size_t i = 0; i < trajectories_size; ++i) {
592 const auto& trajectory = partitioned_trajectories.at(i).first;
593 size_t trajectory_size = trajectory.size();
594 CHECK_GT(trajectory_size, 0U);
595 std::priority_queue<std::pair<size_t, double>,
596 std::vector<std::pair<size_t, double>>, comp_>
597 failsafe_closest_point;
599 for (
size_t j = 0; j < trajectory_size; ++j) {
600 const TrajectoryPoint& trajectory_point = trajectory.at(j);
601 const PathPoint& path_point = trajectory_point.path_point();
602 const double path_point_x = path_point.x();
603 const double path_point_y = path_point.y();
604 const double path_point_theta = path_point.theta();
605 const Vec2d tracking_vector(path_point_x - ego_x_, path_point_y - ego_y_);
606 const double distance = tracking_vector.Length();
607 if (distance < distance_search_range_) {
609 Box2d path_point_box({path_point_x, path_point_y}, path_point_theta,
610 ego_length_, ego_width_);
611 Vec2d shift_vec{shift_distance_ * std::cos(path_point_theta),
612 shift_distance_ * std::sin(path_point_theta)};
613 path_point_box.Shift(shift_vec);
615 Polygon2d(ego_box_).ComputeIoU(Polygon2d(path_point_box));
616 failsafe_closest_point.emplace(j, iou_ratio);
619 if (!failsafe_closest_point.empty()) {
620 size_t closest_point_index = failsafe_closest_point.top().first;
621 double max_iou_ratio = failsafe_closest_point.top().second;
622 failsafe_closest_point_on_trajs.emplace(
623 std::make_pair(i, closest_point_index), max_iou_ratio);
626 if (failsafe_closest_point_on_trajs.empty()) {
629 bool closest_and_not_repeated_traj_found =
false;
630 while (!failsafe_closest_point_on_trajs.empty()) {
631 *current_trajectory_index =
632 failsafe_closest_point_on_trajs.top().first.first;
633 *current_trajectory_point_index =
634 failsafe_closest_point_on_trajs.top().first.second;
635 if (CheckTrajTraversed(
636 trajectories_encodings[*current_trajectory_index])) {
637 failsafe_closest_point_on_trajs.pop();
639 closest_and_not_repeated_traj_found =
true;
640 UpdateTrajHistory(trajectories_encodings[*current_trajectory_index]);
644 if (!closest_and_not_repeated_traj_found) {
652bool OpenSpaceTrajectoryPartition::InsertGearShiftTrajectory(
653 const bool flag_change_to_next,
const size_t current_trajectory_index,
654 const std::vector<TrajGearPair>& partitioned_trajectories,
656 const auto* last_frame =
injector_->frame_history()->Latest();
657 auto* current_gear_status =
660 const auto& last_gear_status =
661 last_frame->open_space_info().gear_switch_states();
662 *(current_gear_status) = last_gear_status;
664 AERROR <<
"Lost last frame";
666 const auto& curr_gear =
667 partitioned_trajectories.at(current_trajectory_index).second;
668 if (flag_change_to_next || !current_gear_status->gear_shift_period_finished ||
669 curr_gear != ego_gear_) {
671 if (current_gear_status->gear_shift_period_started) {
672 current_gear_status->gear_shift_start_time =
673 Clock::Instance()->NowInSeconds();
674 current_gear_status->gear_shift_position =
675 partitioned_trajectories.at(current_trajectory_index).second;
676 current_gear_status->gear_shift_period_started =
false;
677 current_gear_status->gear_shift_period_time = 0.0;
679 if (current_gear_status->gear_shift_period_time >
681 current_gear_status->gear_shift_position == ego_gear_) {
682 current_gear_status->gear_shift_period_finished =
true;
683 current_gear_status->gear_shift_period_started =
true;
684 AINFO <<
"finished gear shift";
686 double init_kappa = partitioned_trajectories.at(current_trajectory_index)
690 GenerateGearShiftTrajectory(current_gear_status->gear_shift_position,
691 init_kappa, gear_switch_idle_time_trajectory);
692 current_gear_status->gear_shift_period_time =
693 Clock::Instance()->NowInSeconds() -
694 current_gear_status->gear_shift_start_time;
702void OpenSpaceTrajectoryPartition::GenerateGearShiftTrajectory(
705 gear_switch_idle_time_trajectory->first.clear();
709 for (
double t = 0.0; t < gear_shift_max_t; t += gear_shift_unit_t) {
710 TrajectoryPoint point;
714 point.mutable_path_point()->set_s(0.0);
715 point.mutable_path_point()->set_kappa(init_kappa);
716 point.set_relative_time(t);
719 gear_switch_idle_time_trajectory->first.emplace_back(point);
721 ADEBUG <<
"gear_switch_idle_time_trajectory"
722 << gear_switch_idle_time_trajectory->first.size();
723 gear_switch_idle_time_trajectory->second = gear_position;
726void OpenSpaceTrajectoryPartition::GenerateStopTrajectory(
727 DiscretizedTrajectory*
const trajectory_data,
728 double standstill_acceleration) {
729 double relative_time = 0.0;
731 static constexpr int stop_trajectory_length = 10;
732 static constexpr double relative_stop_time = 0.1;
733 trajectory_data->clear();
734 static constexpr double vEpsilon = 0.00001;
735 standstill_acceleration =
737 ? standstill_acceleration
738 : -1.0 * standstill_acceleration;
739 for (
size_t i = 0; i < stop_trajectory_length; i++) {
740 TrajectoryPoint point;
744 point.mutable_path_point()->set_s(0.0);
745 point.mutable_path_point()->set_kappa(0.0);
746 point.set_relative_time(relative_time);
748 point.set_a(standstill_acceleration);
749 trajectory_data->emplace_back(point);
750 relative_time += relative_stop_time;
754void OpenSpaceTrajectoryPartition::AdjustRelativeTimeAndS(
755 const std::vector<TrajGearPair>& partitioned_trajectories,
756 const size_t current_trajectory_index,
757 const size_t closest_trajectory_point_index,
758 DiscretizedTrajectory* unpartitioned_trajectory_result,
760 const size_t partitioned_trajectories_size = partitioned_trajectories.size();
761 CHECK_GT(partitioned_trajectories_size, current_trajectory_index);
765 *(current_partitioned_trajectory) =
766 partitioned_trajectories.at(current_trajectory_index);
767 auto trajectory = &(current_partitioned_trajectory->first);
769 trajectory->at(closest_trajectory_point_index).relative_time();
771 trajectory->at(closest_trajectory_point_index).path_point().s();
772 const size_t trajectory_size = trajectory->size();
773 for (
size_t i = 0; i < trajectory_size; ++i) {
774 TrajectoryPoint* trajectory_point = &(trajectory->at(i));
775 trajectory_point->set_relative_time(trajectory_point->relative_time() -
777 trajectory_point->mutable_path_point()->set_s(
778 trajectory_point->path_point().s() - s_shift);
788 const size_t unpartitioned_trajectory_size =
789 unpartitioned_trajectory_result->size();
803 for (
size_t i = 0; i < unpartitioned_trajectory_size; ++i) {
804 TrajectoryPoint* trajectory_point =
805 &(unpartitioned_trajectory_result->at(i));
806 trajectory_point->set_relative_time(trajectory_point->relative_time() -
808 trajectory_point->mutable_path_point()->set_s(
809 trajectory_point->path_point().s() - s_shift);
A general class to denote the return status of an API call.
static Status OK()
generate a success status.
Rectangular (undirected) bounding box in 2-D.
The class of polygon in 2-D.
Implements a class of 2-dimensional vectors.
a singleton clock that can be used to get the current timestamp.
const OpenSpaceInfo & open_space_info() const
const LocalView & local_view() const
const common::VehicleState & vehicle_state() const
OpenSpaceInfo * mutable_open_space_info()
bool open_space_provider_success() const
GearSwitchStates * mutable_gear_switch_states()
TrajGearPair * mutable_fallback_trajectory()
void set_fallback_flag(const bool flag)
const DiscretizedTrajectory & stitched_trajectory_result() const
bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
std::shared_ptr< DependencyInjector > injector_
virtual bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector)
Planning module main class.
SLPoint InterpolateUsingLinearApproximation(const SLPoint &p0, const SLPoint &p1, const double w)
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
std::pair< DiscretizedTrajectory, canbus::Chassis::GearPosition > TrajGearPair
Define the Polygon2d class.
optional double back_edge_to_center
optional double wheel_base
optional double linear_velocity
bool gear_shift_period_finished
std::shared_ptr< canbus::Chassis > chassis
optional uint64 interpolated_pieces_num
optional double speed_replan_distance
optional double heading_offset_to_midpoint
optional double gear_shift_max_t
optional double longitudinal_offset_to_midpoint
optional double linear_velocity_threshold_on_ego
optional double distance_search_range
optional double gear_shift_unit_t
optional double gear_shift_period_duration
optional double heading_track_range
optional bool use_gear_shift_trajectory
optional double lateral_offset_to_midpoint
optional double heading_search_range
optional double vehicle_box_iou_threshold_to_midpoint