-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolMethod.H
174 lines (129 loc) · 4.87 KB
/
controlMethod.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*---------------------------------------------------------------------------*\
Class
Foam::controlMethod
Description
controlMethod is a base class of the maneuveringOutput, which provides control algorithm for the maneuvering motions.
\*---------------------------------------------------------------------------*/
#ifndef controlMethod_H
#define controlMethod_H
#include "fvCFD.H"
class controlMethod
{
public:
virtual ~controlMethod() = default;
controlMethod() = default;
controlMethod(const dictionary &);
enum controlType
{
sailing, // on/off control
turning,
zigzag,
coursekeeping,
};
static const Enum<controlType> controlTypeNames;
//- controlMethod factory
static std::shared_ptr<controlMethod> create(const dictionary &);
//- Calculate output signal from current process value, target value
// and current time delta
//virtual scalar calculate(scalar , scalar , const scalar ) = 0;
//- Calculate output signal from current process value and current time delta
virtual scalar calculate(scalar, const scalar ) = 0;
//- Write to runtime dict
virtual void write(Ostream &) const;
//- refer to start Time
scalar cStartTime() const;
//- refer to end Time
scalar cEndTime() const;
//- refer to output value
scalar outputSignal() const;
protected:
const enum controlType controlType_;
// Start time of controller
scalar cStartTime_;
// End time of controller
scalar cEndTime_;
//output value
scalar outputSignal_;
};
class turningControl : public controlMethod
{
public:
turningControl() = default;
turningControl(const dictionary &);
// currentYaw refers to current Yaw angle
scalar calculate(scalar currentYaw, const scalar deltaT);
void write(Ostream &) const override;
private:
// target yaw angle
scalar cTarget_;
// maximum controller value
scalar cMax_;
// controller rate
scalar cRate_;
// Preserve old output signal for histeresis correction
scalar outputSignal_;
};
class zigzagControl : public controlMethod
{
public:
zigzagControl() = default;
zigzagControl(const dictionary &);
// currentYaw refers to current yaw angle.
scalar calculate(scalar currentYaw, scalar deltaT);
void write(Ostream &) const override;
private:
// target yaw angle
scalar cTarget_;
// maximum controller value
scalar cMax_;
// controller rate
scalar cRate_;
// output rudder angle
scalar outputSignal_;
// restore the yaw angle of the previous time-step.
scalar oldYaw_;
};
class sailingControl : public controlMethod
{
public:
sailingControl() = default;
sailingControl(const dictionary &);
// currentV refers to current sailing velocity
scalar calculate(scalar currentV, scalar deltaT);
void write(Ostream &) const override;
private:
scalar P_; // Proportional control term
scalar I_; // Integral control term
scalar D_; // Differential control term
scalar cTarget_; // target sailing velocity
scalar outputMax_; // Max output signal (saturation)
scalar outputMin_; // Min output signal
scalar errorMax_; // Constains received absolute error value
scalar integralErrorMax_; // Constains built-up integral error
scalar oldError_; // Old error
scalar errorIntegral_; // Error integral w.r.t. time
scalar outputSignal_; // output RPS
};
class coursekeepingControl : public controlMethod
{
public:
coursekeepingControl() = default;
coursekeepingControl(const dictionary &);
// currentV refers to current sailing velocity
scalar calculate(scalar currentV, scalar deltaT);
void write(Ostream &) const override;
private:
scalar P_; // Proportional control term
scalar I_; // Integral control term
scalar D_; // Differential control term
scalar cTarget_; // target sailing velocity
scalar cRate_; // controller rate
scalar outputMax_; // Max output signal (saturation)
scalar outputMin_; // Min output signal
scalar errorMax_; // Constains received absolute error value
scalar integralErrorMax_; // Constains built-up integral error
scalar oldError_; // Old error
scalar errorIntegral_; // Error integral w.r.t. time
scalar outputSignal_; // output RPS
};
#endif