Apollo 10.0
自动驾驶开放平台
lane_follow_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
21
22#include <limits>
23#include <vector>
24
26
27namespace apollo {
28namespace external_command {
29
30bool LaneFollowCommandProcessor::ProcessSpecialCommand(
31 const std::shared_ptr<LaneFollowCommand>& command,
32 const std::shared_ptr<apollo::planning::PlanningCommand>& planning_command)
33 const {
34 return true;
35}
36
37bool LaneFollowCommandProcessor::Convert(
38 const std::shared_ptr<LaneFollowCommand>& command,
39 std::shared_ptr<apollo::routing::RoutingRequest>& routing_request) const {
40 routing_request = std::make_shared<apollo::routing::RoutingRequest>();
41 std::vector<apollo::routing::LaneWaypoint> lane_way_points;
42 auto lane_way_tool = GetLaneWayTool();
43 if (!command->is_start_pose_set()) {
44 if (lane_way_tool->IsParkandgoScenario()) {
45 AINFO << "adc is outside road, in park and go scenario";
46 if (!SetStartPose(&lane_way_points)) {
47 return false;
48 }
49 apollo::routing::LaneWaypoint best_lane_way_point;
50 double min_distance = std::numeric_limits<double>::max();
51 AINFO << "lane_way_points.size()" << lane_way_points.size();
52 for (const auto& lane_way_point : lane_way_points) {
53 auto tmp_routing_request =
54 std::make_shared<apollo::routing::RoutingRequest>();
55 tmp_routing_request->CopyFrom(*routing_request);
56 tmp_routing_request->add_waypoint()->CopyFrom(lane_way_point);
57 for (const auto& way_point : command->way_point()) {
58 if (!lane_way_tool->ConvertToLaneWayPoint(
59 way_point, tmp_routing_request->add_waypoint())) {
60 AINFO << "Cannot convert the end pose to lane way point: "
61 << way_point.DebugString();
62 return false;
63 }
64 }
65 if (!lane_way_tool->ConvertToLaneWayPoint(
66 command->end_pose(), tmp_routing_request->add_waypoint())) {
67 AERROR << "Cannot convert the end pose to lane way point: "
68 << command->end_pose().DebugString();
69 return false;
70 }
71 auto routing_response =
72 std::make_shared<apollo::routing::RoutingResponse>();
73 if (!routing_->Process(tmp_routing_request, routing_response.get())) {
74 AINFO << "routing_ error " << tmp_routing_request->DebugString();
75 continue;
76 }
77 AINFO << routing_response->DebugString();
78 if (routing_response->measurement().distance() < min_distance) {
79 min_distance = routing_response->measurement().distance();
80 best_lane_way_point.Clear();
81 best_lane_way_point.CopyFrom(lane_way_point);
82 }
83 }
84 if (min_distance >= std::numeric_limits<double>::max()) {
85 AINFO << "can not find any valid lane waypoint near parking space";
86 return false;
87 }
88 routing_request->add_waypoint()->CopyFrom(best_lane_way_point);
89 } else {
90 if (!SetStartPose(routing_request)) {
91 return false;
92 }
93 }
94 } else {
95 routing_request->set_is_start_pose_set(true);
96 }
97 // Add the way points into RoutingRequest.
98 for (const auto& way_point : command->way_point()) {
99 if (!lane_way_tool->ConvertToLaneWayPoint(
100 way_point, routing_request->add_waypoint())) {
101 AERROR << "Cannot convert the end pose to lane way point: "
102 << way_point.DebugString();
103 return false;
104 }
105 }
106 // Get the end pose and update in RoutingRequest.
107 if (!lane_way_tool->ConvertToLaneWayPoint(command->end_pose(),
108 routing_request->add_waypoint())) {
109 AERROR << "Cannot convert the end pose to lane way point: "
110 << command->end_pose().DebugString();
111 return false;
112 }
113 return true;
114}
115
116} // namespace external_command
117} // 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