17#include "Kismet/GameplayStatics.h"
18#include "TimerManager.h"
19#include "UObject/Class.h"
24ASensor::ASensor(
const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
26 RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT(
"SceneRoot"));
27 RootComponent->SetMobility(EComponentMobility::Movable);
34 UWorld* World = GetWorld();
52 World->GetTimerManager().SetTimer(Handle, FTimerDelegate::CreateLambda([
this]
56 FString ActorInformation = IActorInformation::Execute_GetActorInformation(
this);
57 FString Message = FString::Printf(TEXT(
"Spawned %s"), *ActorInformation);
81 FString ActorID = IActorInformation::Execute_GetActorID(
this);
82 FString SensorTransformSensorID = ActorID +
"/transform";
94 Super::EndPlay(EndPlayReason);
102 FString Sensor = UEnum::GetDisplayValueAsText(
GetSensorType()).ToString();
104 FString Message = FString::Printf(TEXT(
"Destroyed %s sensor with ID: %s"), *Sensor, *ID);
107 if (EndPlayReason == EEndPlayReason::EndPlayInEditor
108 || EndPlayReason == EEndPlayReason::Quit)
112 WeakComponentPtr.Reset();
119 TArray<AActor*> AttachedActors;
120 GetAttachedActors(AttachedActors);
121 for (AActor* Actor : AttachedActors)
168 ROSTopic->ConditionalBeginDestroy();
190 MessageType =
"sensor_msgs/PointCloud2";
198 MessageType =
"sensor_msgs/Image";
202 MessageType =
"geometry_msgs/Transform";
207 MessageType =
"std_msgs/String";
212 UE_LOG(LogTemp, Warning, TEXT(
"Unhandled ROS sensor message creation for sensor: %s"), *SensorNameString);
216 FString TopicName = FString::Printf(TEXT(
"/agrarsense/out/sensors/%s"), *
GetSensorIdentifier());
218 ROSTopic = NewObject<UTopic>(UTopic::StaticClass());
225 FString Message = FString::Printf(TEXT(
"%s sensor created ROS topic. Name: '%s' MessageType: '%s' "), *
GetSensorName(), *TopicName, *MessageType);
234 FString UnixTimeStamp = FString::FromInt(FDateTime::Now().ToUnixTimestamp());
253 LogFile = NewObject<ULogFile>(ULogFile::StaticClass());
257 FString UnixTimeStamp = FString::FromInt(FDateTime::Now().ToUnixTimestamp());
259 FString ActorID = IActorInformation::Execute_GetActorID(
this);
262 ActorID.ReplaceInline(TEXT(
"/"), TEXT(
""), ESearchCase::IgnoreCase);
264 FString FileName = FString::Printf(TEXT(
"%s_%s_%s"), *
GetSensorName(), *ActorID, *UnixTimeStamp);
271 if (!IsValid(
LogFile) && IsValid(
this))
284 if (PrimitiveComponent)
286 TWeakObjectPtr<UPrimitiveComponent> Component(PrimitiveComponent);
@ SemanticSegmentationCamera
static TArray< TWeakObjectPtr< UPrimitiveComponent > > ComponentsToHide
virtual void DestroyROSTopic()
virtual void CreateLogFile()
void ROSBridgeStateChanged(EROSState ROSState)
UROSIntegrationGameInstance * ROSInstance
static void HideComponentForAllCameras(UPrimitiveComponent *PrimitiveComponent)
virtual void BeginPlay() override
FSensorDestroy OnSensorDestroy
static FPrimitiveAdded OnPrimitiveAdded
FString GetSensorIdentifier() const
virtual void CreateDataSavePath()
FString GetSensorName() const
virtual ESensorTypes GetSensorType() const
FString ExportToJsonFile(const FString &FileName)
void WriteToLogFile(const FString &Message)
FORCEINLINE bool IsROSConnected() const
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
virtual void CreateROSTopic()
ASensor(const FObjectInitializer &ObjectInitializer)
static TMap< FString, FColor > GetSemanticColors()
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)
static FString GetDataFolder()
static UROSIntegrationGameInstance * GetROSGameInstance(const UObject *WorldContextObject)
static UROSHandler * GetROSHandle(const UObject *WorldContextObject)
static FString ConvertSensorTypeToString(ESensorTypes Sensortype)
void Write(const FString &Text)
void Create(const FString &FileNameWithoutExtension, FLogFileSettings Settings)
FROSDelegate_ROState OnROSStateChanged
static TMap< FString, FColor > GetSemanticColors()
static ATransformSensor * SpawnTransformSensor(const FTransform &transform, AActor *Owner, const FString sensorIdentifier, const FString sensorName, bool SimulateSensor=true)
static void AddSensor(ASensor *SensorPtr)
static void RemoveSensor(ASensor *SensorPtr)
static FString ExportSensorToJSON(const FString &FileName, ASensor *Sensor)
FFileWriteOptions FileWriteOptions
FFileCreationOptions FileCreationOptions