15#include "Kismet/GameplayStatics.h"
16#include "TimerManager.h"
17#include "UObject/Class.h"
22ASensor::ASensor(
const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
24 RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT(
"SceneRoot"));
31 UWorld* World = GetWorld();
49 World->GetTimerManager().SetTimer(Handle, FTimerDelegate::CreateLambda([
this]
68 Super::EndPlay(EndPlayReason);
76 FString Sensor = UEnum::GetDisplayValueAsText(
GetSensorType()).ToString();
78 FString Message = FString::Printf(TEXT(
"Destroyed %s sensor with ID: %s"), *Sensor, *ID);
81 if (EndPlayReason == EEndPlayReason::EndPlayInEditor
82 || EndPlayReason == EEndPlayReason::Quit)
86 WeakComponentPtr.Reset();
92 TArray<AActor*> AttachedActors;
93 GetAttachedActors(AttachedActors);
94 for (AActor* Actor : AttachedActors)
141 ROSTopic->ConditionalBeginDestroy();
163 MessageType =
"sensor_msgs/PointCloud2";
171 MessageType =
"sensor_msgs/Image";
175 MessageType =
"geometry_msgs/Transform";
180 MessageType =
"std_msgs/String";
185 UE_LOG(LogTemp, Warning, TEXT(
"Unhandled ROS sensor message creation for sensor: %s"), *SensorNameString);
189 FString TopicName = FString::Printf(TEXT(
"/agrarsense/out/sensors/%s"), *
GetSensorIdentifier());
191 ROSTopic = NewObject<UTopic>(UTopic::StaticClass());
198 FString Message = FString::Printf(TEXT(
"%s sensor created ROS topic. Name: '%s' MessageType: '%s' "), *
GetSensorName(), *TopicName, *MessageType);
207 FString UnixTimeStamp = FString::FromInt(FDateTime::Now().ToUnixTimestamp());
226 LogFile = NewObject<ULogFile>(ULogFile::StaticClass());
230 FString UnixTimeStamp = FString::FromInt(FDateTime::Now().ToUnixTimestamp());
235 ActorID.ReplaceInline(TEXT(
"/"), TEXT(
""), ESearchCase::IgnoreCase);
237 FString FileName = FString::Printf(TEXT(
"%s_%s_%s"), *
GetSensorName(), *ActorID, *UnixTimeStamp);
244 if (!IsValid(
LogFile) && IsValid(
this))
257 if (PrimitiveComponent)
259 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)
virtual FString GetActorID_Implementation() const override
bool IsROSConnected() const
void WriteToLogFile(const FString &Message)
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
virtual void CreateROSTopic()
virtual FString GetActorInformation_Implementation() const override
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 void AddSensor(ASensor *SensorPtr)
static void RemoveSensor(ASensor *SensorPtr)
static FString ExportSensorToJSON(const FString &FileName, ASensor *Sensor)
FFileWriteOptions FileWriteOptions
FFileCreationOptions FileCreationOptions