CARLA
 
载入中...
搜索中...
未找到
ServerSideSensor.cpp
浏览该文件的文档.
1// Copyright (c) 2017 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
8
9#include "carla/Logging.h"
11
12#include <exception>
13
14constexpr size_t GBufferTextureCount = 13;
15
16namespace carla {
17namespace client {
18
20 if (IsAlive() && IsListening()) {
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
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
47 log_debug("calling sensor Stop() ", GetDisplayId());
48 if (!IsListening()) {
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::Send(std::string message) {
59 log_debug("calling sensor Send() ", GetDisplayId());
60 if (GetActorDescription().description.id != "sensor.other.v2x_custom")
61 {
62 log_warning("Send methods are not supported on non-V2x sensors (sensor.other.v2x_custom).");
63 return;
64 }
65 GetEpisode().Lock()->Send(*this,message);
66 }
67
68 void ServerSideSensor::ListenToGBuffer(uint32_t GBufferId, CallbackFunctionType callback) {
69 log_debug(GetDisplayId(), ": subscribing to gbuffer stream");
71 if (GetActorDescription().description.id != "sensor.camera.rgb")
72 {
73 log_warning("GBuffer methods are not supported on non-RGB sensors (sensor.camera.rgb).");
74 return;
75 }
76 GetEpisode().Lock()->SubscribeToGBuffer(*this, GBufferId, std::move(callback));
77 listening_mask.set(0);
78 listening_mask.set(GBufferId + 1);
79 }
80
81 void ServerSideSensor::StopGBuffer(uint32_t GBufferId) {
82 log_debug(GetDisplayId(), ": unsubscribing from gbuffer stream");
84 if (GetActorDescription().description.id != "sensor.camera.rgb")
85 {
86 log_warning("GBuffer methods are not supported on non-RGB sensors (sensor.camera.rgb).");
87 return;
88 }
89 GetEpisode().Lock()->UnSubscribeFromGBuffer(*this, GBufferId);
90 listening_mask.reset(GBufferId + 1);
91 }
92
94 GetEpisode().Lock()->EnableForROS(*this);
95 }
96
98 GetEpisode().Lock()->DisableForROS(*this);
99 }
100
102 return GetEpisode().Lock()->IsEnabledForROS(*this);
103 }
104
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
#define RELEASE_ASSERT(pred)
Definition Debug.h:84
constexpr size_t GBufferTextureCount
static bool IsValid(const ACarlaWheeledVehicle *Vehicle)
std::function< void(SharedPtr< sensor::SensorData >)> CallbackFunctionType
bool IsEnabledForROS()
Return if the sensor is publishing for ROS2
void EnableForROS()
Enable this sensor for ROS2 publishing
void ListenToGBuffer(uint32_t GBufferId, CallbackFunctionType callback)
Listen fr
void Send(std::string message)
Send data via this sensor
void Stop() override
Stop listening for new measurements.
void DisableForROS()
Disable this sensor for ROS2 publishing
bool IsListening() const override
Return whether this Sensor instance is currently listening to the associated sensor in the simulator.
void Listen(CallbackFunctionType callback) override
Register a callback to be executed each time a new measurement is received.
void StopGBuffer(uint32_t GBufferId)
Stop listening for a specific gbuffer stream.
const rpc::Actor & GetActorDescription() const
const std::string & GetDisplayId() const
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
static void log_error(Args &&... args)
Definition Logging.h:110
static void log_warning(Args &&... args)
Definition Logging.h:96
static void log_debug(Args &&... args)
Definition Logging.h:68