25#include "absl/strings/str_cat.h"
26#include "absl/strings/str_join.h"
44 if (reference_line_ ==
nullptr) {
45 AERROR <<
"Should NOT set discretized path when reference line is nullptr. "
46 "Please set reference line first.";
49 discretized_path_ = std::move(path);
50 if (!XYToSL(discretized_path_, &frenet_path_)) {
51 AERROR <<
"Fail to transfer discretized path to frenet path.";
54 DCHECK_EQ(discretized_path_.size(), frenet_path_.size());
59 if (reference_line_ ==
nullptr) {
60 AERROR <<
"Should NOT set frenet path when reference line is nullptr. "
61 "Please set reference line first.";
64 frenet_path_ = std::move(frenet_path);
65 if (!SLToXY(frenet_path_, &discretized_path_)) {
66 AERROR <<
"Fail to transfer frenet path to discretized path.";
69 DCHECK_EQ(discretized_path_.size(), frenet_path_.size());
74 std::vector<std::tuple<double, PathPointType, double>>
75 path_point_decision_guide) {
76 if (reference_line_ ==
nullptr) {
77 AERROR <<
"Should NOT set path_point_decision_guide when reference line is "
81 if (frenet_path_.empty() || discretized_path_.empty()) {
82 AERROR <<
"Should NOT set path_point_decision_guide when frenet_path or "
83 "world frame trajectory is empty. ";
91 return discretized_path_;
98const std::vector<std::tuple<double, PathData::PathPointType, double>>
100 return path_point_decision_guide_;
104 return discretized_path_.empty() && frenet_path_.empty();
109 reference_line_ = reference_line;
113 return discretized_path_.
Evaluate(s);
119 DCHECK_EQ(discretized_path_.size(), frenet_path_.size());
121 AERROR <<
"ref_s[" << ref_s <<
"] should be > 0";
124 if (ref_s > frenet_path_.back().s()) {
125 AERROR <<
"ref_s is larger than the length of frenet_path_ length ["
126 << frenet_path_.back().s() <<
"].";
131 const double kDistanceEpsilon = 1e-3;
132 for (uint32_t i = 0; i + 1 < frenet_path_.size(); ++i) {
133 if (fabs(ref_s - frenet_path_.at(i).s()) < kDistanceEpsilon) {
134 path_point->CopyFrom(discretized_path_.at(i));
137 if (frenet_path_.at(i).s() < ref_s && ref_s <= frenet_path_.at(i + 1).s()) {
142 double r = (ref_s - frenet_path_.at(index).s()) /
143 (frenet_path_.at(index + 1).s() - frenet_path_.at(index).s());
145 const double discretized_path_s = discretized_path_.at(index).s() +
146 r * (discretized_path_.at(index + 1).s() -
147 discretized_path_.at(index).s());
148 path_point->CopyFrom(discretized_path_.
Evaluate(discretized_path_s));
154 discretized_path_.clear();
155 frenet_path_.clear();
156 path_point_decision_guide_.clear();
157 path_reference_.clear();
158 reference_line_ =
nullptr;
163 std::min(discretized_path_.size(),
164 static_cast<size_t>(FLAGS_trajectory_point_num_for_debug));
168 absl::StrJoin(discretized_path_.begin(),
169 discretized_path_.begin() + limit,
",\n",
176 std::vector<common::PathPoint> path_points;
181 if (!reference_line_->
SLToXY(sl_point, &cartesian_point)) {
182 AERROR <<
"Fail to convert sl point to xy point";
185 const ReferencePoint ref_point =
188 ref_point.heading(), ref_point.kappa(), frenet_point.l(),
190 ADEBUG <<
"frenet_point: " << frenet_point.ShortDebugString();
192 ref_point.kappa(), ref_point.dkappa(), frenet_point.l(),
193 frenet_point.dl(), frenet_point.ddl());
197 if (!path_points.empty()) {
199 const double distance = (last - cartesian_point).Length();
200 s = path_points.back().s() + distance;
201 dkappa = (kappa - path_points.back().kappa()) / distance;
204 cartesian_point.
y(), 0.0, s,
205 theta, kappa, dkappa));
212bool PathData::XYToSL(
const DiscretizedPath &discretized_path,
213 FrenetFramePath *
const frenet_path) {
215 std::vector<common::FrenetFramePoint> frenet_frame_points;
216 const double max_len = reference_line_->
Length();
218 common::FrenetFramePoint frenet_point =
220 if (!frenet_point.has_s()) {
222 if (!reference_line_->
XYToSL(path_point, &sl_point)) {
223 AERROR <<
"Fail to transfer cartesian point to frenet point.";
226 common::FrenetFramePoint frenet_point;
228 frenet_point.set_s(std::max(0.0, std::min(sl_point.s(), max_len)));
229 frenet_point.set_l(sl_point.l());
230 frenet_frame_points.push_back(std::move(frenet_point));
233 frenet_point.set_s(std::max(0.0, std::min(frenet_point.s(), max_len)));
234 frenet_frame_points.push_back(std::move(frenet_point));
236 *frenet_path = FrenetFramePath(std::move(frenet_frame_points));
242 std::vector<common::FrenetFramePoint> frenet_frame_points;
243 frenet_frame_points.emplace_back(frenet_point);
246 if (std::fabs(fp.s() - frenet_point.
s()) < 1e-6) {
249 if (fp.s() > frenet_point.
s()) {
250 frenet_frame_points.push_back(fp);
258 reference_line_ = reference_line;
267 return path_reference_;
271 const std::vector<PathPoint> &path_reference) {
static double CalculateTheta(const double rtheta, const double rkappa, const double l, const double dl)
static double CalculateKappa(const double rkappa, const double rdkappa, const double l, const double dl, const double ddl)
Implements a class of 2-dimensional vectors.
double y() const
Getter for y component
double x() const
Getter for x component
static math::Vec2d ToVec2d(const XY &xy)
static SLPoint ToSLPoint(const double s, const double l)
static PathPoint ToPathPoint(const double x, const double y, const double z=0, const double s=0, const double theta=0, const double kappa=0, const double dkappa=0, const double ddkappa=0)
common::PathPoint Evaluate(const double path_s) const
const std::vector< common::PathPoint > & path_reference() const
const std::string & path_label() const
bool LeftTrimWithRefS(const common::FrenetFramePoint &frenet_point)
void SetReferenceLine(const ReferenceLine *reference_line)
common::PathPoint GetPathPointWithPathS(const double s) const
const FrenetFramePath & frenet_frame_path() const
bool SetPathPointDecisionGuide(std::vector< std::tuple< double, PathPointType, double > > path_point_decision_guide)
bool GetPathPointWithRefS(const double ref_s, common::PathPoint *const path_point) const
bool SetDiscretizedPath(DiscretizedPath path)
bool UpdateFrenetFramePath(const ReferenceLine *reference_line)
std::string DebugString() const
const DiscretizedPath & discretized_path() const
const std::vector< std::tuple< double, PathPointType, double > > & path_point_decision_guide() const
void set_path_label(const std::string &label)
bool SetFrenetPath(FrenetFramePath frenet_path)
void set_path_reference(const std::vector< common::PathPoint > &path_reference)
ReferencePoint GetReferencePoint(const double s) const
bool SLToXY(const common::SLPoint &sl_point, common::math::Vec2d *const xy_point) const
bool XYToSL(const common::math::Vec2d &xy_point, common::SLPoint *const sl_point, double warm_start_s=-1.0) const
Transvert Cartesian coordinates to Frenet.
common::FrenetFramePoint GetFrenetPoint(const common::PathPoint &path_point) const
Planning module main class.
Some string util functions.