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 double heading_angle = first_path_point.theta();
402 const Vec2d init_tracking_vector(
403 second_path_point.x() - first_path_point.x(),
404 second_path_point.y() - first_path_point.y());
405 double tracking_angle = init_tracking_vector.Angle();
410 : canbus::Chassis::GEAR_REVERSE;
413 Vec2d last_pos_vec(first_path_point.x(), first_path_point.y());
414 double distance_s = 0.0;
415 bool is_trajectory_last_point =
false;
417 for (
size_t i = 0; i < horizon - 1; ++i) {
418 const TrajectoryPoint& trajectory_point = raw_trajectory.at(i);
419 const TrajectoryPoint& next_trajectory_point = raw_trajectory.at(i + 1);
422 heading_angle = trajectory_point.path_point().theta();
423 const Vec2d tracking_vector(next_trajectory_point.path_point().x() -
424 trajectory_point.path_point().x(),
425 next_trajectory_point.path_point().y() -
426 trajectory_point.path_point().y());
427 tracking_angle = tracking_vector.Angle();
432 : canbus::Chassis::GEAR_REVERSE;
434 if (cur_gear != *gear) {
435 is_trajectory_last_point =
true;
436 LoadTrajectoryPoint(trajectory_point, is_trajectory_last_point, *gear,
437 &last_pos_vec, &distance_s, trajectory);
438 partitioned_trajectories->emplace_back();
439 current_trajectory_gear = &(partitioned_trajectories->back());
440 current_trajectory_gear->second = cur_gear;
442 is_trajectory_last_point =
false;
445 trajectory = &(current_trajectory_gear->first);
446 gear = &(current_trajectory_gear->second);
448 LoadTrajectoryPoint(trajectory_point, is_trajectory_last_point, *gear,
449 &last_pos_vec, &distance_s, trajectory);
451 is_trajectory_last_point =
true;
452 const TrajectoryPoint& last_trajectory_point = raw_trajectory.back();
453 LoadTrajectoryPoint(last_trajectory_point, is_trajectory_last_point, *gear,
454 &last_pos_vec, &distance_s, trajectory);
457void OpenSpaceTrajectoryPartition::LoadTrajectoryPoint(
458 const TrajectoryPoint& trajectory_point,
459 const bool is_trajectory_last_point,
461 double* distance_s, DiscretizedTrajectory* current_trajectory) {
462 current_trajectory->emplace_back();
463 TrajectoryPoint* point = &(current_trajectory->back());
464 point->set_relative_time(trajectory_point.relative_time());
465 point->mutable_path_point()->set_x(trajectory_point.path_point().x());
466 point->mutable_path_point()->set_y(trajectory_point.path_point().y());
467 point->mutable_path_point()->set_theta(trajectory_point.path_point().theta());
468 point->set_v(trajectory_point.v());
469 point->mutable_path_point()->set_s(*distance_s);
470 Vec2d cur_pos_vec(trajectory_point.path_point().x(),
471 trajectory_point.path_point().y());
473 (cur_pos_vec.DistanceTo(*last_pos_vec));
474 *last_pos_vec = cur_pos_vec;
475 point->mutable_path_point()->set_kappa((is_trajectory_last_point ? -1 : 1) *
476 std::
tan(trajectory_point.steer()) /
478 point->set_a(trajectory_point.a());
481bool OpenSpaceTrajectoryPartition::CheckReachTrajectoryEnd(
482 const DiscretizedTrajectory& trajectory,
484 size_t* current_trajectory_point_index) {
486 const TrajectoryPoint& trajectory_end_point = trajectory.back();
487 const size_t trajectory_size = trajectory.size();
488 const PathPoint& path_end_point = trajectory_end_point.path_point();
489 const double path_end_point_x = path_end_point.x();
490 const double path_end_point_y = path_end_point.y();
491 const Vec2d tracking_vector(ego_x_ - path_end_point_x,
492 ego_y_ - path_end_point_y);
493 const double path_end_point_theta = path_end_point.theta();
494 const double included_angle =
496 const double distance_to_trajs_end =
497 std::sqrt((path_end_point_x - ego_x_) * (path_end_point_x - ego_x_) +
498 (path_end_point_y - ego_y_) * (path_end_point_y - ego_y_));
499 const double lateral_offset =
500 std::abs(distance_to_trajs_end * std::sin(included_angle));
501 const double longitudinal_offset =
502 std::abs(distance_to_trajs_end * std::cos(included_angle));
503 const double traj_end_point_moving_direction =
506 : path_end_point_theta;
508 const double heading_search_to_trajs_end = std::abs(
NormalizeAngle(
509 traj_end_point_moving_direction - vehicle_moving_direction_));
512 double end_point_iou_ratio = 0.0;
513 if (lateral_offset < lateral_offset_to_midpoint_ &&
514 longitudinal_offset < longitudinal_offset_to_midpoint_ &&
515 heading_search_to_trajs_end < heading_offset_to_midpoint_ &&
516 std::abs(ego_v_) < linear_velocity_threshold_on_ego_) {
518 Box2d path_end_point_box({path_end_point_x, path_end_point_y},
519 path_end_point_theta, ego_length_, ego_width_);
520 Vec2d shift_vec{shift_distance_ * std::cos(path_end_point_theta),
521 shift_distance_ * std::sin(path_end_point_theta)};
522 path_end_point_box.Shift(shift_vec);
523 end_point_iou_ratio =
524 Polygon2d(ego_box_).ComputeIoU(Polygon2d(path_end_point_box));
526 if (end_point_iou_ratio > vehicle_box_iou_threshold_to_midpoint_) {
527 if (current_trajectory_index_ + 1 >= trajectories_size) {
528 current_trajectory_index_ = trajectories_size - 1;
529 *current_trajectory_point_index = trajectory_size - 1;
531 current_trajectory_index_ += 1;
532 *current_trajectory_point_index = 0;
534 AINFO <<
"Reach the end of a trajectory, switching to next one";
539 AINFO <<
"Vehicle did not reach end of a trajectory with conditions for "
540 "lateral distance_check: "
541 << (lateral_offset < lateral_offset_to_midpoint_)
542 <<
" and actual lateral distance: " << lateral_offset
543 <<
"; longitudinal distance_check: "
544 << (longitudinal_offset < longitudinal_offset_to_midpoint_)
545 <<
" and actual longitudinal distance: " << longitudinal_offset
546 <<
"; heading_check: "
547 << (heading_search_to_trajs_end < heading_offset_to_midpoint_)
548 <<
" with actual heading: " << heading_search_to_trajs_end
549 <<
"; velocity_check: "
550 << (std::abs(ego_v_) < linear_velocity_threshold_on_ego_)
551 <<
" with actual linear velocity: " << ego_v_ <<
"; iou_check: "
552 << (end_point_iou_ratio > vehicle_box_iou_threshold_to_midpoint_)
553 <<
" with actual iou: " << end_point_iou_ratio;
557bool OpenSpaceTrajectoryPartition::UseFailSafeSearch(
558 const std::vector<TrajGearPair>& partitioned_trajectories,
559 const std::vector<std::string>& trajectories_encodings,
560 size_t* current_trajectory_index,
size_t* current_trajectory_point_index) {
561 AERROR <<
"Trajectory partition fail, using failsafe search";
562 const size_t trajectories_size = partitioned_trajectories.size();
563 std::priority_queue<std::pair<std::pair<size_t, size_t>,
double>,
564 std::vector<std::pair<std::pair<size_t, size_t>,
double>>,
566 failsafe_closest_point_on_trajs;
567 for (
size_t i = 0; i < trajectories_size; ++i) {
568 const auto& trajectory = partitioned_trajectories.at(i).first;
569 size_t trajectory_size = trajectory.size();
570 CHECK_GT(trajectory_size, 0U);
571 std::priority_queue<std::pair<size_t, double>,
572 std::vector<std::pair<size_t, double>>, comp_>
573 failsafe_closest_point;
575 for (
size_t j = 0; j < trajectory_size; ++j) {
576 const TrajectoryPoint& trajectory_point = trajectory.at(j);
577 const PathPoint& path_point = trajectory_point.path_point();
578 const double path_point_x = path_point.x();
579 const double path_point_y = path_point.y();
580 const double path_point_theta = path_point.theta();
581 const Vec2d tracking_vector(path_point_x - ego_x_, path_point_y - ego_y_);
582 const double distance = tracking_vector.Length();
583 if (distance < distance_search_range_) {
585 Box2d path_point_box({path_point_x, path_point_y}, path_point_theta,
586 ego_length_, ego_width_);
587 Vec2d shift_vec{shift_distance_ * std::cos(path_point_theta),
588 shift_distance_ * std::sin(path_point_theta)};
589 path_point_box.Shift(shift_vec);
591 Polygon2d(ego_box_).ComputeIoU(Polygon2d(path_point_box));
592 failsafe_closest_point.emplace(j, iou_ratio);
595 if (!failsafe_closest_point.empty()) {
596 size_t closest_point_index = failsafe_closest_point.top().first;
597 double max_iou_ratio = failsafe_closest_point.top().second;
598 failsafe_closest_point_on_trajs.emplace(
599 std::make_pair(i, closest_point_index), max_iou_ratio);
602 if (failsafe_closest_point_on_trajs.empty()) {
605 bool closest_and_not_repeated_traj_found =
false;
606 while (!failsafe_closest_point_on_trajs.empty()) {
607 *current_trajectory_index =
608 failsafe_closest_point_on_trajs.top().first.first;
609 *current_trajectory_point_index =
610 failsafe_closest_point_on_trajs.top().first.second;
611 if (CheckTrajTraversed(
612 trajectories_encodings[*current_trajectory_index])) {
613 failsafe_closest_point_on_trajs.pop();
615 closest_and_not_repeated_traj_found =
true;
616 UpdateTrajHistory(trajectories_encodings[*current_trajectory_index]);
620 if (!closest_and_not_repeated_traj_found) {
628bool OpenSpaceTrajectoryPartition::InsertGearShiftTrajectory(
629 const bool flag_change_to_next,
const size_t current_trajectory_index,
630 const std::vector<TrajGearPair>& partitioned_trajectories,
632 const auto* last_frame =
injector_->frame_history()->Latest();
633 auto* current_gear_status =
636 const auto& last_gear_status =
637 last_frame->open_space_info().gear_switch_states();
638 *(current_gear_status) = last_gear_status;
640 AERROR <<
"Lost last frame";
642 const auto& curr_gear =
643 partitioned_trajectories.at(current_trajectory_index).second;
644 if (flag_change_to_next || !current_gear_status->gear_shift_period_finished ||
645 curr_gear != ego_gear_) {
647 if (current_gear_status->gear_shift_period_started) {
648 current_gear_status->gear_shift_start_time =
649 Clock::Instance()->NowInSeconds();
650 current_gear_status->gear_shift_position =
651 partitioned_trajectories.at(current_trajectory_index).second;
652 current_gear_status->gear_shift_period_started =
false;
653 current_gear_status->gear_shift_period_time = 0.0;
655 if (current_gear_status->gear_shift_period_time >
657 current_gear_status->gear_shift_position == ego_gear_) {
658 current_gear_status->gear_shift_period_finished =
true;
659 current_gear_status->gear_shift_period_started =
true;
660 AINFO <<
"finished gear shift";
662 double init_kappa = partitioned_trajectories.at(current_trajectory_index)
666 GenerateGearShiftTrajectory(current_gear_status->gear_shift_position,
667 init_kappa, gear_switch_idle_time_trajectory);
668 current_gear_status->gear_shift_period_time =
669 Clock::Instance()->NowInSeconds() -
670 current_gear_status->gear_shift_start_time;
678void OpenSpaceTrajectoryPartition::GenerateGearShiftTrajectory(
681 gear_switch_idle_time_trajectory->first.clear();
685 for (
double t = 0.0; t < gear_shift_max_t; t += gear_shift_unit_t) {
686 TrajectoryPoint point;
690 point.mutable_path_point()->set_s(0.0);
691 point.mutable_path_point()->set_kappa(init_kappa);
692 point.set_relative_time(t);
695 gear_switch_idle_time_trajectory->first.emplace_back(point);
697 ADEBUG <<
"gear_switch_idle_time_trajectory"
698 << gear_switch_idle_time_trajectory->first.size();
699 gear_switch_idle_time_trajectory->second = gear_position;
702void OpenSpaceTrajectoryPartition::GenerateStopTrajectory(
703 DiscretizedTrajectory*
const trajectory_data,
704 double standstill_acceleration) {
705 double relative_time = 0.0;
707 static constexpr int stop_trajectory_length = 10;
708 static constexpr double relative_stop_time = 0.1;
709 trajectory_data->clear();
710 static constexpr double vEpsilon = 0.00001;
711 standstill_acceleration =
713 ? standstill_acceleration
714 : -1.0 * standstill_acceleration;
715 for (
size_t i = 0; i < stop_trajectory_length; i++) {
716 TrajectoryPoint point;
720 point.mutable_path_point()->set_s(0.0);
721 point.mutable_path_point()->set_kappa(0.0);
722 point.set_relative_time(relative_time);
724 point.set_a(standstill_acceleration);
725 trajectory_data->emplace_back(point);
726 relative_time += relative_stop_time;
730void OpenSpaceTrajectoryPartition::AdjustRelativeTimeAndS(
731 const std::vector<TrajGearPair>& partitioned_trajectories,
732 const size_t current_trajectory_index,
733 const size_t closest_trajectory_point_index,
734 DiscretizedTrajectory* unpartitioned_trajectory_result,
736 const size_t partitioned_trajectories_size = partitioned_trajectories.size();
737 CHECK_GT(partitioned_trajectories_size, current_trajectory_index);
741 *(current_partitioned_trajectory) =
742 partitioned_trajectories.at(current_trajectory_index);
743 auto trajectory = &(current_partitioned_trajectory->first);
745 trajectory->at(closest_trajectory_point_index).relative_time();
747 trajectory->at(closest_trajectory_point_index).path_point().s();
748 const size_t trajectory_size = trajectory->size();
749 for (
size_t i = 0; i < trajectory_size; ++i) {
750 TrajectoryPoint* trajectory_point = &(trajectory->at(i));
751 trajectory_point->set_relative_time(trajectory_point->relative_time() -
753 trajectory_point->mutable_path_point()->set_s(
754 trajectory_point->path_point().s() - s_shift);
764 const size_t unpartitioned_trajectory_size =
765 unpartitioned_trajectory_result->size();
779 for (
size_t i = 0; i < unpartitioned_trajectory_size; ++i) {
780 TrajectoryPoint* trajectory_point =
781 &(unpartitioned_trajectory_result->at(i));
782 trajectory_point->set_relative_time(trajectory_point->relative_time() -
784 trajectory_point->mutable_path_point()->set_s(
785 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