Skip to content

Commit

Permalink
fix(lane_change): limit prepare and lane changing length (autowarefou…
Browse files Browse the repository at this point in the history
…ndation#6734)

Signed-off-by: Zulfaqar Azmi <[email protected]>
  • Loading branch information
zulfaqar-azmi-t4 committed Apr 5, 2024
1 parent 06ec361 commit 5d58f1c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,21 @@ lanelet::ConstLanelets generateExpandedLanelets(
* @return rclcpp::Logger The logger instance configured for the specified lane change type.
*/
rclcpp::Logger getLogger(const std::string & type);
/**
* @brief Calculates the distance required during a lane change operation.
*
* Used for computing prepare or lane change length based on current and maximum velocity,
* acceleration, and duration, returning the lesser of accelerated distance or distance at max
* velocity.
*
* @param velocity The current velocity of the vehicle in meters per second (m/s).
* @param maximum_velocity The maximum velocity the vehicle can reach in meters per second (m/s).
* @param acceleration The acceleration of the vehicle in meters per second squared (m/s^2).
* @param duration The duration of the lane change in seconds (s).
* @return The calculated minimum distance in meters (m).
*/
double calcPhaseLength(
const double velocity, const double maximum_velocity, const double acceleration,
const double time);
} // namespace behavior_path_planner::utils::lane_change
#endif // BEHAVIOR_PATH_LANE_CHANGE_MODULE__UTILS__UTILS_HPP_
11 changes: 5 additions & 6 deletions planning/behavior_path_lane_change_module/src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,9 +1180,8 @@ bool NormalLaneChange::getLaneChangePaths(
(prepare_duration < 1e-3) ? 0.0
: ((prepare_velocity - current_velocity) / prepare_duration);

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

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

Expand Down Expand Up @@ -1234,9 +1233,9 @@ bool NormalLaneChange::getLaneChangePaths(
utils::lane_change::calcLaneChangingAcceleration(
initial_lane_changing_velocity, max_path_velocity, lane_changing_time,
sampled_longitudinal_acc);
const auto lane_changing_length =
initial_lane_changing_velocity * lane_changing_time +
0.5 * longitudinal_acc_on_lane_changing * lane_changing_time * lane_changing_time;
const auto lane_changing_length = utils::lane_change::calcPhaseLength(
initial_lane_changing_velocity, getCommonParam().max_vel,
longitudinal_acc_on_lane_changing, lane_changing_time);
const auto terminal_lane_changing_velocity = std::min(
initial_lane_changing_velocity + longitudinal_acc_on_lane_changing * lane_changing_time,
getCommonParam().max_vel);
Expand Down
10 changes: 10 additions & 0 deletions planning/behavior_path_lane_change_module/src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,4 +1168,14 @@ rclcpp::Logger getLogger(const std::string & type)
{
return rclcpp::get_logger("lane_change").get_child(type);
}

double calcPhaseLength(
const double velocity, const double maximum_velocity, const double acceleration,
const double duration)
{
const auto length_with_acceleration =
velocity * duration + 0.5 * acceleration * std::pow(duration, 2);
const auto length_with_max_velocity = maximum_velocity * duration;
return std::min(length_with_acceleration, length_with_max_velocity);
}
} // namespace behavior_path_planner::utils::lane_change

0 comments on commit 5d58f1c

Please sign in to comment.