Agrarsense
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ASensor Class Reference

#include <Sensor.h>

Inheritance diagram for ASensor:
Inheritance graph
[legend]
Collaboration diagram for ASensor:
Collaboration graph
[legend]

Public Member Functions

 ASensor (const FObjectInitializer &ObjectInitializer)
 
FString ExportToJsonFile (const FString &FileName)
 
virtual ESensorTypes GetSensorType () const
 
FString GetSensorIdentifier () const
 
void SetSensorIdentifier (const FString newIdentifier)
 
FString GetSensorName () const
 
virtual FString GetParametersAsString () const
 
void SetSensorName (const FString newName)
 
virtual FString GetTopicName ()
 
UTopic * GetROSTopic () const
 
void SetSimulateSensor (bool SimulateSensor)
 
bool CanSimulateSensor () const
 
ASensorModelGetSensorModel () const
 
void SetSensorModel (ASensorModel *NewSensorModel)
 
FORCEINLINE bool IsROSConnected () const
 
UROSIntegrationGameInstance * GetROSGameInstance () const
 
virtual FString GetActorID_Implementation () const override
 
virtual FString GetActorName_Implementation () const override
 
virtual FString GetActorInformation_Implementation () const override
 
virtual void SetActorName_Implementation (const FString &NewActorName) override
 
virtual void SetActorIDAndName_Implementation (const FString &NewActorName, const FString &NewID) override
 
- Public Member Functions inherited from IActorInformation
FString GetActorID () const
 
FString GetActorName () const
 
FString GetActorInformation () const
 
void SetActorName (const FString &NewActorName)
 
void SetActorIDAndName (const FString &NewActorName, const FString &NewID)
 

Static Public Member Functions

static void HideComponentForAllCameras (UPrimitiveComponent *PrimitiveComponent)
 
static TMap< FString, FColor > GetSemanticColors ()
 
static TArray< TWeakObjectPtr< UPrimitiveComponent > > GetComponentsToHide ()
 
- Static Public Member Functions inherited from IActorInformation
static void SetAndValidateActorIDAndName (FString &ActorName, FString &ActorID, TWeakObjectPtr< AActor > Actor)
 
static bool DestroyActorByID (const FString &ID)
 
static AActor * GetActorByID (const FString &ID)
 
template<typename T >
static TArray< T * > GetActorsWithInterface ()
 
static void PrintAllIds ()
 

Public Attributes

FSensorDestroy OnSensorDestroy
 
FString AttachedToComponent
 
FName AttachedToBone
 

Protected Member Functions

virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
virtual void CreateROSTopic ()
 
virtual void DestroyROSTopic ()
 
virtual void CreateDataSavePath ()
 
bool IsLogFileCreated ()
 
virtual void CreateLogFile ()
 
void WriteToLogFile (const FString &Message)
 

Static Protected Member Functions

template<typename InStructType >
static FString StructToString (const InStructType &InStruct)
 

Protected Attributes

UTopic * ROSTopic = nullptr
 
bool SendDataToROS = true
 
ULogFileLogFile = nullptr
 
FString FileSavePath
 
UROSIntegrationGameInstance * ROSInstance = nullptr
 

Static Protected Attributes

static FPrimitiveAdded OnPrimitiveAdded
 
static const FName NiagaraPointsInt = "User.PointCount"
 
static const FName NiagaraHitPoints = "User.HitPoints"
 
static const FName NiagaraHitColors = "User.HitColors"
 
static const FName NiagaraPointsFloat = "User.Test"
 

Private Member Functions

void ROSBridgeStateChanged (EROSState ROSState)
 

Private Attributes

TObjectPtr< ASensorModelSensorModel
 
FString SensorIdentifier
 
FString SensorName
 
bool SimulateThisSensor = true
 
bool ROSConnected = false
 

Static Private Attributes

static TArray< TWeakObjectPtr< UPrimitiveComponent > > ComponentsToHide
 

Detailed Description

Base class for all sensors.

Definition at line 43 of file Sensor.h.

Constructor & Destructor Documentation

◆ ASensor()

ASensor::ASensor ( const FObjectInitializer &  ObjectInitializer)

Definition at line 23 of file Sensor.cpp.

23 : Super(ObjectInitializer)
24{
25 RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneRoot"));
26 RootComponent->SetMobility(EComponentMobility::Movable);
27}

Member Function Documentation

◆ BeginPlay()

void ASensor::BeginPlay ( )
overrideprotectedvirtual

Reimplemented in ACamera, ACollisionSensor, ALidar, AOverlapSensor, ARadar, and ATransformSensor.

Definition at line 29 of file Sensor.cpp.

30{
31 Super::BeginPlay();
32
33 UWorld* World = GetWorld();
34
36 if (ROSHandler)
37 {
38 // Subscribe to ROS changed event
39 ROSHandler->OnROSStateChanged.AddUniqueDynamic(this, &ASensor::ROSBridgeStateChanged);
40 }
41
43 if (ROSInstance)
44 {
45 // Check if ROS is connected at BeginPlay
46 ROSConnected = ROSInstance->IsROSConnected();
47 }
48
49 // Delay logging sensor information message so each sensor have time setup fully.
50 FTimerHandle Handle;
51 World->GetTimerManager().SetTimer(Handle, FTimerDelegate::CreateLambda([this]
52 {
53 if (IsValid(this))
54 {
55 FString Message = FString::Printf(TEXT("Spawned %s"), *GetActorInformation_Implementation());
56 SimulatorLog::Log(Message);
57 }
58 }), 0.150f, false);
59
60 // Inform sensor manager that new sensor has been spawned.
62
63
64 ESensorTypes ThisSensorType = GetSensorType();
65
66 if (ThisSensorType != ESensorTypes::NONE &&
67 ThisSensorType != ESensorTypes::Transform &&
68 ThisSensorType != ESensorTypes::Collision &&
69 ThisSensorType != ESensorTypes::Overlap)
70 {
71 // Spawn a Transform sensor for any sensor type other than NONE, Transform, Collision, or Overlap.
72 // Meaning each sensor, like a Lidar sensor, has its own Transform sensor that publishes its:
73 // - World location
74 // - GNSS location (if world has GNSS setup)
75
76 // We don't need to keep track of this TransformSensor Actor as it should
77 // be automatically destroyed when the parent sensor is destroyed (ASensor EndPlay)
78 FString SensorTransformSensorID = GetActorID_Implementation() + "/transform";
79 USensorFactory::SpawnTransformSensor(GetActorTransform(), this, SensorTransformSensorID, "transform", true);
80 }
81}
ESensorTypes
Definition: SensorTypes.h:15
void ROSBridgeStateChanged(EROSState ROSState)
Definition: Sensor.cpp:141
UROSIntegrationGameInstance * ROSInstance
Definition: Sensor.h:352
virtual ESensorTypes GetSensorType() const
Definition: Sensor.h:64
virtual FString GetActorID_Implementation() const override
Definition: Sensor.h:207
bool ROSConnected
Definition: Sensor.h:384
virtual FString GetActorInformation_Implementation() const override
Definition: Sensor.h:217
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)
static UROSIntegrationGameInstance * GetROSGameInstance(const UObject *WorldContextObject)
static UROSHandler * GetROSHandle(const UObject *WorldContextObject)
FROSDelegate_ROState OnROSStateChanged
Definition: ROSHandler.h:81
static ATransformSensor * SpawnTransformSensor(const FTransform &transform, AActor *Owner, const FString sensorIdentifier, const FString sensorName, bool SimulateSensor=true)
static void AddSensor(ASensor *SensorPtr)

References USensorManager::AddSensor(), Collision, GetActorID_Implementation(), GetActorInformation_Implementation(), UAgrarsenseStatics::GetROSGameInstance(), UAgrarsenseStatics::GetROSHandle(), GetSensorType(), SimulatorLog::Log(), NONE, UROSHandler::OnROSStateChanged, Overlap, ROSBridgeStateChanged(), ROSConnected, ROSInstance, USensorFactory::SpawnTransformSensor(), and Transform.

◆ CanSimulateSensor()

bool ASensor::CanSimulateSensor ( ) const
inline

Checks whether this sensor can be simulated.

Returns
True if the sensor can be simulated, false otherwise.

Definition at line 161 of file Sensor.h.

162 {
163 return SimulateThisSensor;
164 }
bool SimulateThisSensor
Definition: Sensor.h:381

Referenced by ADVSCamera::ChangeDVSCameraParameters(), ALidar::ChangeLidarParameters(), ARadar::ChangeRadarParameters(), ACollisionSensor::OnCollisionEvent(), ACamera::ShouldSimulate(), ALidar::SimulateRaycastLidar(), ARadar::Tick(), and ATransformSensor::TickParallel().

◆ CreateDataSavePath()

void ASensor::CreateDataSavePath ( )
protectedvirtual

Creates data save path for this sensor. Can be overriden if needed.

Definition at line 225 of file Sensor.cpp.

226{
227 if (FileSavePath.IsEmpty())
228 {
229 FString DataLocation = UAgrarsensePaths::GetDataFolder();
230 FString UnixTimeStamp = FString::FromInt(FDateTime::Now().ToUnixTimestamp());
231 FileSavePath = DataLocation + GetSensorIdentifier() + "_" + UnixTimeStamp + "/";
232 }
233}
FString GetSensorIdentifier() const
Definition: Sensor.h:74
FString FileSavePath
Definition: Sensor.h:349
static FString GetDataFolder()

References FileSavePath, UAgrarsensePaths::GetDataFolder(), and GetSensorIdentifier().

Referenced by ACamera::Init(), and ALidar::Init().

◆ CreateLogFile()

void ASensor::CreateLogFile ( )
protectedvirtual

Create Text file for this sensor if it has not been created already. Text file will be created to ROOT/Data/Run/Logs directory. Filename will be SensorName_ID_UnixTimestamp.txt Can be overriden by individual sensor if needed.

Reimplemented in ACamera.

Definition at line 235 of file Sensor.cpp.

236{
237 if (IsValid(LogFile))
238 {
239 // File has already been created, return
240 return;
241 }
242
243 FLogFileSettings Settings;
246 Settings.QueueLength = 10;
247 Settings.KeepFileOpen = false;
248
249 LogFile = NewObject<ULogFile>(ULogFile::StaticClass());
250 if (LogFile)
251 {
252 // FileName is SensorName_ID_UnixTimeStamp.txt
253 FString UnixTimeStamp = FString::FromInt(FDateTime::Now().ToUnixTimestamp());
254
255 FString ActorID = GetActorID_Implementation();
256
257 // Temp fix, Remove all "/" from ActorID
258 ActorID.ReplaceInline(TEXT("/"), TEXT(""), ESearchCase::IgnoreCase);
259
260 FString FileName = FString::Printf(TEXT("%s_%s_%s"), *GetSensorName(), *ActorID, *UnixTimeStamp);
261 LogFile->Create(FileName, Settings);
262 }
263}
FString GetSensorName() const
Definition: Sensor.h:95
ULogFile * LogFile
Definition: Sensor.h:347
void Create(const FString &FileNameWithoutExtension, FLogFileSettings Settings)
Definition: LogFile.cpp:40
bool KeepFileOpen
Definition: LogFile.h:42
FFileWriteOptions FileWriteOptions
Definition: LogFile.h:45
int32 QueueLength
Definition: LogFile.h:48
FFileCreationOptions FileCreationOptions
Definition: LogFile.h:36

References ULogFile::Create(), FLogFileSettings::FileCreationOptions, FLogFileSettings::FileWriteOptions, GetActorID_Implementation(), GetSensorName(), FLogFileSettings::KeepFileOpen, LogFile, Overwrite, Queue, and FLogFileSettings::QueueLength.

Referenced by WriteToLogFile().

◆ CreateROSTopic()

void ASensor::CreateROSTopic ( )
protectedvirtual

Creates ROS Topic for this sensor. Can be overriden by individual sensor if needed.

Reimplemented in ADVSCamera, and ATransformSensor.

Definition at line 169 of file Sensor.cpp.

170{
171 if (!SendDataToROS
172 || ROSTopic
173 || !ROSInstance
174 || !IsROSConnected())
175 {
176 return;
177 }
178
179 FString MessageType;
180 ESensorTypes SensorType = GetSensorType();
181
182 switch (SensorType)
183 {
186 MessageType = "sensor_msgs/PointCloud2";
187 break;
188
193 case ESensorTypes::DVSCamera: // DVS Camera should override this.
194 MessageType = "sensor_msgs/Image";
195 break;
196
198 MessageType = "geometry_msgs/Transform";
199 break;
200
203 MessageType = "std_msgs/String";
204 break;
205
206 default:
207 FString SensorNameString = UEnumUtilities::ConvertSensorTypeToString(SensorType);
208 UE_LOG(LogTemp, Warning, TEXT("Unhandled ROS sensor message creation for sensor: %s"), *SensorNameString);
209 break;
210 }
211
212 FString TopicName = FString::Printf(TEXT("/agrarsense/out/sensors/%s"), *GetSensorIdentifier());
213
214 ROSTopic = NewObject<UTopic>(UTopic::StaticClass());
215 if (ROSTopic)
216 {
217 ROSTopic->Init(ROSInstance->ROSIntegrationCore, TopicName, MessageType);
218 ROSTopic->Advertise();
219 }
220
221 FString Message = FString::Printf(TEXT("%s sensor created ROS topic. Name: '%s' MessageType: '%s' "), *GetSensorName(), *TopicName, *MessageType);
222 SimulatorLog::Log(Message);
223}
@ SemanticSegmentationCamera
UTopic * ROSTopic
Definition: Sensor.h:341
bool SendDataToROS
Definition: Sensor.h:344
FORCEINLINE bool IsROSConnected() const
Definition: Sensor.h:192
static FString ConvertSensorTypeToString(ESensorTypes Sensortype)

References Collision, UEnumUtilities::ConvertSensorTypeToString(), DepthCamera, DVSCamera, GetSensorIdentifier(), GetSensorName(), GetSensorType(), IsROSConnected(), Lidar, SimulatorLog::Log(), Overlap, Radar, RGBCamera, ROSInstance, ROSTopic, SemanticSegmentationCamera, SendDataToROS, ThermalCamera, and Transform.

Referenced by ALidar::ChangeParameters(), ACollisionSensor::Init(), AOverlapSensor::Init(), ARadar::Init(), ROSBridgeStateChanged(), and ACamera::SetupCamera().

◆ DestroyROSTopic()

void ASensor::DestroyROSTopic ( )
protectedvirtual

Destroy created ROS Topic. Can be overriden by individual sensor if needed.

Reimplemented in ATransformSensor.

Definition at line 157 of file Sensor.cpp.

158{
159 if (ROSTopic)
160 {
161 ROSTopic->Unadvertise();
162 ROSTopic->Unsubscribe();
163 ROSTopic->MarkAsDisconnected();
164 ROSTopic->ConditionalBeginDestroy();
165 ROSTopic = nullptr;
166 }
167}

References ROSTopic.

Referenced by EndPlay(), and ROSBridgeStateChanged().

◆ EndPlay()

void ASensor::EndPlay ( const EEndPlayReason::Type  EndPlayReason)
overrideprotectedvirtual

Reimplemented in ACamera, ADepthCamera, ADVSCamera, AThermalCamera, ACollisionSensor, ALidar, AOverlapSensor, ARadar, and ATransformSensor.

Definition at line 83 of file Sensor.cpp.

84{
85 // Broadcast that this sensor will be destroyed
86 OnSensorDestroy.Broadcast(this);
87
89
90 Super::EndPlay(EndPlayReason);
91
92 UROSHandler* ROSHandler = UAgrarsenseStatics::GetROSHandle(GetWorld());
93 if (ROSHandler)
94 {
95 ROSHandler->OnROSStateChanged.RemoveDynamic(this, &ASensor::ROSBridgeStateChanged);
96 }
97
98 FString Sensor = UEnum::GetDisplayValueAsText(GetSensorType()).ToString();
99 FString ID = GetSensorIdentifier();
100 FString Message = FString::Printf(TEXT("Destroyed %s sensor with ID: %s"), *Sensor, *ID);
101 SimulatorLog::Log(Message);
102
103 if (EndPlayReason == EEndPlayReason::EndPlayInEditor
104 || EndPlayReason == EEndPlayReason::Quit)
105 {
106 for (auto& WeakComponentPtr : ComponentsToHide)
107 {
108 WeakComponentPtr.Reset();
109 }
110 ComponentsToHide.Empty();
111 }
112
113 // Destroy all Actors that are attached to this sensor like:
114 // Sensor model Actor and TransformSensor Actor.
115 TArray<AActor*> AttachedActors;
116 GetAttachedActors(AttachedActors);
117 for (AActor* Actor : AttachedActors)
118 {
119 if (Actor)
120 {
121 Actor->Destroy();
122 }
123 }
124
125 ROSInstance = nullptr;
126
127 if (LogFile)
128 {
129 LogFile->Destroy();
130 LogFile = nullptr;
131 }
132
134}
static TArray< TWeakObjectPtr< UPrimitiveComponent > > ComponentsToHide
Definition: Sensor.h:386
virtual void DestroyROSTopic()
Definition: Sensor.cpp:157
FSensorDestroy OnSensorDestroy
Definition: Sensor.h:269
void Destroy()
Definition: LogFile.cpp:170
static void RemoveSensor(ASensor *SensorPtr)

References ComponentsToHide, ULogFile::Destroy(), DestroyROSTopic(), UAgrarsenseStatics::GetROSHandle(), GetSensorIdentifier(), GetSensorType(), SimulatorLog::Log(), LogFile, UROSHandler::OnROSStateChanged, OnSensorDestroy, USensorManager::RemoveSensor(), ROSBridgeStateChanged(), and ROSInstance.

◆ ExportToJsonFile()

FString ASensor::ExportToJsonFile ( const FString &  FileName)

Export this Sensor and parameters to a JSON file.

Parameters
FileNameThe name of the file without extension.
Returns
FString representing saved Json file path, or an empty string if the export fails.

Definition at line 136 of file Sensor.cpp.

137{
138 return USimulatorJsonExporter::ExportSensorToJSON(FileName, this);
139}
static FString ExportSensorToJSON(const FString &FileName, ASensor *Sensor)

References USimulatorJsonExporter::ExportSensorToJSON().

Referenced by UROSCommands::HandleExportSensors().

◆ GetActorID_Implementation()

virtual FString ASensor::GetActorID_Implementation ( ) const
inlineoverridevirtual

◆ GetActorInformation_Implementation()

virtual FString ASensor::GetActorInformation_Implementation ( ) const
inlineoverridevirtual

Definition at line 217 of file Sensor.h.

218 {
220 const FString ID = GetActorID_Implementation();
221 const FTransform VehicleTransform = GetActorTransform();
222 const FVector Location = VehicleTransform.GetLocation();
223 const FRotator Rotation = VehicleTransform.Rotator();
224 const FString Parameters = GetParametersAsString();
225
226 FString Information = FString::Printf(TEXT("Sensor: %s \nID: %s \nLocation: %s \nRotation: %s \nParameters: %s"),
227 *Sensor, *ID, *Location.ToString(), *Rotation.ToString(), *Parameters);
228
229 return Information;
230 }
virtual FString GetParametersAsString() const
Definition: Sensor.h:104

References UEnumUtilities::ConvertSensorTypeToString().

Referenced by BeginPlay().

◆ GetActorName_Implementation()

virtual FString ASensor::GetActorName_Implementation ( ) const
inlineoverridevirtual

Definition at line 212 of file Sensor.h.

213 {
214 return GetSensorName();
215 }

Referenced by AVehicle::GetActorInformation_Implementation().

◆ GetComponentsToHide()

static TArray< TWeakObjectPtr< UPrimitiveComponent > > ASensor::GetComponentsToHide ( )
inlinestatic

Static method to retrieve an array of weak pointers to UPrimitiveComponents that are ready to be hidden.

Returns
An array of TWeakObjectPtr<UPrimitiveComponent> containing components ready to be hidden.

Definition at line 256 of file Sensor.h.

257 {
258 // Since we don't know whether some UPrimitiveComponent has been destroyed,
259 // we need to check these are still valid.
260 ComponentsToHide.RemoveAll([](const TWeakObjectPtr<UPrimitiveComponent>& WeakComponent)
261 {
262 return !WeakComponent.IsValid();
263 });
264
265 return ComponentsToHide;
266 }

Referenced by ACamera::BeginPlay().

◆ GetParametersAsString()

virtual FString ASensor::GetParametersAsString ( ) const
inlinevirtual

Get this sensor parameters as string

Reimplemented in ACamera, ADepthCamera, ADVSCamera, AThermalCamera, ALidar, AOverlapSensor, and ARadar.

Definition at line 104 of file Sensor.h.

105 {
106 return FString();
107 }

◆ GetROSGameInstance()

UROSIntegrationGameInstance * ASensor::GetROSGameInstance ( ) const
inline

Retrieves the instance of the ROSIntegrationGameInstance set in ASensor::BeginPlay.

Returns
A pointer to the associated ROSIntegrationGameInstance.

Definition at line 202 of file Sensor.h.

203 {
204 return ROSInstance;
205 }

◆ GetROSTopic()

UTopic * ASensor::GetROSTopic ( ) const
inline

Retrieves the ROS topic associated with this sensor.

Returns
A pointer to the associated ROS topic or nullptr.

Definition at line 141 of file Sensor.h.

142 {
143 return ROSTopic;
144 }

Referenced by AOverlapSensor::BuildAndSendMessage(), ACollisionSensor::SendCollisionData(), ALidar::SendDataToTopic(), ACamera::SendImageDataToROS(), ARadar::SendRadarData(), and ATransformSensor::SendTransformDataToROS().

◆ GetSemanticColors()

TMap< FString, FColor > ASensor::GetSemanticColors ( )
static

Definition at line 288 of file Sensor.cpp.

289{
291}
static TMap< FString, FColor > GetSemanticColors()

References USemanticColors::GetSemanticColors().

Referenced by ALidar::BeginPlay().

◆ GetSensorIdentifier()

FString ASensor::GetSensorIdentifier ( ) const
inline

Get sensor's identifier

Returns
sensor identifier as FString

Definition at line 74 of file Sensor.h.

75 {
76 return SensorIdentifier;
77 }
FString SensorIdentifier
Definition: Sensor.h:375

Referenced by CreateDataSavePath(), CreateROSTopic(), ADVSCamera::CreateROSTopic(), ATransformSensor::CreateROSTopic(), EndPlay(), ADVSCamera::Init(), USensorFactory::SetSensorIdentifierAndNameWithFallbacks(), and ACamera::SetupCamera().

◆ GetSensorModel()

ASensorModel * ASensor::GetSensorModel ( ) const
inline

Retrieves the sensor model associated with this sensor.

Note
The returned pointer can be nullptr if no sensor model is set for this sensor.
Returns
A pointer to the associated sensor model or nullptr if not set.

Definition at line 172 of file Sensor.h.

173 {
174 return SensorModel.Get();
175 }
TObjectPtr< ASensorModel > SensorModel
Definition: Sensor.h:372

Referenced by USimulatorJsonParser::AttachActorToSpectatorCamera().

◆ GetSensorName()

FString ASensor::GetSensorName ( ) const
inline

Get sensor's name

Returns
Name

Definition at line 95 of file Sensor.h.

96 {
97 return SensorName;
98 }
FString SensorName
Definition: Sensor.h:378

Referenced by ACamera::AddPostProcessingMaterial(), CreateLogFile(), CreateROSTopic(), and USimulatorJsonExporter::CreateSensorJSONObject().

◆ GetSensorType()

virtual ESensorTypes ASensor::GetSensorType ( ) const
inlinevirtual

◆ GetTopicName()

virtual FString ASensor::GetTopicName ( )
inlinevirtual

Get ROS topic name for this sensor

Returns
Topic name

Definition at line 124 of file Sensor.h.

125 {
126 FString Name = "Undefined";
127
128 if (ROSTopic)
129 {
130 Name = ROSTopic->GetName();
131 }
132
133 return Name;
134 }

◆ HideComponentForAllCameras()

void ASensor::HideComponentForAllCameras ( UPrimitiveComponent *  PrimitiveComponent)
static

Static method to hide a specified primitive component for all cameras in the World.

Parameters
PrimitiveComponentThe UPrimitiveComponent to be hidden for all cameras.

Definition at line 278 of file Sensor.cpp.

279{
280 if (PrimitiveComponent)
281 {
282 TWeakObjectPtr<UPrimitiveComponent> Component(PrimitiveComponent);
283 ComponentsToHide.Add(Component);
284 OnPrimitiveAdded.Broadcast(PrimitiveComponent);
285 }
286}
static FPrimitiveAdded OnPrimitiveAdded
Definition: Sensor.h:354

References ComponentsToHide, and OnPrimitiveAdded.

Referenced by ALidar::BeginPlay(), ASpectator::BeginPlay(), USensorUtilities::HideComponentForAllCameraSensors(), and ARadar::Init().

◆ IsLogFileCreated()

bool ASensor::IsLogFileCreated ( )
inlineprotected

Does log file exists for this sensor.

Definition at line 316 of file Sensor.h.

317 {
318 if (LogFile)
319 {
320 return true;
321 }
322
323 return false;
324 }

◆ IsROSConnected()

FORCEINLINE bool ASensor::IsROSConnected ( ) const
inline

◆ ROSBridgeStateChanged()

void ASensor::ROSBridgeStateChanged ( EROSState  ROSState)
private

Callback when ROS Bridge state changed. Must be marked as UFUNCTION.

Definition at line 141 of file Sensor.cpp.

142{
143 switch (ROSState)
144 {
146 ROSConnected = true;
148 break;
149
151 ROSConnected = false;
153 break;
154 }
155}
virtual void CreateROSTopic()
Definition: Sensor.cpp:169

References Connected, CreateROSTopic(), DestroyROSTopic(), Disconnected, and ROSConnected.

Referenced by BeginPlay(), and EndPlay().

◆ SetActorIDAndName_Implementation()

virtual void ASensor::SetActorIDAndName_Implementation ( const FString &  NewActorName,
const FString &  NewID 
)
inlineoverridevirtual

Definition at line 237 of file Sensor.h.

238 {
239 SetSensorName(NewActorName);
240 SetSensorIdentifier(NewID);
241 }
void SetSensorName(const FString newName)
Definition: Sensor.h:114
void SetSensorIdentifier(const FString newIdentifier)
Definition: Sensor.h:84

◆ SetActorName_Implementation()

virtual void ASensor::SetActorName_Implementation ( const FString &  NewActorName)
inlineoverridevirtual

Definition at line 232 of file Sensor.h.

233 {
234 SetSensorName(NewActorName);
235 }

◆ SetSensorIdentifier()

void ASensor::SetSensorIdentifier ( const FString  newIdentifier)
inline

Set sensor's identifier

Parameters
newIdentifierNew identifier

Definition at line 84 of file Sensor.h.

85 {
86 SensorIdentifier = newIdentifier;
87 SetAndValidateActorIDAndName(SensorName, SensorIdentifier, TWeakObjectPtr<AActor>(this));
88 }
static void SetAndValidateActorIDAndName(FString &ActorName, FString &ActorID, TWeakObjectPtr< AActor > Actor)

Referenced by USensorFactory::SetSensorIdentifierAndNameWithFallbacks().

◆ SetSensorModel()

void ASensor::SetSensorModel ( ASensorModel NewSensorModel)
inline

Sets the sensor model for sensor.

Parameters
NewSensorModelThe new sensor model to set.

Definition at line 182 of file Sensor.h.

183 {
184 SensorModel = NewSensorModel;
185 }

Referenced by USensorFactory::SpawnModelClass().

◆ SetSensorName()

void ASensor::SetSensorName ( const FString  newName)
inline

Set sensor's name

Parameters
newIdentifierNew name

Definition at line 114 of file Sensor.h.

115 {
116 SensorName = newName;
117 }

Referenced by USensorFactory::SetSensorIdentifierAndNameWithFallbacks().

◆ SetSimulateSensor()

void ASensor::SetSimulateSensor ( bool  SimulateSensor)
inline

◆ StructToString()

template<typename InStructType >
static FString ASensor::StructToString ( const InStructType &  InStruct)
inlinestaticprotected

Templated function to convert any struct to JSON string representation for logging and debugging purposes.

Template Parameters
InStructTypeThe type of the structure to be converted to a JSON string.
Parameters
InStructThe structure instance to be converted.
Returns
A FString containing the JSON string representation of the input structure.

Definition at line 305 of file Sensor.h.

306 {
307 FString AsString;
308 FJsonObjectConverter::UStructToJsonObjectString(InStruct, AsString);
309 return AsString;
310 }

◆ WriteToLogFile()

void ASensor::WriteToLogFile ( const FString &  Message)
protected

Write to text file. If the text file doesn't exits, it will be created.

Definition at line 265 of file Sensor.cpp.

266{
267 if (!IsValid(LogFile) && IsValid(this))
268 {
270 }
271
272 if (IsValid(LogFile))
273 {
274 LogFile->Write(Message);
275 }
276}
virtual void CreateLogFile()
Definition: Sensor.cpp:235
void Write(const FString &Text)
Definition: LogFile.cpp:119

References CreateLogFile(), LogFile, and ULogFile::Write().

Referenced by AOverlapSensor::BuildAndSendMessage(), ACamera::CreateLogFile(), ACollisionSensor::OnCollisionEvent(), and ACamera::SaveCameraMetaDataToDisk().

Member Data Documentation

◆ AttachedToBone

FName ASensor::AttachedToBone

Definition at line 275 of file Sensor.h.

Referenced by USimulatorJsonExporter::CreateSensorJSONObject().

◆ AttachedToComponent

FString ASensor::AttachedToComponent

Definition at line 272 of file Sensor.h.

Referenced by USimulatorJsonExporter::CreateSensorJSONObject().

◆ ComponentsToHide

TArray< TWeakObjectPtr< UPrimitiveComponent > > ASensor::ComponentsToHide
staticprivate

Definition at line 386 of file Sensor.h.

Referenced by EndPlay(), and HideComponentForAllCameras().

◆ FileSavePath

FString ASensor::FileSavePath
protected

◆ LogFile

ULogFile* ASensor::LogFile = nullptr
protected

◆ NiagaraHitColors

const FName ASensor::NiagaraHitColors = "User.HitColors"
inlinestaticprotected

Definition at line 359 of file Sensor.h.

Referenced by ALidar::UpdateLidarParticles().

◆ NiagaraHitPoints

const FName ASensor::NiagaraHitPoints = "User.HitPoints"
inlinestaticprotected

Definition at line 358 of file Sensor.h.

Referenced by ARadar::SimulateRadar(), and ALidar::UpdateLidarParticles().

◆ NiagaraPointsFloat

const FName ASensor::NiagaraPointsFloat = "User.Test"
inlinestaticprotected

Definition at line 360 of file Sensor.h.

Referenced by ARadar::SimulateRadar(), and ALidar::UpdateLidarParticles().

◆ NiagaraPointsInt

const FName ASensor::NiagaraPointsInt = "User.PointCount"
inlinestaticprotected

Definition at line 357 of file Sensor.h.

Referenced by ARadar::SimulateRadar(), and ALidar::UpdateLidarParticles().

◆ OnPrimitiveAdded

FPrimitiveAdded ASensor::OnPrimitiveAdded
staticprotected

Definition at line 354 of file Sensor.h.

Referenced by ACamera::BeginPlay(), and HideComponentForAllCameras().

◆ OnSensorDestroy

FSensorDestroy ASensor::OnSensorDestroy

Definition at line 269 of file Sensor.h.

Referenced by EndPlay().

◆ ROSConnected

bool ASensor::ROSConnected = false
private

Definition at line 384 of file Sensor.h.

Referenced by BeginPlay(), and ROSBridgeStateChanged().

◆ ROSInstance

UROSIntegrationGameInstance* ASensor::ROSInstance = nullptr
protected

◆ ROSTopic

UTopic* ASensor::ROSTopic = nullptr
protected

◆ SendDataToROS

bool ASensor::SendDataToROS = true
protected

◆ SensorIdentifier

FString ASensor::SensorIdentifier
private

Definition at line 375 of file Sensor.h.

◆ SensorModel

TObjectPtr<ASensorModel> ASensor::SensorModel
private

Definition at line 372 of file Sensor.h.

◆ SensorName

FString ASensor::SensorName
private

Definition at line 378 of file Sensor.h.

◆ SimulateThisSensor

bool ASensor::SimulateThisSensor = true
private

Definition at line 381 of file Sensor.h.


The documentation for this class was generated from the following files: