Apollo 11.0
自动驾驶开放平台
path_decision.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 "modules/common_msgs/perception_msgs/perception_obstacle.pb.h"
24
27
28namespace apollo {
29namespace planning {
30
32 return obstacles_.Add(obstacle.Id(), obstacle);
33}
34
35const IndexedObstacles &PathDecision::obstacles() const { return obstacles_; }
36
37Obstacle *PathDecision::Find(const std::string &object_id) {
38 return obstacles_.Find(object_id);
39}
40
41const Obstacle *PathDecision::Find(const std::string &object_id) const {
42 return obstacles_.Find(object_id);
43}
44
46 const std::string &perception_obstacle_id) const {
47 for (const auto *obstacle : obstacles_.Items()) {
48 if (std::to_string(obstacle->Perception().id()) == perception_obstacle_id) {
49 return &(obstacle->Perception());
50 }
51 }
52
53 return nullptr;
54}
55
56void PathDecision::SetSTBoundary(const std::string &id,
57 const STBoundary &boundary) {
58 auto *obstacle = obstacles_.Find(id);
59
60 if (!obstacle) {
61 AERROR << "Failed to find obstacle : " << id;
62 return;
63 } else {
64 obstacle->set_path_st_boundary(boundary);
65 }
66}
67
68bool PathDecision::AddLateralDecision(const std::string &tag,
69 const std::string &object_id,
70 const ObjectDecisionType &decision) {
71 auto *obstacle = obstacles_.Find(object_id);
72 if (!obstacle) {
73 AERROR << "failed to find obstacle";
74 return false;
75 }
76 obstacle->AddLateralDecision(tag, decision);
77 return true;
78}
79
81 for (const auto *obstacle : obstacles_.Items()) {
82 auto *obstacle_ptr = obstacles_.Find(obstacle->Id());
83 obstacle_ptr->EraseStBoundary();
84 }
85}
86
87bool PathDecision::AddLongitudinalDecision(const std::string &tag,
88 const std::string &object_id,
89 const ObjectDecisionType &decision) {
90 auto *obstacle = obstacles_.Find(object_id);
91 if (!obstacle) {
92 AERROR << "failed to find obstacle";
93 return false;
94 }
95 obstacle->AddLongitudinalDecision(tag, decision);
96 return true;
97}
98
99bool PathDecision::MergeWithMainStop(const ObjectStop &obj_stop,
100 const std::string &obj_id,
101 const ReferenceLine &reference_line,
102 const SLBoundary &adc_sl_boundary) {
103 common::PointENU stop_point = obj_stop.stop_point();
104 common::SLPoint stop_line_sl;
105 reference_line.XYToSL(stop_point, &stop_line_sl);
106
107 double stop_line_s = stop_line_sl.s();
108 if (stop_line_s < 0.0 || stop_line_s > reference_line.Length()) {
109 AERROR << "Ignore object:" << obj_id << " fence route_s[" << stop_line_s
110 << "] not in range[0, " << reference_line.Length() << "]";
111 return false;
112 }
113
114 // check stop_line_s vs adc_s, ignore if it is further way than main stop
115 const auto &vehicle_config = common::VehicleConfigHelper::GetConfig();
116 stop_line_s = std::fmax(
117 stop_line_s, adc_sl_boundary.end_s() -
118 vehicle_config.vehicle_param().front_edge_to_center());
119
120 if (stop_line_s >= stop_reference_line_s_) {
121 ADEBUG << "stop point is farther than current main stop point.";
122 return false;
123 }
124
125 main_stop_.Clear();
126 main_stop_.set_reason_code(obj_stop.reason_code());
127 main_stop_.set_reason("stop by " + obj_id);
128 main_stop_.mutable_stop_point()->set_x(obj_stop.stop_point().x());
129 main_stop_.mutable_stop_point()->set_y(obj_stop.stop_point().y());
130 main_stop_.set_stop_heading(obj_stop.stop_heading());
131 stop_reference_line_s_ = stop_line_s;
132
133 ADEBUG << " main stop obstacle id:" << obj_id
134 << " stop_line_s:" << stop_line_s << " stop_point: ("
135 << obj_stop.stop_point().x() << obj_stop.stop_point().y()
136 << " ) stop_heading: " << obj_stop.stop_heading();
137 return true;
138}
139
140} // namespace planning
141} // namespace apollo
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
T * Find(const I id)
Find object by id in the container
T * Add(const I id, const T &object)
copy object into the container.
const std::vector< const T * > & Items() const
List all the items in the container.
This is the class that associates an Obstacle with its path properties.
Definition obstacle.h:62
void AddLongitudinalDecision(const std::string &decider_tag, const ObjectDecisionType &decision)
Definition obstacle.cc:646
void AddLateralDecision(const std::string &decider_tag, const ObjectDecisionType &decision)
Definition obstacle.cc:661
const std::string & Id() const
Definition obstacle.h:75
void set_path_st_boundary(const STBoundary &boundary)
Definition obstacle.cc:698
void SetSTBoundary(const std::string &id, const STBoundary &boundary)
const Obstacle * Find(const std::string &object_id) const
const IndexedList< std::string, Obstacle > & obstacles() const
bool MergeWithMainStop(const ObjectStop &obj_stop, const std::string &obj_id, const ReferenceLine &ref_line, const SLBoundary &adc_sl_boundary)
bool AddLateralDecision(const std::string &tag, const std::string &object_id, const ObjectDecisionType &decision)
bool AddLongitudinalDecision(const std::string &tag, const std::string &object_id, const ObjectDecisionType &decision)
Obstacle * AddObstacle(const Obstacle &obstacle)
const perception::PerceptionObstacle * FindPerceptionObstacle(const std::string &perception_obstacle_id) 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.
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
Some util functions.
class register implement
Definition arena_queue.h:37