Apollo 11.0
自动驾驶开放平台
valet_parking_scenario.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 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
26
27namespace apollo {
28namespace planning {
29
35
36bool ValetParkingScenario::Init(std::shared_ptr<DependencyInjector> injector,
37 const std::string& name) {
38 if (init_) {
39 return true;
40 }
41
42 if (!Scenario::Init(injector, name)) {
43 AERROR << "failed to init scenario" << Name();
44 return false;
45 }
46
47 if (!Scenario::LoadConfig<ScenarioValetParkingConfig>(
48 &context_.scenario_config)) {
49 AERROR << "fail to get config of scenario" << Name();
50 return false;
51 }
53 CHECK_NOTNULL(hdmap_);
54 init_ = true;
55 return true;
56}
57
58bool ValetParkingScenario::IsTransferable(const Scenario* const other_scenario,
59 const Frame& frame) {
60 // TODO(all) Implement available parking spot detection by preception results
61 if (!frame.local_view().planning_command->has_parking_command()) {
62 return false;
63 }
64 if (other_scenario == nullptr || frame.reference_line_info().empty()) {
65 return false;
66 }
67 std::string target_parking_spot_id;
68 if (frame.local_view().planning_command->has_parking_command() &&
69 frame.local_view()
70 .planning_command->parking_command()
71 .has_parking_spot_id()) {
72 target_parking_spot_id = frame.local_view()
73 .planning_command->parking_command()
74 .parking_spot_id();
75 } else {
76 ADEBUG << "No parking space id from routing";
77 return false;
78 }
79
80 if (target_parking_spot_id.empty()) {
81 return false;
82 }
83
84 const auto& nearby_path =
85 frame.reference_line_info().front().reference_line().map_path();
86 PathOverlap parking_space_overlap;
87 const auto& vehicle_state = frame.vehicle_state();
88
89 if (!SearchTargetParkingSpotOnPath(nearby_path, target_parking_spot_id,
90 &parking_space_overlap)) {
91 ADEBUG << "No such parking spot found after searching all path forward "
92 "possible"
93 << target_parking_spot_id;
94 return false;
95 }
96 double parking_spot_range_to_start =
98 if (!CheckDistanceToParkingSpot(frame, vehicle_state, nearby_path,
99 parking_spot_range_to_start,
100 parking_space_overlap)) {
101 ADEBUG << "target parking spot found, but too far, distance larger than "
102 "pre-defined distance"
103 << target_parking_spot_id;
104 return false;
105 }
106 context_.target_parking_spot_id = target_parking_spot_id;
107 return true;
108}
109
110bool ValetParkingScenario::SearchTargetParkingSpotOnPath(
111 const Path& nearby_path, const std::string& target_parking_id,
112 PathOverlap* parking_space_overlap) {
113 const auto& parking_space_overlaps = nearby_path.parking_space_overlaps();
114 for (const auto& parking_overlap : parking_space_overlaps) {
115 if (parking_overlap.object_id == target_parking_id) {
116 *parking_space_overlap = parking_overlap;
117 return true;
118 }
119 }
120 return false;
121}
122
123bool ValetParkingScenario::CheckDistanceToParkingSpot(
124 const Frame& frame, const VehicleState& vehicle_state,
125 const Path& nearby_path, const double parking_start_range,
126 const PathOverlap& parking_space_overlap) {
127 // TODO(Jinyun) parking overlap s are wrong on map, not usable
128 const hdmap::HDMap* hdmap = hdmap::HDMapUtil::BaseMapPtr();
129 hdmap::Id id;
130 double center_point_s, center_point_l;
131 id.set_id(parking_space_overlap.object_id);
132 ParkingSpaceInfoConstPtr target_parking_spot_ptr =
133 hdmap->GetParkingSpaceById(id);
134 Vec2d left_bottom_point = target_parking_spot_ptr->polygon().points().at(0);
135 Vec2d right_bottom_point = target_parking_spot_ptr->polygon().points().at(1);
136 Vec2d right_top_point = target_parking_spot_ptr->polygon().points().at(2);
137 Vec2d left_top_point = target_parking_spot_ptr->polygon().points().at(3);
138 Vec2d center_point = (left_bottom_point + right_bottom_point +
139 right_top_point + left_top_point) /
140 4.0;
141 nearby_path.GetNearestPoint(center_point, &center_point_s, &center_point_l);
142 double vehicle_point_s = 0.0;
143 double vehicle_point_l = 0.0;
144 Vec2d vehicle_vec(vehicle_state.x(), vehicle_state.y());
145 nearby_path.GetNearestPoint(vehicle_vec, &vehicle_point_s, &vehicle_point_l);
146 if (std::abs(center_point_s - vehicle_point_s) < parking_start_range) {
147 return true;
148 }
149 return false;
150}
151
152} // namespace planning
153} // namespace apollo
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
static const HDMap * BaseMapPtr()
const std::vector< PathOverlap > & parking_space_overlaps() const
Definition path.h:325
Frame holds all data for one planning cycle.
Definition frame.h:62
const LocalView & local_view() const
Definition frame.h:163
const common::VehicleState & vehicle_state() const
Definition frame.cc:83
const std::list< ReferenceLineInfo > & reference_line_info() const
Definition frame.cc:123
virtual bool Init(std::shared_ptr< DependencyInjector > injector, const std::string &name)
Definition scenario.cc:43
const std::string & Name() const
Definition scenario.h:98
bool IsTransferable(const Scenario *const other_scenario, const Frame &frame) override
Each scenario should define its own transfer condition, i.e., when it should allow to transfer from o...
bool Init(std::shared_ptr< DependencyInjector > injector, const std::string &name) override
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
std::shared_ptr< const ParkingSpaceInfo > ParkingSpaceInfoConstPtr
class register implement
Definition arena_queue.h:37
std::shared_ptr< PlanningCommand > planning_command
Definition local_view.h:48