32
32
33
33
#include < algorithm>
34
34
#include < cmath>
35
+ #include < functional>
35
36
#include < limits>
36
37
#include < set>
37
38
#include < tuple>
@@ -234,6 +235,10 @@ bool CrosswalkModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
234
235
static_cast <float >(crosswalk_.attribute (" safety_slow_down_speed" ).asDouble ().get ()));
235
236
}
236
237
// Apply safety slow down speed if the crosswalk is occluded
238
+ const auto now = clock_->now ();
239
+ const auto cmp_with_time_buffer = [&](const auto & t, const auto cmp_fn) {
240
+ return t && cmp_fn ((now - *t).seconds (), planner_param_.occlusion_time_buffer );
241
+ };
237
242
if (
238
243
planner_param_.occlusion_enable && !path_intersects.empty () &&
239
244
!is_crosswalk_ignored (crosswalk_, planner_param_.occlusion_ignore_with_traffic_light )) {
@@ -247,21 +252,21 @@ bool CrosswalkModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
247
252
if (!is_ego_on_the_crosswalk) {
248
253
if (is_crosswalk_occluded (
249
254
crosswalk_, *planner_data_->occupancy_grid , path_intersects.front (), detection_range,
250
- objects_ptr->objects , planner_param_))
251
- update_occlusion_timers (
252
- current_initial_occlusion_time_, most_recent_occlusion_time_, clock_-> now (),
253
- planner_param_. occlusion_time_buffer ) ;
254
- else
255
+ objects_ptr->objects , planner_param_)) {
256
+ if (!current_initial_occlusion_time_) current_initial_occlusion_time_ = now;
257
+ if ( cmp_with_time_buffer ( current_initial_occlusion_time_, std::greater_equal< double >{}))
258
+ most_recent_occlusion_time_ = now ;
259
+ } else if (! cmp_with_time_buffer (most_recent_occlusion_time_, std::greater< double >{})) {
255
260
current_initial_occlusion_time_.reset ();
261
+ }
256
262
257
- const auto is_last_occlusion_within_time_buffer =
258
- most_recent_occlusion_time_ && (clock_->now () - *most_recent_occlusion_time_).seconds () <=
259
- planner_param_.occlusion_time_buffer ;
260
- if (is_last_occlusion_within_time_buffer) {
263
+ if (cmp_with_time_buffer (most_recent_occlusion_time_, std::less_equal<double >{})) {
261
264
const auto target_velocity = calcTargetVelocity (path_intersects.front (), *path);
262
265
applySafetySlowDownSpeed (
263
266
*path, path_intersects,
264
267
std::max (target_velocity, planner_param_.occlusion_slow_down_velocity ));
268
+ } else {
269
+ most_recent_occlusion_time_.reset ();
265
270
}
266
271
}
267
272
}
0 commit comments