43 return dx * dx + dy * dy;
47 if (point.has_path_point()) {
61 for (
int i = 0; i < planning_published_trajectory->trajectory_point_size();
66 if (!path_point->has_z()) {
67 path_point->set_z(0.0);
73 const double y)
const {
87 size_t index_start = index_min == 0 ? index_min : index_min - 1;
91 const double kEpsilon = 0.001;
92 if (index_start == index_end ||
110 const double theta,
const double v,
112 double *ptr_s,
double *ptr_s_dot,
114 double *ptr_d_dot)
const {
115 double dx = x - ref_point.
x();
116 double dy = y - ref_point.
y();
118 double cos_ref_theta = std::cos(ref_point.
theta());
119 double sin_ref_theta = std::sin(ref_point.
theta());
123 double cross_rd_nd = cos_ref_theta * dy - sin_ref_theta * dx;
124 *ptr_d = cross_rd_nd;
128 double dot_rd_nd = dx * cos_ref_theta + dy * sin_ref_theta;
129 *ptr_s = ref_point.
s() + dot_rd_nd;
131 double delta_theta = theta - ref_point.
theta();
132 double cos_delta_theta = std::cos(delta_theta);
133 double sin_delta_theta = std::sin(delta_theta);
135 *ptr_d_dot = v * sin_delta_theta;
137 double one_minus_kappa_r_d = 1 - ref_point.
kappa() * (*ptr_d);
138 if (one_minus_kappa_r_d <= 0.0) {
139 AERROR <<
"TrajectoryAnalyzer::ToTrajectoryFrame "
140 "found fatal reference and actual difference. "
141 "Control output might be unstable:"
142 <<
" ref_point.kappa:" << ref_point.
kappa()
143 <<
" ref_point.x:" << ref_point.
x()
144 <<
" ref_point.y:" << ref_point.
y() <<
" car x:" << x
145 <<
" car y:" << y <<
" *ptr_d:" << *ptr_d
146 <<
" one_minus_kappa_r_d:" << one_minus_kappa_r_d;
148 one_minus_kappa_r_d = 0.01;
151 *ptr_s_dot = v * cos_delta_theta / one_minus_kappa_r_d;
155 const double t)
const {
160 const double t)
const {
162 const double relative_time) {
177 if (FLAGS_query_forward_time_point_only) {
180 auto it_lower = it_low - 1;
181 if (it_low->relative_time() - t < t - it_lower->relative_time()) {
189 const double x,
const double y)
const {
191 size_t index_min = 0;
195 if (d_temp < d_min) {
211 const double y)
const {
214 auto dist_square = [&p0, &p1, &x, &y](
const double s) {
221 return dx * dx + dy * dy;
243 const double rear_to_com_distance) {
254 const double rear_to_com_distance,
const PathPoint &path_point)
const {
258 const double cos_heading = std::cos(path_point.
theta());
259 const double sin_heading = std::sin(path_point.
theta());
260 v << rear_to_com_distance * cos_heading, rear_to_com_distance * sin_heading,
263 Eigen::Vector3d pos_vec(path_point.
x(), path_point.
y(), path_point.
z());
265 Eigen::Vector3d com_pos_3d = v + pos_vec;
Implements a class of 2-dimensional vectors.
common::TrajectoryPoint QueryNearestPointByPosition(const double x, const double y) const
query a point of trajectory that its position is closest to the given position.
common::math::Vec2d ComputeCOMPosition(const double rear_to_com_distance, const common::PathPoint &path_point) const
Compute the position of center of mass(COM) of the vehicle, given the distance from rear wheels to th...
TrajectoryAnalyzer()=default
constructor
const std::vector< common::TrajectoryPoint > & trajectory_points() const
get all points of the trajectory
void TrajectoryTransformToCOM(const double rear_to_com_distance)
Transform the current trajectory points to the center of mass(COM) of the vehicle,...
common::PathPoint QueryMatchedPathPoint(const double x, const double y) const
query a point on trajectory that its position is closest to the given position.
common::TrajectoryPoint QueryNearestPointByAbsoluteTime(const double t) const
query a point of trajectory that its absolute time is closest to the give time.
void ToTrajectoryFrame(const double x, const double y, const double theta, const double v, const common::PathPoint &matched_point, double *ptr_s, double *ptr_s_dot, double *ptr_d, double *ptr_d_dot) const
convert a position with theta and speed to trajectory frame,
std::vector< common::TrajectoryPoint > trajectory_points_
common::TrajectoryPoint QueryNearestPointByRelativeTime(const double t) const
query a point of trajectory that its relative time is closest to the give time.
Linear interpolation functions.
Math-related util functions.
T lerp(const T &x0, const double t0, const T &x1, const double t1, const double t)
Linear interpolation between two points of type T.
double GoldenSectionSearch(const std::function< double(double)> &func, const double lower_bound, const double upper_bound, const double tol)
Given a unimodal function defined on the interval, find a value on the interval to minimize the funct...
double slerp(const double a0, const double t0, const double a1, const double t1, const double t)
Spherical linear interpolation between two angles.
Search-related functions.
optional double relative_time
optional PathPoint path_point
repeated apollo::common::TrajectoryPoint trajectory_point
optional apollo::common::Header header
Defines the TrajectoryAnalyzer class.