Apollo 11.0
自动驾驶开放平台
st_boundary.h
浏览该文件的文档.
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
21#pragma once
22
23#include <limits>
24#include <string>
25#include <utility>
26#include <vector>
27
28#include "gtest/gtest_prod.h"
29
30#include "modules/common_msgs/planning_msgs/planning.pb.h"
31
36
37namespace apollo {
38namespace planning {
39
41 public:
46 STBoundary() = default;
47 explicit STBoundary(
48 const std::vector<std::pair<STPoint, STPoint>>& point_pairs,
49 bool is_accurate_boundary = false);
50 explicit STBoundary(const common::math::Box2d& box) = delete;
51 explicit STBoundary(std::vector<common::math::Vec2d> points) = delete;
52
55 static STBoundary CreateInstance(const std::vector<STPoint>& lower_points,
56 const std::vector<STPoint>& upper_points);
57
62 const std::vector<STPoint>& lower_points,
63 const std::vector<STPoint>& upper_points);
64
67 ~STBoundary() = default;
68
69 bool IsEmpty() const { return lower_points_.empty(); }
70
71 bool GetUnblockSRange(const double curr_time, double* s_upper,
72 double* s_lower) const;
73
74 bool GetBoundarySRange(const double curr_time, double* s_upper,
75 double* s_lower) const;
76
77 bool GetBoundarySlopes(const double curr_time, double* ds_upper,
78 double* ds_lower) const;
79 void PrintDebug(std::string suffix = "") const;
80 // if you need to add boundary type, make sure you modify
81 // GetUnblockSRange accordingly.
82 enum class BoundaryType {
83 UNKNOWN,
84 STOP,
85 FOLLOW,
86 YIELD,
89 };
90
91 static std::string TypeName(BoundaryType type);
92
94 const std::string& id() const;
95 double characteristic_length() const;
96
97 void set_id(const std::string& id);
100
101 double min_s() const;
102 double min_t() const;
103 double max_s() const;
104 double max_t() const;
105
106 std::vector<STPoint> upper_points() const { return upper_points_; }
107 std::vector<STPoint> lower_points() const { return lower_points_; }
108
109 // Used by st-optimizer.
110 bool IsPointInBoundary(const STPoint& st_point) const;
111 STBoundary ExpandByS(const double s) const;
112 STBoundary ExpandByT(const double t) const;
113
114 // Unused function so far.
115 STBoundary CutOffByT(const double t) const;
116
117 // Used by Lattice planners.
122
123 void set_upper_left_point(STPoint st_point);
124 void set_upper_right_point(STPoint st_point);
125 void set_bottom_left_point(STPoint st_point);
126 void set_bottom_right_point(STPoint st_point);
127
128 void set_obstacle_road_right_ending_t(double road_right_ending_t) {
129 obstacle_road_right_ending_t_ = road_right_ending_t;
130 }
132 return obstacle_road_right_ending_t_;
133 }
134
135 private:
138 bool IsValid(
139 const std::vector<std::pair<STPoint, STPoint>>& point_pairs) const;
140
143 bool IsPointNear(const common::math::LineSegment2d& seg,
144 const common::math::Vec2d& point, const double max_dist);
145
150 // TODO(all): When slope is high, this may introduce significant errors.
151 // Also, when accumulated for multiple t, the error can get significant.
152 // This function should be reconsidered, because it may be dangerous.
153 void RemoveRedundantPoints(
154 std::vector<std::pair<STPoint, STPoint>>* point_pairs);
155 FRIEND_TEST(StBoundaryTest, remove_redundant_points);
156
161 bool GetIndexRange(const std::vector<STPoint>& points, const double t,
162 size_t* left, size_t* right) const;
163 FRIEND_TEST(StBoundaryTest, get_index_range);
164
165 private:
166 BoundaryType boundary_type_ = BoundaryType::UNKNOWN;
167
168 std::vector<STPoint> upper_points_;
169 std::vector<STPoint> lower_points_;
170
171 std::string id_;
172 double characteristic_length_ = 1.0;
173 double min_s_ = std::numeric_limits<double>::max();
174 double max_s_ = std::numeric_limits<double>::lowest();
175 double min_t_ = std::numeric_limits<double>::max();
176 double max_t_ = std::numeric_limits<double>::lowest();
177
178 STPoint bottom_left_point_;
179 STPoint bottom_right_point_;
180 STPoint upper_left_point_;
181 STPoint upper_right_point_;
182
183 double obstacle_road_right_ending_t_;
184};
185
186} // namespace planning
187} // namespace apollo
The class of Box2d.
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
The class of polygon in 2-D.
Definition polygon2d.h:42
const std::vector< Vec2d > & points() const
Get the vertices of the polygon.
Definition polygon2d.h:65
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
void set_bottom_right_point(STPoint st_point)
bool GetUnblockSRange(const double curr_time, double *s_upper, double *s_lower) const
const std::string & id() const
static std::string TypeName(BoundaryType type)
bool GetBoundarySlopes(const double curr_time, double *ds_upper, double *ds_lower) const
void set_id(const std::string &id)
STBoundary()=default
Constructors: STBoundary must be initialized with a vector of ST-point pairs.
static STBoundary CreateInstance(const std::vector< STPoint > &lower_points, const std::vector< STPoint > &upper_points)
Wrapper of the constructor (old).
void set_bottom_left_point(STPoint st_point)
void SetCharacteristicLength(const double characteristic_length)
std::vector< STPoint > lower_points() const
STBoundary(const common::math::Box2d &box)=delete
std::vector< STPoint > upper_points() const
BoundaryType boundary_type() const
double obstacle_road_right_ending_t() const
STBoundary ExpandByT(const double t) const
void PrintDebug(std::string suffix="") const
~STBoundary()=default
Default destructor.
static STBoundary CreateInstanceAccurate(const std::vector< STPoint > &lower_points, const std::vector< STPoint > &upper_points)
Wrapper of the constructor.
STBoundary ExpandByS(const double s) const
void set_upper_right_point(STPoint st_point)
STPoint bottom_right_point() const
bool IsPointInBoundary(const STPoint &st_point) const
bool GetBoundarySRange(const double curr_time, double *s_upper, double *s_lower) const
STPoint bottom_left_point() const
STBoundary CutOffByT(const double t) const
STPoint upper_right_point() const
void SetBoundaryType(const BoundaryType &boundary_type)
void set_upper_left_point(STPoint st_point)
STPoint upper_left_point() const
double characteristic_length() const
void set_obstacle_road_right_ending_t(double road_right_ending_t)
STBoundary(std::vector< common::math::Vec2d > points)=delete
Planning module main class.
class register implement
Definition arena_queue.h:37
Define the Polygon2d class.
Defines the Vec2d class.