24#include "gtest/gtest_prod.h"
26#include "absl/strings/str_cat.h"
28#include "modules/common_msgs/planning_msgs/planning_internal.pb.h"
29#include "modules/common_msgs/routing_msgs/routing.pb.h"
30#include "modules/planning/planning_base/proto/planning_semantic_map_config.pb.h"
66 std::string label_name_y) {
67 auto* options = chart->mutable_options();
68 double xmin(std::numeric_limits<double>::max()),
69 xmax(std::numeric_limits<double>::lowest()),
70 ymin(std::numeric_limits<double>::max()),
71 ymax(std::numeric_limits<double>::lowest());
72 for (
int i = 0; i < chart->line_size(); i++) {
73 auto* line = chart->mutable_line(i);
74 for (
auto& pt : line->point()) {
75 xmin = std::min(xmin, pt.x());
76 ymin = std::min(ymin, pt.y());
77 xmax = std::max(xmax, pt.x());
78 ymax = std::max(ymax, pt.y());
80 auto* properties = line->mutable_properties();
81 (*properties)[
"borderWidth"] =
"2";
82 (*properties)[
"pointRadius"] =
"0";
83 (*properties)[
"lineTension"] =
"0";
84 (*properties)[
"fill"] =
"false";
85 (*properties)[
"showLine"] =
"true";
87 options->mutable_x()->set_min(xmin);
88 options->mutable_x()->set_max(xmax);
89 options->mutable_x()->set_label_string(label_name_x);
90 options->mutable_y()->set_min(ymin);
91 options->mutable_y()->set_max(ymax);
92 options->mutable_y()->set_label_string(label_name_y);
96 if (reference_line_provider_) {
97 reference_line_provider_->Stop();
102 injector_->planning_context()->mutable_planning_status()->Clear();
103 last_command_.Clear();
110 if (!CheckPlanningConfig(config)) {
111 return Status(ErrorCode::PLANNING_ERROR,
112 "planning config error: " + config.DebugString());
121 injector_->planning_context()->mutable_planning_status()->Clear();
129 if (
config_.has_reference_line_config()) {
132 reference_line_provider_ = std::make_unique<ReferenceLineProvider>(
133 injector_->vehicle_state(), reference_line_config);
134 reference_line_provider_->Start();
140 ErrorCode::PLANNING_ERROR,
141 "planning is not initialized with config : " +
config_.DebugString());
147 FLAGS_planning_birdview_img_feature_renderer_config_file,
149 <<
"Failed to load renderer config"
150 << FLAGS_planning_birdview_img_feature_renderer_config_file;
152 BirdviewImgFeatureRenderer::Instance()->Init(renderer_config);
161Status OnLanePlanning::InitFrame(
const uint32_t sequence_num,
165 vehicle_state, reference_line_provider_.get()));
168 return Status(ErrorCode::PLANNING_ERROR,
"Fail to init frame: nullptr.");
171 std::list<ReferenceLine> reference_lines;
172 std::list<hdmap::RouteSegments> segments;
173 reference_line_provider_->GetReferenceLines(&reference_lines, &segments);
174 DCHECK_EQ(reference_lines.size(), segments.size());
179 for (
auto& ref_line : reference_lines) {
180 ref_line.SetEgoPosition(Vec2d(vehicle_state.
x(), vehicle_state.
y()));
181 if (!ref_line.Segment(Vec2d(vehicle_state.
x(), vehicle_state.
y()),
182 planning::FLAGS_look_backward_distance,
184 const std::string msg =
"Fail to shrink reference line.";
186 return Status(ErrorCode::PLANNING_ERROR, msg);
189 for (
auto& seg : segments) {
190 if (!seg.Shrink(Vec2d(vehicle_state.
x(), vehicle_state.
y()),
191 planning::FLAGS_look_backward_distance, forward_limit)) {
192 const std::string msg =
"Fail to shrink routing segments.";
194 return Status(ErrorCode::PLANNING_ERROR, msg);
198 auto status =
frame_->Init(
199 injector_->vehicle_state(), reference_lines, segments,
200 reference_line_provider_->FutureRouteWaypoints(),
injector_->ego_info());
202 AERROR <<
"failed to init frame:" << status.ToString();
209void OnLanePlanning::GenerateStopTrajectory(ADCTrajectory* ptr_trajectory_pb) {
210 ptr_trajectory_pb->clear_trajectory_point();
212 const auto& vehicle_state =
injector_->vehicle_state()->vehicle_state();
213 const double max_t = FLAGS_fallback_total_time;
214 const double unit_t = FLAGS_fallback_time_unit;
217 auto* path_point = tp.mutable_path_point();
218 path_point->set_x(vehicle_state.
x());
219 path_point->set_y(vehicle_state.
y());
220 path_point->set_theta(vehicle_state.
heading());
221 path_point->set_s(0.0);
224 for (
double t = 0.0; t < max_t; t += unit_t) {
225 tp.set_relative_time(t);
226 auto next_point = ptr_trajectory_pb->add_trajectory_point();
227 next_point->CopyFrom(tp);
237 const double start_system_timestamp =
238 std::chrono::duration<double>(
239 std::chrono::system_clock::now().time_since_epoch())
243 ADEBUG <<
"Get localization:"
253 const double vehicle_state_timestamp = vehicle_state.
timestamp();
254 DCHECK_GE(start_timestamp, vehicle_state_timestamp)
255 <<
"start_timestamp is behind vehicle_state_timestamp by "
256 << start_timestamp - vehicle_state_timestamp <<
" secs";
259 const std::string msg =
260 "Update VehicleStateProvider failed "
261 "or the vehicle state is out dated.";
263 ptr_trajectory_pb->mutable_decision()
264 ->mutable_main_decision()
265 ->mutable_not_ready()
267 status.
Save(ptr_trajectory_pb->mutable_header()->mutable_status());
271 GenerateStopTrajectory(ptr_trajectory_pb);
275 if (start_timestamp + 1e-6 < vehicle_state_timestamp) {
278 monitor_logger_buffer.ERROR(
"ego system time is behind GPS time");
281 if (start_timestamp - vehicle_state_timestamp <
282 FLAGS_message_latency_threshold) {
283 vehicle_state = AlignTimeStamp(vehicle_state, start_timestamp);
287 reference_line_provider_->UpdateVehicleState(vehicle_state);
292 reference_line_provider_->Reset();
294 injector_->planning_context()->mutable_planning_status()->Clear();
295 reference_line_provider_->UpdatePlanningCommand(
304 const double planning_cycle_time =
305 1.0 /
static_cast<double>(FLAGS_planning_loop_rate);
307 std::string replan_reason;
308 std::vector<TrajectoryPoint> stitching_trajectory =
311 planning_cycle_time, FLAGS_trajectory_stitching_preserved_length,
315 injector_->ego_info()->Update(stitching_trajectory.back(), vehicle_state);
316 const uint32_t frame_num =
static_cast<uint32_t
>(
seq_num_++);
317 AINFO <<
"Planning start frame sequence id = [" << frame_num <<
"]";
318 status = InitFrame(frame_num, stitching_trajectory.back(), vehicle_state);
320 injector_->ego_info()->CalculateFrontObstacleClearDistance(
322 injector_->ego_info()->CalculateCurrentRouteInfo(
323 reference_line_provider_.get());
326 if (FLAGS_enable_record_debug) {
327 frame_->RecordInputDebug(ptr_trajectory_pb->mutable_debug());
329 ptr_trajectory_pb->mutable_latency_stats()->set_init_frame_time_ms(
334 if (FLAGS_publish_estop) {
339 EStop* estop = estop_trajectory.mutable_estop();
340 estop->set_is_estop(
true);
342 status.
Save(estop_trajectory.mutable_header()->mutable_status());
343 ptr_trajectory_pb->CopyFrom(estop_trajectory);
345 ptr_trajectory_pb->mutable_decision()
346 ->mutable_main_decision()
347 ->mutable_not_ready()
349 status.
Save(ptr_trajectory_pb->mutable_header()->mutable_status());
350 GenerateStopTrajectory(ptr_trajectory_pb);
355 frame_->set_current_frame_planned_trajectory(*ptr_trajectory_pb);
356 const uint32_t n =
frame_->SequenceNum();
361 for (
auto& ref_line_info : *
frame_->mutable_reference_line_info()) {
362 auto traffic_status =
364 if (!traffic_status.ok() || !ref_line_info.IsDrivable()) {
365 ref_line_info.SetDrivable(
false);
366 AWARN <<
"Reference line " << ref_line_info.Lanes().Id()
367 <<
" traffic decider failed";
371 status =
Plan(start_timestamp, stitching_trajectory, ptr_trajectory_pb);
376 trajectory_print_curve.
AddPoint(
"trajxy", p.path_point().x(),
382 for (
const auto& obstacle :
frame_->obstacles()) {
383 obstacle->PrintPolygonCurve();
387 print_box.
AddAdcBox(vehicle_state.
x(), vehicle_state.
y(),
388 vehicle_state.
heading(),
true);
391 const auto end_system_timestamp =
392 std::chrono::duration<double>(
393 std::chrono::system_clock::now().time_since_epoch())
395 const auto time_diff_ms =
396 (end_system_timestamp - start_system_timestamp) * 1000;
397 ADEBUG <<
"total planning time spend: " << time_diff_ms <<
" ms.";
399 ptr_trajectory_pb->mutable_latency_stats()->set_total_time_ms(time_diff_ms);
400 ADEBUG <<
"Planning latency: "
404 status.
Save(ptr_trajectory_pb->mutable_header()->mutable_status());
406 if (FLAGS_publish_estop) {
407 AERROR <<
"Planning failed and set estop";
411 EStop* estop = ptr_trajectory_pb->mutable_estop();
412 estop->set_is_estop(
true);
417 ptr_trajectory_pb->set_is_replan(stitching_trajectory.size() == 1);
419 ptr_trajectory_pb->set_replan_reason(replan_reason);
422 if (
frame_->open_space_info().is_on_open_space_trajectory()) {
424 ADEBUG <<
"Planning pb:" << ptr_trajectory_pb->
header().DebugString();
425 frame_->set_current_frame_planned_trajectory(*ptr_trajectory_pb);
427 auto* ref_line_task =
428 ptr_trajectory_pb->mutable_latency_stats()->add_task_stats();
429 ref_line_task->set_time_ms(reference_line_provider_->LastTimeDelay() *
431 ref_line_task->set_name(
"ReferenceLineProvider");
434 ADEBUG <<
"Planning pb:" << ptr_trajectory_pb->
header().DebugString();
436 frame_->set_current_frame_planned_trajectory(*ptr_trajectory_pb);
437 if (FLAGS_enable_planning_smoother) {
443 const auto end_planning_perf_timestamp =
444 std::chrono::duration<double>(
445 std::chrono::system_clock::now().time_since_epoch())
447 const auto plnning_perf_ms =
448 (end_planning_perf_timestamp - start_system_timestamp) * 1000;
449 AINFO <<
"Planning Perf: planning name [" <<
Name() <<
"], "
450 << plnning_perf_ms <<
" ms.";
451 AINFO <<
"Planning end frame sequence id = [" << frame_num <<
"]";
456 if (!FLAGS_enable_record_debug) {
459 for (
auto& reference_line_info : *
frame_->mutable_reference_line_info()) {
460 auto rl_debug = debug->mutable_planning_data()->add_reference_line();
461 rl_debug->set_id(reference_line_info.Lanes().Id());
462 rl_debug->set_length(reference_line_info.reference_line().Length());
463 rl_debug->set_cost(reference_line_info.Cost());
464 rl_debug->set_is_change_lane_path(reference_line_info.IsChangeLanePath());
465 rl_debug->set_is_drivable(reference_line_info.IsDrivable());
466 rl_debug->set_is_protected(reference_line_info.GetRightOfWayStatus() ==
470 const auto& reference_points =
471 reference_line_info.reference_line().reference_points();
472 double kappa_rms = 0.0;
473 double dkappa_rms = 0.0;
474 double kappa_max_abs = std::numeric_limits<double>::lowest();
475 double dkappa_max_abs = std::numeric_limits<double>::lowest();
476 for (
const auto& reference_point : reference_points) {
477 double kappa_sq = reference_point.kappa() * reference_point.kappa();
478 double dkappa_sq = reference_point.dkappa() * reference_point.dkappa();
479 kappa_rms += kappa_sq;
480 dkappa_rms += dkappa_sq;
481 kappa_max_abs = kappa_max_abs < kappa_sq ? kappa_sq : kappa_max_abs;
482 dkappa_max_abs = dkappa_max_abs < dkappa_sq ? dkappa_sq : dkappa_max_abs;
484 double reference_points_size =
static_cast<double>(reference_points.size());
485 kappa_rms /= reference_points_size;
486 dkappa_rms /= reference_points_size;
487 kappa_rms = std::sqrt(kappa_rms);
488 dkappa_rms = std::sqrt(dkappa_rms);
489 rl_debug->set_kappa_rms(kappa_rms);
490 rl_debug->set_dkappa_rms(dkappa_rms);
491 rl_debug->set_kappa_max_abs(kappa_max_abs);
492 rl_debug->set_dkappa_max_abs(dkappa_max_abs);
494 bool is_off_road =
false;
495 double minimum_boundary = std::numeric_limits<double>::infinity();
497 const double adc_half_width =
499 const auto& reference_line_path =
500 reference_line_info.reference_line().GetMapPath();
501 const auto sample_s = 0.1;
502 const auto reference_line_length =
503 reference_line_info.reference_line().Length();
504 double average_offset = 0.0;
505 double sample_count = 0.0;
506 for (
double s = 0.0; s < reference_line_length; s += sample_s) {
507 double left_width = reference_line_path.GetLaneLeftWidth(s);
508 double right_width = reference_line_path.GetLaneRightWidth(s);
509 average_offset += 0.5 * std::abs(left_width - right_width);
510 if (left_width < adc_half_width || right_width < adc_half_width) {
513 if (left_width < minimum_boundary) {
514 minimum_boundary = left_width;
516 if (right_width < minimum_boundary) {
517 minimum_boundary = right_width;
521 rl_debug->set_is_offroad(is_off_road);
522 rl_debug->set_minimum_boundary(minimum_boundary);
523 rl_debug->set_average_offset(average_offset / sample_count);
528 const double current_time_stamp,
529 const std::vector<TrajectoryPoint>& stitching_trajectory,
531 auto* ptr_debug = ptr_trajectory_pb->mutable_debug();
532 if (FLAGS_enable_record_debug) {
533 ptr_debug->mutable_planning_data()->mutable_init_point()->CopyFrom(
534 stitching_trajectory.back());
535 frame_->mutable_open_space_info()->set_debug(ptr_debug);
536 frame_->mutable_open_space_info()->sync_debug_instance();
539 auto status =
planner_->Plan(stitching_trajectory.back(),
frame_.get(),
542 ptr_debug->mutable_planning_data()->set_front_clear_distance(
543 injector_->ego_info()->front_clear_distance());
545 if (
frame_->open_space_info().is_on_open_space_trajectory()) {
546 frame_->mutable_open_space_info()->sync_debug_instance();
547 const auto& publishable_trajectory =
548 frame_->open_space_info().publishable_trajectory_data().first;
549 const auto& publishable_trajectory_gear =
550 frame_->open_space_info().publishable_trajectory_data().second;
552 const auto& is_collision =
frame_->open_space_info().is_collision();
553 publishable_trajectory.PopulateTrajectoryProtobuf(ptr_trajectory_pb);
554 ptr_trajectory_pb->set_gear(publishable_trajectory_gear);
555 ptr_trajectory_pb->set_trajectory_type(trajectory_type);
556 ptr_trajectory_pb->set_is_collision(is_collision);
558 auto* engage_advice = ptr_trajectory_pb->mutable_engage_advice();
561 if (
injector_->vehicle_state()->vehicle_state().driving_mode() !=
562 Chassis::DrivingMode::Chassis_DrivingMode_COMPLETE_AUTO_DRIVE) {
564 engage_advice->set_reason(
565 "Ready to engage when staring with OPEN_SPACE_PLANNER");
568 engage_advice->set_reason(
"Keep engage while in parking");
571 ptr_trajectory_pb->mutable_decision()
572 ->mutable_main_decision()
574 ->set_status(MainParking::IN_PARKING);
576 if (FLAGS_enable_record_debug) {
578 frame_->mutable_open_space_info()->RecordDebug(ptr_debug);
579 ADEBUG <<
"Open space debug information added!";
582 ExportOpenSpaceChart(ptr_trajectory_pb->
debug(), *ptr_trajectory_pb,
586 const auto* best_ref_info =
frame_->FindDriveReferenceLineInfo();
587 const auto* target_ref_info =
frame_->FindTargetReferenceLineInfo();
588 if (!best_ref_info) {
589 const std::string msg =
"planner failed to make a driving plan";
594 return Status(ErrorCode::PLANNING_ERROR, msg);
599 for (
const auto& trajectory_point : stitching_trajectory) {
600 current_frame_planned_path.push_back(trajectory_point.path_point());
602 const auto& best_ref_path = best_ref_info->path_data().discretized_path();
603 std::copy(best_ref_path.begin() + 1, best_ref_path.end(),
604 std::back_inserter(current_frame_planned_path));
605 frame_->set_current_frame_planned_path(current_frame_planned_path);
607 ptr_debug->MergeFrom(best_ref_info->debug());
608 if (FLAGS_export_chart) {
609 ExportOnLaneChart(best_ref_info->debug(), ptr_debug);
611 ExportReferenceLineDebug(ptr_debug);
613 const auto* failed_ref_info =
frame_->FindFailedReferenceLineInfo();
614 if (failed_ref_info) {
615 ExportFailedLaneChangeSTChart(failed_ref_info->debug(), ptr_debug);
618 ptr_trajectory_pb->mutable_latency_stats()->MergeFrom(
619 best_ref_info->latency_stats());
621 ptr_trajectory_pb->set_right_of_way_status(
622 best_ref_info->GetRightOfWayStatus());
624 for (
const auto&
id : best_ref_info->TargetLaneId()) {
625 ptr_trajectory_pb->add_lane_id()->CopyFrom(
id);
628 for (
const auto&
id : target_ref_info->TargetLaneId()) {
629 ptr_trajectory_pb->add_target_lane_id()->CopyFrom(
id);
632 ptr_trajectory_pb->set_trajectory_type(best_ref_info->trajectory_type());
634 if (FLAGS_enable_rss_info) {
635 *ptr_trajectory_pb->mutable_rss_info() = best_ref_info->
rss_info();
638 best_ref_info->ExportDecision(ptr_trajectory_pb->mutable_decision(),
642 if (FLAGS_enable_record_debug) {
643 auto* reference_line = ptr_debug->mutable_planning_data()->add_path();
644 reference_line->set_name(
"planning_reference_line");
645 const auto& reference_points =
646 best_ref_info->reference_line().reference_points();
650 bool empty_path =
true;
651 for (
const auto& reference_point : reference_points) {
652 auto* path_point = reference_line->add_path_point();
653 path_point->set_x(reference_point.x());
654 path_point->set_y(reference_point.y());
655 path_point->set_theta(reference_point.heading());
656 path_point->set_kappa(reference_point.kappa());
657 path_point->set_dkappa(reference_point.dkappa());
659 path_point->set_s(0.0);
662 double dx = reference_point.x() - prev_x;
663 double dy = reference_point.y() - prev_y;
664 s += std::hypot(dx, dy);
665 path_point->set_s(s);
667 prev_x = reference_point.x();
668 prev_y = reference_point.y();
673 current_time_stamp, best_ref_info->trajectory()));
677 debug_traj.
AddPoint(
"traj_sv", traj_pt.path_point().s(), traj_pt.v());
678 debug_traj.
AddPoint(
"traj_sa", traj_pt.path_point().s(), traj_pt.a());
679 debug_traj.
AddPoint(
"traj_sk", traj_pt.path_point().s(),
680 traj_pt.path_point().kappa());
683 ADEBUG <<
"current_time_stamp: " << current_time_stamp;
686 std::vector<TrajectoryPoint>(stitching_trajectory.begin(),
687 stitching_trajectory.end() - 1));
691 best_ref_info->ExportEngageAdvice(
692 ptr_trajectory_pb->mutable_engage_advice(),
699bool OnLanePlanning::CheckPlanningConfig(
const PlanningConfig& config) {
705 double y_min,
double y_max, std::string y_label,
706 bool display,
Chart* chart) {
707 auto* options = chart->mutable_options();
708 options->mutable_x()->set_min(x_min);
709 options->mutable_x()->set_max(x_max);
710 options->mutable_y()->set_min(y_min);
711 options->mutable_y()->set_max(y_max);
712 options->mutable_x()->set_label_string(x_label);
713 options->mutable_y()->set_label_string(y_label);
714 options->set_legend_display(display);
718 if (st_graph.
name() ==
"DP_ST_SPEED_OPTIMIZER") {
719 chart->set_title(
"Speed Heuristic");
721 chart->set_title(
"Planning S-T Graph");
726 for (
const auto& boundary : st_graph.
boundary()) {
729 StGraphBoundaryDebug_StBoundaryType_Name(boundary.type()).substr(17);
731 auto* boundary_chart = chart->add_polygon();
732 auto* properties = boundary_chart->mutable_properties();
733 (*properties)[
"borderWidth"] =
"2";
734 (*properties)[
"pointRadius"] =
"0";
735 (*properties)[
"lineTension"] =
"0";
736 (*properties)[
"cubicInterpolationMode"] =
"monotone";
737 (*properties)[
"showLine"] =
"true";
738 (*properties)[
"showText"] =
"true";
739 (*properties)[
"fill"] =
"false";
741 if (type ==
"DRIVABLE_REGION") {
742 (*properties)[
"color"] =
"\"rgba(0, 255, 0, 0.5)\"";
744 (*properties)[
"color"] =
"\"rgba(255, 0, 0, 0.8)\"";
747 boundary_chart->set_label(boundary.name() +
"_" + type);
748 for (
const auto& point : boundary.point()) {
749 auto* point_debug = boundary_chart->add_point();
750 point_debug->set_x(point.t());
751 point_debug->set_y(point.s());
755 auto* speed_profile = chart->add_line();
756 auto* properties = speed_profile->mutable_properties();
757 (*properties)[
"color"] =
"\"rgba(255, 255, 255, 0.5)\"";
759 auto* point_debug = speed_profile->add_point();
760 point_debug->set_x(point.t());
761 point_debug->set_y(point.s());
766 chart->set_title(sl_frame.
name());
769 auto* sl_line = chart->add_line();
770 sl_line->set_label(
"SL Path");
771 for (
const auto& sl_point : sl_frame.
sl_path()) {
772 auto* point_debug = sl_line->add_point();
773 point_debug->set_x(sl_point.s());
774 point_debug->set_x(sl_point.l());
779 const ::google::protobuf::RepeatedPtrField<SpeedPlan>& speed_plans,
781 chart->set_title(
"Speed Plan");
785 for (
const auto& speed_plan : speed_plans) {
786 auto* line = chart->add_line();
787 line->set_label(speed_plan.name());
788 for (
const auto& point : speed_plan.speed_point()) {
789 auto* point_debug = line->add_point();
790 point_debug->set_x(point.s());
791 point_debug->set_y(point.v());
795 auto* properties = line->mutable_properties();
796 (*properties)[
"borderWidth"] =
"2";
797 (*properties)[
"pointRadius"] =
"0";
798 (*properties)[
"fill"] =
"false";
799 (*properties)[
"showLine"] =
"true";
800 if (speed_plan.name() ==
"DpStSpeedOptimizer") {
801 (*properties)[
"color"] =
"\"rgba(27, 249, 105, 0.5)\"";
802 }
else if (speed_plan.name() ==
"QpSplineStSpeedOptimizer") {
803 (*properties)[
"color"] =
"\"rgba(54, 162, 235, 1)\"";
808void OnLanePlanning::ExportFailedLaneChangeSTChart(
812 auto* dst_data = debug_chart->mutable_planning_data();
813 for (
const auto& st_graph : src_data.st_graph()) {
818void OnLanePlanning::ExportOnLaneChart(
819 const planning_internal::Debug& debug_info,
820 planning_internal::Debug* debug_chart) {
821 const auto& src_data = debug_info.planning_data();
822 auto* dst_data = debug_chart->mutable_planning_data();
823 for (
const auto& st_graph : src_data.st_graph()) {
826 for (
const auto& sl_frame : src_data.sl_frame()) {
829 AddSpeedPlan(src_data.speed_plan(), dst_data->add_chart());
832void OnLanePlanning::ExportOpenSpaceChart(
833 const planning_internal::Debug& debug_info,
834 const ADCTrajectory& trajectory_pb, planning_internal::Debug* debug_chart) {
836 if (FLAGS_enable_record_debug) {
837 AddOpenSpaceOptimizerResult(debug_info, debug_chart);
838 AddPartitionedTrajectory(debug_info, debug_chart);
839 AddStitchSpeedProfile(debug_chart);
840 AddPublishedSpeed(trajectory_pb, debug_chart);
841 AddPublishedAcceleration(trajectory_pb, debug_chart);
846void OnLanePlanning::AddOpenSpaceOptimizerResult(
847 const planning_internal::Debug& debug_info,
848 planning_internal::Debug* debug_chart) {
850 if (!
frame_->open_space_info().open_space_provider_success()) {
854 auto chart = debug_chart->mutable_planning_data()->add_chart();
855 auto open_space_debug = debug_info.planning_data().open_space();
857 chart->set_title(
"Open Space Trajectory Optimizer Visualization");
859 open_space_debug.xy_boundary(1) + 1.0,
"x (meter)",
860 open_space_debug.xy_boundary(2) - 1.0,
861 open_space_debug.xy_boundary(3) + 1.0,
"y (meter)",
true,
864 chart->mutable_options()->set_sync_xy_window_size(
true);
865 chart->mutable_options()->set_aspect_ratio(0.9);
866 int obstacle_index = 1;
867 for (
const auto& obstacle : open_space_debug.obstacles()) {
868 auto* obstacle_outline = chart->add_line();
869 obstacle_outline->set_label(absl::StrCat(
"Bdr", obstacle_index));
871 for (
int vertice_index = 0;
872 vertice_index < obstacle.vertices_x_coords_size(); vertice_index++) {
873 auto* point_debug = obstacle_outline->add_point();
874 point_debug->set_x(obstacle.vertices_x_coords(vertice_index));
875 point_debug->set_y(obstacle.vertices_y_coords(vertice_index));
878 auto* obstacle_properties = obstacle_outline->mutable_properties();
879 (*obstacle_properties)[
"borderWidth"] =
"2";
880 (*obstacle_properties)[
"pointRadius"] =
"0";
881 (*obstacle_properties)[
"lineTension"] =
"0";
882 (*obstacle_properties)[
"fill"] =
"false";
883 (*obstacle_properties)[
"showLine"] =
"true";
886 auto smoothed_trajectory = open_space_debug.smoothed_trajectory();
887 auto* smoothed_line = chart->add_line();
888 smoothed_line->set_label(
"Smooth");
890 for (
int i = 0; i < smoothed_trajectory.vehicle_motion_point_size() / 2;
892 auto& point = smoothed_trajectory.vehicle_motion_point(i);
893 const auto x = point.trajectory_point().path_point().x();
894 const auto y = point.trajectory_point().path_point().y();
908 auto* point_debug = smoothed_line->add_point();
909 point_debug->set_x(x);
910 point_debug->set_y(y);
914 auto* smoothed_properties = smoothed_line->mutable_properties();
915 (*smoothed_properties)[
"borderWidth"] =
"2";
916 (*smoothed_properties)[
"pointRadius"] =
"0";
917 (*smoothed_properties)[
"lineTension"] =
"0";
918 (*smoothed_properties)[
"fill"] =
"false";
919 (*smoothed_properties)[
"showLine"] =
"true";
921 auto warm_start_trajectory = open_space_debug.warm_start_trajectory();
922 auto* warm_start_line = chart->add_line();
923 warm_start_line->set_label(
"WarmStart");
924 for (
int i = 0; i < warm_start_trajectory.vehicle_motion_point_size() / 2;
926 auto* point_debug = warm_start_line->add_point();
927 auto& point = warm_start_trajectory.vehicle_motion_point(i);
928 point_debug->set_x(point.trajectory_point().path_point().x());
929 point_debug->set_y(point.trajectory_point().path_point().y());
932 auto* warm_start_properties = warm_start_line->mutable_properties();
933 (*warm_start_properties)[
"borderWidth"] =
"2";
934 (*warm_start_properties)[
"pointRadius"] =
"0";
935 (*warm_start_properties)[
"lineTension"] =
"0";
936 (*warm_start_properties)[
"fill"] =
"false";
937 (*warm_start_properties)[
"showLine"] =
"true";
940void OnLanePlanning::AddPartitionedTrajectory(
941 const planning_internal::Debug& debug_info,
942 planning_internal::Debug* debug_chart) {
944 if (!
frame_->open_space_info().open_space_provider_success()) {
948 const auto& open_space_debug = debug_info.planning_data().open_space();
949 const auto& chosen_trajectories =
950 open_space_debug.chosen_trajectory().trajectory();
951 if (chosen_trajectories.empty() ||
952 chosen_trajectories[0].trajectory_point().empty()) {
956 const auto& vehicle_state =
frame_->vehicle_state();
957 auto chart = debug_chart->mutable_planning_data()->add_chart();
958 auto chart_kappa = debug_chart->mutable_planning_data()->add_chart();
959 auto chart_theta = debug_chart->mutable_planning_data()->add_chart();
960 chart->set_title(
"Open Space Partitioned Trajectory");
961 chart_kappa->set_title(
"total kappa");
962 chart_theta->set_title(
"total theta");
963 auto* options = chart->mutable_options();
964 options->mutable_x()->set_label_string(
"x (meter)");
965 options->mutable_y()->set_label_string(
"y (meter)");
966 options->set_sync_xy_window_size(
true);
967 options->set_aspect_ratio(0.9);
970 auto* adc_shape = chart->add_car();
971 adc_shape->set_x(vehicle_state.
x());
972 adc_shape->set_y(vehicle_state.
y());
973 adc_shape->set_heading(vehicle_state.
heading());
974 adc_shape->set_label(
"ADV");
975 adc_shape->set_color(
"rgba(54, 162, 235, 1)");
978 const auto& chosen_trajectory = chosen_trajectories[0];
979 auto* chosen_line = chart->add_line();
980 chosen_line->set_label(
"Chosen");
981 for (
const auto& point : chosen_trajectory.trajectory_point()) {
982 auto* point_debug = chosen_line->add_point();
983 point_debug->set_x(point.path_point().x());
984 point_debug->set_y(point.path_point().y());
986 auto* chosen_properties = chosen_line->mutable_properties();
987 (*chosen_properties)[
"borderWidth"] =
"2";
988 (*chosen_properties)[
"pointRadius"] =
"0";
989 (*chosen_properties)[
"lineTension"] =
"0";
990 (*chosen_properties)[
"fill"] =
"false";
991 (*chosen_properties)[
"showLine"] =
"true";
992 auto* theta_line = chart_theta->add_line();
993 auto* kappa_line = chart_kappa->add_line();
995 size_t partitioned_trajectory_label = 0;
996 for (
const auto& partitioned_trajectory :
997 open_space_debug.partitioned_trajectories().trajectory()) {
998 auto* partition_line = chart->add_line();
999 partition_line->set_label(
1000 absl::StrCat(
"Partitioned ", partitioned_trajectory_label));
1001 ++partitioned_trajectory_label;
1002 for (
const auto& point : partitioned_trajectory.trajectory_point()) {
1003 auto* point_debug = partition_line->add_point();
1004 auto* point_theta = theta_line->add_point();
1005 auto* point_kappa = kappa_line->add_point();
1006 point_debug->set_x(point.path_point().x());
1007 point_debug->set_y(point.path_point().y());
1008 point_theta->set_x(point.relative_time());
1009 point_kappa->set_x(point.relative_time());
1010 point_theta->set_y(point.path_point().theta());
1011 point_kappa->set_y(point.path_point().kappa());
1014 auto* partition_properties = partition_line->mutable_properties();
1015 (*partition_properties)[
"borderWidth"] =
"2";
1016 (*partition_properties)[
"pointRadius"] =
"0";
1017 (*partition_properties)[
"lineTension"] =
"0";
1018 (*partition_properties)[
"fill"] =
"false";
1019 (*partition_properties)[
"showLine"] =
"true";
1084void OnLanePlanning::AddStitchSpeedProfile(
1085 planning_internal::Debug* debug_chart) {
1086 if (!
injector_->frame_history()->Latest()) {
1087 AINFO <<
"Planning frame is empty!";
1092 if (!
frame_->open_space_info().open_space_provider_success()) {
1096 auto chart = debug_chart->mutable_planning_data()->add_chart();
1097 chart->set_title(
"Open Space Speed Plan Visualization");
1098 auto* options = chart->mutable_options();
1100 double xmin(std::numeric_limits<double>::max()),
1101 xmax(std::numeric_limits<double>::lowest()),
1102 ymin(std::numeric_limits<double>::max()),
1103 ymax(std::numeric_limits<double>::lowest());
1105 auto* speed_profile = chart->add_line();
1106 speed_profile->set_label(
"Speed Profile");
1107 const auto& last_trajectory =
1108 injector_->frame_history()->Latest()->current_frame_planned_trajectory();
1109 for (
const auto& point : last_trajectory.trajectory_point()) {
1110 auto* point_debug = speed_profile->add_point();
1111 point_debug->set_x(point.relative_time() +
1112 last_trajectory.header().timestamp_sec());
1113 point_debug->set_y(point.v());
1114 if (point_debug->x() > xmax) xmax = point_debug->x();
1115 if (point_debug->x() < xmin) xmin = point_debug->x();
1116 if (point_debug->y() > ymax) ymax = point_debug->y();
1117 if (point_debug->y() < ymin) ymin = point_debug->y();
1119 options->mutable_x()->set_window_size(xmax - xmin);
1120 options->mutable_x()->set_label_string(
"time (s)");
1121 options->mutable_y()->set_min(ymin);
1122 options->mutable_y()->set_max(ymax);
1123 options->mutable_y()->set_label_string(
"speed (m/s)");
1125 auto* speed_profile_properties = speed_profile->mutable_properties();
1126 (*speed_profile_properties)[
"borderWidth"] =
"2";
1127 (*speed_profile_properties)[
"pointRadius"] =
"0";
1128 (*speed_profile_properties)[
"lineTension"] =
"0";
1129 (*speed_profile_properties)[
"fill"] =
"false";
1130 (*speed_profile_properties)[
"showLine"] =
"true";
1133void OnLanePlanning::AddPublishedSpeed(
const ADCTrajectory& trajectory_pb,
1134 planning_internal::Debug* debug_chart) {
1136 if (!
frame_->open_space_info().open_space_provider_success()) {
1140 auto chart = debug_chart->mutable_planning_data()->add_chart();
1141 chart->set_title(
"Speed Partition Visualization");
1142 auto* options = chart->mutable_options();
1145 auto* speed_profile = chart->add_line();
1146 speed_profile->set_label(
"Speed Profile");
1147 double xmin(std::numeric_limits<double>::max()),
1148 xmax(std::numeric_limits<double>::lowest()),
1149 ymin(std::numeric_limits<double>::max()),
1150 ymax(std::numeric_limits<double>::lowest());
1151 for (
const auto& point : trajectory_pb.trajectory_point()) {
1152 auto* point_debug = speed_profile->add_point();
1153 point_debug->set_x(point.relative_time() +
1154 trajectory_pb.header().timestamp_sec());
1156 point_debug->set_y(point.v());
1159 point_debug->set_y(-point.v());
1161 if (point_debug->x() > xmax) xmax = point_debug->x();
1162 if (point_debug->x() < xmin) xmin = point_debug->x();
1163 if (point_debug->y() > ymax) ymax = point_debug->y();
1164 if (point_debug->y() < ymin) ymin = point_debug->y();
1166 options->mutable_x()->set_window_size(xmax - xmin);
1167 options->mutable_x()->set_label_string(
"time (s)");
1168 options->mutable_y()->set_min(ymin);
1169 options->mutable_y()->set_max(ymax);
1170 options->mutable_y()->set_label_string(
"speed (m/s)");
1172 auto* speed_profile_properties = speed_profile->mutable_properties();
1173 (*speed_profile_properties)[
"borderWidth"] =
"2";
1174 (*speed_profile_properties)[
"pointRadius"] =
"0";
1175 (*speed_profile_properties)[
"lineTension"] =
"0";
1176 (*speed_profile_properties)[
"fill"] =
"false";
1177 (*speed_profile_properties)[
"showLine"] =
"true";
1179 auto* sliding_line = chart->add_line();
1180 sliding_line->set_label(
"Time");
1182 auto* point_debug_up = sliding_line->add_point();
1184 point_debug_up->set_y(2.1);
1185 auto* point_debug_down = sliding_line->add_point();
1187 point_debug_down->set_y(-1.1);
1190 auto* sliding_line_properties = sliding_line->mutable_properties();
1191 (*sliding_line_properties)[
"borderWidth"] =
"2";
1192 (*sliding_line_properties)[
"pointRadius"] =
"0";
1193 (*sliding_line_properties)[
"lineTension"] =
"0";
1194 (*sliding_line_properties)[
"fill"] =
"false";
1195 (*sliding_line_properties)[
"showLine"] =
"true";
1198VehicleState OnLanePlanning::AlignTimeStamp(
const VehicleState& vehicle_state,
1199 const double curr_timestamp)
const {
1202 auto future_xy =
injector_->vehicle_state()->EstimateFuturePosition(
1203 curr_timestamp - vehicle_state.timestamp());
1205 VehicleState aligned_vehicle_state = vehicle_state;
1206 aligned_vehicle_state.set_x(future_xy.x());
1207 aligned_vehicle_state.set_y(future_xy.y());
1208 aligned_vehicle_state.set_timestamp(curr_timestamp);
1209 return aligned_vehicle_state;
1212void OnLanePlanning::AddPublishedAcceleration(
1213 const ADCTrajectory& trajectory_pb, planning_internal::Debug* debug) {
1215 if (!
frame_->open_space_info().open_space_provider_success()) {
1218 double xmin(std::numeric_limits<double>::max()),
1219 xmax(std::numeric_limits<double>::lowest()),
1220 ymin(std::numeric_limits<double>::max()),
1221 ymax(std::numeric_limits<double>::lowest());
1222 auto chart = debug->mutable_planning_data()->add_chart();
1223 chart->set_title(
"Acceleration Partition Visualization");
1224 auto* options = chart->mutable_options();
1227 auto* acceleration_profile = chart->add_line();
1228 acceleration_profile->set_label(
"Acceleration Profile");
1229 for (
const auto& point : trajectory_pb.trajectory_point()) {
1230 auto* point_debug = acceleration_profile->add_point();
1231 point_debug->set_x(point.relative_time() +
1232 trajectory_pb.header().timestamp_sec());
1234 point_debug->set_y(point.a());
1236 point_debug->set_y(-point.a());
1237 if (point_debug->x() > xmax) xmax = point_debug->x();
1238 if (point_debug->x() < xmin) xmin = point_debug->x();
1239 if (point_debug->y() > ymax) ymax = point_debug->y();
1240 if (point_debug->y() < ymin) ymin = point_debug->y();
1242 options->mutable_x()->set_window_size(xmax - xmin);
1243 options->mutable_x()->set_label_string(
"time (s)");
1244 options->mutable_y()->set_min(ymin);
1245 options->mutable_y()->set_max(ymax);
1246 options->mutable_y()->set_label_string(
"acceleration (m/s)");
1248 auto* acceleration_profile_properties =
1249 acceleration_profile->mutable_properties();
1250 (*acceleration_profile_properties)[
"borderWidth"] =
"2";
1251 (*acceleration_profile_properties)[
"pointRadius"] =
"0";
1252 (*acceleration_profile_properties)[
"lineTension"] =
"0";
1253 (*acceleration_profile_properties)[
"fill"] =
"false";
1254 (*acceleration_profile_properties)[
"showLine"] =
"true";
1256 auto* sliding_line = chart->add_line();
1257 sliding_line->set_label(
"Time");
1259 auto* point_debug_up = sliding_line->add_point();
1261 point_debug_up->set_y(2.1);
1262 auto* point_debug_down = sliding_line->add_point();
1264 point_debug_down->set_y(-1.1);
1267 auto* sliding_line_properties = sliding_line->mutable_properties();
1268 (*sliding_line_properties)[
"borderWidth"] =
"2";
1269 (*sliding_line_properties)[
"pointRadius"] =
"0";
1270 (*sliding_line_properties)[
"lineTension"] =
"0";
1271 (*sliding_line_properties)[
"fill"] =
"false";
1272 (*sliding_line_properties)[
"showLine"] =
"true";
Define the birdview img feature renderer class
A general class to denote the return status of an API call.
bool ok() const
check whether the return status is OK.
const std::string & error_message() const
returns the error message of the status, empty if the status is OK.
std::string ToString() const
returns a string representation in a readable format.
void Save(StatusPb *status_pb)
save the error_code and error message to protobuf
static Status OK()
generate a success status.
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
The class of vehicle state.
Implements a class of 2-dimensional vectors.
a singleton clock that can be used to get the current timestamp.
static double NowInSeconds()
gets the current time in second.
static const HDMap * BaseMapPtr()
Frame holds all data for one planning cycle.
common::Status Plan(const double current_time_stamp, const std::vector< common::TrajectoryPoint > &stitching_trajectory, ADCTrajectory *const trajectory) override
Plan the trajectory given current vehicle state
void RunOnce(const LocalView &local_view, ADCTrajectory *const ptr_trajectory_pb) override
main logic of the planning module, runs periodically triggered by timer.
virtual ~OnLanePlanning()
common::Status Init(const PlanningConfig &config) override
module initialization function
std::string Name() const override
Planning name.
virtual apollo::common::Status Init(const PlanningConfig &config)
std::unique_ptr< Frame > frame_
virtual void FillPlanningPb(const double timestamp, ADCTrajectory *const trajectory_pb)
TrafficDecider traffic_decider_
std::unique_ptr< PublishableTrajectory > last_publishable_trajectory_
const hdmap::HDMap * hdmap_
std::shared_ptr< Planner > planner_
std::shared_ptr< DependencyInjector > injector_
static double LookForwardDistance(const double velocity)
void AddAdcBox(double x, double y, double heading, bool is_rear_axle_point=true)
void AddPoint(std::string key, double x, double y)
add point to curve key
apollo::common::Status Smooth(const FrameHistory *frame_history, const Frame *current_frame, ADCTrajectory *const current_trajectory_pb)
apollo::common::Status Execute(Frame *frame, ReferenceLineInfo *reference_line_info)
bool Init(const std::shared_ptr< DependencyInjector > &injector)
static std::vector< common::TrajectoryPoint > ComputeStitchingTrajectory(const canbus::Chassis &vehicle_chassis, const common::VehicleState &vehicle_state, const double current_timestamp, const double planning_cycle_time, const size_t preserved_points_num, const bool replan_by_offset, const PublishableTrajectory *prev_trajectory, std::string *replan_reason, const control::ControlInteractiveMsg &control_interactive_msg)
Planning module main class.
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
bool IsVehicleStateValid(const VehicleState &vehicle_state)
bool IsDifferentRouting(const PlanningCommand &first, const PlanningCommand &second)
void SetChartminmax(apollo::dreamview::Chart *chart, std::string label_name_x, std::string label_name_y)
void AddSpeedPlan(const ::google::protobuf::RepeatedPtrField< SpeedPlan > &speed_plans, Chart *chart)
void AddSTGraph(const STGraphDebug &st_graph, Chart *chart)
void PopulateChartOptions(double x_min, double x_max, std::string x_label, double y_min, double y_max, std::string y_label, bool display, Chart *chart)
void AddSLFrame(const SLFrameDebug &sl_frame, Chart *chart)
Contains a number of helper functions related to quaternions.
Declaration of the class ReferenceLineProvider.
optional VehicleParam vehicle_param
optional double linear_velocity
optional double timestamp
optional RSSInfo rss_info
optional LatencyStats latency_stats
repeated apollo::common::TrajectoryPoint trajectory_point
optional TrajectoryType trajectory_type
optional apollo::common::Header header
optional apollo::planning_internal::Debug debug
std::shared_ptr< routing::LaneWaypoint > end_lane_way_point
std::shared_ptr< localization::LocalizationEstimate > localization_estimate
std::shared_ptr< PlanningCommand > planning_command
std::shared_ptr< control::ControlInteractiveMsg > control_interactive_msg
std::shared_ptr< canbus::Chassis > chassis
optional ReferenceLineConfig reference_line_config
optional PlanningLearningMode learning_mode
optional PlanningData planning_data
repeated apollo::common::SLPoint sl_path
repeated apollo::common::SpeedPoint speed_profile
repeated StGraphBoundaryDebug boundary
LocalView contains all necessary data as planning input