Apollo 11.0
自动驾驶开放平台
precise_parking_command_processor.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2024 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#include <limits>
23#include <string>
24#include <vector>
27
28namespace apollo {
29namespace external_command {
30
31bool PreciseParkingCommandProcessor::Convert(
32 const std::shared_ptr<PreciseParkingCommand>& command,
33 std::shared_ptr<apollo::routing::RoutingRequest>& routing_request) const {
34 routing_request = std::make_shared<apollo::routing::RoutingRequest>();
35 if (!command->is_start_pose_set()) {
36 if (!SetStartPose(routing_request)) {
37 return false;
38 }
39 } else {
40 routing_request->set_is_start_pose_set(true);
41 }
42 auto lane_way_tool = GetLaneWayTool();
43 std::vector<hdmap::AreaInfoConstPtr> areas;
44 common::PointENU point;
45 point.set_x(command->parking_spot_pose().x());
46 point.set_y(command->parking_spot_pose().y());
47 if (hdmap::HDMapUtil::BaseMapPtr()->GetAreas(point, 1e-1, &areas) < 0 || areas.empty()) {
48 AERROR << "can not find any junction near parking spot";
49 return false;
50 };
51 std::vector<apollo::routing::LaneWaypoint> lane_way_points;
52 lane_way_tool->GetPreciseParkingLaneWayPoint(areas.front(), &lane_way_points);
53 apollo::routing::LaneWaypoint best_lane_way_point;
54 double min_distance = std::numeric_limits<double>::max();
55 for (const auto& lane_way_point : lane_way_points) {
56 auto tmp_routing_request = std::make_shared<apollo::routing::RoutingRequest>();
57 tmp_routing_request->CopyFrom(*routing_request);
58 tmp_routing_request->add_waypoint()->CopyFrom(lane_way_point);
59 auto routing_response = std::make_shared<apollo::routing::RoutingResponse>();
60 if (!routing_->Process(tmp_routing_request, routing_response.get())) {
61 continue;
62 }
63 AINFO << routing_response->DebugString();
64 if (routing_response->measurement().distance() < min_distance) {
65 min_distance = routing_response->measurement().distance();
66 best_lane_way_point.Clear();
67 best_lane_way_point.CopyFrom(lane_way_point);
68 }
69 }
70 if (min_distance >= std::numeric_limits<double>::max()) {
71 AERROR << "can not find any valid lane waypoint near parking space";
72 return false;
73 }
74 routing_request->add_waypoint()->CopyFrom(best_lane_way_point);
75 return true;
76}
77
78bool PreciseParkingCommandProcessor::ProcessSpecialCommand(
79 const std::shared_ptr<PreciseParkingCommand>& command,
80 const std::shared_ptr<apollo::planning::PlanningCommand>& planning_command) const {
81 auto custom_command = planning_command->mutable_custom_command();
82 custom_command->PackFrom(*command);
83 return true;
84}
85
86} // namespace external_command
87} // namespace apollo
bool SetStartPose(std::vector< apollo::routing::LaneWaypoint > *lane_way_points) const
Set the start pose of lane_way_points with current vehicle pose.
const std::shared_ptr< apollo::external_command::LaneWayTool > & GetLaneWayTool() const
static const HDMap * BaseMapPtr()
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37