Apollo 10.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
28 public:
30 void AddVirtualObstacle(double* obstacle_x, double* obstacle_y,
31 int vertice_num) {
32 std::vector<common::math::Vec2d> obstacle_vertices;
33 for (int i = 0; i < vertice_num; i++) {
34 common::math::Vec2d vertice(obstacle_x[i], obstacle_y[i]);
35 obstacle_vertices.emplace_back(vertice);
36 }
37 obstacles_list.emplace_back(obstacle_vertices);
38 }
39 const std::vector<std::vector<common::math::Vec2d>>&
41 return obstacles_list;
42 }
43
44 private:
45 std::vector<std::vector<common::math::Vec2d>> obstacles_list;
46};
47
49 public:
52 double* obstacle_x, double* obstacle_y, int vertice_num) {
53 std::vector<common::math::Vec2d> soft_boundary_vertices;
54 for (int i = 0; i < vertice_num; i++) {
55 common::math::Vec2d vertice(obstacle_x[i], obstacle_y[i]);
56 soft_boundary_vertices.emplace_back(vertice);
57 }
58 soft_boundary_list.emplace_back(soft_boundary_vertices);
59
60 for (int i = 0; i < soft_boundary_list.size(); ++i) {
61 for (const auto& vertice : soft_boundary_list[i]) {
62 AERROR << "Soft boundary: " << i << ", "
63 << vertice.x() << ", " << vertice.y();
64 }
65 }
66 }
67 const std::vector<std::vector<common::math::Vec2d>>&
69 return soft_boundary_list;
70 }
71
72 private:
73 std::vector<std::vector<common::math::Vec2d>> soft_boundary_list;
74};
75
77 public:
79 void LoadResult() {
80 x_ = std::move(result_.x);
81 y_ = std::move(result_.y);
82 phi_ = std::move(result_.phi);
83 v_ = std::move(result_.v);
84 a_ = std::move(result_.a);
85 steer_ = std::move(result_.steer);
86 }
87 std::vector<double>* GetX() {
88 return &x_;
89 }
90 std::vector<double>* GetY() {
91 return &y_;
92 }
93 std::vector<double>* GetPhi() {
94 return &phi_;
95 }
96 std::vector<double>* GetV() {
97 return &v_;
98 }
99 std::vector<double>* GetA() {
100 return &a_;
101 }
102 std::vector<double>* GetSteer() {
103 return &steer_;
104 }
106 return &result_;
107 }
108
109 private:
110 HybridAStartResult result_;
111 std::vector<double> x_;
112 std::vector<double> y_;
113 std::vector<double> phi_;
114 std::vector<double> v_;
115 std::vector<double> a_;
116 std::vector<double> steer_;
117};
118
119extern "C" {
121 FLAGS_planner_open_space_config_filename
122 = "modules/planning/planning_component/"
123 "conf/planner_hybrid_a_star_config.pb.txt";
124 apollo::planning::WarmStartConfig planner_open_space_config_;
125
127 FLAGS_planner_open_space_config_filename, &planner_open_space_config_))
128 << "Failed to load open space config file "
129 << FLAGS_planner_open_space_config_filename;
130 return new HybridAStar(planner_open_space_config_);
131}
142 HybridAObstacleContainer* obstacles_ptr,
143 double* obstacle_x,
144 double* obstacle_y,
145 int vertice_num) {
146 obstacles_ptr->AddVirtualObstacle(obstacle_x, obstacle_y, vertice_num);
147}
149 HybridASoftBoundaryContainer* soft_boundary_ptr,
150 double* soft_boundary_x,
151 double* soft_boundary_y,
152 int vertice_num) {
153 soft_boundary_ptr->AddVirtualSoftBoundary(
154 soft_boundary_x, soft_boundary_y, vertice_num);
155}
156bool Plan(
157 HybridAStar* planner_ptr,
158 HybridAObstacleContainer* obstacles_ptr,
159 HybridASoftBoundaryContainer* soft_boundary_ptr,
160 HybridAResultContainer* result_ptr,
161 double sx,
162 double sy,
163 double sphi,
164 double ex,
165 double ey,
166 double ephi,
167 double* XYbounds) {
168 AERROR << "sx: " << sx;
169 std::vector<double> XYbounds_(XYbounds, XYbounds + 4);
170 return planner_ptr->Plan(
171 sx,
172 sy,
173 sphi,
174 ex,
175 ey,
176 ephi,
177 XYbounds_,
178 obstacles_ptr->GetObstaclesVerticesVec(),
179 result_ptr->PrepareResult(),
180 soft_boundary_ptr->GetSoftBoundaryVerticesVec(),
181 false);
182}
184 HybridAResultContainer* result_ptr,
185 double* x,
186 double* y,
187 double* phi,
188 double* v,
189 double* a,
190 double* steer,
191 size_t* output_size) {
192 result_ptr->LoadResult();
193 size_t size = result_ptr->GetX()->size();
194 std::cout << "return size is " << size << std::endl;
195 for (size_t i = 0; i < size; i++) {
196 x[i] = result_ptr->GetX()->at(i);
197 y[i] = result_ptr->GetY()->at(i);
198 phi[i] = result_ptr->GetPhi()->at(i);
199 v[i] = result_ptr->GetV()->at(i);
200 }
201 for (size_t i = 0; i < size - 1; i++) {
202 a[i] = result_ptr->GetA()->at(i);
203 steer[i] = result_ptr->GetSteer()->at(i);
204 }
205 *output_size = size;
206}
207};
208
209} // namespace planning
210} // 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