8#include "CoreMinimal.h"
9#include "GameFramework/Actor.h"
10#include "Engine/EngineTypes.h"
11#include "Engine/World.h"
12#include "Templates/SharedPointer.h"
13#include "UObject/ObjectPtr.h"
14#include "Containers/UnrealString.h"
15#include "Components/PrimitiveComponent.h"
16#include "JsonObjectConverter.h"
20#include "ROSIntegration/Classes/ROSIntegrationGameInstance.h"
21#include "ROSIntegration/Classes/RI/Topic.h"
31#include "Sensor.generated.h"
49 ASensor(
const FObjectInitializer& ObjectInitializer);
56 UFUNCTION(BlueprintCallable)
57 FString ExportToJsonFile(
const FString& FileName);
63 UFUNCTION(BlueprintCallable)
73 UFUNCTION(BlueprintPure)
74 FString GetSensorIdentifier()
const
76 return SensorIdentifier;
83 UFUNCTION(BlueprintCallable)
84 void SetSensorIdentifier(const FString newIdentifier)
86 SensorIdentifier = newIdentifier;
87 SetAndValidateActorIDAndName(SensorName, SensorIdentifier, TWeakObjectPtr<AActor>(
this));
94 UFUNCTION(BlueprintPure)
95 FString GetSensorName()
const
103 UFUNCTION(BlueprintPure)
104 virtual FString GetParametersAsString()
const
113 UFUNCTION(BlueprintCallable)
114 void SetSensorName(const FString newName)
116 SensorName = newName;
123 UFUNCTION(BlueprintPure)
124 virtual FString GetTopicName()
126 FString Name =
"Undefined";
130 Name = ROSTopic->GetName();
140 UFUNCTION(BlueprintCallable)
141 UTopic* GetROSTopic()
const
150 UFUNCTION(BlueprintCallable)
151 void SetSimulateSensor(
bool SimulateSensor)
153 SimulateThisSensor = SimulateSensor;
160 UFUNCTION(BlueprintCallable)
161 inline
bool CanSimulateSensor()
const
163 return SimulateThisSensor;
171 UFUNCTION(BlueprintCallable, BlueprintPure)
174 return SensorModel.Get();
181 UFUNCTION(BlueprintCallable)
184 SensorModel = NewSensorModel;
191 UFUNCTION(BlueprintCallable)
192 bool IsROSConnected()
const
201 UFUNCTION(BlueprintPure)
202 UROSIntegrationGameInstance* GetROSGameInstance()
const
209 return GetSensorIdentifier();
214 return GetSensorName();
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();
226 FString Information = FString::Printf(TEXT(
"Sensor: %s \nID: %s \nLocation: %s \nRotation: %s \nParameters: %s"),
227 *Sensor, *ID, *Location.ToString(), *Rotation.ToString(), *Parameters);
234 SetSensorName(NewActorName);
239 SetSensorName(NewActorName);
240 SetSensorIdentifier(NewID);
247 static void HideComponentForAllCameras(UPrimitiveComponent* PrimitiveComponent);
249 UFUNCTION(BlueprintCallable)
250 static TMap<FString, FColor> GetSemanticColors();
260 ComponentsToHide.RemoveAll([](
const TWeakObjectPtr<UPrimitiveComponent>& WeakComponent)
262 return !WeakComponent.IsValid();
265 return ComponentsToHide;
268 UPROPERTY(BlueprintAssignable)
269 FSensorDestroy OnSensorDestroy;
271 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sensor")
272 FString AttachedToComponent;
274 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sensor")
275 FName AttachedToBone;
279 virtual
void BeginPlay() override;
281 virtual
void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
286 virtual
void CreateROSTopic();
291 virtual
void DestroyROSTopic();
296 virtual
void CreateDataSavePath();
304 template<typename InStructType>
305 static FString StructToString(const InStructType& InStruct)
308 FJsonObjectConverter::UStructToJsonObjectString(InStruct, AsString);
315 UFUNCTION(BlueprintCallable, BlueprintPure)
316 bool IsLogFileCreated()
331 UFUNCTION(BlueprintCallable)
332 virtual void CreateLogFile();
337 UFUNCTION(BlueprintCallable)
338 void WriteToLogFile(
const FString& Message);
341 UTopic* ROSTopic =
nullptr;
343 UPROPERTY(VisibleAnywhere, Category = "Sensor")
344 bool SendDataToROS = true;
349 FString FileSavePath;
352 UROSIntegrationGameInstance* ROSInstance =
nullptr;
354 static FPrimitiveAdded OnPrimitiveAdded;
357 inline static const FName NiagaraPointsInt = "User.PointCount";
358 inline static const FName NiagaraHitPoints = "User.HitPoints";
359 inline static const FName NiagaraHitColors = "User.HitColors";
360 inline static const FName NiagaraPointsFloat = "User.Test";
369 void ROSBridgeStateChanged(
EROSState ROSState);
374 UPROPERTY(EditAnywhere, Category = "Sensor")
375 FString SensorIdentifier;
377 UPROPERTY(EditAnywhere, Category = "Sensor")
380 UPROPERTY(EditAnywhere, Category = "Sensor")
381 bool SimulateThisSensor = true;
383 UPROPERTY(VisibleAnywhere, Category = "Sensor")
384 bool ROSConnected = false;
386 static TArray<TWeakObjectPtr<UPrimitiveComponent>> ComponentsToHide;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSensorDestroy, ASensor *, sensor)
virtual FString GetActorID_Implementation() const override
static TArray< TWeakObjectPtr< UPrimitiveComponent > > GetComponentsToHide()
virtual void SetActorName_Implementation(const FString &NewActorName) override
virtual void SetActorIDAndName_Implementation(const FString &NewActorName, const FString &NewID) override
virtual FString GetActorName_Implementation() const override
virtual FString GetActorInformation_Implementation() const override
static FString ConvertSensorTypeToString(ESensorTypes Sensortype)