Apollo 11.0
自动驾驶开放平台
zone_cover_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
23namespace apollo {
24namespace external_command {
25
26bool ZoneCoverCommandProcessor::Convert(
27 const std::shared_ptr<ZoneCoverCommand>& command,
28 std::shared_ptr<apollo::routing::RoutingRequest>& routing_request) const {
29 routing_request = std::make_shared<apollo::routing::RoutingRequest>();
30 if (!command->is_start_pose_set()) {
31 if (!SetStartPose(routing_request)) {
32 return false;
33 }
34 } else {
35 routing_request->set_is_start_pose_set(true);
36 }
37 auto lane_way_tool = GetLaneWayTool();
38 const auto zone_cover_area_id = command->zone_cover_area_id();
39 if (zone_cover_area_id.empty()) {
40 AERROR << "zone_cover_area_id is empty, error";
41 return false;
42 }
43
44 hdmap::AreaInfoConstPtr zone_cover_area
46 if (nullptr == zone_cover_area) {
47 AERROR << "can not find zone_cover_area: " << zone_cover_area_id;
48 return false;
49 };
50
51 std::vector<apollo::routing::LaneWaypoint> lane_way_points;
52 lane_way_tool->GetPreciseParkingLaneWayPoint(zone_cover_area, &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 ZoneCoverCommandProcessor::ProcessSpecialCommand(
79 const std::shared_ptr<ZoneCoverCommand>& 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()
AreaInfoConstPtr GetAreaById(const Id &id) const
Definition hdmap.cc:42
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
apollo::hdmap::Id MakeMapId(const std::string &id)
create a Map ID given a string.
Definition hdmap_util.h:85
std::shared_ptr< const AreaInfo > AreaInfoConstPtr
class register implement
Definition arena_queue.h:37