-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoTunePID.h
64 lines (53 loc) · 1.42 KB
/
AutoTunePID.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
#ifndef AUTOTUNEPID_H
#define AUTOTUNEPID_H
#include <Arduino.h>
enum TuningMethod {
ZieglerNichols,
CohenCoon,
RelayFeedback,
IMC,
Manual
};
class AutoTunePID {
public:
AutoTunePID(float minOutput, float maxOutput, TuningMethod method = ZieglerNichols);
void setSetpoint(float setpoint);
void setTuningMethod(TuningMethod method);
void setManualGains(float kp, float ki, float kd);
void enableInputFilter(float alpha);
void enableOutputFilter(float alpha);
void update(float currentInput);
float getOutput();
float getKp();
float getKi();
float getKd();
private:
void computePID();
void autoTuneZieglerNichols();
void autoTuneCohenCoon();
void autoTuneRelayFeedback();
void autoTuneIMC();
float applyFilter(float input, float &filteredValue, float alpha);
float _setpoint;
float _minOutput;
float _maxOutput;
float _kp, _ki, _kd;
float _error, _previousError;
float _integral, _derivative;
float _output;
float _Ku, _Tu;
TuningMethod _method;
unsigned long _lastUpdate;
unsigned long _tuningStartTime;
unsigned long _tuningDuration;
bool _tuning;
float _maxObservedOutput;
float _minObservedOutput;
bool _inputFilterEnabled;
bool _outputFilterEnabled;
float _inputFilteredValue;
float _outputFilteredValue;
float _inputFilterAlpha;
float _outputFilterAlpha;
};
#endif