Apollo 11.0
自动驾驶开放平台
stage_free_space.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2023 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 <string>
24#include <vector>
25
27
28namespace apollo {
29namespace planning {
30
32 const StagePipeline& config,
33 const std::shared_ptr<DependencyInjector>& injector,
34 const std::string& config_dir,
35 void* context) {
36 CHECK_NOTNULL(context);
37 bool ret = Stage::Init(config, injector, config_dir, context);
38 if (!ret) {
39 AERROR << Name() << "init failed!";
40 return false;
41 }
42 scenario_config_.CopyFrom(GetContextAs<FreeSpaceContext>()->scenario_config);
43 return ret;
44}
45
47 auto* mutable_open_space_info = frame->mutable_open_space_info();
48 const auto& free_space_command = GetContextAs<FreeSpaceContext>()->free_space_command;
49 // Set free space drivable roi boundary
50 std::vector<std::vector<common::math::Vec2d>> roi_boundary;
51 roi_boundary.emplace_back();
52 const auto& parking_roi = free_space_command.drivable_roi();
53 for (int j = 0; j < parking_roi.point_size(); j++) {
54 roi_boundary.back().emplace_back(parking_roi.point(j).x(), parking_roi.point(j).y());
55 }
56 if (roi_boundary.back().begin()->DistanceTo(*roi_boundary.back().rbegin()) > 0.01) {
57 roi_boundary.back().push_back(*roi_boundary.begin()->begin());
58 }
59 // Set XY boundary
60 OpenSpaceRoiUtil::GetRoiXYBoundary(roi_boundary, mutable_open_space_info->mutable_ROI_xy_boundary());
61 // Set free space non drivable roi boundary
62 auto roi_x_min = mutable_open_space_info->mutable_ROI_xy_boundary()->at(0);
63 auto roi_x_max = mutable_open_space_info->mutable_ROI_xy_boundary()->at(1);
64 auto roi_y_min = mutable_open_space_info->mutable_ROI_xy_boundary()->at(2);
65 auto roi_y_max = mutable_open_space_info->mutable_ROI_xy_boundary()->at(3);
66 for (int i = 0; i < free_space_command.non_drivable_roi_size(); i++) {
67 roi_boundary.emplace_back();
68 const auto& parking_roi = free_space_command.non_drivable_roi(i);
69 for (int j = 0; j < parking_roi.point_size(); j++) {
70 auto x = parking_roi.point(j).x();
71 auto y = parking_roi.point(j).y();
72 if (x < roi_x_min || x > roi_x_max || y < roi_y_min || y > roi_y_max) {
73 AERROR << "non drivable roi should be contained by drivable roi";
75 }
76 roi_boundary.back().emplace_back(x, y);
77 }
78 }
79 if (roi_boundary.back().begin()->DistanceTo(*roi_boundary.back().rbegin()) > 0.01) {
80 roi_boundary.back().push_back(*roi_boundary.begin()->begin());
81 }
82 // Set end pose
83 auto* open_space_end_pose = mutable_open_space_info->mutable_open_space_end_pose();
84 open_space_end_pose->push_back(free_space_command.parking_spot_pose().x());
85 open_space_end_pose->push_back(free_space_command.parking_spot_pose().y());
86 open_space_end_pose->push_back(free_space_command.parking_spot_pose().heading());
87 open_space_end_pose->push_back(0);
88
90 double d_x = frame->vehicle_state().x() - free_space_command.parking_spot_pose().x();
91 double d_y = frame->vehicle_state().y() - free_space_command.parking_spot_pose().y();
92 double d_heading = frame->vehicle_state().heading() - free_space_command.parking_spot_pose().heading();
93 AINFO << "Current position diff with end pose! x= " << d_x << ";y= " << d_y << ";heading" << d_heading
94 << ";Distance with end pose:" << std::sqrt(d_x * d_x + d_y * d_y);
95 // Add obstacle boundary to roi_bound
96 if (scenario_config_.enabled_perception_obstacles()) {
98 scenario_config_.filtering_distance(),
99 scenario_config_.perception_obstacle_buffer(),
100 mutable_open_space_info->ROI_xy_boundary(),
101 frame,
102 &roi_boundary);
103 }
104 *mutable_open_space_info->mutable_obstacles_vertices_vec() = roi_boundary;
105 // transform by origin point
106 const auto& xy_boundary = mutable_open_space_info->ROI_xy_boundary();
107 Vec2d origin_point(xy_boundary[0], xy_boundary[2]);
108 OpenSpaceRoiUtil::TransformByOriginPoint(origin_point, 0.0, mutable_open_space_info);
109 // Formulate as Ax < b
110 if (!OpenSpaceRoiUtil::FormulateBoundaryConstraints(mutable_open_space_info)) {
112 }
113 mutable_open_space_info->set_is_on_open_space_trajectory(true);
114
115 StageResult result = ExecuteTaskOnOpenSpace(frame);
116 if (result.HasError()) {
117 AERROR << "StageFreeSpace planning error";
119 }
121}
122
123StageResult StageFreeSpace::FinishStage() {
125}
126
127} // namespace planning
128} // namespace apollo
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
Frame holds all data for one planning cycle.
Definition frame.h:62
const common::VehicleState & vehicle_state() const
Definition frame.cc:83
OpenSpaceInfo * mutable_open_space_info()
Definition frame.h:169
static bool FormulateBoundaryConstraints(OpenSpaceInfo *const open_space_info)
main process to compute and load info needed by open space planner
static bool LoadObstacles(const double filtering_distance, const double perception_obstacle_buffer, const std::vector< double > &xy_boundary, Frame *const frame, std::vector< std::vector< common::math::Vec2d > > *const roi_parking_boundary)
Load obstacle polygon to roi_boundary in clock wise order
static void TransformByOriginPoint(const common::math::Vec2d &origin_point, const double heading, std::vector< std::vector< common::math::Vec2d > > *roi_parking_boundary)
static void GetRoiXYBoundary(const std::vector< std::vector< common::math::Vec2d > > &roi_parking_boundary, std::vector< double > *const XYBoundary)
get XY boundary which is minmax x or y in roi boundary
StageResult Process(const common::TrajectoryPoint &planning_init_point, Frame *frame) override
Each stage does its business logic inside Process function.
bool Init(const StagePipeline &config, const std::shared_ptr< DependencyInjector > &injector, const std::string &config_dir, void *context)
const StageResult & SetStageStatus(const StageStatusType &stage_status)
Set the stage status.
bool HasError() const
Check if StageResult contains error.
StageResult ExecuteTaskOnOpenSpace(Frame *frame)
Definition stage.cc:206
virtual bool Init(const StagePipeline &config, const std::shared_ptr< DependencyInjector > &injector, const std::string &config_dir, void *context)
Definition stage.cc:43
const std::string & Name() const
Definition stage.cc:99
Planning module main class.
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37