8#include "CoreMinimal.h"
12#include "Components/SkeletalMeshComponent.h"
13#include "Components/StaticMeshComponent.h"
15#include "ROSIntegration/Public/std_msgs/Float32.h"
17#include "PIDDrone.generated.h"
41 if (DroneSkeletalMesh)
43 return DroneSkeletalMesh->GetComponentTransform();
47 return GetActorTransform();
54 UFUNCTION(BlueprintCallable, Category =
"Drone")
57 DroneParameters.DroneAction = mode;
60 UPROPERTY(BlueprintAssignable, Category =
"Drone")
61 FDroneFinished OnDroneFinished;
67 UFUNCTION(BlueprintCallable, Category = "
Drone")
70 return DroneParameters.DroneAction;
73 UFUNCTION(BlueprintCallable, Category =
"Drone")
76 return DroneParameters;
79 UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
80 void ResetDroneEvent();
82 UFUNCTION(BlueprintCallable, Category = "
Drone")
85 UFUNCTION(BlueprintCallable, Category = "
Drone")
86 void AddWayPoint(FVector Waypoint)
89 transform.SetLocation(Waypoint);
91 DroneParameters.
Points.Add(transform);
94 UFUNCTION(BlueprintCallable, Category =
"Drone")
95 float GetDroneDistanceToNextPoint()
103 return distanceToNextPoint;
106 UFUNCTION(BlueprintCallable, Category =
"Drone")
107 float GetDroneSpeed()
const
109 if (!DroneSkeletalMesh)
114 return FMath::Max(FMath::Abs(DroneSkeletalMesh->GetComponentVelocity().X), FMath::Abs(DroneSkeletalMesh->GetComponentVelocity().Y));
117 UFUNCTION(BlueprintCallable, Category =
"Drone")
118 void ClearWaypoints()
120 DroneParameters.Points.Empty();
126 UFUNCTION(BlueprintCallable, Category =
"Drone")
127 void SetFlightpath();
129 UFUNCTION(BlueprintCallable, Category = "
Drone")
130 void SetManualControl(
bool value)
132 manualControl = value;
139 void MoveDroneToPosition(
const FTransform
Transform);
146 UFUNCTION(BlueprintCallable, Category =
"Drone")
147 TArray<FTransform> GenerateRoamingPoints(
float radius, int32 roamingPoints);
153 UFUNCTION(BlueprintCallable, Category = "
Drone")
154 float GetYawRotationDifference(USkeletalMeshComponent* DroneSkeletalMesh, UStaticMeshComponent* DesiredLocation);
156 virtual
void SetCurrentTransformToMovedFromGarageTransform()
override
158 if (DroneSkeletalMesh)
160 MovedFromGarageTransform = DroneSkeletalMesh->GetComponentTransform();
161 UE_LOG(LogTemp, Warning, TEXT(
"Moved from garage transform %s"), *MovedFromGarageTransform.ToString());
166 MovedFromGarageTransform = GetActorTransform();
167 UE_LOG(LogTemp, Warning, TEXT(
"ACTOR Moved from garage transform WHAT IS THIS: %s"), *MovedFromGarageTransform.ToString());
174 ShowForwardArrow = Show;
179 drawDebugPoints = show;
182 UFUNCTION(BlueprintCallable, Category =
"Drone")
183 bool GetShowForwardArrow()
const
185 return ShowForwardArrow;
188 UFUNCTION(BlueprintCallable, Category =
"Drone")
189 USkeletalMeshComponent* GetDroneSkeletalMesh()
const
191 return DroneSkeletalMesh;
207 virtual
void Tick(
float DeltaTime) override;
209 virtual
void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
215 void HandleDestroy();
217 void AutoPilot(const
float DeltaTime);
219 void DrawDebugPoints();
221 UFUNCTION(BlueprintCallable)
222 void AssignRoamingPoints(const TArray<FTransform> Points);
224 UFUNCTION(BlueprintCallable)
225 void SetDroneRotation(USkeletalMeshComponent* target, FRotator rotator);
227 void UpdateGroundHeight();
229 UFUNCTION(BlueprintCallable)
230 bool IsRoaming()
const
235 UFUNCTION(BlueprintCallable)
236 void SetDesiredLocationMesh(UStaticMeshComponent* meshcomponent)
238 PositionMesh = meshcomponent;
241 UFUNCTION(BlueprintCallable)
242 FVector GetCurrentWaypointTarget();
244 UFUNCTION(BlueprintCallable)
245 FTransform GetCurrentWaypointTarget_Transform();
253 UWorld* World =
nullptr;
255 FVector StartingPosition;
258 USkeletalMeshComponent* DroneSkeletalMesh =
nullptr;
261 UStaticMeshComponent* PositionMesh =
nullptr;
267 TArray<FVector> WayPoints = {
269 {11779.536955,6566.541435,5000}
272 bool waypointReached =
false;
274 bool manualControl =
false;
276 bool ShowForwardArrow =
false;
278 bool drawDebugPoints =
false;
280 int32 passedWaypoints = 0;
282 float DroneHeightFromGround = 0.0f;
284 float distanceToNextPoint = 0.0f;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDroneFinished, FTransform, _LastWaypoint)
static EDroneAction GetDroneAction(FString actionstring)
TSharedPtr< ROSMessages::std_msgs::String > ROSMessage
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
virtual void BeginPlay() override
virtual FTransform GetInteractableWorldTransform_Implementation() const override
void SetDrawDebugPoints(bool show)
FDroneParameters DroneParameters
virtual EVehicleTypes GetVehicleType() const override
TArray< FTransform > dronePath
FTimerHandle DestroyHandle
void SetShowForwardArrow(bool Show)
void ROSBridgeStateChanged(EROSState ROSState)
TArray< FTransform > Points