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
 
AVehicleIsAttachedToVehicle () const
 
void SetSensorName (const FString newName)
 
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
 
void SetParentActorPtr (AActor *ParentActorPtr)
 
- 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
 
FString CreateTimeStampString () const
 
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
 
AActor * ParentActor = 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 44 of file Sensor.h.

Constructor & Destructor Documentation

◆ ASensor()

ASensor::ASensor ( const FObjectInitializer &  ObjectInitializer)

Definition at line 27 of file Sensor.cpp.

27 : Super(ObjectInitializer)
28{
29 RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneRoot"));
30 RootComponent->SetMobility(EComponentMobility::Movable);
31}

Member Function Documentation

◆ BeginPlay()

void ASensor::BeginPlay ( )
overrideprotectedvirtual

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

Definition at line 33 of file Sensor.cpp.

34{
35 Super::BeginPlay();
36
37 UWorld* World = GetWorld();
38
40 if (ROSHandler)
41 {
42 // Subscribe to ROS changed event
43 ROSHandler->OnROSStateChanged.AddUniqueDynamic(this, &ASensor::ROSBridgeStateChanged);
44 }
45
47 if (ROSInstance)
48 {
49 // Check if ROS is connected at BeginPlay
50 ROSConnected = ROSInstance->IsROSConnected();
51 }
52
53 // Delay logging sensor information message so each sensor have time setup fully.
54 FTimerHandle Handle;
55 World->GetTimerManager().SetTimer(Handle, FTimerDelegate::CreateLambda([this]
56 {
57 if (IsValid(this))
58 {
59 FString ActorInformation = IActorInformation::Execute_GetActorInformation(this);
60 FString Message = FString::Printf(TEXT("Spawned %s"), *ActorInformation);
61
62 SimulatorLog::Log(Message);
63 }
64 }), 0.150f, false);
65
66 // Inform sensor manager that new sensor has been spawned.
68
69 ESensorTypes ThisSensorType = GetSensorType();
70
71 if (ThisSensorType != ESensorTypes::NONE &&
72 ThisSensorType != ESensorTypes::Transform &&
73 ThisSensorType != ESensorTypes::Collision &&
74 ThisSensorType != ESensorTypes::Overlap)
75 {
76 // Spawn a Transform sensor for any sensor type other than NONE, Transform, Collision, or Overlap.
77 // Meaning each sensor, like a Lidar sensor, has its own Transform sensor that publishes its:
78 // - World location
79 // - GNSS location (if world has GNSS setup)
80
81 // We don't need to keep track of this TransformSensor Actor as it should
82 // be automatically destroyed when the parent sensor is destroyed (ASensor EndPlay)
83 const FString ActorID = IActorInformation::Execute_GetActorID(this);
84 const FString SensorTransformSensorID = ActorID + "/transform";
85
86 FSensorSpawnParameters SpawnParams;
87 SpawnParams.Transform = GetActorTransform();
88 SpawnParams.SensorIdentifier = SensorTransformSensorID;
89 SpawnParams.SensorName = "transform";
90 SpawnParams.SimulateSensor = true;
91 SpawnParams.Parent = this;
92
93 FTransformSensorParameters SensorParams;
94 SensorParams.SaveTransformDataToDisk = false;
95 SensorParams.OwningActor = this;
96
97 USensorFactory::SpawnTransformSensor(SpawnParams, SensorParams);
98 }
99}
ESensorTypes
Definition: SensorTypes.h:15
void ROSBridgeStateChanged(EROSState ROSState)
Definition: Sensor.cpp:169
UROSIntegrationGameInstance * ROSInstance
Definition: Sensor.h:375
virtual ESensorTypes GetSensorType() const
Definition: Sensor.h:65
bool ROSConnected
Definition: Sensor.h:407
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 FSensorSpawnParameters SpawnParameters, FTransformSensorParameters SensorParameters)
static void AddSensor(ASensor *SensorPtr)

References USensorManager::AddSensor(), Collision, UAgrarsenseStatics::GetROSGameInstance(), UAgrarsenseStatics::GetROSHandle(), GetSensorType(), SimulatorLog::Log(), NONE, UROSHandler::OnROSStateChanged, Overlap, FTransformSensorParameters::OwningActor, FSensorSpawnParameters::Parent, ROSBridgeStateChanged(), ROSConnected, ROSInstance, FTransformSensorParameters::SaveTransformDataToDisk, FSensorSpawnParameters::SensorIdentifier, FSensorSpawnParameters::SensorName, FSensorSpawnParameters::SimulateSensor, USensorFactory::SpawnTransformSensor(), FSensorSpawnParameters::Transform, 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 170 of file Sensor.h.

171 {
172 return SimulateThisSensor;
173 }
bool SimulateThisSensor
Definition: Sensor.h:404

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.

Reimplemented in ACollisionSensor, AOverlapSensor, and ATransformSensor.

Definition at line 254 of file Sensor.cpp.

255{
256 if (FileSavePath.IsEmpty())
257 {
258 const FString DataLocation = UAgrarsensePaths::GetDataFolder();
259
261 {
262 FString VehicleName = Vehicle->GetActorID_Implementation();
263 FileSavePath = DataLocation + VehicleName + "/" + GetActorID_Implementation() + "/";
264 }
265 else
266 {
267 FileSavePath = DataLocation + GetActorID_Implementation() + "/";
268 }
269 }
270}
AVehicle * IsAttachedToVehicle() const
Definition: Sensor.cpp:159
virtual FString GetActorID_Implementation() const override
Definition: Sensor.h:216
FString FileSavePath
Definition: Sensor.h:372
static FString GetDataFolder()

References FileSavePath, GetActorID_Implementation(), UAgrarsensePaths::GetDataFolder(), IsAttachedToVehicle(), and Vehicle.

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, ACollisionSensor, ALidar, AOverlapSensor, and ATransformSensor.

Definition at line 272 of file Sensor.cpp.

273{
274 if (IsValid(LogFile))
275 {
276 // File has already been created, return
277 return;
278 }
279
280 FLogFileSettings Settings;
283 Settings.QueueLength = 10;
284 Settings.KeepFileOpen = false;
285
286 LogFile = NewObject<ULogFile>(ULogFile::StaticClass());
287 if (LogFile)
288 {
289 // FileName is SensorName_ID_UnixTimeStamp.txt
290 FString UnixTimeStamp = FString::FromInt(FDateTime::Now().ToUnixTimestamp());
291
292 FString ActorID = IActorInformation::Execute_GetActorID(this);
293
294 // Temp fix, Remove all "/" from ActorID
295 ActorID.ReplaceInline(TEXT("/"), TEXT(""), ESearchCase::IgnoreCase);
296
297 FString FileName = FString::Printf(TEXT("%s_%s_%s"), *GetSensorName(), *ActorID, *UnixTimeStamp);
298 LogFile->Create(FileName, Settings);
299 }
300}
FString GetSensorName() const
Definition: Sensor.h:96
ULogFile * LogFile
Definition: Sensor.h:367
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, 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 197 of file Sensor.cpp.

198{
199 if (!SendDataToROS
200 || ROSTopic
201 || !ROSInstance
202 || !IsROSConnected())
203 {
204 return;
205 }
206
207 FString MessageType;
208 ESensorTypes SensorType = GetSensorType();
209
210 switch (SensorType)
211 {
214 MessageType = "sensor_msgs/PointCloud2";
215 break;
216
222 case ESensorTypes::DVSCamera: // DVS Camera should override this.
223 MessageType = "sensor_msgs/Image";
224 break;
225
227 MessageType = "geometry_msgs/Transform";
228 break;
229
232 MessageType = "std_msgs/String";
233 break;
234
235 default:
236 FString SensorNameString = UEnumUtilities::ConvertSensorTypeToString(SensorType);
237 UE_LOG(LogTemp, Warning, TEXT("Unhandled ROS sensor message creation for sensor: %s"), *SensorNameString);
238 break;
239 }
240
241 const FString TopicName = FString::Printf(TEXT("/agrarsense/out/sensors/%s"), *GetSensorIdentifier());
242
243 ROSTopic = NewObject<UTopic>(UTopic::StaticClass());
244 if (ROSTopic)
245 {
246 ROSTopic->Init(ROSInstance->ROSIntegrationCore, TopicName, MessageType);
247 ROSTopic->Advertise();
248 }
249
250 const FString Message = FString::Printf(TEXT("%s sensor created ROS topic. Name: '%s' MessageType: '%s' "), *GetSensorName(), *TopicName, *MessageType);
251 SimulatorLog::Log(Message);
252}
@ SemanticSegmentationCamera
@ InstanceSegmentationCamera
FString GetSensorIdentifier() const
Definition: Sensor.h:75
UTopic * ROSTopic
Definition: Sensor.h:361
bool SendDataToROS
Definition: Sensor.h:364
FORCEINLINE bool IsROSConnected() const
Definition: Sensor.h:201
static FString ConvertSensorTypeToString(ESensorTypes Sensortype)

References Collision, UEnumUtilities::ConvertSensorTypeToString(), DepthCamera, DVSCamera, GetSensorIdentifier(), GetSensorName(), GetSensorType(), InstanceSegmentationCamera, 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().

◆ CreateTimeStampString()

FString ASensor::CreateTimeStampString ( ) const
protected

Definition at line 330 of file Sensor.cpp.

331{
332 FDateTime Now = FDateTime::Now();
333 FString TimeStamp = FString::Printf(TEXT("%02d:%02d:%04d:%02d:%02d:%02d:%03d"),
334 Now.GetDay(), Now.GetMonth(), Now.GetYear(),
335 Now.GetHour(), Now.GetMinute(), Now.GetSecond(), Now.GetMillisecond());
336
337 return TimeStamp;
338}

Referenced by ACamera::SaveCameraMetaDataToDisk(), ALidar::SaveLidarMetaDataToDisk(), and ATransformSensor::SaveTransformMetaDataToDisk().

◆ DestroyROSTopic()

void ASensor::DestroyROSTopic ( )
protectedvirtual

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

Reimplemented in ATransformSensor.

Definition at line 185 of file Sensor.cpp.

186{
187 if (ROSTopic)
188 {
189 ROSTopic->Unadvertise();
190 ROSTopic->Unsubscribe();
191 ROSTopic->MarkAsDisconnected();
192 ROSTopic->ConditionalBeginDestroy();
193 ROSTopic = nullptr;
194 }
195}

References ROSTopic.

Referenced by EndPlay(), and ROSBridgeStateChanged().

◆ EndPlay()

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

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

Definition at line 101 of file Sensor.cpp.

102{
103 // Broadcast that this sensor will be destroyed
104 OnSensorDestroy.Broadcast(this);
105
107
108 Super::EndPlay(EndPlayReason);
109
110 UROSHandler* ROSHandler = UAgrarsenseStatics::GetROSHandle(GetWorld());
111 if (ROSHandler)
112 {
113 ROSHandler->OnROSStateChanged.RemoveDynamic(this, &ASensor::ROSBridgeStateChanged);
114 }
115
116 const FString Sensor = UEnum::GetDisplayValueAsText(GetSensorType()).ToString();
117 const FString ID = GetSensorIdentifier();
118 const FString Message = FString::Printf(TEXT("Destroyed %s sensor with ID: %s"), *Sensor, *ID);
119 SimulatorLog::Log(Message);
120
121 if (EndPlayReason == EEndPlayReason::EndPlayInEditor
122 || EndPlayReason == EEndPlayReason::Quit)
123 {
124 for (auto& WeakComponentPtr : ComponentsToHide)
125 {
126 WeakComponentPtr.Reset();
127 }
128 ComponentsToHide.Empty();
129 }
130
131 // Destroy all Actors that are attached to this sensor like:
132 // Sensor model Actor and TransformSensor Actor.
133 TArray<AActor*> AttachedActors;
134 GetAttachedActors(AttachedActors);
135 for (AActor* Actor : AttachedActors)
136 {
137 if (Actor)
138 {
139 Actor->Destroy();
140 }
141 }
142
143 ROSInstance = nullptr;
144
145 if (LogFile)
146 {
147 LogFile->Destroy();
148 LogFile = nullptr;
149 }
150
152}
static TArray< TWeakObjectPtr< UPrimitiveComponent > > ComponentsToHide
Definition: Sensor.h:409
virtual void DestroyROSTopic()
Definition: Sensor.cpp:185
FSensorDestroy OnSensorDestroy
Definition: Sensor.h:283
void Destroy()
Definition: LogFile.cpp:174
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 154 of file Sensor.cpp.

155{
156 return USimulatorJsonExporter::ExportSensorToJSON(FileName, this);
157}
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 226 of file Sensor.h.

227 {
229 const FString ID = IActorInformation::Execute_GetActorID(this);
230 const FTransform Transform = GetActorTransform();
231 const FVector Location = Transform.GetLocation();
232 const FRotator Rotation = Transform.Rotator();
233 const FString Parameters = GetParametersAsString();
234
235 FString Information = FString::Printf(TEXT("Sensor: %s \nID: %s \nLocation: %s \nRotation: %s \nParameters: %s"),
236 *Sensor, *ID, *Location.ToString(), *Rotation.ToString(), *Parameters);
237
238 return Information;
239 }
virtual FString GetParametersAsString() const
Definition: Sensor.h:105

References UEnumUtilities::ConvertSensorTypeToString(), and Transform.

◆ GetActorName_Implementation()

virtual FString ASensor::GetActorName_Implementation ( ) const
inlineoverridevirtual

Definition at line 221 of file Sensor.h.

222 {
223 return GetSensorName();
224 }

◆ 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 270 of file Sensor.h.

271 {
272 // Since we don't know whether some UPrimitiveComponent has been destroyed,
273 // we need to check these are still valid.
274 ComponentsToHide.RemoveAll([](const TWeakObjectPtr<UPrimitiveComponent>& WeakComponent)
275 {
276 return !WeakComponent.IsValid();
277 });
278
279 return ComponentsToHide;
280 }

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 105 of file Sensor.h.

106 {
107 return FString();
108 }

◆ 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 211 of file Sensor.h.

212 {
213 return ROSInstance;
214 }

◆ 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 150 of file Sensor.h.

151 {
152 return ROSTopic;
153 }

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 325 of file Sensor.cpp.

326{
328}
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 75 of file Sensor.h.

76 {
77 return SensorIdentifier;
78 }
FString SensorIdentifier
Definition: Sensor.h:398

Referenced by 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 181 of file Sensor.h.

182 {
183 return SensorModel.Get();
184 }
TObjectPtr< ASensorModel > SensorModel
Definition: Sensor.h:395

Referenced by USimulatorJsonParser::AttachActorToSpectatorCamera().

◆ GetSensorName()

FString ASensor::GetSensorName ( ) const
inline

Get sensor's name

Returns
Name

Definition at line 96 of file Sensor.h.

97 {
98 return SensorName;
99 }
FString SensorName
Definition: Sensor.h:401

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

◆ GetSensorType()

virtual ESensorTypes ASensor::GetSensorType ( ) const
inlinevirtual

◆ GetTopicName()

FString ASensor::GetTopicName ( )
inline

Get ROS topic name for this sensor

Returns
Topic name

Definition at line 133 of file Sensor.h.

134 {
135 FString Name = "Undefined";
136
137 if (ROSTopic)
138 {
139 Name = ROSTopic->GetName();
140 }
141
142 return Name;
143 }

◆ 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 315 of file Sensor.cpp.

316{
317 if (PrimitiveComponent)
318 {
319 TWeakObjectPtr<UPrimitiveComponent> Component(PrimitiveComponent);
320 ComponentsToHide.Add(Component);
321 OnPrimitiveAdded.Broadcast(PrimitiveComponent);
322 }
323}
static FPrimitiveAdded OnPrimitiveAdded
Definition: Sensor.h:377

References ComponentsToHide, and OnPrimitiveAdded.

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

◆ IsAttachedToVehicle()

AVehicle * ASensor::IsAttachedToVehicle ( ) const

Definition at line 159 of file Sensor.cpp.

160{
161 AVehicle* VehicleActor = Cast<AVehicle>(ParentActor);
162 if (VehicleActor)
163 {
164 return VehicleActor;
165 }
166 return nullptr;
167}
AActor * ParentActor
Definition: Sensor.h:370

References ParentActor.

Referenced by CreateDataSavePath(), ACollisionSensor::CreateDataSavePath(), AOverlapSensor::CreateDataSavePath(), ATransformSensor::CreateDataSavePath(), ACollisionSensor::CreateLogFile(), AOverlapSensor::CreateLogFile(), and ATransformSensor::CreateLogFile().

◆ IsLogFileCreated()

bool ASensor::IsLogFileCreated ( )
inlineprotected

Does log file exists for this sensor.

Definition at line 336 of file Sensor.h.

337 {
338 if (LogFile)
339 {
340 return true;
341 }
342
343 return false;
344 }

◆ 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 169 of file Sensor.cpp.

170{
171 switch (ROSState)
172 {
174 ROSConnected = true;
176 break;
177
179 ROSConnected = false;
181 break;
182 }
183}
virtual void CreateROSTopic()
Definition: Sensor.cpp:197

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 246 of file Sensor.h.

247 {
248 SetSensorName(NewActorName);
249 SetSensorIdentifier(NewID);
250 }
void SetSensorName(const FString newName)
Definition: Sensor.h:123
void SetSensorIdentifier(const FString newIdentifier)
Definition: Sensor.h:85

◆ SetActorName_Implementation()

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

Definition at line 241 of file Sensor.h.

242 {
243 SetSensorName(NewActorName);
244 }

◆ SetParentActorPtr()

void ASensor::SetParentActorPtr ( AActor *  ParentActorPtr)
inline

Definition at line 252 of file Sensor.h.

253 {
254 ParentActor = ParentActorPtr;
255 }

◆ SetSensorIdentifier()

void ASensor::SetSensorIdentifier ( const FString  newIdentifier)
inline

Set sensor's identifier

Parameters
newIdentifierNew identifier

Definition at line 85 of file Sensor.h.

86 {
87 SensorIdentifier = newIdentifier;
88 SetAndValidateActorIDAndName(SensorName, SensorIdentifier, TWeakObjectPtr<AActor>(this));
89 }
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 191 of file Sensor.h.

192 {
193 SensorModel = NewSensorModel;
194 }

Referenced by USensorFactory::SpawnModelClass().

◆ SetSensorName()

void ASensor::SetSensorName ( const FString  newName)
inline

Set sensor's name

Parameters
newIdentifierNew name

Definition at line 123 of file Sensor.h.

124 {
125 SensorName = newName;
126 }

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 325 of file Sensor.h.

326 {
327 FString AsString;
328 FJsonObjectConverter::UStructToJsonObjectString(InStruct, AsString);
329 return AsString;
330 }

◆ 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 302 of file Sensor.cpp.

303{
304 if (!IsValid(LogFile) && IsValid(this))
305 {
307 }
308
309 if (IsValid(LogFile))
310 {
311 LogFile->Write(Message);
312 }
313}
virtual void CreateLogFile()
Definition: Sensor.cpp:272
void Write(const FString &Text)
Definition: LogFile.cpp:123

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

Referenced by AOverlapSensor::BuildAndSendMessage(), ACamera::CreateLogFile(), ALidar::CreateLogFile(), ATransformSensor::CreateLogFile(), ACollisionSensor::OnCollisionEvent(), ACamera::SaveCameraMetaDataToDisk(), ALidar::SaveLidarMetaDataToDisk(), and ATransformSensor::SaveTransformMetaDataToDisk().

Member Data Documentation

◆ AttachedToBone

FName ASensor::AttachedToBone

Definition at line 289 of file Sensor.h.

Referenced by USimulatorJsonExporter::CreateSensorJSONObject().

◆ AttachedToComponent

FString ASensor::AttachedToComponent

Definition at line 286 of file Sensor.h.

Referenced by USimulatorJsonExporter::CreateSensorJSONObject().

◆ ComponentsToHide

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

Definition at line 409 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 382 of file Sensor.h.

Referenced by ALidar::UpdateLidarParticles().

◆ NiagaraHitPoints

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

Definition at line 381 of file Sensor.h.

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

◆ NiagaraPointsFloat

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

Definition at line 383 of file Sensor.h.

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

◆ NiagaraPointsInt

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

Definition at line 380 of file Sensor.h.

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

◆ OnPrimitiveAdded

FPrimitiveAdded ASensor::OnPrimitiveAdded
staticprotected

Definition at line 377 of file Sensor.h.

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

◆ OnSensorDestroy

FSensorDestroy ASensor::OnSensorDestroy

Definition at line 283 of file Sensor.h.

Referenced by EndPlay().

◆ ParentActor

AActor* ASensor::ParentActor = nullptr
protected

Definition at line 370 of file Sensor.h.

Referenced by ATransformSensor::CreateDataSavePath(), and IsAttachedToVehicle().

◆ ROSConnected

bool ASensor::ROSConnected = false
private

Definition at line 407 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 398 of file Sensor.h.

◆ SensorModel

TObjectPtr<ASensorModel> ASensor::SensorModel
private

Definition at line 395 of file Sensor.h.

◆ SensorName

FString ASensor::SensorName
private

Definition at line 401 of file Sensor.h.

◆ SimulateThisSensor

bool ASensor::SimulateThisSensor = true
private

Definition at line 404 of file Sensor.h.


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