Skip to content

Commit cb760a4

Browse files
committed
fix timer
Signed-off-by: Maxime CLEMENT <maxime.clement@tier4.jp>
1 parent dacf85e commit cb760a4

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,4 @@ double calculate_detection_range(
180180
const auto time_to_crosswalk = dist_ego_to_crosswalk / std::max(min_ego_velocity, ego_velocity);
181181
return time_to_crosswalk > 0.0 ? time_to_crosswalk / occluded_object_velocity : 20.0;
182182
}
183-
184-
void update_occlusion_timers(
185-
std::optional<rclcpp::Time> & initial_time,
186-
std::optional<rclcpp::Time> & most_recent_slowdown_time, const rclcpp::Time & now,
187-
const double buffer)
188-
{
189-
if (!initial_time) initial_time = now;
190-
if ((now - *initial_time).seconds() >= buffer) most_recent_slowdown_time = now;
191-
}
192183
} // namespace behavior_velocity_planner

planning/behavior_velocity_crosswalk_module/src/occluded_crosswalk.hpp

-9
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,6 @@ std::vector<autoware_auto_perception_msgs::msg::PredictedObject> select_and_infl
9696
void clear_occlusions_behind_objects(
9797
grid_map::GridMap & grid_map,
9898
const std::vector<autoware_auto_perception_msgs::msg::PredictedObject> & objects);
99-
100-
/// @brief update timers so that the slowdown activates if the initial time is older than the buffer
101-
/// @param initial_time initial time
102-
/// @param most_recent_slowdown_time time to set only if initial_time is older than the buffer
103-
/// @param buffer [s] time buffer
104-
void update_occlusion_timers(
105-
std::optional<rclcpp::Time> & initial_time,
106-
std::optional<rclcpp::Time> & most_recent_slowdown_time, const rclcpp::Time & now,
107-
const double buffer);
10899
} // namespace behavior_velocity_planner
109100

110101
#endif // OCCLUDED_CROSSWALK_HPP_

planning/behavior_velocity_crosswalk_module/src/scene_crosswalk.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <algorithm>
3434
#include <cmath>
35+
#include <functional>
3536
#include <limits>
3637
#include <set>
3738
#include <tuple>
@@ -234,6 +235,10 @@ bool CrosswalkModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
234235
static_cast<float>(crosswalk_.attribute("safety_slow_down_speed").asDouble().get()));
235236
}
236237
// 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+
};
237242
if (
238243
planner_param_.occlusion_enable && !path_intersects.empty() &&
239244
!is_crosswalk_ignored(crosswalk_, planner_param_.occlusion_ignore_with_traffic_light)) {
@@ -247,21 +252,21 @@ bool CrosswalkModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
247252
if (!is_ego_on_the_crosswalk) {
248253
if (is_crosswalk_occluded(
249254
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>{})) {
255260
current_initial_occlusion_time_.reset();
261+
}
256262

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>{})) {
261264
const auto target_velocity = calcTargetVelocity(path_intersects.front(), *path);
262265
applySafetySlowDownSpeed(
263266
*path, path_intersects,
264267
std::max(target_velocity, planner_param_.occlusion_slow_down_velocity));
268+
} else {
269+
most_recent_occlusion_time_.reset();
265270
}
266271
}
267272
}

0 commit comments

Comments
 (0)