47 bool has_plan =
false;
48 auto it = std::find_if(
55 (it->IsDrivable() && it->IsChangeLanePath() &&
56 it->trajectory().GetSpatialLength() > FLAGS_change_lane_min_length);
58 AERROR <<
"Fail to plan for lane change.";
62 if (!has_plan || !FLAGS_prioritize_change_lane) {
64 if (reference_line_info.IsChangeLanePath()) {
68 &reference_line_info);
70 AERROR <<
"planner failed to make a driving plan for: "
71 << reference_line_info.Lanes().Id();
81 if (complete_rtk_trajectory_.empty() || complete_rtk_trajectory_.size() < 2) {
82 const std::string msg =
83 "RTKReplayPlanner doesn't have a recorded trajectory or "
84 "the recorded trajectory doesn't have enough valid trajectory "
87 return Status(ErrorCode::PLANNING_ERROR, msg);
90 std::uint32_t matched_index =
91 QueryPositionMatchedPoint(planning_init_point, complete_rtk_trajectory_);
93 std::uint32_t forward_buffer =
94 static_cast<std::uint32_t
>(FLAGS_rtk_trajectory_forward);
96 std::uint32_t end_index = std::min<std::uint32_t>(
97 static_cast<std::uint32_t
>(complete_rtk_trajectory_.size()),
98 matched_index + forward_buffer);
101 std::vector<TrajectoryPoint> trajectory_points(
102 complete_rtk_trajectory_.begin() + matched_index,
103 complete_rtk_trajectory_.begin() + end_index);
106 double zero_time = complete_rtk_trajectory_[matched_index].relative_time();
107 for (
auto& trajectory_point : trajectory_points) {
108 trajectory_point.set_relative_time(trajectory_point.relative_time() -
115 while (trajectory_points.size() <
116 static_cast<size_t>(FLAGS_rtk_trajectory_forward)) {
117 const auto& last_point = trajectory_points.rbegin();
118 auto new_point = last_point;
119 new_point->set_relative_time(new_point->relative_time() +
120 FLAGS_rtk_trajectory_resolution);
121 trajectory_points.push_back(*new_point);
128 if (!complete_rtk_trajectory_.empty()) {
129 complete_rtk_trajectory_.clear();
132 std::ifstream file_in(filename.c_str());
133 if (!file_in.is_open()) {
134 AERROR <<
"RTKReplayPlanner cannot open trajectory file: " << filename;
140 getline(file_in, line);
143 getline(file_in, line);
148 const std::vector<std::string> tokens =
149 absl::StrSplit(line, absl::ByAnyChar(
"\t "));
150 if (tokens.size() < 11) {
151 AERROR <<
"RTKReplayPlanner parse line failed; the data dimension does "
158 point.mutable_path_point()->set_x(std::stod(tokens[0]));
159 point.mutable_path_point()->set_y(std::stod(tokens[1]));
160 point.mutable_path_point()->set_z(std::stod(tokens[2]));
162 point.set_v(std::stod(tokens[3]));
163 point.set_a(std::stod(tokens[4]));
165 point.mutable_path_point()->set_kappa(std::stod(tokens[5]));
166 point.mutable_path_point()->set_dkappa(std::stod(tokens[6]));
168 point.set_relative_time(std::stod(tokens[7]));
170 point.mutable_path_point()->set_theta(std::stod(tokens[8]));
172 point.mutable_path_point()->set_s(std::stod(tokens[10]));
173 complete_rtk_trajectory_.push_back(std::move(point));