提交 3b16d429 编写于 作者: 知行合一2018's avatar 知行合一2018 提交者: Liangliang Zhang

Planning: used std::transform for coordinate transformation to increase...

Planning: used std::transform for coordinate transformation to increase algorithm efficiency and save space.
上级 b0982f46
...@@ -132,21 +132,5 @@ double DiscretizedTrajectory::GetSpatialLength() const { ...@@ -132,21 +132,5 @@ double DiscretizedTrajectory::GetSpatialLength() const {
trajectory_points_.front().path_point().s(); trajectory_points_.front().path_point().s();
} }
std::uint32_t DiscretizedTrajectory::NumOfPoints() const {
return trajectory_points_.size();
}
const std::vector<TrajectoryPoint>& DiscretizedTrajectory::trajectory_points()
const {
return trajectory_points_;
}
void DiscretizedTrajectory::SetTrajectoryPoints(
const std::vector<common::TrajectoryPoint>& trajectory_points) {
trajectory_points_ = trajectory_points;
}
void DiscretizedTrajectory::Clear() { trajectory_points_.clear(); }
} // namespace planning } // namespace planning
} // namespace apollo } // namespace apollo
...@@ -78,6 +78,7 @@ class DiscretizedTrajectory : public Trajectory { ...@@ -78,6 +78,7 @@ class DiscretizedTrajectory : public Trajectory {
uint32_t NumOfPoints() const; uint32_t NumOfPoints() const;
const std::vector<common::TrajectoryPoint>& trajectory_points() const; const std::vector<common::TrajectoryPoint>& trajectory_points() const;
std::vector<common::TrajectoryPoint>& trajectory_points();
virtual void Clear(); virtual void Clear();
...@@ -85,6 +86,27 @@ class DiscretizedTrajectory : public Trajectory { ...@@ -85,6 +86,27 @@ class DiscretizedTrajectory : public Trajectory {
std::vector<common::TrajectoryPoint> trajectory_points_; std::vector<common::TrajectoryPoint> trajectory_points_;
}; };
inline std::uint32_t DiscretizedTrajectory::NumOfPoints() const {
return trajectory_points_.size();
}
inline const std::vector<common::TrajectoryPoint>&
DiscretizedTrajectory::trajectory_points() const {
return trajectory_points_;
}
inline std::vector<common::TrajectoryPoint>&
DiscretizedTrajectory::trajectory_points() {
return trajectory_points_;
}
inline void DiscretizedTrajectory::SetTrajectoryPoints(
const std::vector<common::TrajectoryPoint>& trajectory_points) {
trajectory_points_ = trajectory_points;
}
inline void DiscretizedTrajectory::Clear() { trajectory_points_.clear(); }
} // namespace planning } // namespace planning
} // namespace apollo } // namespace apollo
......
...@@ -63,31 +63,39 @@ void TrajectoryStitcher::TransformLastPublishedTrajectory( ...@@ -63,31 +63,39 @@ void TrajectoryStitcher::TransformLastPublishedTrajectory(
return; return;
} }
const double time_diff = current_time - prev_trajectory->header_time(); const double time_diff = current_time - prev_trajectory->header_time();
auto matched_point = prev_trajectory->Evaluate(time_diff); const auto& matched_point = prev_trajectory->Evaluate(time_diff);
if (!matched_point.has_path_point()) { if (!matched_point.has_path_point()) {
return; return;
} }
const double cos_theta = std::cos(-matched_point.path_point().theta());
const double sin_theta = std::sin(-matched_point.path_point().theta()); const double cos_theta = std::cos(matched_point.path_point().theta());
std::vector<TrajectoryPoint> transformed_points; const double sin_theta = std::sin(matched_point.path_point().theta());
for (const auto& old_point : prev_trajectory->trajectory_points()) { const double x_shift = matched_point.path_point().x();
TrajectoryPoint point = old_point; const double y_shift = matched_point.path_point().y();
Eigen::Vector3d before_rotate( const double z_shift = matched_point.path_point().z();
old_point.path_point().x() - matched_point.path_point().x(),
old_point.path_point().y() - matched_point.path_point().y(), auto& points = prev_trajectory->trajectory_points();
old_point.path_point().z() - matched_point.path_point().z()); // x_new = (x_old - x_shift) * cos(theta) + (y_old - y_shift) * sin(theta)
const double after_rotate_x = // y_new = (y_old - y_shift) * cos(theta) - (x_old - x_shift) * sin(theta)
before_rotate.x() * cos_theta - before_rotate.y() * sin_theta; std::transform(
const double after_rotate_y = std::begin(points), std::end(points), std::begin(points),
before_rotate.x() * sin_theta + before_rotate.y() * cos_theta; [&](const TrajectoryPoint& old_point) {
point.mutable_path_point()->set_x(after_rotate_x); const double x_new =
point.mutable_path_point()->set_y(after_rotate_y); (old_point.path_point().x() - x_shift) * cos_theta +
point.mutable_path_point()->set_z(before_rotate.z()); (old_point.path_point().y() - y_shift) * sin_theta;
point.mutable_path_point()->set_theta(common::math::WrapAngle( const double y_new =
old_point.path_point().theta() - matched_point.path_point().theta())); (old_point.path_point().y() - y_shift) * cos_theta -
transformed_points.emplace_back(point); (old_point.path_point().x() - x_shift) * sin_theta;
} const double z_new = old_point.path_point().z() - z_shift;
prev_trajectory->SetTrajectoryPoints(transformed_points); TrajectoryPoint new_point = old_point;
new_point.mutable_path_point()->set_x(x_new);
new_point.mutable_path_point()->set_y(y_new);
new_point.mutable_path_point()->set_z(z_new);
new_point.mutable_path_point()->set_theta(
common::math::WrapAngle(old_point.path_point().theta() -
matched_point.path_point().theta()));
return new_point;
});
} }
// only used in navigation mode // only used in navigation mode
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册