Skip to content

Commit a841ecf

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

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
@@ -33,6 +33,7 @@
3333

3434
#include <algorithm>
3535
#include <cmath>
36+
#include <functional>
3637
#include <limits>
3738
#include <set>
3839
#include <tuple>
@@ -235,6 +236,10 @@ bool CrosswalkModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
235236
static_cast<float>(crosswalk_.attribute("safety_slow_down_speed").asDouble().get()));
236237
}
237238
// 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+
};
238243
if (
239244
planner_param_.occlusion_enable && !path_intersects.empty() &&
240245
!is_crosswalk_ignored(crosswalk_, planner_param_.occlusion_ignore_with_traffic_light)) {
@@ -248,21 +253,21 @@ bool CrosswalkModule::modifyPathVelocity(PathWithLaneId * path, StopReason * sto
248253
if (!is_ego_on_the_crosswalk) {
249254
if (is_crosswalk_occluded(
250255
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>{})) {
256261
current_initial_occlusion_time_.reset();
262+
}
257263

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

0 commit comments

Comments
 (0)