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