Apollo 11.0
自动驾驶开放平台
hybrid_a_star_wrapper.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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
17/*
18 * @file
19 */
20
21#include "cyber/common/file.h"
23
24namespace apollo {
25namespace planning {
26
28public:
30 void AddVirtualObstacle(double* obstacle_x, double* obstacle_y, int vertice_num) {
31 std::vector<common::math::Vec2d> obstacle_vertices;
32 for (int i = 0; i < vertice_num; i++) {
33 common::math::Vec2d vertice(obstacle_x[i], obstacle_y[i]);
34 obstacle_vertices.emplace_back(vertice);
35 }
36 obstacles_list.emplace_back(obstacle_vertices);
37 }
38 const std::vector<std::vector<common::math::Vec2d>>& GetObstaclesVerticesVec() {
39 return obstacles_list;
40 }
41
42private:
43 std::vector<std::vector<common::math::Vec2d>> obstacles_list;
44};
45
47public:
49 void AddVirtualSoftBoundary(double* obstacle_x, double* obstacle_y, int vertice_num) {
50 std::vector<common::math::Vec2d> soft_boundary_vertices;
51 for (int i = 0; i < vertice_num; i++) {
52 common::math::Vec2d vertice(obstacle_x[i], obstacle_y[i]);
53 soft_boundary_vertices.emplace_back(vertice);
54 }
55 soft_boundary_list.emplace_back(soft_boundary_vertices);
56
57 for (int i = 0; i < soft_boundary_list.size(); ++i) {
58 for (const auto& vertice : soft_boundary_list[i]) {
59 AERROR << "Soft boundary: " << i << ", " << vertice.x() << ", " << vertice.y();
60 }
61 }
62 }
63 const std::vector<std::vector<common::math::Vec2d>>& GetSoftBoundaryVerticesVec() {
64 return soft_boundary_list;
65 }
66
67private:
68 std::vector<std::vector<common::math::Vec2d>> soft_boundary_list;
69};
70
72public:
74 void LoadResult() {
75 x_ = std::move(result_.x);
76 y_ = std::move(result_.y);
77 phi_ = std::move(result_.phi);
78 v_ = std::move(result_.v);
79 a_ = std::move(result_.a);
80 steer_ = std::move(result_.steer);
81 }
82 std::vector<double>* GetX() {
83 return &x_;
84 }
85 std::vector<double>* GetY() {
86 return &y_;
87 }
88 std::vector<double>* GetPhi() {
89 return &phi_;
90 }
91 std::vector<double>* GetV() {
92 return &v_;
93 }
94 std::vector<double>* GetA() {
95 return &a_;
96 }
97 std::vector<double>* GetSteer() {
98 return &steer_;
99 }
101 return &result_;
102 }
103
104private:
105 HybridAStartResult result_;
106 std::vector<double> x_;
107 std::vector<double> y_;
108 std::vector<double> phi_;
109 std::vector<double> v_;
110 std::vector<double> a_;
111 std::vector<double> steer_;
112};
113
114extern "C" {
116 FLAGS_planner_open_space_config_filename
117 = "/apollo/modules/planning/planning_component/"
118 "conf/planner_hybrid_a_star_config.pb.txt";
119 apollo::planning::WarmStartConfig planner_open_space_config_;
120
122 FLAGS_planner_open_space_config_filename, &planner_open_space_config_))
123 << "Failed to load open space config file " << FLAGS_planner_open_space_config_filename;
124 return new HybridAStar(planner_open_space_config_);
125}
136 HybridAObstacleContainer* obstacles_ptr,
137 double* obstacle_x,
138 double* obstacle_y,
139 int vertice_num) {
140 obstacles_ptr->AddVirtualObstacle(obstacle_x, obstacle_y, vertice_num);
141}
143 HybridASoftBoundaryContainer* soft_boundary_ptr,
144 double* soft_boundary_x,
145 double* soft_boundary_y,
146 int vertice_num) {
147 soft_boundary_ptr->AddVirtualSoftBoundary(soft_boundary_x, soft_boundary_y, vertice_num);
148}
149bool Plan(
150 HybridAStar* planner_ptr,
151 HybridAObstacleContainer* obstacles_ptr,
152 HybridASoftBoundaryContainer* soft_boundary_ptr,
153 HybridAResultContainer* result_ptr,
154 double sx,
155 double sy,
156 double sphi,
157 double ex,
158 double ey,
159 double ephi,
160 double* XYbounds) {
161 AERROR << "sx: " << sx;
162 std::vector<double> XYbounds_(XYbounds, XYbounds + 4);
163 return planner_ptr->Plan(
164 sx,
165 sy,
166 sphi,
167 ex,
168 ey,
169 ephi,
170 XYbounds_,
171 obstacles_ptr->GetObstaclesVerticesVec(),
172 result_ptr->PrepareResult(),
173 soft_boundary_ptr->GetSoftBoundaryVerticesVec(),
174 false);
175}
177 HybridAResultContainer* result_ptr,
178 double* x,
179 double* y,
180 double* phi,
181 double* v,
182 double* a,
183 double* steer,
184 size_t* output_size) {
185 result_ptr->LoadResult();
186 size_t size = result_ptr->GetX()->size();
187 std::cout << "return size is " << size << std::endl;
188 for (size_t i = 0; i < size; i++) {
189 x[i] = result_ptr->GetX()->at(i);
190 y[i] = result_ptr->GetY()->at(i);
191 phi[i] = result_ptr->GetPhi()->at(i);
192 v[i] = result_ptr->GetV()->at(i);
193 }
194 for (size_t i = 0; i < size - 1; i++) {
195 a[i] = result_ptr->GetA()->at(i);
196 steer[i] = result_ptr->GetSteer()->at(i);
197 }
198 *output_size = size;
199}
200};
201
202} // namespace planning
203} // namespace apollo
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
const std::vector< std::vector< common::math::Vec2d > > & GetObstaclesVerticesVec()
void AddVirtualObstacle(double *obstacle_x, double *obstacle_y, int vertice_num)
void AddVirtualSoftBoundary(double *obstacle_x, double *obstacle_y, int vertice_num)
const std::vector< std::vector< common::math::Vec2d > > & GetSoftBoundaryVerticesVec()
bool Plan(double sx, double sy, double sphi, double ex, double ey, double ephi, const std::vector< double > &XYbounds, const std::vector< std::vector< common::math::Vec2d > > &obstacles_vertices_vec, HybridAStartResult *result, const std::vector< std::vector< common::math::Vec2d > > &soft_boundary_vertices_vec={}, bool reeds_sheep_last_straight=false)
Planning module main class.
#define ACHECK(cond)
Definition log.h:80
#define AERROR
Definition log.h:44
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
Definition file.cc:132
void AddVirtualSoftBoundary(HybridASoftBoundaryContainer *soft_boundary_ptr, double *soft_boundary_x, double *soft_boundary_y, int vertice_num)
HybridAObstacleContainer * CreateObstaclesPtr()
HybridASoftBoundaryContainer * CreateSoftBoundaryPtr()
bool Plan(HybridAStar *planner_ptr, HybridAObstacleContainer *obstacles_ptr, HybridASoftBoundaryContainer *soft_boundary_ptr, HybridAResultContainer *result_ptr, double sx, double sy, double sphi, double ex, double ey, double ephi, double *XYbounds)
void AddVirtualObstacle(HybridAObstacleContainer *obstacles_ptr, double *obstacle_x, double *obstacle_y, int vertice_num)
void GetResult(HybridAResultContainer *result_ptr, double *x, double *y, double *phi, double *v, double *a, double *steer, size_t *output_size)
HybridAResultContainer * CreateResultPtr()
HybridAStar * CreatePlannerPtr()
class register implement
Definition arena_queue.h:37