Skip to content

Commit 5d58f1c

Browse files
fix(lane_change): limit prepare and lane changing length (autowarefoundation#6734)
Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp>
1 parent 06ec361 commit 5d58f1c

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

planning/behavior_path_lane_change_module/include/behavior_path_lane_change_module/utils/utils.hpp

+16
Original file line numberDiff line numberDiff line change
@@ -220,5 +220,21 @@ lanelet::ConstLanelets generateExpandedLanelets(
220220
* @return rclcpp::Logger The logger instance configured for the specified lane change type.
221221
*/
222222
rclcpp::Logger getLogger(const std::string & type);
223+
/**
224+
* @brief Calculates the distance required during a lane change operation.
225+
*
226+
* Used for computing prepare or lane change length based on current and maximum velocity,
227+
* acceleration, and duration, returning the lesser of accelerated distance or distance at max
228+
* velocity.
229+
*
230+
* @param velocity The current velocity of the vehicle in meters per second (m/s).
231+
* @param maximum_velocity The maximum velocity the vehicle can reach in meters per second (m/s).
232+
* @param acceleration The acceleration of the vehicle in meters per second squared (m/s^2).
233+
* @param duration The duration of the lane change in seconds (s).
234+
* @return The calculated minimum distance in meters (m).
235+
*/
236+
double calcPhaseLength(
237+
const double velocity, const double maximum_velocity, const double acceleration,
238+
const double time);
223239
} // namespace behavior_path_planner::utils::lane_change
224240
#endif // BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__UTILS_HPP_

planning/behavior_path_lane_change_module/src/scene.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -1180,9 +1180,8 @@ bool NormalLaneChange::getLaneChangePaths(
11801180
(prepare_duration < 1e-3) ? 0.0
11811181
: ((prepare_velocity - current_velocity) / prepare_duration);
11821182

1183-
const double prepare_length =
1184-
current_velocity * prepare_duration +
1185-
0.5 * longitudinal_acc_on_prepare * std::pow(prepare_duration, 2);
1183+
const auto prepare_length = utils::lane_change::calcPhaseLength(
1184+
current_velocity, getCommonParam().max_vel, longitudinal_acc_on_prepare, prepare_duration);
11861185

11871186
auto prepare_segment = getPrepareSegment(current_lanes, backward_path_length, prepare_length);
11881187

@@ -1234,9 +1233,9 @@ bool NormalLaneChange::getLaneChangePaths(
12341233
utils::lane_change::calcLaneChangingAcceleration(
12351234
initial_lane_changing_velocity, max_path_velocity, lane_changing_time,
12361235
sampled_longitudinal_acc);
1237-
const auto lane_changing_length =
1238-
initial_lane_changing_velocity * lane_changing_time +
1239-
0.5 * longitudinal_acc_on_lane_changing * lane_changing_time * lane_changing_time;
1236+
const auto lane_changing_length = utils::lane_change::calcPhaseLength(
1237+
initial_lane_changing_velocity, getCommonParam().max_vel,
1238+
longitudinal_acc_on_lane_changing, lane_changing_time);
12401239
const auto terminal_lane_changing_velocity = std::min(
12411240
initial_lane_changing_velocity + longitudinal_acc_on_lane_changing * lane_changing_time,
12421241
getCommonParam().max_vel);

planning/behavior_path_lane_change_module/src/utils/utils.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1168,4 +1168,14 @@ rclcpp::Logger getLogger(const std::string & type)
11681168
{
11691169
return rclcpp::get_logger("lane_change").get_child(type);
11701170
}
1171+
1172+
double calcPhaseLength(
1173+
const double velocity, const double maximum_velocity, const double acceleration,
1174+
const double duration)
1175+
{
1176+
const auto length_with_acceleration =
1177+
velocity * duration + 0.5 * acceleration * std::pow(duration, 2);
1178+
const auto length_with_max_velocity = maximum_velocity * duration;
1179+
return std::min(length_with_acceleration, length_with_max_velocity);
1180+
}
11711181
} // namespace behavior_path_planner::utils::lane_change

0 commit comments

Comments
 (0)