-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathActuatorManager.h
131 lines (98 loc) · 3 KB
/
ActuatorManager.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* ActuatorCalculus.h
*
* Created on: 16 abr. 2017
* Author: Sergio
*/
#ifndef ACTUATORMANAGER_H_
#define ACTUATORMANAGER_H_
#include "PID_v1_ext.h"
#include "RudderFeedback.h"
#include "ActuatorController.h"
#include "DeadbandTrim.h"
#include "PID_AutoTune_v0.h"
// All configurations are managed in Fenix_config.h
#include "Fenix_config.h"
// All configurations are managed in Fenix_config.h
////for DEBUGGING
////#include "GPSport.h"
////#include <simplot.h> //SIMPLOT FOR DEBUGGING PURPOSE ONLY
////#define DEBUG
//// ACTUATOR PARAMETERS
//#define SPEED_CRUISE 255
// INSTALATION PARAMETERS: POSSIBLE VALUES
// Rudder gain
#define RUD_B_MIN 0.2 //Fast boats
#define RUD_B_MED 1 //Cruisers
#define RUD_B_MAX 1.5 //Sailing
// TODO: Installation side always STARBOARD. Implement PORTBOARD
// Installation side
typedef enum type_instSide {STARBOARD, PORTBOARD} type_instSide;
class ActuatorManager: public PID_ext, public PID_ATune,
public RudderFeedback,
public ActuatorController {
public:
ActuatorManager(double Kp, double Ki, double Kd, int ControllerDirection, int MRA, int error, int deltaCenterOfRudder, int minFeedback, int maxFeedback);
virtual ~ActuatorManager();
void setup(double aTuneNoise, double aTuneStep, double aTuneLookBack);
void startAutoMode();
void stopAutoMode();
int Compute(float setPoint, float processVariable);
int Compute(float PIDerrorPrima);
int Compute_Autotune(float PIDerrorPrima);
int compute_VA(void);
int controlActuator (int target, bool deadband = false, int trim = 0);
void ResetTunings();
double getOutput() const {
return _Output;
}
void setInput(double input) {
_Input = input;
}
double getInput() const {
return _Input;
}
void setSetpoint(double setpoint) {
_Setpoint = setpoint;
}
int getTargetRudder() const {
return _targetRudder;
}
void setTargetRudder(int targetRudder) {
if (targetRudder > getMaxRudder()) {targetRudder = getMaxRudder();}
else if (targetRudder < getMinRudder()) {targetRudder = getMinRudder();}
_targetRudder = targetRudder;
}
type_instSide getInstallationSide() const {
return _installation_side;
}
void setInstallationSide(type_instSide installationSide = STARBOARD) {
_installation_side = installationSide;
}
void setupAutoTune(double aTuneNoise, double aTuneStep, double aTuneLookBack);
void startAutoTune(void);
void stopAutoTune (void);
bool evaluateAutoTune (void);
bool CopyToPIDAutoTune(void);
void setATuneInput(double aTuneInput) {
_ATune_Input = aTuneInput;
}
//DeadbandTrim
DeadbandTrim dbt;
protected:
int changeRudder(int delta_rudder);
private:
//PID: Define Variables we'll be connecting to
double _Setpoint, _Input, _Output;
double _KpIni, _KiIni, _KdIni;
// target rudder in manual mode
int _targetRudder=1;
//Installation side
type_instSide _installation_side = STARBOARD;
//ATunePID
boolean _tuning = false;
//ATune PID: Define Variables we'll be connecting to
double _ATune_Input, _ATune_Output;
void SetMode(int Mode);
};
#endif /* ACTUATORMANAGER_H_ */