Agrarsense
PIDDrone.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 "Vehicle.h"
10#include "DroneParameters.h"
11#include "PIDDrone.generated.h"
12
13class USkeletalMeshComponent;
14class UStaticMeshComponent;
15
16UCLASS()
17class AGRARSENSE_API APIDDrone : public AVehicle
18{
19 GENERATED_BODY()
20
21public:
22
23 APIDDrone();
24
29 virtual EVehicleTypes GetVehicleType() const override { return EVehicleTypes::Drone; }
30
31 virtual FTransform GetInteractableWorldTransform_Implementation() const override
32 {
33 if (mesh)
34 {
35 return mesh->GetComponentTransform();
36 }
37 else
38 {
39 return GetActorTransform();
40 }
41 }
42
46 UFUNCTION(BlueprintCallable, Category = "Drone")
47 void SetDroneAction(EDroneAction mode)
48 {
49 DroneParameters.DroneAction = mode;
50 }
51
56 UFUNCTION(BlueprintCallable, Category = "Drone")
58 {
59 return DroneParameters.DroneAction;
60 }
61
62 UFUNCTION(BlueprintCallable, Category = "Drone")
63 FDroneParameters GetDroneParameters() const
64 {
65 return DroneParameters;
66 }
67
68 UFUNCTION(BlueprintCallable, Category = "Drone")
69 void ChangeDroneParameters(const FDroneParameters& newParameters)
70 {
71#if WITH_EDITOR
72 UE_LOG(LogTemp, Warning, TEXT("Parameters Changed!"));
73#endif
74 SetDroneParameters(newParameters);
75 }
76
77 void SetDroneParameters(const FDroneParameters& InParameters)
78 {
79 DroneParameters = InParameters;
80 }
81
82 UFUNCTION(BlueprintCallable, Category = "Drone")
83 void AddWayPoint(FVector Waypoint)
84 {
85 FTransform transform;
86 transform.SetLocation(Waypoint);
87
88 DroneParameters.Points.Add(transform);
89 }
90
91 UFUNCTION(BlueprintCallable, Category = "Drone")
92 void ClearWaypoints()
93 {
94 DroneParameters.Points.Empty();
95 }
96
100 UFUNCTION(BlueprintCallable, Category = "Drone")
101 void FlySetFlightpath();
102
103 UFUNCTION(BlueprintCallable, Category = "Drone")
104 void SetManualControl(bool value)
105 {
106 manualControl = value;
107 }
108
113 void MoveDroneToPosition(const FTransform Transform);
114
120 UFUNCTION(BlueprintCallable, Category = "Drone")
121 TArray<FTransform> GenerateRoamingPoints(float radius, int32 roamingPoints);
122
123 virtual void SetCurrentTransformToMovedFromGarageTransform() override
124 {
125 if (mesh)
126 {
127 MovedFromGarageTransform = mesh->GetComponentTransform();
128 UE_LOG(LogTemp, Warning, TEXT("Moved from garage transform %s"), *MovedFromGarageTransform.ToString());
129
130 }
131 else
132 {
133 MovedFromGarageTransform = GetActorTransform();
134 UE_LOG(LogTemp, Warning, TEXT("ACTOR Moved from garage transform WHAT IS THIS: %s"), *MovedFromGarageTransform.ToString());
135
136 }
137 }
138
139private:
140
141 virtual void BeginPlay() override;
142
143 virtual void Tick(float DeltaTime) override;
144
145 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
146
147 void AutoPilot(float DeltaTime);
148
149 UFUNCTION(BlueprintCallable)
150 bool IsRoaming() const
151 {
152 return DroneParameters.DroneAction == EDroneAction::Roaming;
153 }
154
155 UFUNCTION(BlueprintCallable)
156 void SetDesiredLocationMesh(UStaticMeshComponent* meshcomponent)
157 {
158 desiredPositionMesh = meshcomponent;
159 }
160
161 UFUNCTION(BlueprintCallable)
162 void AssignRoamingPoints(const TArray<FTransform> Points);
163
164 UFUNCTION(BlueprintCallable)
165 void SetDroneRotation(USkeletalMeshComponent* target, FRotator rotator);
166
167 UFUNCTION(BlueprintCallable)
168 FVector GetCurrentWaypointTarget();
169
171
172 UPROPERTY()
174
175 UPROPERTY()
176 UWorld* World = nullptr;
177
178 FVector StartingPosition;
179
180 USkeletalMeshComponent* mesh = nullptr;
181 UStaticMeshComponent* desiredPositionMesh = nullptr;
182
183 bool waypointReached = false;
184 bool manualControl = false;
185
186 /* For testing purposes. Hardcoded coordinates */
187 TArray<FVector> WayPoints = {
188 {3790, 8050, 5000},
189 {11779.536955,6566.541435,5000}
190 };
191
192 int32 passedWaypoints = 0;
193
194};
EDroneAction
Definition: DroneAction.h:15
EFlightMode
static EDroneAction GetDroneAction(FString actionstring)
EVehicleTypes
Definition: VehicleTypes.h:15
virtual FTransform GetInteractableWorldTransform_Implementation() const override
Definition: PIDDrone.h:31
void SetDroneParameters(const FDroneParameters &InParameters)
Definition: PIDDrone.h:77
FDroneParameters DroneParameters
Definition: PIDDrone.h:170
virtual EVehicleTypes GetVehicleType() const override
Definition: PIDDrone.h:29
TArray< FTransform > Points