Apollo 11.0
自动驾驶开放平台
destination.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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 <memory>
23#include <vector>
24
25#include "modules/common_msgs/map_msgs/map_lane.pb.h"
29
30namespace apollo {
31namespace planning {
32
35
36bool Destination::Init(const std::string& name,
37 const std::shared_ptr<DependencyInjector>& injector) {
38 if (!TrafficRule::Init(name, injector)) {
39 return false;
40 }
41 // Load the config this task.
42 return TrafficRule::LoadConfig<DestinationConfig>(&config_);
43}
44
46 ReferenceLineInfo* const reference_line_info) {
47 CHECK_NOTNULL(frame);
48 CHECK_NOTNULL(reference_line_info);
49
50 MakeDecisions(frame, reference_line_info);
51
52 return Status::OK();
53}
54
58int Destination::MakeDecisions(Frame* frame,
59 ReferenceLineInfo* const reference_line_info) {
60 CHECK_NOTNULL(frame);
61 CHECK_NOTNULL(reference_line_info);
62
63 if (!frame->is_near_destination()) {
64 return 0;
65 }
66
67 const auto routing_end = frame->local_view().end_lane_way_point;
68 if (nullptr == routing_end) {
69 AERROR << "routing_request has no end";
70 return -1;
71 }
72 common::SLPoint dest_sl;
73 const auto& reference_line = reference_line_info->reference_line();
74 reference_line.XYToSL(routing_end->pose(), &dest_sl);
75 const auto& adc_sl = reference_line_info->AdcSlBoundary();
76
77 const auto& vehicle_config =
78 common::VehicleConfigHelper::Instance()->GetConfig();
79 const double ego_front_to_center =
80 vehicle_config.vehicle_param().front_edge_to_center();
81 if (dest_sl.s() + ego_front_to_center > reference_line.Length()) {
82 AWARN << "dest_sl.s() + ego_front_to_center > reference_line->length()"
83 <<"may cause ego is stoped by PATH_END fence not by destination";
84 }
85 const auto& dest =
86 injector_->planning_context()->mutable_planning_status()->destination();
87 if (adc_sl.start_s() > dest_sl.s() && !dest.has_passed_destination()) {
88 ADEBUG << "Destination at back, but we have not reached destination yet";
89 return 0;
90 }
91
92 const std::string stop_wall_id = FLAGS_destination_obstacle_id;
93 const std::vector<std::string> wait_for_obstacle_ids;
94
95 const auto& pull_over_status =
96 injector_->planning_context()->planning_status().pull_over();
97 if (pull_over_status.has_position() && pull_over_status.position().has_x() &&
98 pull_over_status.position().has_y()) {
99 // build stop decision based on pull-over position
100 ADEBUG << "BuildStopDecision: pull-over position";
101 common::SLPoint pull_over_sl;
102 reference_line.XYToSL(pull_over_status.position(), &pull_over_sl);
103
104 const double stop_line_s = pull_over_sl.s() +
108 config_.stop_distance();
109 util::BuildStopDecision(stop_wall_id, stop_line_s, config_.stop_distance(),
110 StopReasonCode::STOP_REASON_PULL_OVER,
111 wait_for_obstacle_ids, Getname(), frame,
112 reference_line_info);
113 return 0;
114 }
115
116 // build stop decision
117 ADEBUG << "BuildStopDecision: destination";
118 const double dest_lane_s =
119 std::fmax(0.0, routing_end->s() - FLAGS_virtual_stop_wall_length -
120 config_.stop_distance());
122 stop_wall_id, routing_end->id(), dest_lane_s, config_.stop_distance(),
123 StopReasonCode::STOP_REASON_DESTINATION, wait_for_obstacle_ids, Getname(),
124 frame, reference_line_info);
125
126 return 0;
127}
128
129} // namespace planning
130} // 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
@Brief This is a helper class that can load vehicle configurations.
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
common::Status ApplyRule(Frame *const frame, ReferenceLineInfo *const reference_line_info)
bool Init(const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
Frame holds all data for one planning cycle.
Definition frame.h:62
const LocalView & local_view() const
Definition frame.h:163
const bool is_near_destination() const
Definition frame.h:154
ReferenceLineInfo holds all data for one reference line.
const ReferenceLine & reference_line() const
const SLBoundary & AdcSlBoundary() const
bool XYToSL(const common::math::Vec2d &xy_point, common::SLPoint *const sl_point, double warm_start_s=-1.0) const
Transvert Cartesian coordinates to Frenet.
virtual bool Init(const std::string &name, const std::shared_ptr< DependencyInjector > &injector)
std::shared_ptr< DependencyInjector > injector_
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AWARN
Definition log.h:43
int BuildStopDecision(const std::string &stop_wall_id, const double stop_line_s, const double stop_distance, const StopReasonCode &stop_reason_code, const std::vector< std::string > &wait_for_obstacles, const std::string &decision_tag, Frame *const frame, ReferenceLineInfo *const reference_line_info, double stop_wall_width)
Definition common.cc:28
class register implement
Definition arena_queue.h:37
optional VehicleParam vehicle_param
std::shared_ptr< routing::LaneWaypoint > end_lane_way_point
Definition local_view.h:49