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(BlueprintCallable, Category =
"Drone")
82 UFUNCTION(BlueprintCallable, Category = "
Drone")
83 void AddWayPoint(FVector Waypoint)
86 transform.SetLocation(Waypoint);
88 DroneParameters.
Points.Add(transform);
91 UFUNCTION(BlueprintCallable, Category =
"Drone")
92 float GetDroneDistanceToNextPoint()
100 return distanceToNextPoint;
103 UFUNCTION(BlueprintCallable, Category =
"Drone")
104 float GetDroneSpeed()
const
106 if (!DroneSkeletalMesh)
111 return FMath::Max(FMath::Abs(DroneSkeletalMesh->GetComponentVelocity().X), FMath::Abs(DroneSkeletalMesh->GetComponentVelocity().Y));
114 UFUNCTION(BlueprintCallable, Category =
"Drone")
115 void ClearWaypoints()
117 DroneParameters.Points.Empty();
123 UFUNCTION(BlueprintCallable, Category =
"Drone")
124 void SetFlightpath();
126 UFUNCTION(BlueprintCallable, Category = "
Drone")
127 void SetManualControl(
bool value)
129 manualControl = value;
136 void MoveDroneToPosition(
const FTransform
Transform);
143 UFUNCTION(BlueprintCallable, Category =
"Drone")
144 TArray<FTransform> GenerateRoamingPoints(
float radius, int32 roamingPoints);
150 UFUNCTION(BlueprintCallable, Category = "
Drone")
151 float GetYawRotationDifference(USkeletalMeshComponent* DroneSkeletalMesh, UStaticMeshComponent* DesiredLocation);
153 virtual
void SetCurrentTransformToMovedFromGarageTransform()
override
155 if (DroneSkeletalMesh)
157 MovedFromGarageTransform = DroneSkeletalMesh->GetComponentTransform();
158 UE_LOG(LogTemp, Warning, TEXT(
"Moved from garage transform %s"), *MovedFromGarageTransform.ToString());
163 MovedFromGarageTransform = GetActorTransform();
164 UE_LOG(LogTemp, Warning, TEXT(
"ACTOR Moved from garage transform WHAT IS THIS: %s"), *MovedFromGarageTransform.ToString());
171 ShowForwardArrow = Show;
176 drawDebugPoints = show;
179 UFUNCTION(BlueprintCallable, Category =
"Drone")
180 bool GetShowForwardArrow()
const
182 return ShowForwardArrow;
185 UFUNCTION(BlueprintCallable, Category =
"Drone")
186 USkeletalMeshComponent* GetDroneSkeletalMesh()
const
188 return DroneSkeletalMesh;
204 virtual
void Tick(
float DeltaTime) override;
206 virtual
void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
212 void HandleDestroy();
214 void AutoPilot(const
float DeltaTime);
216 void DrawDebugPoints();
218 UFUNCTION(BlueprintCallable)
219 void AssignRoamingPoints(const TArray<FTransform> Points);
221 UFUNCTION(BlueprintCallable)
222 void SetDroneRotation(USkeletalMeshComponent* target, FRotator rotator);
224 void UpdateGroundHeight();
226 UFUNCTION(BlueprintCallable)
227 bool IsRoaming()
const
232 UFUNCTION(BlueprintCallable)
233 void SetDesiredLocationMesh(UStaticMeshComponent* meshcomponent)
235 PositionMesh = meshcomponent;
238 UFUNCTION(BlueprintCallable)
239 FVector GetCurrentWaypointTarget();
241 UFUNCTION(BlueprintCallable)
242 FTransform GetCurrentWaypointTarget_Transform();
250 UWorld* World =
nullptr;
252 FVector StartingPosition;
255 USkeletalMeshComponent* DroneSkeletalMesh =
nullptr;
258 UStaticMeshComponent* PositionMesh =
nullptr;
264 TArray<FVector> WayPoints = {
266 {11779.536955,6566.541435,5000}
269 bool waypointReached =
false;
271 bool manualControl =
false;
273 bool ShowForwardArrow =
false;
275 bool drawDebugPoints =
false;
277 int32 passedWaypoints = 0;
279 float DroneHeightFromGround = 0.0f;
281 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