Skip to content

Commit

Permalink
fix(lane_change): limit prepare and lane changing length (#6734)
Browse files Browse the repository at this point in the history
Signed-off-by: Zulfaqar Azmi <[email protected]>
  • Loading branch information
zulfaqar-azmi-t4 authored Apr 4, 2024
1 parent 41aab51 commit f088fb4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,23 @@ Polygon2d getEgoCurrentFootprint(
bool isWithinIntersection(
const std::shared_ptr<RouteHandler> & route_handler, const lanelet::ConstLanelet & lanelet,
const Polygon2d & polygon);

/**
* @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

namespace behavior_path_planner::utils::lane_change::debug
Expand Down
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 @@ -1293,9 +1293,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 @@ -1347,9 +1346,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 @@ -1184,6 +1184,16 @@ bool isWithinIntersection(
return boost::geometry::within(
polygon, utils::toPolygon2d(lanelet::utils::to2D(lanelet_polygon.basicPolygon())));
}

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

namespace behavior_path_planner::utils::lane_change::debug
Expand Down

0 comments on commit f088fb4

Please sign in to comment.