Apollo 10.0
自动驾驶开放平台
apollo::prediction::ObstacleClusters类 参考

#include <obstacle_clusters.h>

apollo::prediction::ObstacleClusters 的协作图:

Public 成员函数

 ObstacleClusters ()=default
 Constructor
 
void Init ()
 Remove all lane graphs
 
LaneGraph GetLaneGraph (const double start_s, const double length, const bool consider_lane_split, std::shared_ptr< const apollo::hdmap::LaneInfo > lane_info_ptr)
 Obtain a lane graph given a lane info and s
 
LaneGraph GetLaneGraphWithoutMemorizing (const double start_s, const double length, const bool is_on_lane, std::shared_ptr< const apollo::hdmap::LaneInfo > lane_info_ptr)
 Obtain a lane graph given a lane info and s, but don't memorize it.
 
bool ForwardNearbyObstacle (const LaneSequence &lane_sequence, const double s, LaneObstacle *const lane_obstacle)
 Get the nearest obstacle on lane sequence at s
 
void AddObstacle (const int obstacle_id, const std::string &lane_id, const double lane_s, const double lane_l)
 Add an obstacle into clusters
 
void ClearObstacle ()
 
void SortObstacles ()
 Sort lane obstacles by lane s
 
bool ForwardNearbyObstacle (const LaneSequence &lane_sequence, const int obstacle_id, const double obstacle_s, const double obstacle_l, NearbyObstacle *const nearby_obstacle_ptr)
 Get the forward nearest obstacle on lane sequence at s
 
bool BackwardNearbyObstacle (const LaneSequence &lane_sequence, const int obstacle_id, const double obstacle_s, const double obstacle_l, NearbyObstacle *const nearby_obstacle_ptr)
 Get the backward nearest obstacle on lane sequence at s
 
StopSign QueryStopSignByLaneId (const std::string &lane_id)
 Query stop sign by lane ID
 
std::unordered_map< std::string, std::vector< LaneObstacle > > & GetLaneObstacles ()
 

详细描述

在文件 obstacle_clusters.h33 行定义.

构造及析构函数说明

◆ ObstacleClusters()

apollo::prediction::ObstacleClusters::ObstacleClusters ( )
default

Constructor

成员函数说明

◆ AddObstacle()

void apollo::prediction::ObstacleClusters::AddObstacle ( const int  obstacle_id,
const std::string &  lane_id,
const double  lane_s,
const double  lane_l 
)

Add an obstacle into clusters

参数
obstacleid
laneid
lanes
lanel

在文件 obstacle_clusters.cc48 行定义.

50 {
51 LaneObstacle lane_obstacle;
52 lane_obstacle.set_obstacle_id(obstacle_id);
53 lane_obstacle.set_lane_id(lane_id);
54 lane_obstacle.set_lane_s(lane_s);
55 lane_obstacle.set_lane_l(lane_l);
56 lane_obstacles_[lane_id].push_back(std::move(lane_obstacle));
57}

◆ BackwardNearbyObstacle()

bool apollo::prediction::ObstacleClusters::BackwardNearbyObstacle ( const LaneSequence lane_sequence,
const int  obstacle_id,
const double  obstacle_s,
const double  obstacle_l,
NearbyObstacle *const  nearby_obstacle_ptr 
)

Get the backward nearest obstacle on lane sequence at s

参数
Lanesequence
soffset in the first lane of the lane sequence
theforward obstacle on lane
返回
If the backward obstacle is found

在文件 obstacle_clusters.cc103 行定义.

106 {
107 if (lane_sequence.lane_segment().empty()) {
108 AERROR << "Empty lane sequence found.";
109 return false;
110 }
111 const LaneSegment& lane_segment = lane_sequence.lane_segment(0);
112 std::string lane_id = lane_segment.lane_id();
113
114 // Search current lane
115 if (lane_obstacles_.find(lane_id) != lane_obstacles_.end() &&
116 !lane_obstacles_[lane_id].empty()) {
117 for (int i = static_cast<int>(lane_obstacles_[lane_id].size()) - 1; i >= 0;
118 --i) {
119 const LaneObstacle& lane_obstacle = lane_obstacles_[lane_id][i];
120 if (lane_obstacle.obstacle_id() == obstacle_id) {
121 continue;
122 }
123 double relative_s = lane_obstacle.lane_s() - obstacle_s;
124 double relative_l = lane_obstacle.lane_l() - obstacle_l;
125 if (relative_s < 0.0) {
126 nearby_obstacle_ptr->set_id(lane_obstacle.obstacle_id());
127 nearby_obstacle_ptr->set_s(relative_s);
128 nearby_obstacle_ptr->set_l(relative_l);
129 return true;
130 }
131 }
132 }
133
134 // Search backward lanes
135 std::shared_ptr<const LaneInfo> lane_info_ptr =
137 bool found_one_behind = false;
138 double relative_s = -std::numeric_limits<double>::infinity();
139 double relative_l = 0.0;
140 for (const auto& predecessor_lane_id :
141 lane_info_ptr->lane().predecessor_id()) {
142 std::string lane_id = predecessor_lane_id.id();
143 if (lane_obstacles_.find(lane_id) == lane_obstacles_.end() ||
144 lane_obstacles_[lane_id].empty()) {
145 continue;
146 }
147 std::shared_ptr<const LaneInfo> pred_lane_info_ptr =
148 PredictionMap::LaneById(predecessor_lane_id.id());
149 const LaneObstacle& backward_obs = lane_obstacles_[lane_id].back();
150 double delta_s = backward_obs.lane_s() -
151 (obstacle_s + pred_lane_info_ptr->total_length());
152 found_one_behind = true;
153 if (delta_s > relative_s) {
154 relative_s = delta_s;
155 relative_l = backward_obs.lane_l() - obstacle_l;
156 nearby_obstacle_ptr->set_id(backward_obs.obstacle_id());
157 nearby_obstacle_ptr->set_s(relative_s);
158 nearby_obstacle_ptr->set_l(relative_l);
159 }
160 }
161
162 return found_one_behind;
163}
static std::shared_ptr< const hdmap::LaneInfo > LaneById(const std::string &id)
Get a shared pointer to a lane by lane ID.
#define AERROR
Definition log.h:44

◆ ClearObstacle()

void apollo::prediction::ObstacleClusters::ClearObstacle ( )

在文件 obstacle_clusters.cc59 行定义.

59 {
60 lane_obstacles_.clear();
61}

◆ ForwardNearbyObstacle() [1/2]

bool apollo::prediction::ObstacleClusters::ForwardNearbyObstacle ( const LaneSequence lane_sequence,
const double  s,
LaneObstacle *const  lane_obstacle 
)

Get the nearest obstacle on lane sequence at s

参数
Lanesequence
soffset in the first lane of the lane sequence
theforward obstacle on lane
返回
If the forward obstacle is found

◆ ForwardNearbyObstacle() [2/2]

bool apollo::prediction::ObstacleClusters::ForwardNearbyObstacle ( const LaneSequence lane_sequence,
const int  obstacle_id,
const double  obstacle_s,
const double  obstacle_l,
NearbyObstacle *const  nearby_obstacle_ptr 
)

Get the forward nearest obstacle on lane sequence at s

参数
Lanesequence
soffset in the first lane of the lane sequence
theforward obstacle on lane
返回
If the forward obstacle is found

在文件 obstacle_clusters.cc73 行定义.

76 {
77 double accumulated_s = 0.0;
78 for (const LaneSegment& lane_segment : lane_sequence.lane_segment()) {
79 std::string lane_id = lane_segment.lane_id();
80 double lane_length = lane_segment.total_length();
81 if (lane_obstacles_.find(lane_id) == lane_obstacles_.end() ||
82 lane_obstacles_[lane_id].empty()) {
83 accumulated_s += lane_length;
84 continue;
85 }
86 for (const LaneObstacle& lane_obstacle : lane_obstacles_[lane_id]) {
87 if (lane_obstacle.obstacle_id() == obstacle_id) {
88 continue;
89 }
90 double relative_s = accumulated_s + lane_obstacle.lane_s() - obstacle_s;
91 double relative_l = lane_obstacle.lane_l() - obstacle_l;
92 if (relative_s > 0.0) {
93 nearby_obstacle_ptr->set_id(lane_obstacle.obstacle_id());
94 nearby_obstacle_ptr->set_s(relative_s);
95 nearby_obstacle_ptr->set_l(relative_l);
96 return true;
97 }
98 }
99 }
100 return false;
101}

◆ GetLaneGraph()

LaneGraph apollo::prediction::ObstacleClusters::GetLaneGraph ( const double  start_s,
const double  length,
const bool  consider_lane_split,
std::shared_ptr< const apollo::hdmap::LaneInfo lane_info_ptr 
)

Obtain a lane graph given a lane info and s

参数
lanestart s
lanetotal length
ifconsider lane split ahead
laneinfo
返回
a corresponding lane graph

在文件 obstacle_clusters.cc29 行定义.

31 {
32 std::string lane_id = lane_info_ptr->id().id();
33 RoadGraph road_graph(start_s, length, consider_lane_split, lane_info_ptr);
34 LaneGraph lane_graph;
35 road_graph.BuildLaneGraph(&lane_graph);
36 return lane_graph;
37}

◆ GetLaneGraphWithoutMemorizing()

LaneGraph apollo::prediction::ObstacleClusters::GetLaneGraphWithoutMemorizing ( const double  start_s,
const double  length,
const bool  is_on_lane,
std::shared_ptr< const apollo::hdmap::LaneInfo lane_info_ptr 
)

Obtain a lane graph given a lane info and s, but don't memorize it.

参数
lanestart s
lanetotal length
ifthe obstacle is on lane
laneinfo
返回
a corresponding lane graph

在文件 obstacle_clusters.cc39 行定义.

41 {
42 RoadGraph road_graph(start_s, length, true, lane_info_ptr);
43 LaneGraph lane_graph;
44 road_graph.BuildLaneGraphBidirection(&lane_graph);
45 return lane_graph;
46}

◆ GetLaneObstacles()

std::unordered_map< std::string, std::vector< LaneObstacle > > & apollo::prediction::ObstacleClusters::GetLaneObstacles ( )
inline

在文件 obstacle_clusters.h128 行定义.

128 {
129 return lane_obstacles_;
130 }

◆ Init()

void apollo::prediction::ObstacleClusters::Init ( )

Remove all lane graphs

◆ QueryStopSignByLaneId()

StopSign apollo::prediction::ObstacleClusters::QueryStopSignByLaneId ( const std::string &  lane_id)

Query stop sign by lane ID

参数
laneID
返回
the stop sign

在文件 obstacle_clusters.cc165 行定义.

165 {
166 StopSign stop_sign;
167 // Find the stop_sign by lane_id in the hashtable
168 if (lane_id_stop_sign_map_.find(lane_id) != lane_id_stop_sign_map_.end()) {
169 return lane_id_stop_sign_map_[lane_id];
170 }
171 std::shared_ptr<const LaneInfo> lane_info_ptr =
173 CHECK_NOTNULL(lane_info_ptr);
174 for (const auto& overlap_id : lane_info_ptr->lane().overlap_id()) {
175 auto overlap_info_ptr = PredictionMap::OverlapById(overlap_id.id());
176 if (overlap_info_ptr == nullptr) {
177 continue;
178 }
179 for (const auto& object : overlap_info_ptr->overlap().object()) {
180 // find the overlap with stop_sign
181 if (object.has_stop_sign_overlap_info()) {
182 for (const auto& obj : overlap_info_ptr->overlap().object()) {
183 // find the obj of in the overlap
184 if (obj.has_lane_overlap_info()) {
185 if (!stop_sign.has_lane_s() ||
186 stop_sign.lane_s() > obj.lane_overlap_info().start_s()) {
187 stop_sign.set_stop_sign_id(object.id().id());
188 stop_sign.set_lane_id(lane_id);
189 stop_sign.set_lane_s(obj.lane_overlap_info().start_s());
190 lane_id_stop_sign_map_[lane_id] = stop_sign;
191 }
192 }
193 }
194 }
195 }
196 }
197 return lane_id_stop_sign_map_[lane_id];
198}
static std::shared_ptr< const hdmap::OverlapInfo > OverlapById(const std::string &id)
Get a shared pointer to an overlap by overlap ID.

◆ SortObstacles()

void apollo::prediction::ObstacleClusters::SortObstacles ( )

Sort lane obstacles by lane s

在文件 obstacle_clusters.cc63 行定义.

63 {
64 for (auto iter = lane_obstacles_.begin(); iter != lane_obstacles_.end();
65 ++iter) {
66 std::sort(iter->second.begin(), iter->second.end(),
67 [](const LaneObstacle& obs0, const LaneObstacle& obs1) -> bool {
68 return obs0.lane_s() < obs1.lane_s();
69 });
70 }
71}

该类的文档由以下文件生成: