-
Notifications
You must be signed in to change notification settings - Fork 0
/
SentinelDrone.h
89 lines (66 loc) · 2.51 KB
/
SentinelDrone.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "PIDController.h"
#include "Camera/CameraComponent.h"
#include "Containers/Queue.h"
#include <vector>
#include <queue>
#include "Components/StaticMeshComponent.h"
#include "SentinelDrone.generated.h"
UCLASS()
class DRONEENVIRONMENT_API ASentinelDrone : public APawn
{
GENERATED_BODY()
public:
ASentinelDrone();
protected:
virtual void BeginPlay() override;
//virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
public:
virtual void Tick(float DeltaTime) override;
UFUNCTION(BlueprintCallable, Category = "DroneControl")
void SetPropellerRPM(int PropellerIndex, float RPM);
// PID Controller and configuration
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PID")
UPIDController* PIDController;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PID")
FPIDConfig PIDConfig;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PID")
FVector Pos_Setpoint;
private:
void ExecutePIDControl(float DeltaTime);
void CalculateAllAngularVelocities();
void CalculateAllThrusts();
void ApplyAllThrusts();
void UpdatePropellerRotation(float DeltaTime);
void VisualizeThrustVector(const FVector& StartLocation, const FVector& ThrustVector);
float CalculateThrust(float AngularVelocity);
void ApplyThrust(float Thrust, FName SocketName);
void LogDataToCSV(float ElapsedTime, FVector PosSetpoint, FVector CurrentLocation, FVector Pos_Error, FVector Vel_Error, FVector4 PIDOutput, float DroneMass);
void LogMessages(float TimeElapsed, float WorldGravity, const TArray<float>& Thrusters, FVector PosSetpoint, FVector CurrentPosition, FVector Pos_Error, FVector4 PID_Output);
//void MoveAltitude(float Value);
UPROPERTY(VisibleAnywhere)
UStaticMeshComponent* DroneBody;
UPROPERTY(VisibleAnywhere)
TArray<UStaticMeshComponent*> Propellers;
UPROPERTY(VisibleAnywhere)
UCameraComponent* DroneCamera;
FPIDState PIDState;
TArray<float> RPMs;
TArray<float> AngularVelocities;
TArray<float> Thrusts;
//float Mass;
FVector Dimensions;
FVector Position;
FVector Velocity;
FRotator Orientation;
FVector AngularVelocity;
float TotalElapsedTime;
float Tick_num;
//
//private:
//
// std::queue<FVector> PosControllerBuffer;
// std::queue<FVector> AngleControllerBuffer;
};