@@ -228,33 +228,31 @@ bool TrafficLightModule::modifyPathVelocity(PathWithLaneId * path, StopReason *
228
228
229
229
first_ref_stop_path_point_index_ = stop_line_point_idx;
230
230
231
- // Check if stop is coming.
232
- const bool is_stop_signal = isStopSignal ();
231
+ // Update traffic signal information
232
+ updateTrafficSignal ();
233
+
234
+ const bool is_unknown_signal = isUnknownSignal (looking_tl_state_);
235
+ const bool is_signal_timed_out = isTrafficSignalTimedOut ();
233
236
234
237
// Decide if stop or proceed using the remaining time to red signal
238
+ // If the upcoming traffic signal color is unknown or timed out, do not use the time to red and
239
+ // stop for the traffic signal
235
240
const auto rest_time_to_red_signal =
236
241
planner_data_->getRestTimeToRedSignal (traffic_light_reg_elem_.id ());
237
- if (
238
- planner_param_.v2i_use_rest_time && rest_time_to_red_signal &&
239
- !isDataTimeout (rest_time_to_red_signal->stamp )) {
240
- const double rest_time_allowed_to_go_ahead =
241
- rest_time_to_red_signal->time_to_red - planner_param_.v2i_last_time_allowed_to_pass ;
242
-
243
- const double ego_v = planner_data_->current_velocity ->twist .linear .x ;
244
- if (ego_v >= planner_param_.v2i_velocity_threshold ) {
245
- if (ego_v * rest_time_allowed_to_go_ahead <= signed_arc_length_to_stop_point) {
246
- *path = insertStopPose (input_path, stop_line_point_idx, stop_line_point, stop_reason);
247
- }
248
- } else {
249
- if (rest_time_allowed_to_go_ahead < planner_param_.v2i_required_time_to_departure ) {
250
- *path = insertStopPose (input_path, stop_line_point_idx, stop_line_point, stop_reason);
251
- }
242
+ const bool is_stop_required = is_unknown_signal || is_signal_timed_out;
243
+
244
+ if (planner_param_.v2i_use_rest_time && rest_time_to_red_signal && !is_stop_required) {
245
+ if (!canPassStopLineBeforeRed (*rest_time_to_red_signal, signed_arc_length_to_stop_point)) {
246
+ *path = insertStopPose (input_path, stop_line_point_idx, stop_line_point, stop_reason);
252
247
}
253
248
return true ;
254
249
}
255
250
251
+ // Check if stop is coming.
252
+ const bool is_stop_signal = isStopSignal ();
253
+
256
254
// Update stop signal received time
257
- if (is_stop_signal) {
255
+ if (is_stop_signal || is_unknown_signal || is_signal_timed_out ) {
258
256
if (!stop_signal_received_time_ptr_) {
259
257
stop_signal_received_time_ptr_ = std::make_unique<Time>(clock_->now ());
260
258
}
@@ -301,8 +299,6 @@ bool TrafficLightModule::modifyPathVelocity(PathWithLaneId * path, StopReason *
301
299
302
300
bool TrafficLightModule::isStopSignal ()
303
301
{
304
- updateTrafficSignal ();
305
-
306
302
// If there is no upcoming traffic signal information,
307
303
// SIMULATION: it will PASS to prevent stopping on the planning simulator
308
304
// or scenario simulator.
@@ -315,11 +311,6 @@ bool TrafficLightModule::isStopSignal()
315
311
return true ;
316
312
}
317
313
318
- // Stop if the traffic signal information has timed out
319
- if (isTrafficSignalTimedOut ()) {
320
- return true ;
321
- }
322
-
323
314
return isTrafficSignalStop (looking_tl_state_);
324
315
}
325
316
@@ -522,4 +513,39 @@ bool TrafficLightModule::isDataTimeout(const rclcpp::Time & data_time) const
522
513
return is_data_timeout;
523
514
}
524
515
516
+ bool TrafficLightModule::canPassStopLineBeforeRed (
517
+ const TrafficSignalTimeToRedStamped & time_to_red_signal,
518
+ const double distance_to_stop_line) const
519
+ {
520
+ if (isDataTimeout (time_to_red_signal.stamp )) {
521
+ return false ;
522
+ }
523
+
524
+ const double rest_time_allowed_to_go_ahead =
525
+ time_to_red_signal.time_to_red - planner_param_.v2i_last_time_allowed_to_pass ;
526
+
527
+ const double ego_v = planner_data_->current_velocity ->twist .linear .x ;
528
+ if (ego_v >= planner_param_.v2i_velocity_threshold ) {
529
+ if (ego_v * rest_time_allowed_to_go_ahead <= distance_to_stop_line) {
530
+ return false ;
531
+ }
532
+ } else {
533
+ if (rest_time_allowed_to_go_ahead < planner_param_.v2i_required_time_to_departure ) {
534
+ return false ;
535
+ }
536
+ }
537
+
538
+ return true ;
539
+ }
540
+
541
+ bool TrafficLightModule::isUnknownSignal (const TrafficSignal & tl_state) const
542
+ {
543
+ if (tl_state.elements .empty ()) {
544
+ return false ;
545
+ }
546
+
547
+ const bool has_unknown = hasTrafficLightCircleColor (tl_state, TrafficSignalElement::UNKNOWN);
548
+ return has_unknown;
549
+ }
550
+
525
551
} // namespace behavior_velocity_planner
0 commit comments