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 
15 namespace ros2 {
16  class ROS2;
17 }
18 
19 namespace sensor {
20 
21 namespace s11n {
22  class RadarSerializer;
23 }
24 
25 namespace data {
26 
27  struct RadarDetection {
28  float velocity; // m/s
29  float azimuth; // rad
30  float altitude; // rad
31  float depth; // m
32  };
33 
34  class RadarData {
35  static_assert(sizeof(float) == sizeof(uint32_t), "Invalid float size");
36  static_assert(sizeof(float) * 4 == sizeof(RadarDetection), "Invalid RadarDetection size");
37 
38  public:
39  explicit RadarData() = default;
40 
41  constexpr static auto detection_size = sizeof(RadarDetection);
42 
43  RadarData &operator=(RadarData &&) = default;
44 
45  /// Set a new resolution for the RadarData.
46  /// Allocates / Deallocates space in memory if needed.
47  ///
48  /// @warning This is expensive, not to be called each tick!
49  void SetResolution(uint32_t resolution) {
50  // Remove the capacity of the vector to zero
51  _detections.clear();
52  _detections.shrink_to_fit();
53  // Set the new vector's capacity
54  _detections.reserve(resolution);
55  }
56 
57  /// Returns the number of current detections.
58  size_t GetDetectionCount() const {
59  return _detections.size();
60  }
61 
62  /// Deletes the current detections.
63  /// It doesn't change the resolution nor the allocated memory.
64  void Reset() {
65  _detections.clear();
66  }
67 
68  /// Adds a new detection.
69  void WriteDetection(RadarDetection detection) {
70  _detections.push_back(detection);
71  }
72 
73  private:
74  std::vector<RadarDetection> _detections;
75 
76  friend class s11n::RadarSerializer;
77  friend class carla::ros2::ROS2;
78  };
79 
80 } // namespace s11n
81 } // namespace sensor
82 } // namespace carla
size_t GetDetectionCount() const
Returns the number of current detections.
Definition: RadarData.h:58
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:49
void WriteDetection(RadarDetection detection)
Adds a new detection.
Definition: RadarData.h:69
std::vector< RadarDetection > _detections
Definition: RadarData.h:74
Serializes the data generated by Radar sensors.
void Reset()
Deletes the current detections.
Definition: RadarData.h:64