Apollo 11.0
自动驾驶开放平台
discretized_trajectory.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
22
23#include <limits>
24
25#include "cyber/common/log.h"
28
29namespace apollo {
30namespace planning {
31
33
35 const std::vector<TrajectoryPoint>& trajectory_points)
36 : std::vector<TrajectoryPoint>(trajectory_points) {
37 ACHECK(!trajectory_points.empty())
38 << "trajectory_points should NOT be empty()";
39}
40
42 assign(trajectory.trajectory_point().begin(),
43 trajectory.trajectory_point().end());
44}
45
47 const double relative_time) const {
48 auto comp = [](const TrajectoryPoint& p, const double relative_time) {
49 return p.relative_time() < relative_time;
50 };
51
52 auto it_lower = std::lower_bound(begin(), end(), relative_time, comp);
53
54 if (it_lower == begin()) {
55 return front();
56 } else if (it_lower == end()) {
57 AWARN << "When evaluate trajectory, relative_time(" << relative_time
58 << ") is too large";
59 return back();
60 }
62 *(it_lower - 1), *it_lower, relative_time);
63}
64
65size_t DiscretizedTrajectory::QueryLowerBoundPoint(const double relative_time,
66 const double epsilon) const {
67 ACHECK(!empty());
68
69 if (relative_time >= back().relative_time()) {
70 return size() - 1;
71 }
72 auto func = [&epsilon](const TrajectoryPoint& tp,
73 const double relative_time) {
74 return tp.relative_time() + epsilon < relative_time;
75 };
76 auto it_lower = std::lower_bound(begin(), end(), relative_time, func);
77 return std::distance(begin(), it_lower);
78}
79
81 const common::math::Vec2d& position) const {
82 double dist_sqr_min = std::numeric_limits<double>::max();
83 size_t index_min = 0;
84 for (size_t i = 0; i < size(); ++i) {
85 const common::math::Vec2d curr_point(data()[i].path_point().x(),
86 data()[i].path_point().y());
87
88 const double dist_sqr = curr_point.DistanceSquareTo(position);
89 if (dist_sqr < dist_sqr_min) {
90 dist_sqr_min = dist_sqr;
91 index_min = i;
92 }
93 }
94 return index_min;
95}
96
98 const common::math::Vec2d& position, const double buffer) const {
99 double dist_sqr_min = std::numeric_limits<double>::max();
100 size_t index_min = 0;
101 for (size_t i = 0; i < size(); ++i) {
102 const common::math::Vec2d curr_point(data()[i].path_point().x(),
103 data()[i].path_point().y());
104
105 const double dist_sqr = curr_point.DistanceSquareTo(position);
106 if (dist_sqr < dist_sqr_min + buffer) {
107 dist_sqr_min = dist_sqr;
108 index_min = i;
109 }
110 }
111 return index_min;
112}
113
115 const TrajectoryPoint& trajectory_point) {
116 if (!empty()) {
117 CHECK_GT(trajectory_point.relative_time(), back().relative_time());
118 }
119 push_back(trajectory_point);
120}
121
123 const size_t index) const {
124 CHECK_LT(index, NumOfPoints());
125 return data()[index];
126}
127
129 ACHECK(!empty());
130 return front();
131}
132
134 if (empty()) {
135 return 0.0;
136 }
137 return back().relative_time() - front().relative_time();
138}
139
141 if (empty()) {
142 return 0.0;
143 }
144 return back().path_point().s() - front().path_point().s();
145}
146
147} // namespace planning
148} // namespace apollo
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
double DistanceSquareTo(const Vec2d &other) const
Returns the squared distance to the given vector
Definition vec2d.cc:51
size_t QueryNearestPointWithBuffer(const common::math::Vec2d &position, const double buffer) const
const common::TrajectoryPoint & TrajectoryPointAt(const size_t index) const
virtual size_t QueryNearestPoint(const common::math::Vec2d &position) const
virtual size_t QueryLowerBoundPoint(const double relative_time, const double epsilon=1.0e-5) const
virtual common::TrajectoryPoint StartPoint() const
virtual void AppendTrajectoryPoint(const common::TrajectoryPoint &trajectory_point)
virtual common::TrajectoryPoint Evaluate(const double relative_time) const
Planning module main class.
Linear interpolation functions.
#define ACHECK(cond)
Definition log.h:80
#define AWARN
Definition log.h:43
SLPoint InterpolateUsingLinearApproximation(const SLPoint &p0, const SLPoint &p1, const double w)
class register implement
Definition arena_queue.h:37
Definition future.h:29
repeated apollo::common::TrajectoryPoint trajectory_point