Apollo 11.0
自动驾驶开放平台
path_boundary.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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 <tuple>
24
25#include "cyber/common/log.h"
27namespace apollo {
28namespace planning {
29
30double PathBoundary::start_s() const {
31 if (size() == 0) {
32 return 0;
33 } else {
34 return begin()->s;
35 }
36}
37
38double PathBoundary::delta_s() const { return delta_s_; }
39void apollo::planning::PathBoundary::set_delta_s(double s) { delta_s_ = s; }
40
41std::vector<std::pair<double, double>> PathBoundary::boundary() const {
42 std::vector<std::pair<double, double>> boundary;
43 for (auto iter = begin(); iter != end(); iter++) {
44 boundary.emplace_back(iter->l_lower.l, iter->l_upper.l);
45 }
46 return boundary;
47}
48
49void PathBoundary::set_label(const std::string& label) { label_ = label; }
50
51const std::string& PathBoundary::label() const { return label_; }
52
53void PathBoundary::set_blocking_obstacle_id(const std::string& obs_id) {
54 blocking_obstacle_id_ = obs_id;
55}
56void PathBoundary::DebugString(std::string name) {
57 PrintCurves print_curves;
58 std::string lower_name = name + "_lower";
59 std::string upper_name = name + "_upper";
60 for (auto iter = begin(); iter != end(); iter++) {
61 print_curves.AddPoint(lower_name, iter->s, iter->l_lower.l);
62 print_curves.AddPoint(upper_name, iter->s, iter->l_upper.l);
63 }
64 print_curves.PrintToLog();
65}
66
67const std::string& PathBoundary::blocking_obstacle_id() const {
68 return blocking_obstacle_id_;
69}
70
72 double* left_weight,
73 double* right_weight,
74 size_t* left_index,
75 size_t* right_index) const {
76 if (s < front().s || s > back().s) {
77 return false;
78 }
79 PathBoundPoint cmp(s, 0.0, 0.0);
80 const auto iter = std::lower_bound(begin(), end(), cmp);
81 auto last_iter = std::prev(iter);
82 *left_index = std::distance(begin(), last_iter);
83 *right_index = *left_index + 1;
84 if (*left_index > size() - 1 || *right_index > size() - 1) {
85 return false;
86 }
87 *left_weight =
88 (at(*right_index).s - s) / (at(*right_index).s - at(*left_index).s);
89 *right_weight = 1.0 - *left_weight;
90 return true;
91}
92
93double PathBoundary::get_lower_bound_by_s(const double s) {
94 if (s <= front().s) {
95 return front().l_lower.l;
96 }
97 if (s >= back().s) {
98 return back().l_lower.l;
99 }
100 double l_weight = 0.0;
101 double r_weight = 0.0;
102 size_t l_index = 0;
103 size_t r_index = 0;
104 get_interpolated_s_weight(s, &l_weight, &r_weight, &l_index, &r_index);
105
106 return at(l_index).l_lower.l * l_weight + at(r_index).l_lower.l * r_weight;
107}
108
110 if (s <= front().s) {
111 return front().l_upper.l;
112 }
113 if (s >= back().s) {
114 return back().l_upper.l;
115 }
116 double l_weight = 0.0;
117 double r_weight = 0.0;
118 size_t l_index = 0;
119 size_t r_index = 0;
120 get_interpolated_s_weight(s, &l_weight, &r_weight, &l_index, &r_index);
121
122 return at(l_index).l_upper.l * l_weight + at(r_index).l_upper.l * r_weight;
123}
124
126 double left_weight, double right_weight, size_t left_index,
127 size_t right_index) const {
128 if (left_index < 0) {
129 return front().l_lower.l;
130 } else if (right_index >= size()) {
131 return back().l_lower.l;
132 }
133 return at(left_index).l_lower.l * left_weight +
134 at(right_index).l_lower.l * right_weight;
135}
136
138 double left_weight, double right_weight, size_t left_index,
139 size_t right_index) const {
140 if (left_index < 0) {
141 return front().l_upper.l;
142 } else if (right_index >= size()) {
143 return back().l_upper.l;
144 }
145 return at(left_index).l_upper.l * left_weight +
146 at(right_index).l_upper.l * right_weight;
147}
148
149} // namespace planning
150} // namespace apollo
void set_label(const std::string &label)
void DebugString(std::string name)
void set_blocking_obstacle_id(const std::string &obs_id)
double get_upper_bound_by_interpolated_index(double left_weight, double right_weight, size_t left_index, size_t right_index) const
bool get_interpolated_s_weight(const double s, double *left_weight, double *right_weight, size_t *left_index, size_t *right_index) const
const std::string & blocking_obstacle_id() const
const std::string & label() const
std::vector< std::pair< double, double > > boundary() const
double get_lower_bound_by_interpolated_index(double left_weight, double right_weight, size_t left_index, size_t right_index) const
double get_lower_bound_by_s(const double s)
double get_upper_bound_by_s(const double s)
void AddPoint(std::string key, double x, double y)
add point to curve key
Planning module main class.
class register implement
Definition arena_queue.h:37