Agrarsense
PIDDrone.h
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences. This work is licensed under the terms of the MIT license. For a copy, see <https://opensource.org/licenses/MIT>.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Vehicle.h"
7#include "DroneParameters.h"
8#include "PIDDrone.generated.h"
9
13class USkeletalMeshComponent;
14class UStaticMeshComponent;
15//DECLARE_DYNAMIC_MULTICAST_DELEGATE(FLevelEventDelegate_FlightPathCompleted);
16
17UCLASS()
18class AGRARSENSE_API APIDDrone : public AVehicle
19{
20 GENERATED_BODY()
21
22public:
23 APIDDrone();
24 //UPROPERTY(BlueprintAssignable)
25 //FLevelEventDelegate_FlightPathCompleted OnFlightPathCompleted;
26
31 virtual EVehicleTypes GetVehicleType() const override { return EVehicleTypes::Drone; }
32
33 virtual FTransform GetInteractableWorldTransform_Implementation() const override
34 {
35 if (mesh)
36 {
37 return mesh->GetComponentTransform();
38 }
39 else
40 {
41 return GetActorTransform();
42 }
43 }
44
48 UFUNCTION(BlueprintCallable, Category = "Drone")
49 void SetDroneAction(EDroneAction mode)
50 {
51 DroneParameters.DroneAction = mode;
52 }
53
58 UFUNCTION(BlueprintCallable, Category = "Drone")
59 EDroneAction GetDroneAction()
60 {
61 return DroneParameters.DroneAction;
62 }
63
64 UFUNCTION(BlueprintCallable, Category = "Drone")
65 FDroneParameters GetDroneParameters()
66 {
67 return DroneParameters;
68 }
69
70 UFUNCTION(BlueprintCallable, Category = "Drone")
71 void ChangeDroneParameters(const FDroneParameters& newParameters)
72 {
73 UE_LOG(LogTemp, Warning, TEXT("Parameters Chnaged!"));
74 SetDroneParameters(newParameters);
75 }
76
77 void SetDroneParameters(const FDroneParameters& InParameters)
78 {
79 DroneParameters = InParameters;
80 }
81
82
83 UFUNCTION(BlueprintCallable, Category = "Drone")
84 void AddWayPoint(FVector waypoint)
85 {
86 FTransform transform;
87 transform.SetLocation(waypoint);
88
89 DroneParameters.Points.Add(transform);
90 }
91
92 UFUNCTION(BlueprintCallable, Category = "Drone")
93 void ClearWaypoints()
94 {
95 DroneParameters.Points.Empty();
96 }
97
101 UFUNCTION(BlueprintCallable, Category = "Drone")
102 void FlySetFlightpath();
103
104 UFUNCTION(BlueprintCallable, Category = "Drone")
105 void SetManualControl(bool value) {
106 manualControl = value;
107 }
108
113 void MoveDroneToPosition(const FTransform Transform);
114
120 UFUNCTION(BlueprintCallable, Category = "Drone")
121 TArray<FTransform> GenerateRoamingPoints(float radius, int roamingPoints);
122
123 bool manualControl = false;
124
125private:
126
127 virtual void BeginPlay() override;
128
129 virtual void Tick(float DeltaTime) override;
130
131 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
132
133 void AutoPilot(float DeltaTime);
134
135 //FVector GetCurrentWaypointTarget();
136
137 UPROPERTY()
139
140 UPROPERTY()
141 UWorld* World = nullptr;
142
143 FVector StartingPosition;
144
145 USkeletalMeshComponent* mesh = nullptr;
146 UStaticMeshComponent* desiredPositionMesh = nullptr;
147
148 bool bRosConnected = false;
149 bool waypointreached = false;
150
151 /* For testing purposes. Hardcoded coordinates */
152 TArray<FVector> WayPoints = {
153 {3790, 8050, 5000},
154 {11779.536955,6566.541435,5000}
155 };
156
158 {
159 return DroneParameters.DroneAction == EDroneAction::Roaming;
160 }
161
162 int passedWaypoints = 0;
163
164protected:
165
167
168 UFUNCTION(BlueprintCallable)
169 FVector GetCurrentWaypointTarget();
170
171 UFUNCTION(BlueprintCallable)
172 void SetDesiredLocationMesh(UStaticMeshComponent *meshcomponent) {
173 desiredPositionMesh = meshcomponent;
174 }
175
176 UFUNCTION(BlueprintCallable)
177 void AssignRoamingPoints(TArray<FTransform> Points)
178 {
179 // Empty current waypoints if any
180 ClearWaypoints();
181
182
183 for (FTransform point : Points)
184 {
185 // Assing new waypoints to the array
186 WayPoints.Add(point.GetLocation());
187 }
188 };
189
190 UFUNCTION(BlueprintCallable)
191 void SetDroneRotation(USkeletalMeshComponent* target, FRotator rotator);
192
193};
EDroneAction
Definition: DroneAction.h:15
EFlightMode
EVehicleTypes
Definition: VehicleTypes.h:15
virtual FTransform GetInteractableWorldTransform_Implementation() const override
Definition: PIDDrone.h:33
void SetDroneParameters(const FDroneParameters &InParameters)
Definition: PIDDrone.h:77
bool isRoaming()
Definition: PIDDrone.h:157
FDroneParameters DroneParameters
Definition: PIDDrone.h:166
virtual EVehicleTypes GetVehicleType() const override
Definition: PIDDrone.h:31
TArray< FTransform > Points