CARLA
Loading...
Searching...
No Matches
RadarData.h
Go to the documentation of this file.
1// Copyright (c) 2026 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
13namespace carla {
14
15namespace ros2 {
16 class ROS2;
17}
18
19namespace sensor {
20
21namespace s11n {
22 class RadarSerializer;
23}
24
25namespace data {
26
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
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.
72
73 const std::vector<RadarDetection>& GetDetections() const {
74 return _detections;
75 }
76
77 private:
78 std::vector<RadarDetection> _detections;
79
81 friend class carla::ros2::ROS2;
82 };
83
84} // namespace s11n
85} // namespace sensor
86} // namespace carla
sensor::data::RadarDetection detection
RadarData & operator=(RadarData &&)=default
void Reset()
Deletes the current detections.
Definition RadarData.h:64
void SetResolution(uint32_t resolution)
Set a new resolution for the RadarData.
Definition RadarData.h:49
size_t GetDetectionCount() const
Returns the number of current detections.
Definition RadarData.h:58
const std::vector< RadarDetection > & GetDetections() const
Definition RadarData.h:73
static constexpr auto detection_size
Definition RadarData.h:41
void WriteDetection(RadarDetection detection)
Adds a new detection.
Definition RadarData.h:69
std::vector< RadarDetection > _detections
Definition RadarData.h:78
Serializes the data generated by Radar sensors.
This file contains definitions of common data structures used in traffic manager.