CARLA
RadarData.h
Go to the documentation of this file.
1 // Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include <cstdint>
10 #include <vector>
11 #include <cstdio>
12 
13 namespace carla {
14 namespace sensor {
15 
16 namespace s11n {
17  class RadarSerializer;
18 }
19 
20 namespace data {
21 
22  struct RadarDetection {
23  float velocity; // m/s
24  float azimuth; // rad
25  float altitude; // rad
26  float depth; // m
27  };
28 
29  class RadarData {
30  static_assert(sizeof(float) == sizeof(uint32_t), "Invalid float size");
31  static_assert(sizeof(float) * 4 == sizeof(RadarDetection), "Invalid RadarDetection size");
32 
33  public:
34  explicit RadarData() = default;
35 
36  constexpr static auto detection_size = sizeof(RadarDetection);
37 
38  RadarData &operator=(RadarData &&) = default;
39 
40  /// Set a new resolution for the RadarData.
41  /// Allocates / Deallocates space in memory if needed.
42  ///
43  /// @warning This is expensive, not to be called each tick!
44  void SetResolution(uint32_t resolution) {
45  // Remove the capacity of the vector to zero
46  _detections.clear();
47  _detections.shrink_to_fit();
48  // Set the new vector's capacity
49  _detections.reserve(resolution);
50  }
51 
52  /// Returns the number of current detections.
53  size_t GetDetectionCount() const {
54  return _detections.size();
55  }
56 
57  /// Deletes the current detections.
58  /// It doesn't change the resolution nor the allocated memory.
59  void Reset() {
60  _detections.clear();
61  }
62 
63  /// Adds a new detection.
64  void WriteDetection(RadarDetection detection) {
65  _detections.push_back(detection);
66  }
67 
68  private:
69  std::vector<RadarDetection> _detections;
70 
71  friend class s11n::RadarSerializer;
72  };
73 
74 } // namespace s11n
75 } // namespace sensor
76 } // namespace carla
size_t GetDetectionCount() const
Returns the number of current detections.
Definition: RadarData.h:53
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
void SetResolution(uint32_t resolution)
Set a new resolution for the RadarData.
Definition: RadarData.h:44
void WriteDetection(RadarDetection detection)
Adds a new detection.
Definition: RadarData.h:64
std::vector< RadarDetection > _detections
Definition: RadarData.h:69
Serializes the data generated by Radar sensors.
void Reset()
Deletes the current detections.
Definition: RadarData.h:59