28using common::math::Vec2d;
31 const std::string &config_dir,
32 const std::string &name,
33 const std::shared_ptr<DependencyInjector> &injector) {
37 if (!Task::LoadConfig<OpenSpacePathPlanningConfig>(&config_)) {
41 AINFO << config_.DebugString();
51void OpenSpacePathPlanning::Stop() {
53 if (thread_init_flag_) {
56 data_ready_.store(
false);
57 path_update_.store(
false);
61Status OpenSpacePathPlanning::Process() {
62 AINFO <<
"data_ready_: " << (data_ready_ ?
"true" :
"false");
63 auto* previous_frame =
injector_->frame_history()->Latest();
65 AINFO <<
"Not replan";
67 mutable_path_planning_trajectory_result()) =
68 previous_frame->open_space_info().path_planning_trajectory_result();
72 if (!previous_frame->open_space_info().
73 path_planning_trajectory_result().empty()) {
74 AINFO <<
"Previous frame has path planning result";
76 mutable_path_planning_trajectory_result()) =
77 previous_frame->open_space_info().path_planning_trajectory_result();
80 AINFO <<
"Path planning";
83 AINFO <<
"Path planning updated";
85 mutable_path_planning_trajectory_result());
86 path_update_.store(
false);
93void OpenSpacePathPlanning::PathPlanning() {
95 task_future_ = cyber::Async(
96 &OpenSpacePathPlanning::GeneratePathThread,
this);
97 thread_init_flag_.store(
true);
101 double start_x =
injector_->vehicle_state()->x();
102 double start_y =
injector_->vehicle_state()->y();
103 double start_theta =
injector_->vehicle_state()->heading();
105 open_space_info.origin_heading(),
106 open_space_info.origin_point(),
107 &start_x, &start_y, &start_theta);
110 std::lock_guard<std::mutex> lock(data_mutex_);
111 thread_data_.
start_pose = {start_x, start_y, start_theta};
112 thread_data_.
end_pose = open_space_info.open_space_end_pose();
113 thread_data_.
rotate_angle = open_space_info.origin_heading();
116 thread_data_.
obstacles_A = open_space_info.obstacles_A();
117 thread_data_.
obstacles_b = open_space_info.obstacles_b();
119 open_space_info.obstacles_vertices_vec();
121 open_space_info.soft_boundary_vertices_vec();
122 thread_data_.
XYbounds = open_space_info.ROI_xy_boundary();
129 data_ready_.store(
true);
132 const auto& end_pose = open_space_info.open_space_end_pose();
133 const auto& rotate_angle = open_space_info.origin_heading();
134 const auto& translate_origin = open_space_info.origin_point();
135 const auto& obstacles_edges_num = open_space_info.obstacles_edges_num();
136 const auto& obstacles_A = open_space_info.obstacles_A();
137 const auto& obstacles_b = open_space_info.obstacles_b();
138 const auto& obstacles_vertices_vec =
139 open_space_info.obstacles_vertices_vec();
140 const auto& soft_boundary_vertices_vec =
141 open_space_info.soft_boundary_vertices_vec();
142 const auto& XYbounds = open_space_info.ROI_xy_boundary();
143 const bool reeds_sheep_last_straight =
149 if (path_finder_->Plan(start_x, start_y, start_theta,
150 end_pose[0], end_pose[1],
151 end_pose[2], XYbounds,
152 obstacles_vertices_vec,
154 soft_boundary_vertices_vec,
155 reeds_sheep_last_straight)) {
156 path_update_.store(
true);
157 AINFO <<
"State warm start problem solved successfully!";
159 AERROR <<
"State warm start problem failed to solve";
164void OpenSpacePathPlanning::GeneratePathThread() {
165 while (!data_ready_) {
168 OpenSpacePathPlanningThreadData thread_data;
170 std::lock_guard<std::mutex> lock(data_mutex_);
171 thread_data = thread_data_;
175 <<
" " << thread_data.start_pose[1]
176 <<
" " << thread_data.start_pose[2];
177 bool ret = path_finder_->Plan(
178 thread_data.start_pose[0], thread_data.start_pose[1],
179 thread_data.start_pose[2], thread_data.end_pose[0],
180 thread_data.end_pose[1], thread_data.end_pose[2],
181 thread_data.XYbounds, thread_data.obstacles_vertices_vec,
183 thread_data.reeds_sheep_last_straight);
186 std::lock_guard<std::mutex> lock(data_mutex_);
187 path_update_.store(
true);
188 AINFO <<
"path find success!";
190 AERROR <<
"path find failed";
192 thread_init_flag_.store(
false);
193 data_ready_.store(
false);
197void OpenSpacePathPlanning::LoadResult(
198 DiscretizedTrajectory*
const trajectory_data) {
199 trajectory_data->clear();
203 for (
size_t i = 0; i < result_.
x.size(); i++) {
210 common::TrajectoryPoint point;
211 point.mutable_path_point()->set_x(result_.
x[i]);
212 point.mutable_path_point()->set_y(result_.
y[i]);
213 point.mutable_path_point()->set_theta(result_.
phi[i]);
214 point.set_v(result_.
v[i]);
215 point.set_steer(result_.
steer[i]);
216 point.set_a(result_.
a[i]);
217 point.set_relative_time(i * 0.5);
218 trajectory_data->emplace_back(point);
A general class to denote the return status of an API call.
static Status OK()
generate a success status.
const OpenSpaceInfo & open_space_info() const
OpenSpaceInfo * mutable_open_space_info()
const std::vector< double > & open_space_end_pose() const
const common::math::Vec2d & origin_point() const
double origin_heading() const
bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
static void PathPointNormalizing(double rotate_angle, const common::math::Vec2d &translate_origin, double *x, double *y, double *phi)
static void PathPointDeNormalizing(double rotate_angle, const common::math::Vec2d &translate_origin, double *x, double *y, double *phi)
std::shared_ptr< DependencyInjector > injector_
virtual bool Init(const std::string &config_dir, const std::string &name, const std::shared_ptr< DependencyInjector > &injector)
Planning module main class.
std::vector< double > steer
std::vector< double > phi
optional bool enable_parallel_parking_last_trajectory_straight
optional bool enable_vertical_parking_last_trajectory_straight
optional WarmStartConfig warm_start_config
optional bool enable_path_planning_thread
bool reeds_sheep_last_straight
Eigen::MatrixXd obstacles_A
std::vector< double > start_pose
Eigen::MatrixXd obstacles_b
std::vector< std::vector< common::math::Vec2d > > soft_boundary_vertices_vec
std::vector< std::vector< common::math::Vec2d > > obstacles_vertices_vec
std::vector< double > end_pose
Eigen::MatrixXi obstacles_edges_num
std::vector< double > XYbounds
apollo::common::math::Vec2d translate_origin