CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
client
ServerSideSensor.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/client/ServerSideSensor.h
"
8
9
#include "
carla/Logging.h
"
10
#include "
carla/client/detail/Simulator.h
"
11
12
#include <exception>
13
14
constexpr
size_t
GBufferTextureCount
= 13;
15
16
namespace
carla
{
17
namespace
client {
18
19
ServerSideSensor::~ServerSideSensor
() {
20
if
(
IsAlive
() &&
IsListening
()) {
21
log_warning(
22
"sensor object went out of the scope but the sensor is still alive"
,
23
"in the simulation:"
,
24
GetDisplayId
());
25
}
26
if
(
IsListening
() &&
GetEpisode
().IsValid()) {
27
try
{
28
for
(uint32_t i = 1; i !=
GBufferTextureCount
+ 1; ++i) {
29
if
(
listening_mask
.test(i))
30
StopGBuffer
(i - 1);
31
}
32
Stop
();
33
}
catch
(
const
std::exception &e) {
34
log_error(
"exception trying to stop sensor:"
,
GetDisplayId
(),
':'
, e.what());
35
}
36
}
37
}
38
39
void
ServerSideSensor::Listen
(
CallbackFunctionType
callback) {
40
log_debug(
"calling sensor Listen() "
,
GetDisplayId
());
41
log_debug(
GetDisplayId
(),
": subscribing to stream"
);
42
GetEpisode
().
Lock
()->SubscribeToSensor(*
this
, std::move(callback));
43
listening_mask
.set(0);
44
}
45
46
void
ServerSideSensor::Stop
() {
47
log_debug(
"calling sensor Stop() "
,
GetDisplayId
());
48
if
(!
IsListening
()) {
49
log_warning(
50
"attempting to unsubscribe from stream but sensor wasn't listening:"
,
51
GetDisplayId
());
52
return
;
53
}
54
GetEpisode
().
Lock
()->UnSubscribeFromSensor(*
this
);
55
listening_mask
.reset(0);
56
}
57
58
void
ServerSideSensor::ListenToGBuffer
(uint32_t GBufferId,
CallbackFunctionType
callback) {
59
log_debug(
GetDisplayId
(),
": subscribing to gbuffer stream"
);
60
RELEASE_ASSERT
(GBufferId <
GBufferTextureCount
);
61
if
(
GetActorDescription
().description.
id
!=
"sensor.camera.rgb"
)
62
{
63
log_warning(
"GBuffer methods are not supported on non-RGB sensors (sensor.camera.rgb)."
);
64
return
;
65
}
66
GetEpisode
().
Lock
()->SubscribeToGBuffer(*
this
, GBufferId, std::move(callback));
67
listening_mask
.set(0);
68
listening_mask
.set(GBufferId + 1);
69
}
70
71
void
ServerSideSensor::StopGBuffer
(uint32_t GBufferId) {
72
log_debug(
GetDisplayId
(),
": unsubscribing from gbuffer stream"
);
73
RELEASE_ASSERT
(GBufferId <
GBufferTextureCount
);
74
if
(
GetActorDescription
().description.
id
!=
"sensor.camera.rgb"
)
75
{
76
log_warning(
"GBuffer methods are not supported on non-RGB sensors (sensor.camera.rgb)."
);
77
return
;
78
}
79
GetEpisode
().
Lock
()->UnSubscribeFromGBuffer(*
this
, GBufferId);
80
listening_mask
.reset(GBufferId + 1);
81
}
82
83
void
ServerSideSensor::EnableForROS
() {
84
GetEpisode
().
Lock
()->EnableForROS(*
this
);
85
}
86
87
void
ServerSideSensor::DisableForROS
() {
88
GetEpisode
().
Lock
()->DisableForROS(*
this
);
89
}
90
91
bool
ServerSideSensor::IsEnabledForROS
(){
92
return
GetEpisode
().
Lock
()->IsEnabledForROS(*
this
);
93
}
94
95
void
ServerSideSensor::Send
(
const
rpc::CustomV2XBytes
&data) {
96
log_debug(
"calling sensor Send() "
,
GetDisplayId
());
97
if
(
GetActorDescription
().description.
id
!=
"sensor.other.v2x_custom"
)
98
{
99
log_warning(
"Send methods are not supported on non-V2X sensors (sensor.other.v2x_custom)."
);
100
return
;
101
}
102
GetEpisode
().
Lock
()->Send(*
this
, data);
103
}
104
105
bool
ServerSideSensor::Destroy
() {
106
log_debug(
"calling sensor Destroy() "
,
GetDisplayId
());
107
if
(
IsListening
()) {
108
for
(uint32_t i = 1; i !=
GBufferTextureCount
+ 1; ++i) {
109
if
(
listening_mask
.test(i)) {
110
StopGBuffer
(i - 1);
111
}
112
}
113
Stop
();
114
}
115
return
Actor::Destroy();
116
}
117
118
}
// namespace client
119
}
// namespace carla
RELEASE_ASSERT
#define RELEASE_ASSERT(pred)
Definition
Debug.h:84
Logging.h
GBufferTextureCount
constexpr size_t GBufferTextureCount
Definition
ServerSideSensor.cpp:14
ServerSideSensor.h
Simulator.h
carla::client::Actor::IsAlive
bool IsAlive() const
Definition
client/Actor.h:177
carla::client::Sensor::CallbackFunctionType
std::function< void(SharedPtr< sensor::SensorData >)> CallbackFunctionType
Definition
LibCarla/source/carla/client/Sensor.h:20
carla::client::ServerSideSensor::IsEnabledForROS
bool IsEnabledForROS()
Return if the sensor is publishing for ROS2.
Definition
ServerSideSensor.cpp:91
carla::client::ServerSideSensor::~ServerSideSensor
~ServerSideSensor()
Definition
ServerSideSensor.cpp:19
carla::client::ServerSideSensor::Send
void Send(const rpc::CustomV2XBytes &data)
Send a binary message through this sensor.
Definition
ServerSideSensor.cpp:95
carla::client::ServerSideSensor::EnableForROS
void EnableForROS()
Enable this sensor for ROS2 publishing.
Definition
ServerSideSensor.cpp:83
carla::client::ServerSideSensor::listening_mask
std::bitset< 16 > listening_mask
Definition
ServerSideSensor.h:72
carla::client::ServerSideSensor::Destroy
bool Destroy() override
Definition
ServerSideSensor.cpp:105
carla::client::ServerSideSensor::ListenToGBuffer
void ListenToGBuffer(uint32_t GBufferId, CallbackFunctionType callback)
Listen fr.
Definition
ServerSideSensor.cpp:58
carla::client::ServerSideSensor::Stop
void Stop() override
Stop listening for new measurements.
Definition
ServerSideSensor.cpp:46
carla::client::ServerSideSensor::DisableForROS
void DisableForROS()
Disable this sensor for ROS2 publishing.
Definition
ServerSideSensor.cpp:87
carla::client::ServerSideSensor::IsListening
bool IsListening() const override
Return whether this Sensor instance is currently listening to the associated sensor in the simulator.
Definition
ServerSideSensor.h:38
carla::client::ServerSideSensor::Listen
void Listen(CallbackFunctionType callback) override
Register a callback to be executed each time a new measurement is received.
Definition
ServerSideSensor.cpp:39
carla::client::ServerSideSensor::StopGBuffer
void StopGBuffer(uint32_t GBufferId)
Stop listening for a specific gbuffer stream.
Definition
ServerSideSensor.cpp:71
carla::client::detail::ActorState::GetEpisode
EpisodeProxy & GetEpisode()
Definition
client/detail/ActorState.h:85
carla::client::detail::ActorState::GetActorDescription
const rpc::Actor & GetActorDescription() const
Definition
client/detail/ActorState.h:81
carla::client::detail::ActorState::GetDisplayId
const std::string & GetDisplayId() const
Definition
client/detail/ActorState.h:35
carla::client::detail::EpisodeProxyImpl::Lock
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
Definition
EpisodeProxy.cpp:39
carla::rpc::Actor::id
ActorId id
Definition
rpc/Actor.h:25
carla::rpc::CustomV2XBytes
Fixed-size binary payload carried by the custom V2X sensor (sensor.other.v2x_custom).
Definition
CustomV2XBytes.h:19
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
Generated by
1.18.0