14#include "DrawDebugHelpers.h"
21 PrimaryActorTick.bCanEverTick =
false;
23 BoundsComponent = CreateDefaultSubobject<UBoundsVisualizerComponent>(TEXT(
"BoundsComponent"));
42 UPrimitiveComponent* TriggerComponent = Cast<UPrimitiveComponent>(
BoundsComponent);
45 const int32 OverlapSensorIndex = 2;
46 const ECollisionChannel OverlapSensorChannel = UCollisionProfile::Get()->ConvertToCollisionChannel(
false, OverlapSensorIndex);
50 BoundsComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
51 BoundsComponent->SetCollisionResponseToChannel(OverlapSensorChannel, ECollisionResponse::ECR_Overlap);
56 BoundsComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
67 ROSMessages::std_msgs::String StringMsg;
68 ROSMessage = MakeShared<ROSMessages::std_msgs::String>(StringMsg);
85 BoundsComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
105 Super::EndPlay(EndPlayReason);
122 FString ActorID = IActorInformation::Execute_GetActorID(
this);
124 FString Msg = FString::Printf(TEXT(
"OverlapSensor with ID: %s changed overlap bounds to: %s"), *ActorID, *NewSize.ToString());
147 FString Msg = FString::Printf(TEXT(
"OverlapSensor.cpp: Changed overlap relative position to: %s"), *Vector.ToString());
153 if (Response != ECollisionResponse::ECR_Overlap && Response != ECollisionResponse::ECR_Ignore)
166 int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult)
169 AOverlapSensor* OtherOverlapSensor = Cast<AOverlapSensor>(OtherActor);
170 if (OtherOverlapSensor)
179 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
182 AOverlapSensor* OtherOverlapSensor = Cast< AOverlapSensor>(OtherActor);
183 if (OtherOverlapSensor)
203 if (AActor* VehicleActorPtr = GetParentActor())
205 From = VehicleActorPtr;
207 float DistanceInMeters = FVector::Dist(From->GetActorLocation(), Actor->GetActorLocation()) / 100.0f;
212 Message = FString::Printf(TEXT(
"%s: %s, Distance: %.2f m"), *Prefix, *Actor->GetName(), DistanceInMeters);
216 Message = FString::Printf(TEXT(
"%s: %s: ID: %s, Distance: %.2f m"), *Prefix, *Actor->GetName(), *ID, DistanceInMeters);
230 FString Msg = FString::Printf(TEXT(
"Actor '%s' with ID: '%s' %s"), *
VehicleName, *
VehicleID, *Message);
239 if (Actor && Actor->GetClass()->ImplementsInterface(UActorInformation::StaticClass()))
244 ID = IActorInformation::Execute_GetActorID(Actor);
static constexpr float SIZE_DIVISOR
void OnOverlapEnd(UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex)
void SetOverlapRelativePosition(const FVector &Vector)
TSharedPtr< ROSMessages::std_msgs::String > ROSMessage
AOverlapSensor(const FObjectInitializer &ObjectInitializer)
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
virtual void BeginPlay() override
UBoundsVisualizerComponent * BoundsComponent
void Init(FOverlapSensorParameters InParameters)
void SetVisualizeOverlapArea(bool Visualize)
void SetOverlapBounds(const FVector &NewSize)
FOverlapSensorParameters Parameters
void BuildAndSendMessage(const FString &Prefix, AActor *Actor)
void SetOverlapResponseToAllChannels(const ECollisionResponse Response)
FString TryGetID(AActor *Actor)
void OnOverlapBegin(UPrimitiveComponent *OverlappedComponent, AActor *OtherActor, UPrimitiveComponent *OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &SweepResult)
void SetSimulateSensor(bool SimulateSensor)
UTopic * GetROSTopic() const
void WriteToLogFile(const FString &Message)
FORCEINLINE bool IsROSConnected() const
virtual void CreateROSTopic()
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)