Skip to content

Commit

Permalink
make current lanes as member variables to reduce computation time and…
Browse files Browse the repository at this point in the history
… reduce code repetition

Signed-off-by: Daniel Sanchez <[email protected]>
  • Loading branch information
danielsanchezaran committed Nov 28, 2024
1 parent 62e9aa8 commit d1ce2fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class StartPlannerModule : public SceneModuleInterface
PlannerData planner_data;
ModuleStatus current_status;
PullOutStatus main_thread_pull_out_status;
lanelet::ConstLanelets current_lanelets;
lanelet::ConstLanelets extended_current_lanelets;
bool is_stopped;

StartPlannerData clone() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "autoware/behavior_path_start_planner_module/util.hpp"
#include "autoware/motion_utils/trajectory/trajectory.hpp"

#include <autoware/behavior_path_planner_common/data_manager.hpp>
#include <autoware_lanelet2_extension/utility/message_conversion.hpp>
#include <autoware_lanelet2_extension/utility/query.hpp>
#include <autoware_lanelet2_extension/utility/utilities.hpp>
Expand Down Expand Up @@ -380,7 +381,7 @@ bool StartPlannerModule::isModuleRunning() const
bool StartPlannerModule::isCurrentPoseOnMiddleOfTheRoad() const
{
const Pose & current_pose = planner_data_->self_odometry->pose.pose;
const lanelet::ConstLanelets current_lanes = utils::getCurrentLanes(planner_data_);
const lanelet::ConstLanelets & current_lanes = start_planner_data_->current_lanelets;

Check warning on line 384 in planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp#L384

Added line #L384 was not covered by tests
const double lateral_distance_to_center_lane =
lanelet::utils::getArcCoordinates(current_lanes, current_pose).distance;

Expand Down Expand Up @@ -426,7 +427,8 @@ bool StartPlannerModule::isPreventingRearVehicleFromPassingThrough(const Pose &
const auto & route_handler = planner_data_->route_handler;
const Pose start_pose = planner_data_->route_handler->getOriginalStartPose();

const auto target_lanes = utils::getCurrentLanes(planner_data_);
const auto & target_lanes = start_planner_data_->current_lanelets;

Check warning on line 430 in planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp#L430

Added line #L430 was not covered by tests

if (target_lanes.empty()) return false;

// Define functions to get distance between a point and a lane's boundaries.
Expand Down Expand Up @@ -821,12 +823,6 @@ BehaviorModuleOutput StartPlannerModule::planWaitingApproval()

waitApproval();

const double backward_path_length =
planner_data_->parameters.backward_path_length + parameters_->max_back_distance;
const auto current_lanes = utils::getExtendedCurrentLanes(
planner_data_, backward_path_length, std::numeric_limits<double>::max(),
/*forward_only_in_route*/ true);

auto stop_path = status_.driving_forward ? getCurrentPath() : status_.backward_path;
const auto drivable_lanes = generateDrivableLanes(stop_path);
const auto & dp = planner_data_->drivable_area_expansion_parameters;
Expand Down Expand Up @@ -1323,11 +1319,7 @@ bool StartPlannerModule::hasReachedPullOutEnd() const
const auto current_pose = planner_data_->self_odometry->pose.pose;

// check that ego has passed pull out end point
const double backward_path_length =
planner_data_->parameters.backward_path_length + parameters_->max_back_distance;
const auto current_lanes = utils::getExtendedCurrentLanes(
planner_data_, backward_path_length, std::numeric_limits<double>::max(),
/*forward_only_in_route*/ true);
const auto & current_lanes = start_planner_data_->extended_current_lanelets;

Check warning on line 1322 in planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp#L1322

Added line #L1322 was not covered by tests

const auto arclength_current = lanelet::utils::getArcCoordinates(current_lanes, current_pose);
const auto arclength_pull_out_end =
Expand Down Expand Up @@ -1372,7 +1364,7 @@ TurnSignalInfo StartPlannerModule::calcTurnSignalInfo()
path.points, status_.pull_out_path.start_pose.position);
const auto shift_end_idx =
autoware::motion_utils::findNearestIndex(path.points, status_.pull_out_path.end_pose.position);
const lanelet::ConstLanelets current_lanes = utils::getExtendedCurrentLanes(planner_data_);
const auto & current_lanes = start_planner_data_->extended_current_lanelets;

Check warning on line 1367 in planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp#L1367

Added line #L1367 was not covered by tests

const auto is_ignore_signal = [this](const lanelet::Id & id) {
if (!ignore_signal_.has_value()) {
Expand Down Expand Up @@ -1450,12 +1442,7 @@ bool StartPlannerModule::isSafePath() const
planner_data_->self_odometry->twist.twist.linear.y);
const auto & dynamic_object = planner_data_->dynamic_object;
const auto & route_handler = planner_data_->route_handler;
const double backward_path_length =
planner_data_->parameters.backward_path_length + parameters_->max_back_distance;

const auto current_lanes = utils::getExtendedCurrentLanes(
planner_data_, backward_path_length, std::numeric_limits<double>::max(),
/*forward_only_in_route*/ true);
const auto & current_lanes = start_planner_data_->extended_current_lanelets;

Check warning on line 1445 in planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp#L1445

Added line #L1445 was not covered by tests

// for ego predicted path
const size_t ego_seg_idx = planner_data_->findEgoSegmentIndex(pull_out_path.points);
Expand Down Expand Up @@ -1575,11 +1562,7 @@ std::optional<PullOutStatus> StartPlannerModule::planFreespacePath(
const double end_pose_search_end_distance = parameters.end_pose_search_end_distance;
const double end_pose_search_interval = parameters.end_pose_search_interval;

const double backward_path_length =
planner_data->parameters.backward_path_length + parameters.max_back_distance;
const auto current_lanes = utils::getExtendedCurrentLanes(
planner_data, backward_path_length, std::numeric_limits<double>::max(),
/*forward_only_in_route*/ true);
const auto & current_lanes = start_planner_data_->extended_current_lanelets;

Check warning on line 1565 in planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp#L1565

Added line #L1565 was not covered by tests

const auto current_arc_coords = lanelet::utils::getArcCoordinates(current_lanes, current_pose);

Expand Down Expand Up @@ -1946,5 +1929,18 @@ void StartPlannerModule::StartPlannerData::update(
current_status = current_status_;
main_thread_pull_out_status = pull_out_status_;
is_stopped = is_stopped_;

// compute current lanes
{
auto planner_data_ptr = std::make_shared<PlannerData>(planner_data);

current_lanelets = utils::getCurrentLanes(planner_data_ptr);

Check warning on line 1937 in planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp#L1937

Added line #L1937 was not covered by tests

const double backward_path_length =
planner_data_.parameters.backward_path_length + parameters_.max_back_distance;
extended_current_lanelets = utils::getExtendedCurrentLanes(

Check warning on line 1941 in planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp#L1939-L1941

Added lines #L1939 - L1941 were not covered by tests
planner_data_ptr, backward_path_length, std::numeric_limits<double>::max(),
/*forward_only_in_route*/ true);

Check warning on line 1943 in planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp

View check run for this annotation

Codecov / codecov/patch

planning/behavior_path_planner/autoware_behavior_path_start_planner_module/src/start_planner_module.cpp#L1943

Added line #L1943 was not covered by tests
}
}
} // namespace autoware::behavior_path_planner

0 comments on commit d1ce2fd

Please sign in to comment.