Apollo  6.0
Open source self driving car software
v2x_object.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2020 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 
17 #pragma once
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include <Eigen/Core>
24 
25 #include "absl/strings/str_cat.h"
26 
30 
31 namespace apollo {
32 namespace v2x {
33 namespace ft {
34 namespace base {
35 
41 
42 enum class V2xType {
43  UNKNOWN = 0,
44  ZOMBIES_CAR = 1,
45  BLIND_ZONE = 2,
46  HOST_VEHICLE = 13,
47 };
48 
49 enum class MessageType {
51  ROADSIDE = 0,
52  VEHICLE = 1,
53 };
54 
55 // Value and Variance
56 template <typename Val, typename Var>
57 class Info {
58  public:
59  Info() = default;
60  Info(Val val, Var var) {
61  value_ = val;
62  variance_ = var;
63  }
64  ~Info() = default;
65  // Info(const Info &) = delete;
66  Info(const Info &rhs) {
67  value_ = rhs.value_;
68  variance_ = rhs.variance_;
69  }
70  // Info &operator=(const Info &) = delete;
71  Info &operator=(const Info &rhs) {
72  value_ = rhs.value_;
73  variance_ = rhs.variance_;
74  return *this;
75  }
76 
77  void Set(Val value, Var variance) {
78  value_ = value;
79  variance_ = variance;
80  }
81  Val Value() const { return value_; }
82 
83  Var Variance() const { return variance_; }
84 
85  protected:
86  Val value_ = {};
87  Var variance_ = {};
88 };
89 
90 class Info3f : public Info<Eigen::Vector3f, Eigen::Matrix3f> {
91  public:
92  Info3f() {
93  value_.setZero();
94  variance_.setZero();
95  }
96  ~Info3f() = default;
97 
98  float x() const { return value_(0); }
99 
100  float y() const { return value_(1); }
101 
102  float z() const { return value_(2); }
103 
104  float length() const { return value_(0); }
105 
106  float width() const { return value_(1); }
107 
108  float height() const { return value_(2); }
109 };
110 
111 class Info3d : public Info<Eigen::Vector3d, Eigen::Matrix3d> {
112  public:
113  double x() const { return value_(0); }
114 
115  double y() const { return value_(1); }
116 
117  double z() const { return value_(2); }
118 
119  double length() const { return value_(0); }
120 
121  double width() const { return value_(1); }
122 
123  double height() const { return value_(2); }
124 };
125 
126 struct alignas(16) Object {
134  Object() : is_temporary_lost(false, 0.0) {}
135  ~Object() = default;
136  Object(const Object &) = default;
137  Object &operator=(const Object &) = default;
138  bool operator<(const Object &rhs) const { return timestamp < rhs.timestamp; }
139  bool operator>(const Object &rhs) const { return timestamp > rhs.timestamp; }
140  bool operator==(const Object &rhs) const {
141  return timestamp == rhs.timestamp;
142  }
143  std::string ToString() const;
144  void Reset();
145  // camera, lidar, radar and others
147  // ROADSIDE
149  // @brief sensor-specific object supplements, optional
152  // message timestamp
153  double timestamp = 0.0;
154  // original sensor timestamp
155  double sensor_timestamp = 0.0;
156  // @brief age of the tracked object, required
157  double tracking_time = 0.0;
158  // @brief timestamp of latest measurement, required
159  double latest_tracked_time = 0.0;
160  std::string frame_id = "";
161  // @brief track id, required
162  int track_id = -1;
163  // @breif object id per frame, required
164  int global_id = -1;
165  // @brief center position of the boundingbox (x, y, z), required
167  // @brief anchor point, required
169  // 0-2Pi from east
170  Infod theta;
171  // @brief theta variance, required
173  // @brief main direction of the object, required
175  /* @brief size = [length, width, height] of boundingbox
176  length is the size of the main direction, required
177  */
179  // @brief convex hull of the object, required
180  // Point3f polygon;
181  // @brief object type, required
183 
185  // @brief type variance, required
186  double type_variance = 1.0;
187  // @brief probability for each type, required
188  std::vector<float> type_probs;
189  // @brief object sub-type, optional
191  // @brief probability for each sub-type, optional
192  std::vector<float> sub_type_probs;
193 
194  std::vector<std::vector<Info3d>> tentacles;
195 
196  std::vector<Info3d> polygon;
197 
198  // tracking information
199  // @brief the variance of tracked
201  // @brief velocity of the object, required
203  // @brief acceleration of the object, required
205  // @brief motion state of the tracked object, required
207 
209  std::string DebugString() const {
210  return absl::StrCat("id: ", track_id, ", ", //
211  "time: ", timestamp, ", ", //
212  "sensor type: ", sensor_type, ", ", //
213  "x: ", position.x(), ", ", //
214  "y: ", position.y(), ", ", //
215  "vx: ", velocity.x(), ", ", //
216  "vy: ", velocity.y(), ", ", //
217  "yaw: ", theta.Value());
218  }
219 };
220 
221 typedef std::shared_ptr<Object> ObjectPtr;
222 typedef std::shared_ptr<const Object> ObjectConstPtr;
223 
224 struct alignas(16) ObjectList {
225  ObjectList() = default;
226  ~ObjectList() = default;
227  ObjectList(const ObjectList &) = default;
228  ObjectList &operator=(const ObjectList &) = default;
229  bool operator<(const ObjectList &rhs) const {
230  return timestamp < rhs.timestamp;
231  }
232  bool operator>(const ObjectList &rhs) const {
233  return timestamp > rhs.timestamp;
234  }
235  bool operator==(const ObjectList &rhs) const {
236  return timestamp == rhs.timestamp;
237  }
238 
240  // @brief sensor-specific object supplements, optional
242  // LidarObjectSupplement lidar_supplement;
243  // RadarObjectSupplement radar_supplement;
245 
246  // message timestamp
247  double timestamp = 0.0;
248  // original sensor timestamp
249  double sensor_timestamp = 0.0;
250  // @brief age of the tracked object, require
251  std::string frame_id = "";
252 
253  std::vector<ObjectPtr> objects;
254 };
255 
256 typedef std::shared_ptr<ObjectList> ObjectListPtr;
257 typedef std::shared_ptr<const ObjectList> ObjectListConstPtr;
258 
259 } // namespace base
260 } // namespace ft
261 } // namespace v2x
262 } // namespace apollo
CameraObjectSupplement camera_supplement
Definition: v2x_object.h:241
double x() const
Definition: v2x_object.h:113
Eigen::Vector3f Point3f
Definition: v2x_object.h:133
Info3d anchor_point
Definition: v2x_object.h:168
std::vector< ObjectPtr > objects
Definition: v2x_object.h:253
Eigen::Vector2f Point2f
Definition: v2x_object.h:132
double timestamp
Definition: v2x_object.h:247
Val Value() const
Definition: v2x_object.h:81
Infod theta_variance
Definition: v2x_object.h:172
float length() const
Definition: v2x_object.h:104
Eigen::Vector3f Vector3f
Definition: base_map_fwd.h:29
float y() const
Definition: v2x_object.h:100
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: object_supplement.h:249
bool operator==(const ObjectList &rhs) const
Definition: v2x_object.h:235
CameraObjectSupplement camera_supplement
Definition: v2x_object.h:150
std::shared_ptr< ObjectList > ObjectListPtr
Definition: v2x_object.h:256
std::vector< std::vector< Info3d > > tentacles
Definition: v2x_object.h:194
V2xType
Definition: v2x_object.h:42
Info< bool, float > Infob
Definition: v2x_object.h:127
Info3f()
Definition: v2x_object.h:92
Object()
Definition: v2x_object.h:134
Definition: v2x_object.h:126
FusionObjectSupplement fusion_supplement
Definition: v2x_object.h:244
Var variance_
Definition: v2x_object.h:87
Definition: v2x_object.h:90
Info(const Info &rhs)
Definition: v2x_object.h:66
Definition: v2x_object.h:224
double width() const
Definition: v2x_object.h:121
float height() const
Definition: v2x_object.h:108
FusionObjectSupplement fusion_supplement
Definition: v2x_object.h:151
std::shared_ptr< const ObjectList > ObjectListConstPtr
Definition: v2x_object.h:257
Definition: v2x_object.h:57
Info3d velocity
Definition: v2x_object.h:202
Var Variance() const
Definition: v2x_object.h:83
double length() const
Definition: v2x_object.h:119
double y() const
Definition: v2x_object.h:115
Info3d acceleration
Definition: v2x_object.h:204
Infob is_temporary_lost
Definition: v2x_object.h:208
std::vector< float > sub_type_probs
Definition: v2x_object.h:192
Info3d direction
Definition: v2x_object.h:174
Info< Eigen::Vector2f, Eigen::Matrix2f > Info2f
Definition: v2x_object.h:130
SensorType sensor_type
Definition: v2x_object.h:239
Info< float, float > Infof
Definition: v2x_object.h:128
Infob is_stationary
Definition: v2x_object.h:206
float width() const
Definition: v2x_object.h:106
float z() const
Definition: v2x_object.h:102
bool operator<(const ObjectList &rhs) const
Definition: v2x_object.h:229
bool operator==(const Object &rhs) const
Definition: v2x_object.h:140
void Set(Val value, Var variance)
Definition: v2x_object.h:77
double height() const
Definition: v2x_object.h:123
Definition: v2x_object.h:111
double z() const
Definition: v2x_object.h:117
Info & operator=(const Info &rhs)
Definition: v2x_object.h:71
Val value_
Definition: v2x_object.h:86
std::shared_ptr< Object > ObjectPtr
Definition: v2x_object.h:221
std::vector< Info3d > polygon
Definition: v2x_object.h:196
std::string DebugString() const
Definition: v2x_object.h:209
Eigen::Vector2f Vector2f
Definition: base_map_fwd.h:30
Infod theta
Definition: v2x_object.h:170
std::vector< float > type_probs
Definition: v2x_object.h:188
apollo::cyber::base::std value
Definition: object_supplement.h:104
bool operator<(const Object &rhs) const
Definition: v2x_object.h:138
Info< Eigen::Vector2d, Eigen::Matrix2d > Info2d
Definition: v2x_object.h:131
SensorType
Sensor types are set in the order of lidar, radar, camera, ultrasonic Please make sure SensorType has...
Definition: sensor_meta.h:29
MessageType
Definition: v2x_object.h:49
Info(Val val, Var var)
Definition: v2x_object.h:60
std::shared_ptr< const Object > ObjectConstPtr
Definition: v2x_object.h:222
ObjectType
Definition: object_types.h:26
double timestamp
Definition: v2x_object.h:153
float x() const
Definition: v2x_object.h:98
ObjectSubType
Definition: object_types.h:63
bool operator>(const Object &rhs) const
Definition: v2x_object.h:139
Info3d size
Definition: v2x_object.h:178
Infod track_variance
Definition: v2x_object.h:200
Info< double, double > Infod
Definition: v2x_object.h:129
bool operator>(const ObjectList &rhs) const
Definition: v2x_object.h:232
Info3d position
Definition: v2x_object.h:166