Each stage does its business logic inside Process function.
If the stage want to transit to a different stage after finish, it should set the type of 'next_stage_'.
42 {
44 CHECK_NOTNULL(frame);
46
47 auto context = GetContextAs<TrafficLightUnprotectedRightTurnContext>();
48 const auto& scenario_config = context->scenario_config;
49
51 if (result.HasError()) {
52 AERROR <<
"TrafficLightRightTurnUnprotectedStop planning error";
53 }
54
55 if (context->current_traffic_light_overlap_ids.empty()) {
57 }
58
59 const auto& reference_line_info = frame->reference_line_info().front();
60 const double adc_front_edge_s = reference_line_info.AdcSlBoundary().end_s();
61
62 bool traffic_light_all_stop = true;
63 bool traffic_light_all_green = true;
64 bool traffic_light_no_right_turn_on_red = false;
65 PathOverlap* current_traffic_light_overlap = nullptr;
66
67 for (const auto& traffic_light_overlap_id :
68 context->current_traffic_light_overlap_ids) {
69
70 current_traffic_light_overlap =
71 reference_line_info.GetOverlapOnReferenceLine(
73 if (!current_traffic_light_overlap) {
74 continue;
75 }
76
77
78 reference_line_info.SetJunctionRightOfWay(
79 current_traffic_light_overlap->start_s, false);
80
81 const double distance_adc_to_stop_line =
82 current_traffic_light_overlap->start_s - adc_front_edge_s;
83 auto signal_color = frame->GetSignal(traffic_light_overlap_id).color();
84 ADEBUG <<
"traffic_light_overlap_id[" << traffic_light_overlap_id
85 << "] start_s[" << current_traffic_light_overlap->start_s
86 << "] distance_adc_to_stop_line[" << distance_adc_to_stop_line
87 << "] color[" << signal_color << "]";
88
89
90 if (distance_adc_to_stop_line > scenario_config.max_valid_stop_distance()) {
91 traffic_light_all_stop = false;
92 break;
93 }
94
95
96 if (signal_color != TrafficLight::GREEN) {
97 traffic_light_all_green = false;
98 traffic_light_no_right_turn_on_red =
99 CheckTrafficLightNoRightTurnOnRed(traffic_light_overlap_id);
100 break;
101 }
102 }
103
104 if (traffic_light_all_stop && traffic_light_all_green) {
105 return FinishStage(true);
106 }
107
108 if (traffic_light_no_right_turn_on_red) {
109 if (traffic_light_all_stop && !traffic_light_all_green) {
110
111 const double distance_adc_pass_stop_line =
112 adc_front_edge_s - current_traffic_light_overlap->end_s;
113 ADEBUG <<
"distance_adc_pass_stop_line[" << distance_adc_pass_stop_line
114 << "]";
115 if (distance_adc_pass_stop_line > scenario_config.min_pass_s_distance()) {
116 return FinishStage(false);
117 }
118
119 if (scenario_config.enable_right_turn_on_red()) {
120
121
122 if (context->stop_start_time == 0.0) {
124 } else {
125 auto start_time = context->stop_start_time;
127 ADEBUG <<
"stop_start_time[" << start_time <<
"] wait_time["
128 << wait_time << "]";
129 if (wait_time >
130 scenario_config.red_light_right_turn_stop_duration_sec()) {
131 return FinishStage(false);
132 }
133 }
134 }
135 }
136 } else {
137 return FinishStage(false);
138 }
139
141}
static double NowInSeconds()
gets the current time in second.
virtual StageResult FinishScenario()
StageResult ExecuteTaskOnReferenceLine(const common::TrajectoryPoint &planning_start_point, Frame *frame)