Apollo 10.0
自动驾驶开放平台
parking_routing_manager.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2020 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 *****************************************************************************/
17
24
25namespace apollo {
26namespace task_manager {
27
32
34 : monitor_logger_buffer_(
35 apollo::common::monitor::MonitorMessageItem::TASK_MANAGER) {}
36
38 const ParkingRoutingTask& parking_routing_task) {
39 return common::Status::OK();
40}
41
43 ParkingRoutingTask* parking_routing_task) {
44 auto hdmap_ = hdmap::HDMapUtil::BaseMapPtr();
45 hdmap::Id id;
46 id.set_id(parking_routing_task->routing_request()
49 auto parking_space_info = hdmap_->GetParkingSpaceById(id);
50 auto request_parking_info =
51 parking_routing_task->mutable_routing_request()->mutable_parking_info();
52 if (parking_space_info == nullptr) {
53 AERROR << "Can not find parking space" << id_ << "in map";
54 return false;
55 }
56 auto points = parking_space_info->polygon().points();
57 // 0 1 2 3: left_top right_top right_rear left_rear corner point for heading
58 // upward
59 Vec2d center_point(0, 0);
60 for (size_t i = 0; i < points.size(); i++) {
61 center_point += points[i];
62 }
63 center_point /= 4.0;
64 request_parking_info->mutable_parking_point()->set_x(center_point.x());
65 request_parking_info->mutable_parking_point()->set_y(center_point.y());
66 request_parking_info->mutable_parking_point()->set_z(0);
67 apollo::common::PointENU center_enu;
68 center_enu.set_x(center_point.x());
69 center_enu.set_y(center_point.y());
71 double nearest_s;
72 double nearest_l;
73 hdmap_->GetNearestLane(center_enu, &nearest_lane, &nearest_s, &nearest_l);
74 double lane_heading = nearest_lane->Heading(nearest_s);
75 double diff_angle = common::math::AngleDiff(
76 lane_heading, parking_space_info->parking_space().heading());
77
78 if (std::fabs(diff_angle) < M_PI / 3.0) {
79 AINFO << "Find a parallel parking" << id_ << "lane_heading" << lane_heading
80 << "parking heading" << parking_space_info->parking_space().heading();
81 request_parking_info->set_parking_space_type(
82 ParkingSpaceType::PARALLEL_PARKING);
83 auto left_down = request_parking_info->mutable_corner_point()->add_point();
84 left_down->set_x(points[0].x());
85 left_down->set_y(points[0].y());
86 auto right_down = request_parking_info->mutable_corner_point()->add_point();
87 right_down->set_x(points[1].x());
88 right_down->set_y(points[1].y());
89 auto right_up = request_parking_info->mutable_corner_point()->add_point();
90 right_up->set_x(points[2].x());
91 right_up->set_y(points[2].y());
92 auto left_up = request_parking_info->mutable_corner_point()->add_point();
93 left_up->set_x(points[3].x());
94 left_up->set_y(points[3].y());
95 } else {
96 AINFO << "Find a vertical parking";
97 request_parking_info->set_parking_space_type(
98 ParkingSpaceType::VERTICAL_PLOT);
99 auto left_down = request_parking_info->mutable_corner_point()->add_point();
100 left_down->set_x(points[0].x());
101 left_down->set_y(points[0].y());
102 auto right_down = request_parking_info->mutable_corner_point()->add_point();
103 right_down->set_x(points[1].x());
104 right_down->set_y(points[1].y());
105 auto right_up = request_parking_info->mutable_corner_point()->add_point();
106 right_up->set_x(points[2].x());
107 right_up->set_y(points[2].y());
108 auto left_up = request_parking_info->mutable_corner_point()->add_point();
109 left_up->set_x(points[3].x());
110 left_up->set_y(points[3].y());
111 }
112 // extend last point to aviod referenceline generated failed in parking
113 auto last_waypoint = parking_routing_task->mutable_routing_request()
114 ->mutable_waypoint()
115 ->rbegin();
116 auto extend_waypoint = parking_routing_task->mutable_routing_request()
117 ->mutable_waypoint()
118 ->Add();
119 static constexpr double kExtendParkingLength = 20;
120 apollo::common::PointENU extend_point;
121 extend_point.set_x(last_waypoint->pose().x() +
122 kExtendParkingLength * std::cos(lane_heading));
123 extend_point.set_y(last_waypoint->pose().y() +
124 kExtendParkingLength * std::sin(lane_heading));
125 hdmap_->GetNearestLaneWithHeading(extend_point, 20, lane_heading, M_PI_2,
126 &nearest_lane, &nearest_s, &nearest_l);
127 extend_point = nearest_lane->GetSmoothPoint(nearest_s);
128 extend_waypoint->mutable_pose()->set_x(extend_point.x());
129 extend_waypoint->mutable_pose()->set_y(extend_point.y());
130 extend_waypoint->set_id(nearest_lane->id().id());
131 extend_waypoint->set_s(nearest_s);
132
133 return true;
134}
135
136} // namespace task_manager
137} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
void set_x(const double x)
Setter for x component
Definition vec2d.h:60
double y() const
Getter for y component
Definition vec2d.h:57
double x() const
Getter for x component
Definition vec2d.h:54
static const HDMap * BaseMapPtr()
bool ConstructParkingRoutingRequest(ParkingRoutingTask *parking_routing_task)
common::Status Init(const task_manager::ParkingRoutingTask &parking_routing_task)
module initialization function
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
Math-related util functions.
double AngleDiff(const double from, const double to)
Calculate the difference between angle from and to
Definition math_utils.cc:61
std::shared_ptr< const LaneInfo > LaneInfoConstPtr
std::shared_ptr< const ParkingSpaceInfo > ParkingSpaceInfoConstPtr
class register implement
Definition arena_queue.h:37
optional string parking_space_id
Definition poi.proto:15
optional apollo::routing::ParkingInfo parking_info
Definition routing.proto:18
optional apollo::routing::RoutingRequest routing_request