Apollo 10.0
自动驾驶开放平台
valet_parking_command_processor.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#include <limits>
23#include <string>
24#include <vector>
26
27namespace apollo {
28namespace external_command {
29
30bool ValetParkingCommandProcessor::Convert(
31 const std::shared_ptr<ValetParkingCommand>& command,
32 std::shared_ptr<apollo::routing::RoutingRequest>& routing_request) const {
33 routing_request = std::make_shared<apollo::routing::RoutingRequest>();
34 if (!command->is_start_pose_set()) {
35 if (!SetStartPose(routing_request)) {
36 return false;
37 }
38 } else {
39 routing_request->set_is_start_pose_set(true);
40 }
41 auto lane_way_tool = GetLaneWayTool();
42 std::string parking_id = command->parking_spot_id();
43 // Add the way points into RoutingRequest.
44 for (const auto& way_point : command->way_point()) {
45 if (!lane_way_tool->ConvertToLaneWayPoint(
46 way_point, routing_request->add_waypoint())) {
47 AERROR << "Cannot convert the end pose to lane way point: "
48 << way_point.DebugString();
49 return false;
50 }
51 }
52 std::vector<apollo::routing::LaneWaypoint> lane_way_points;
53 lane_way_tool->GetParkingLaneWayPoint(parking_id, &lane_way_points);
54 apollo::routing::LaneWaypoint best_lane_way_point;
55 double min_distance = std::numeric_limits<double>::max();
56 for (const auto& lane_way_point : lane_way_points) {
57 auto tmp_routing_request =
58 std::make_shared<apollo::routing::RoutingRequest>();
59 tmp_routing_request->CopyFrom(*routing_request);
60 tmp_routing_request->add_waypoint()->CopyFrom(lane_way_point);
61 auto routing_response =
62 std::make_shared<apollo::routing::RoutingResponse>();
63 if (!routing_->Process(tmp_routing_request, routing_response.get())) {
64 continue;
65 }
66 AINFO << routing_response->DebugString();
67 if (routing_response->measurement().distance() < min_distance) {
68 min_distance = routing_response->measurement().distance();
69 best_lane_way_point.Clear();
70 best_lane_way_point.CopyFrom(lane_way_point);
71 }
72 }
73 if (min_distance >= std::numeric_limits<double>::max()) {
74 AERROR << "can not find any valid lane waypoint near parking space";
75 return false;
76 }
77 routing_request->add_waypoint()->CopyFrom(best_lane_way_point);
78 return true;
79}
80
81bool ValetParkingCommandProcessor::ProcessSpecialCommand(
82 const std::shared_ptr<ValetParkingCommand>& command,
83 const std::shared_ptr<apollo::planning::PlanningCommand>& planning_command)
84 const {
85 auto parking_command = planning_command->mutable_parking_command();
86 parking_command->set_parking_spot_id(command->parking_spot_id());
87 return true;
88}
89
90} // namespace external_command
91} // 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
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37