-
Notifications
You must be signed in to change notification settings - Fork 0
/
PIDController.h
90 lines (67 loc) · 2.9 KB
/
PIDController.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
90
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "Containers/Queue.h"
#include <vector>
#include <queue>
#include "PIDController.generated.h"
USTRUCT(BlueprintType)
struct FPIDState
{
GENERATED_BODY()
UPROPERTY(Transient)
FVector ControllerIntegralTerm; // Initialized to ensure a valid starting value
FVector AngleIntegralTerm;
// FVector LastVelocityError;
//
// int32 PosControllerCurQueueSize = 0.f;
// int32 AngleControllerCurQueueSize = 0.f;
//
// FVector Pos_ControllerSumBuffer = FVector::ZeroVector;
// FVector Angle_ControllerSumBuffer = FVector::ZeroVector;
//
};
USTRUCT(BlueprintType)
struct FPIDConfig
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PID")
FVector ProportionalGain = FVector(0.f, 0.f, 0.f);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PID")
FVector IntegralGain = FVector(0.f, 0.f, 0.f);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PID")
FVector DerivativeGain = FVector(0.f, 0.f, 0.f);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PID")
FVector AngleProportionalGain = FVector(0.f, 0.f, 0.f);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PID")
FVector AngleIntegralGain = FVector(0.f, 0.f, 0.f);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PID")
FVector AngleDerivativeGain = FVector(0.f, 0.f, 0.f);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PID")
float MinimumRPM = 0.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PID")
float MaximumRPM = 10464.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Buffer")
int PositionBuffer_Size;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Buffer")
int AngleBuffer_Size;
};
USTRUCT(BlueprintType)
struct FPIDResult
{
GENERATED_BODY()
UPROPERTY()
FVector4 MotorRPMs;
UPROPERTY()
FVector AngleError;
};
UCLASS()
class DRONEENVIRONMENT_API UPIDController : public UObject
{
GENERATED_BODY()
public:
//UFUNCTION(BlueprintCallable, Category = "PID")
FPIDResult UpdatePID(const FPIDConfig& Config, FPIDState& State, FVector PositionError, FVector DroneVelocity, FRotator DroneOrientation, FVector CurrentAngVel, FVector DroneInertiaTensor,float Mass,float Grav,float DeltaTime);
void Log_Messages(float Roll_Torque, float Pitch_Torque, float Yaw_Torque, FVector VelSetpoint, float U_1, float U_2, float U_3, FVector4 Motor_RPMs, FVector Des_Angle, FVector Angle_Error, FVector AngleVel_Error, FVector CurrentVel, FVector DesAcc, FVector AngleITerm, FVector AnglePTerm, FVector AngleDTerm, FVector PTerm, FVector ITerm, FVector DTerm);
//void EnqueueAndMaintainSize(std::queue<FVector>& Queue, FVector Element, int32& CurrentSize, int32 MaxSize, FVector& SumBuffer);
};