Apollo  6.0
Open source self driving car software
track_data.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 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 #pragma once
17 
18 #include <deque>
19 #include <map>
20 #include <memory>
21 #include <utility>
22 
24 
25 namespace apollo {
26 namespace perception {
27 namespace lidar {
28 
29 enum class MotionState {
30  STATIC = 0,
31  SKEPTICAL_MOVE = 1,
32  TRUSTED_MOVE = 2,
33 };
34 
35 class TrackData {
36  public:
37  TrackData();
38  TrackData(TrackedObjectPtr obj, int track_id);
39  virtual ~TrackData();
40  std::pair<double, TrackedObjectPtr> GetLatestObject() {
41  if (history_objects_.size() != 0) {
42  return *history_objects_.rbegin();
43  }
44  return std::pair<double, TrackedObjectPtr>(0.0, TrackedObjectPtr(nullptr));
45  }
46  std::pair<double, TrackedObjectConstPtr> GetLatestObject() const {
47  if (history_objects_.size() != 0) {
48  return *history_objects_.rbegin();
49  }
50  return std::pair<double, TrackedObjectPtr>(0.0, TrackedObjectPtr(nullptr));
51  }
52  std::pair<double, TrackedObjectPtr> GetOldestObject() {
53  if (history_objects_.size() != 0) {
54  return *history_objects_.begin();
55  }
56  return std::pair<double, TrackedObjectPtr>(0.0, TrackedObjectPtr(nullptr));
57  }
58 
59  std::pair<double, TrackedObjectConstPtr> GetOldestObject() const {
60  if (history_objects_.size() != 0) {
61  return *history_objects_.begin();
62  }
63  return std::pair<double, TrackedObjectPtr>(0.0, TrackedObjectPtr(nullptr));
64  }
65 
66  // when idx > 0, get object from oldest
67  // when idx <= 0, get object from latest
68  // when abs_idx is large than history size, return farest object close to idx
69  std::pair<double, TrackedObjectPtr> GetHistoryObject(int idx);
70 
71  std::pair<double, TrackedObjectConstPtr> GetHistoryObject(int idx) const;
72 
73  virtual void Reset();
74 
75  virtual void Reset(TrackedObjectPtr obj, double time, int track_id);
76 
77  virtual void PushTrackedObjectToTrack(TrackedObjectPtr obj, double time);
78 
79  int track_id_ = -1;
80  int age_ = 0;
81  int consecutive_invisible_count_ = 0;
82  int total_visible_count_ = 0;
83  static const int kMaxHistorySize;
84  std::map<double, TrackedObjectPtr> history_objects_;
85  int max_history_size_ = 40;
86  // motion state related
87  // used for judge object is static or not
89  size_t continuous_motion_frames_ = 0;
90  size_t continuous_static_frames_ = 0;
91  // if currenet frame is evaluated as in motion (implemented in post_process),
92  // then the next pub_remain_frames should not be set as static,
93  // in order to improve sensibility from static to motion
94  size_t pub_remain_frames_ = 0;
95  // if currenet frame is evaluated as static (implemented in post_process),
96  // this flag is used to determine check velocity consistency or not,
97  // in order to keep velocity consistency when measurement is unstable
98  bool should_check_velocity_consistency_ = true;
99  // the next two deques are used to calculate motion score
100  std::deque<double> history_norm_variance_;
101  std::deque<double> history_theta_variance_;
102 };
103 
104 typedef std::shared_ptr<TrackData> TrackDataPtr;
105 typedef std::shared_ptr<const TrackData> TrackDataConstPtr;
106 
107 } // namespace lidar
108 } // namespace perception
109 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::deque< double > history_norm_variance_
Definition: track_data.h:100
std::pair< double, TrackedObjectConstPtr > GetLatestObject() const
Definition: track_data.h:46
std::pair< double, TrackedObjectConstPtr > GetOldestObject() const
Definition: track_data.h:59
std::deque< double > history_theta_variance_
Definition: track_data.h:101
std::pair< double, TrackedObjectPtr > GetLatestObject()
Definition: track_data.h:40
std::shared_ptr< const TrackData > TrackDataConstPtr
Definition: track_data.h:105
MotionState
Definition: track_data.h:29
static const int kMaxHistorySize
Definition: track_data.h:83
std::shared_ptr< TrackData > TrackDataPtr
Definition: track_data.h:104
std::pair< double, TrackedObjectPtr > GetOldestObject()
Definition: track_data.h:52
Definition: track_data.h:35
std::shared_ptr< TrackedObject > TrackedObjectPtr
Definition: tracked_object.h:156
std::map< double, TrackedObjectPtr > history_objects_
Definition: track_data.h:84