Skip to content

Commit 10e063d

Browse files
committed
feat(behavior_velocity_traffic_light): stop when the signal is unknown or timed out
Signed-off-by: Tomohito Ando <tomohito.ando@tier4.jp>
1 parent eb15a2b commit 10e063d

File tree

2 files changed

+57
-25
lines changed

2 files changed

+57
-25
lines changed

planning/behavior_velocity_traffic_light_module/src/scene.cpp

+51-25
Original file line numberDiff line numberDiff line change
@@ -228,33 +228,31 @@ bool TrafficLightModule::modifyPathVelocity(PathWithLaneId * path, StopReason *
228228

229229
first_ref_stop_path_point_index_ = stop_line_point_idx;
230230

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();
233236

234237
// 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
235240
const auto rest_time_to_red_signal =
236241
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);
252247
}
253248
return true;
254249
}
255250

251+
// Check if stop is coming.
252+
const bool is_stop_signal = isStopSignal();
253+
256254
// Update stop signal received time
257-
if (is_stop_signal) {
255+
if (is_stop_signal || is_unknown_signal || is_signal_timed_out) {
258256
if (!stop_signal_received_time_ptr_) {
259257
stop_signal_received_time_ptr_ = std::make_unique<Time>(clock_->now());
260258
}
@@ -301,8 +299,6 @@ bool TrafficLightModule::modifyPathVelocity(PathWithLaneId * path, StopReason *
301299

302300
bool TrafficLightModule::isStopSignal()
303301
{
304-
updateTrafficSignal();
305-
306302
// If there is no upcoming traffic signal information,
307303
// SIMULATION: it will PASS to prevent stopping on the planning simulator
308304
// or scenario simulator.
@@ -315,11 +311,6 @@ bool TrafficLightModule::isStopSignal()
315311
return true;
316312
}
317313

318-
// Stop if the traffic signal information has timed out
319-
if (isTrafficSignalTimedOut()) {
320-
return true;
321-
}
322-
323314
return isTrafficSignalStop(looking_tl_state_);
324315
}
325316

@@ -522,4 +513,39 @@ bool TrafficLightModule::isDataTimeout(const rclcpp::Time & data_time) const
522513
return is_data_timeout;
523514
}
524515

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+
525551
} // namespace behavior_velocity_planner

planning/behavior_velocity_traffic_light_module/src/scene.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,16 @@ class TrafficLightModule : public SceneModuleInterface
110110

111111
bool isTrafficSignalTimedOut() const;
112112

113+
bool isUnknownSignal(const TrafficSignal & tl_state) const;
114+
113115
void updateTrafficSignal();
114116

115117
bool isDataTimeout(const rclcpp::Time & data_time) const;
116118

119+
bool canPassStopLineBeforeRed(
120+
const TrafficSignalTimeToRedStamped & time_to_red_signal,
121+
const double distance_to_stop_line) const;
122+
117123
// Lane id
118124
const int64_t lane_id_;
119125

0 commit comments

Comments
 (0)