Agrarsense
OverlapSensor.h
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "Engine/EngineTypes.h"
10#include "Components/PrimitiveComponent.h"
11#include "Components/SphereComponent.h"
12#include "Components/BoxComponent.h"
13
17
18#include "ROSIntegration/Public/std_msgs/String.h"
19
20#include "OverlapSensor.generated.h"
21
22class AVehicle;
23
29UCLASS()
30class AGRARSENSE_API AOverlapSensor : public ASensor
31{
32 GENERATED_BODY()
33
34public:
35
36 AOverlapSensor(const FObjectInitializer& ObjectInitializer);
37
38 UFUNCTION(BlueprintCallable)
39 void Init(FOverlapSensorParameters InParameters);
40
45 virtual ESensorTypes GetSensorType() const override
46 {
48 }
49
53 UFUNCTION(BlueprintCallable)
54 void SetOverlapBounds(const FVector& NewSize);
55
59 UFUNCTION(BlueprintCallable)
60 void SetVisualizeOverlapArea(bool Visualize);
61
65 UFUNCTION(BlueprintCallable)
66 void SetOverlapRelativePosition(const FVector& Vector);
67
75 UFUNCTION(BlueprintCallable)
76 void SetOverlapResponseToAllChannels(const ECollisionResponse Response);
77
78 UFUNCTION(BlueprintCallable)
79 bool IsVisualizingOverlapArea() const
80 {
81 return IsVisible;
82 }
83
84 virtual FString GetParametersAsString() const override
85 {
86 return StructToString(Parameters);
87 }
88
89protected:
90
91 UFUNCTION()
92 void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
93 int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
94
95 UFUNCTION()
96 void OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
97 int32 OtherBodyIndex);
98
99 UPROPERTY(VisibleAnywhere)
100 UBoxComponent* BoxComponent = nullptr;
101
102 UPROPERTY(VisibleAnywhere)
103 USphereComponent* SphereComponent = nullptr;
104
105 UPROPERTY(VisibleAnywhere)
106 UBoundsVisualizerComponent* VisualizerComponent = nullptr;
107
108private:
109
110 virtual void BeginPlay() override;
111
112 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
113
114 void BuildAndSendMessage(const FString& Prefix, AActor* Actor);
115
116 FString TryGetID(AActor* Actor);
117
118 TSharedPtr<ROSMessages::std_msgs::String> ROSMessage;
119
121
123
124 UPROPERTY()
125 AVehicle* Vehicle = nullptr;
126
127 FString VehicleName;
128
129 FString VehicleID;
130
131 bool IsVisible = false;
132
133};
ESensorTypes
Definition: SensorTypes.h:15
virtual FString GetParametersAsString() const override
Definition: OverlapSensor.h:84
virtual ESensorTypes GetSensorType() const override
Definition: OverlapSensor.h:45
Definition: Sensor.h:44
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
Definition: Vehicle.cpp:86
virtual void BeginPlay() override
Definition: Vehicle.cpp:26