CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
ros2
publishers
CarlaRadarPublisher.cpp
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
#include "
carla/ros2/publishers/CarlaRadarPublisher.h
"
8
9
#include "
carla/ros2/publishers/RadarPolarToCartesian.h
"
10
#include "
carla/sensor/data/RadarData.h
"
11
12
#include <cstring>
13
14
namespace
carla
{
15
namespace
ros2
{
16
17
namespace
{
18
19
// Cartesian projection prefixed to each RadarDetection so subscribers see
20
// (x, y, z, velocity, azimuth, altitude, depth) per point. Memory layout
21
// must match kRadarFields: 3 leading floats + the raw RadarDetection
22
// payload (velocity, azimuth, altitude, depth).
23
struct
RadarDetectionWithPosition {
24
float
x;
25
float
y;
26
float
z;
27
sensor::data::RadarDetection detection;
28
};
29
30
static_assert
(
31
sizeof
(RadarDetectionWithPosition)
32
== 3u *
sizeof
(float) +
sizeof
(sensor::data::RadarDetection),
33
"RadarDetectionWithPosition must be tightly packed for the wire layout"
);
34
35
}
// namespace
36
37
std::size_t
CarlaRadarPublisher::GetPointSize
()
const
{
38
return
sizeof
(RadarDetectionWithPosition);
39
}
40
41
const
PointFieldDescriptor
*
CarlaRadarPublisher::GetFieldDescriptors
()
const
{
42
return
kRadarFields
.data();
43
}
44
45
std::size_t
CarlaRadarPublisher::GetFieldDescriptorCount
()
const
{
46
return
kRadarFields
.size();
47
}
48
49
std::vector<std::uint8_t>
CarlaRadarPublisher::ComputePointCloud
(
50
std::uint32_t height, std::uint32_t width,
const
std::uint8_t *data)
const
{
51
const
std::size_t total_points =
52
static_cast<
std::size_t
>
(height) *
static_cast<
std::size_t
>
(width);
53
const
auto
*detections =
54
reinterpret_cast<
const
sensor::data::RadarDetection
*
>
(data);
55
56
std::vector<RadarDetectionWithPosition> radar_points(total_points);
57
for
(std::size_t i = 0; i < total_points; ++i) {
58
const
auto
&detection = detections[i];
59
const
auto
cartesian =
RadarPolarToCartesian
(
60
detection.depth, detection.azimuth, detection.altitude);
61
radar_points[i].x = cartesian[0];
62
radar_points[i].y = cartesian[1];
63
radar_points[i].z = cartesian[2];
64
radar_points[i].detection = detection;
65
}
66
67
const
auto
*byte_ptr =
reinterpret_cast<
const
std::uint8_t *
>
(radar_points.data());
68
return
std::vector<std::uint8_t>(
69
byte_ptr, byte_ptr + radar_points.size() *
sizeof
(RadarDetectionWithPosition));
70
}
71
72
}
// namespace ros2
73
}
// namespace carla
CarlaRadarPublisher.h
RadarData.h
RadarPolarToCartesian.h
carla::ros2::CarlaRadarPublisher::ComputePointCloud
std::vector< std::uint8_t > ComputePointCloud(std::uint32_t height, std::uint32_t width, const std::uint8_t *data) const override
Definition
CarlaRadarPublisher.cpp:49
carla::ros2::CarlaRadarPublisher::GetFieldDescriptorCount
std::size_t GetFieldDescriptorCount() const override
Definition
CarlaRadarPublisher.cpp:45
carla::ros2::CarlaRadarPublisher::GetPointSize
std::size_t GetPointSize() const override
Definition
CarlaRadarPublisher.cpp:37
carla::ros2::CarlaRadarPublisher::GetFieldDescriptors
const PointFieldDescriptor * GetFieldDescriptors() const override
Definition
CarlaRadarPublisher.cpp:41
carla::ros2
Definition
AutowareSteeringCompensation.h:15
carla::ros2::kRadarFields
constexpr std::array< PointFieldDescriptor, 7 > kRadarFields
Definition
PointCloudFieldsLayout.h:80
carla::ros2::RadarPolarToCartesian
std::array< float, 3 > RadarPolarToCartesian(float depth, float azimuth, float altitude) noexcept
Definition
RadarPolarToCartesian.h:25
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
carla::ros2::PointFieldDescriptor
Definition
PointCloudFieldsLayout.h:33
carla::sensor::data::RadarDetection
Definition
RadarData.h:27
Generated by
1.18.0