Apollo 11.0
自动驾驶开放平台
reference_line_end.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
22
23#include <memory>
24
25#include "modules/common_msgs/basic_msgs/pnc_point.pb.h"
28
29namespace apollo {
30namespace planning {
31
33
35 const std::string& name,
36 const std::shared_ptr<DependencyInjector>& injector) {
37 if (!TrafficRule::Init(name, injector)) {
38 return false;
39 }
40 // Load the config this task.
41 return TrafficRule::LoadConfig<ReferenceLineEndConfig>(&config_);
42}
43
45 Frame* frame, ReferenceLineInfo* const reference_line_info) {
46 const auto& reference_line = reference_line_info->reference_line();
47
48 ADEBUG << "ReferenceLineEnd length[" << reference_line.Length() << "]";
49 for (const auto& segment : reference_line_info->Lanes()) {
50 ADEBUG << " lane[" << segment.lane->lane().id().id() << "]";
51 }
52 // check
53 double remain_s =
54 reference_line.Length() - reference_line_info->AdcSlBoundary().end_s();
55 if (remain_s > config_.min_reference_line_remain_length()) {
56 return Status::OK();
57 }
58
59 // create a virtual stop wall at the end of reference line to stop the adc
60 std::string virtual_obstacle_id =
61 REF_LINE_END_VO_ID_PREFIX + reference_line_info->Lanes().Id();
62 double obstacle_start_s =
63 reference_line.Length() - 2 * FLAGS_virtual_stop_wall_length;
64 auto* obstacle = frame->CreateStopObstacle(
65 reference_line_info, virtual_obstacle_id, obstacle_start_s);
66 if (!obstacle) {
68 "Failed to create reference line end obstacle");
69 }
70 Obstacle* stop_wall = reference_line_info->AddObstacle(obstacle);
71 if (!stop_wall) {
72 return Status(
74 "Failed to create path obstacle for reference line end obstacle");
75 }
76
77 // build stop decision
78 const double stop_line_s = obstacle_start_s - config_.stop_distance();
79 auto stop_point = reference_line.GetReferencePoint(stop_line_s);
80
81 ObjectDecisionType stop;
82 auto stop_decision = stop.mutable_stop();
83 stop_decision->set_reason_code(StopReasonCode::STOP_REASON_DESTINATION);
84 stop_decision->set_distance_s(-config_.stop_distance());
85 stop_decision->set_stop_heading(stop_point.heading());
86 stop_decision->mutable_stop_point()->set_x(stop_point.x());
87 stop_decision->mutable_stop_point()->set_y(stop_point.y());
88 stop_decision->mutable_stop_point()->set_z(0.0);
89
90 auto* path_decision = reference_line_info->path_decision();
91 path_decision->AddLongitudinalDecision(Getname(), stop_wall->Id(), stop);
92
93 return Status::OK();
94}
95
96} // namespace planning
97} // 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
const std::string & Id() const
Frame holds all data for one planning cycle.
Definition frame.h:62
const Obstacle * CreateStopObstacle(ReferenceLineInfo *const reference_line_info, const std::string &obstacle_id, const double obstacle_s, double stop_wall_width=4.0)
: create static virtual object with lane width, mainly used for virtual stop wall
Definition frame.cc:214
This is the class that associates an Obstacle with its path properties.
Definition obstacle.h:62
const std::string & Id() const
Definition obstacle.h:75
bool AddLongitudinalDecision(const std::string &tag, const std::string &object_id, const ObjectDecisionType &decision)
bool Init(const std::string &name, const std::shared_ptr< DependencyInjector > &injector) override
common::Status ApplyRule(Frame *const frame, ReferenceLineInfo *const reference_line_info)
ReferenceLineInfo holds all data for one reference line.
const hdmap::RouteSegments & Lanes() const
const ReferenceLine & reference_line() const
Obstacle * AddObstacle(const Obstacle *obstacle)
const SLBoundary & AdcSlBoundary() const
virtual bool Init(const std::string &name, const std::shared_ptr< DependencyInjector > &injector)
Planning module main class.
#define ADEBUG
Definition log.h:41
class register implement
Definition arena_queue.h:37