Apollo 11.0
自动驾驶开放平台
piecewise_trajectory1d.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 <cmath>
24
25#include "cyber/common/log.h"
26
27namespace apollo {
28namespace planning {
29
30double PiecewiseTrajectory1d::Evaluate(const std::uint32_t order,
31 const double param) const {
32 auto it_lower = std::lower_bound(accumulated_param_lengths_.begin(),
33 accumulated_param_lengths_.end(), param);
34 ACHECK(it_lower != accumulated_param_lengths_.end());
35
36 size_t index = (size_t)(it_lower - accumulated_param_lengths_.begin());
37
38 double param_overhead = 0.0;
39 if (index != 0) {
40 param_overhead = accumulated_param_lengths_[index - 1];
41 }
42 return trajectory_segments_[index]->Evaluate(order, param - param_overhead);
43}
44
46 if (accumulated_param_lengths_.empty()) {
47 return 0.0;
48 }
49 return accumulated_param_lengths_.back();
50}
51
52std::string PiecewiseTrajectory1d::ToString() const { return ""; }
53
55 const std::shared_ptr<Curve1d> trajectory) {
56 if (trajectory_segments_.empty()) {
57 trajectory_segments_.push_back(trajectory);
58 } else {
59 double s1 = trajectory->Evaluate(0, 0.0);
60 double v1 = trajectory->Evaluate(1, 0.0);
61 double a1 = trajectory->Evaluate(2, 0.0);
62 double j1 = trajectory->Evaluate(3, 0.0);
63
64 auto last_trajectory = trajectory_segments_.back();
65 double last_param_length = last_trajectory->ParamLength();
66 double s0 = last_trajectory->Evaluate(0, last_param_length);
67 double v0 = last_trajectory->Evaluate(1, last_param_length);
68 double a0 = last_trajectory->Evaluate(2, last_param_length);
69 double j0 = last_trajectory->Evaluate(3, last_param_length);
70
71 if (std::fabs(s0 - s1) > 1.0e-4) {
72 AWARN << "The appended segment is not smooth in order 0";
73 }
74
75 if (std::fabs(v0 - v1) > 1.0e-4) {
76 AWARN << "The appended segment is not smooth in order 1";
77 }
78
79 if (std::fabs(a0 - a1) > 1.0e-4) {
80 AWARN << "The appended segment is not smooth in order 2";
81 }
82
83 if (std::fabs(j0 - j1) > 1.0e-4) {
84 AWARN << "The appended segment is not smooth in order 3";
85 }
86 trajectory_segments_.push_back(trajectory);
87 }
88
89 double accumulated_param_length = trajectory->ParamLength();
90 if (accumulated_param_lengths_.size() > 0) {
91 accumulated_param_length += accumulated_param_lengths_.back();
92 }
93 accumulated_param_lengths_.push_back(accumulated_param_length);
94}
95
97 if (trajectory_segments_.empty()) {
98 return;
99 }
100 trajectory_segments_.pop_back();
101 accumulated_param_lengths_.pop_back();
102}
103
105 return trajectory_segments_.size();
106}
107
108} // namespace planning
109} // namespace apollo
void AppendSegment(const std::shared_ptr< Curve1d > trajectory)
double Evaluate(const std::uint32_t order, const double param) const
Planning module main class.
#define ACHECK(cond)
Definition log.h:80
#define AWARN
Definition log.h:43
class register implement
Definition arena_queue.h:37