Apollo  6.0
Open source self driving car software
obstacle.h
Go to the documentation of this file.
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 #pragma once
23 
24 #include <deque>
25 #include <list>
26 #include <memory>
27 #include <string>
28 #include <unordered_set>
29 #include <vector>
30 
37 #include "modules/prediction/proto/feature.pb.h"
38 #include "modules/prediction/proto/prediction_conf.pb.h"
39 #include "modules/prediction/proto/prediction_obstacle.pb.h"
40 
45 namespace apollo {
46 namespace prediction {
47 
52 class Obstacle {
53  public:
57  static std::unique_ptr<Obstacle> Create(
58  const perception::PerceptionObstacle& perception_obstacle,
59  const double timestamp, const int prediction_id,
60  ObstacleClusters* clusters_ptr);
61 
62  static std::unique_ptr<Obstacle> Create(const Feature& feature,
63  ObstacleClusters* clusters_ptr);
64 
65  Obstacle() = default;
66 
70  virtual ~Obstacle() = default;
71 
72  void SetJunctionAnalyzer(JunctionAnalyzer* junction_analyzer) {
73  junction_analyzer_ = junction_analyzer;
74  }
75 
81  bool Insert(const perception::PerceptionObstacle& perception_obstacle,
82  const double timestamp, const int prediction_id);
83 
88  bool InsertFeature(const Feature& feature);
89 
90  void ClearOldInformation();
91 
92  void TrimHistory(const size_t remain_size);
93 
98  perception::PerceptionObstacle::Type type() const;
99 
100  bool IsPedestrian() const;
101 
106  int id() const;
107 
112  double timestamp() const;
113 
114  bool ReceivedOlderMessage(const double timestamp) const;
115 
121  const Feature& feature(const size_t i) const;
122 
128  Feature* mutable_feature(const size_t i);
129 
134  const Feature& latest_feature() const;
135 
140  const Feature& earliest_feature() const;
141 
146  Feature* mutable_latest_feature();
147 
151  void SetNearbyObstacles();
152 
157  size_t history_size() const;
158 
163  bool IsStill();
164 
169  bool IsSlow();
170 
175  bool IsOnLane() const;
176 
181  bool ToIgnore();
182 
187  bool IsNearJunction();
188 
194  bool IsInJunction(const std::string& junction_id) const;
195 
200  bool IsCloseToJunctionExit() const;
201 
206  bool HasJunctionFeatureWithExits() const;
207 
211  void BuildJunctionFeature();
212 
216  void BuildLaneGraph();
217 
223 
227  void SetCaution();
228 
229  bool IsCaution() const;
230 
231  void SetEvaluatorType(const ObstacleConf::EvaluatorType& evaluator_type);
232 
233  void SetPredictorType(const ObstacleConf::PredictorType& predictor_type);
234 
235  const ObstacleConf& obstacle_conf() { return obstacle_conf_; }
236 
237  PredictionObstacle GeneratePredictionObstacle();
238 
239  private:
240  void SetStatus(const perception::PerceptionObstacle& perception_obstacle,
241  double timestamp, Feature* feature);
242 
243  bool SetId(const perception::PerceptionObstacle& perception_obstacle,
244  Feature* feature, const int prediction_id = -1);
245 
246  void SetType(const perception::PerceptionObstacle& perception_obstacle,
247  Feature* feature);
248 
249  void SetIsNearJunction(
250  const perception::PerceptionObstacle& perception_obstacle,
251  Feature* feature);
252 
253  void SetTimestamp(const perception::PerceptionObstacle& perception_obstacle,
254  const double timestamp, Feature* feature);
255 
256  void SetPolygonPoints(
257  const perception::PerceptionObstacle& perception_obstacle,
258  Feature* feature);
259 
260  void SetPosition(const perception::PerceptionObstacle& perception_obstacle,
261  Feature* feature);
262 
263  void SetVelocity(const perception::PerceptionObstacle& perception_obstacle,
264  Feature* feature);
265 
266  void AdjustHeadingByLane(Feature* feature);
267 
268  void UpdateVelocity(const double theta, double* velocity_x,
269  double* velocity_y, double* velocity_heading,
270  double* speed);
271 
272  void SetAcceleration(Feature* feature);
273 
274  void SetTheta(const perception::PerceptionObstacle& perception_obstacle,
275  Feature* feature);
276 
277  void SetLengthWidthHeight(
278  const perception::PerceptionObstacle& perception_obstacle,
279  Feature* feature);
280 
281  void UpdateLaneBelief(Feature* feature);
282 
283  void SetCurrentLanes(Feature* feature);
284 
285  void SetNearbyLanes(Feature* feature);
286 
287  void SetSurroundingLaneIds(Feature* feature, const double radius);
288 
289  void SetLaneSequenceStopSign(LaneSequence* lane_sequence_ptr);
290 
294  void SetLanePoints(Feature* feature);
295  void SetLanePoints(const Feature* feature, const double lane_point_spacing,
296  const uint64_t max_num_lane_point,
297  const bool is_bidirection, LaneGraph* const lane_graph);
298 
301  void SetLaneSequencePath(LaneGraph* const lane_graph);
302 
303  void SetMotionStatus();
304 
305  void SetMotionStatusBySpeed();
306 
307  void InsertFeatureToHistory(const Feature& feature);
308 
309  void SetJunctionFeatureWithEnterLane(const std::string& enter_lane_id,
310  Feature* const feature_ptr);
311 
312  void SetJunctionFeatureWithoutEnterLane(Feature* const feature_ptr);
313 
314  void DiscardOutdatedHistory();
315 
316  void GetNeighborLaneSegments(
317  std::shared_ptr<const apollo::hdmap::LaneInfo> center_lane_info,
318  bool is_left, int recursion_depth,
319  std::list<std::string>* const lane_ids_ordered,
320  std::unordered_set<std::string>* const existing_lane_ids);
321 
322  bool HasJunctionExitLane(
323  const LaneSequence& lane_sequence,
324  const std::unordered_set<std::string>& exit_lane_id_set);
325 
326  void SetClusters(ObstacleClusters* clusters_ptr);
327 
328  private:
329  int id_ = FLAGS_ego_vehicle_id;
330 
331  perception::PerceptionObstacle::Type type_ =
333 
334  std::deque<Feature> feature_history_;
335 
336  std::vector<std::shared_ptr<const hdmap::LaneInfo>> current_lanes_;
337 
338  ObstacleConf obstacle_conf_;
339 
340  ObstacleClusters* clusters_ptr_ = nullptr;
341  JunctionAnalyzer* junction_analyzer_ = nullptr;
342 };
343 
344 } // namespace prediction
345 } // namespace apollo
bool IsOnLane() const
Check if the obstacle is on any lane.
bool ReceivedOlderMessage(const double timestamp) const
Prediction obstacle.
Definition: obstacle.h:52
int id() const
Get the obstacle&#39;s ID.
Feature * mutable_latest_feature()
Get a pointer to the latest feature.
const ObstacleConf & obstacle_conf()
Definition: obstacle.h:235
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool IsInJunction(const std::string &junction_id) const
Check if the obstacle is a junction.
bool IsSlow()
Check if the obstacle is slow.
size_t history_size() const
Get the number of historical features.
void SetPredictorType(const ObstacleConf::PredictorType &predictor_type)
PredictionObstacle GeneratePredictionObstacle()
virtual ~Obstacle()=default
Destructor.
bool InsertFeature(const Feature &feature)
Insert a feature proto message.
void SetNearbyObstacles()
Set nearby obstacles.
Feature * mutable_feature(const size_t i)
Get a pointer to the ith feature from latest to earliest.
const Feature & earliest_feature() const
Get the earliest feature.
double timestamp() const
Get the obstacle&#39;s timestamp.
const Feature & feature(const size_t i) const
Get the ith feature from latest to earliest.
Definition: obstacle_clusters.h:33
void TrimHistory(const size_t remain_size)
Defines the DigitalFilter class.
void BuildLaneGraph()
Build obstacle&#39;s lane graph.
void SetEvaluatorType(const ObstacleConf::EvaluatorType &evaluator_type)
bool IsNearJunction()
Check if the obstacle is near a junction.
void BuildLaneGraphFromLeftToRight()
Build obstacle&#39;s lane graph with lanes being ordered. This would be useful for lane-scanning algorith...
Definition: junction_analyzer.h:30
bool Insert(const perception::PerceptionObstacle &perception_obstacle, const double timestamp, const int prediction_id)
Insert a perception obstacle with its timestamp.
bool IsStill()
Check if the obstacle is still.
void SetCaution()
Set the obstacle as caution level.
Defines the templated KalmanFilter class.
bool IsCloseToJunctionExit() const
Check if the obstacle is close to a junction exit.
perception::PerceptionObstacle::Type type() const
Get the type of perception obstacle&#39;s type.
void BuildJunctionFeature()
Build junction feature.
bool ToIgnore()
Check if the obstacle can be ignored.
static std::unique_ptr< Obstacle > Create(const perception::PerceptionObstacle &perception_obstacle, const double timestamp, const int prediction_id, ObstacleClusters *clusters_ptr)
Constructor.
void SetJunctionAnalyzer(JunctionAnalyzer *junction_analyzer)
Definition: obstacle.h:72
bool HasJunctionFeatureWithExits() const
Check if the obstacle has junction feature.
const Feature & latest_feature() const
Get the latest feature.