Agrarsense
CollisionSensor.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"
10
11#include "ROSIntegration/Public/std_msgs/String.h"
12
13#include "CollisionSensor.generated.h"
14
16{
17 FString Actor;
18 FString OtherActor;
20
21 FString ToString()
22 {
23 FString X = FString::SanitizeFloat(NormalImpulse.X);
24 FString Y = FString::SanitizeFloat(NormalImpulse.Y);
25 FString Z = FString::SanitizeFloat(NormalImpulse.Z);
26 return FString::Printf(TEXT("%s, %s, %s, %s, %s"), *Actor, *OtherActor, *X, *Y, *Z);
27 }
28
30 {
31 return FString::Printf(TEXT("Actor %s collided with %s with impulse of %s"), *Actor, *OtherActor, *NormalImpulse.ToString());
32 }
33};
34
38UCLASS()
39class AGRARSENSE_API ACollisionSensor : public ASensor
40{
41 GENERATED_BODY()
42
43public:
44
45 ACollisionSensor(const FObjectInitializer& ObjectInitializer);
46
52 UFUNCTION(BlueprintCallable)
53 void Init(AActor* NewOwner, bool SimulateSensor = true);
54
59 virtual ESensorTypes GetSensorType() const override
60 {
62 }
63
64protected:
65
66 virtual void BeginPlay() override;
67
68 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
69
70private:
71
72 void SendCollisionData(const FString& CollisionDataString);
73
74 UFUNCTION()
75 void OnCollisionEvent(AActor* Actor, AActor* OtherActor, FVector NormalImpulse, const FHitResult& Hit);
76
77 UPROPERTY()
78 TWeakObjectPtr<AActor> CurrentOwner;
79
80 TSharedPtr<ROSMessages::std_msgs::String> CollisionMessage;
81};
ESensorTypes
Definition: SensorTypes.h:15
virtual ESensorTypes GetSensorType() const override
Definition: Sensor.h:44
FString ToStringHumanReadable()
FString OtherActor
FVector NormalImpulse
FString ToString()