Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Kristian Soltesz
PIDopt
Commits
ad22ab9e
Commit
ad22ab9e
authored
Jan 08, 2018
by
Kristian Soltesz
Browse files
code clean
parent
814213e3
Changes
1
Show whitespace changes
Inline
Side-by-side
pidfIAE.m
View file @
ad22ab9e
function
[
K
F
,
p
,
w
]
=
pidfIAE
(
P
,
Ms
,
Mt
,
Mks
,
p
K
,
w
)
function
[
K
,
p
,
w
]
=
pidfIAE
(
P
,
Ms
,
Mt
,
Mks
,
p
C
,
w
)
% Computes PID parameters, that minimize load step IAE, and filter for
% noise attenuation.
%
...
...
@@ -17,12 +17,12 @@ function [KF,p,w]=pidfIAE(P,Ms,Mt,Mks,pK,w)
% See the git repo for further documentation.
% regularize
if
p
K
(
1
)
~=
0
k
0
=
p
K
(
1
);
p
K
=
p
K
/
k
0
;
P
=
P
*
k
0
;
if
p
C
(
1
)
~=
0
c
0
=
p
C
(
1
);
p
C
=
p
C
/
c
0
;
P
=
P
*
c
0
;
else
k
0
=
1
;
c
0
=
1
;
end
% Frequency grid (heuristic) - change as needed
...
...
@@ -35,9 +35,9 @@ Tmin = 1/w(end);
pF
=
Tmin
;
% Organize parameters parameters
p
=
[
p
K
(:);
pF
(:)];
p
K
=
@
(
p
)
p
(
1
:
3
);
pF
=
@
(
p
)
p
(
4
);
% FIXME: rescale to fit Lund parametrization of filter
p
=
[
p
C
(:);
pF
(:)];
p
C
=
@
(
p
)
p
(
1
:
3
);
pF
=
@
(
p
)
p
(
4
);
w
=
w
(:);
p
(
4
)
=
max
(
p
(
4
),
Tmin
);
...
...
@@ -52,22 +52,23 @@ Pw = fr(P); % Frequency response
% Transfer functions
s
=
zpk
(
's'
);
K1
=
[
1
;
1
/
s
;
s
];
K
=
@
(
p
)
pK
(
p
)
.'*
K1
;
F
=
@
(
p
)
1
/((
pF
(
p
)
*
s
)
^
2
+
2
*
z
*
pF
(
p
)
*
s
+
1
);
% Alternative parametrization
S
=
@
(
p
)
feedback
(
1
,
P
*
K
(
p
)
*
F
(
p
));
C1
=
[
1
;
1
/
s
;
s
];
C
=
@
(
p
)
pC
(
p
)
.'*
C1
;
F
=
@
(
p
)
1
/((
pF
(
p
)
*
s
)
^
2
+
2
*
z
*
pF
(
p
)
*
s
+
1
);
K
=
@
(
p
)
series
(
F
(
p
),
C
(
p
));
S
=
@
(
p
)
feedback
(
1
,
series
(
P
,
K
(
p
)));
% Sensitivities
K
_p
K
=
@
(
p
)
K
1
;
% dK/dp
K
C
_p
C
=
@
(
p
)
C
1
;
% dK/dp
C
F_pF
=
@
(
p
)(
-
2
)
*
F
(
p
)
^
2
*
s
*
(
s
*
pF
(
p
)
+
z
);
% dF/dpF
K
F
_p
=
@
(
p
)[
F
(
p
)
*
K
_p
K
(
p
);
K
(
p
)
*
F_pF
(
p
)];
% dK
F
/dp
K_p
=
@
(
p
)[
F
(
p
)
*
C
_p
C
(
p
);
C
(
p
)
*
F_pF
(
p
)];
% dK/dp
% Optimization
cfg
=
optimset
(
'algorithm'
,
'active-set'
,
'GradConstr'
,
'on'
,
'GradObj'
,
...
'on'
,
'Display'
,
'off'
,
'maxIter'
,
10
);
p
=
fmincon
(
@
(
p
)
J
(
p
),
p
,[],[],[],[],[
eps
0
0
Tmin
],[],
@
(
p
)
cNL
(
p
),
cfg
);
p
(
1
:
end
-
1
)
=
p
(
1
:
end
-
1
)
*
k
0
;
K
F
=
minreal
(
K
(
p
)
*
F
(
p
)
);
p
(
1
:
end
-
1
)
=
p
(
1
:
end
-
1
)
*
c
0
;
K
=
minreal
(
K
(
p
));
% Objective and gradient
function
[
J
,
J_p
]
=
J
(
p
)
...
...
@@ -75,7 +76,7 @@ KF = minreal(K(p)*F(p));
[
e
,
t
]
=
step
(
P
*
S
(
p
));
[
e
,
t
]
=
resample
(
e
,
t
);
J
=
trapz
(
t
,
abs
(
e
));
e_p
=
step
(
minreal
(
-
P
^
2
*
K
F
_p
(
p
))
*
S
(
p
)
^
2
,
t
);
% step(P*dS/dp)
e_p
=
step
(
minreal
(
-
P
^
2
*
K_p
(
p
))
*
S
(
p
)
^
2
,
t
);
% step(P*dS/dp)
J_p
=
trapz
(
t
,
mdot
(
sign
(
e
),
e_p
));
end
...
...
@@ -92,9 +93,9 @@ KF = minreal(K(p)*F(p));
cT
=
Tm
-
Mt
;
% Mks
K
F
w
=
fr
(
K
(
p
)
*
F
(
p
));
K
F
m
=
abs
(
K
F
w
);
KSm
=
K
F
m
.*
Sm
*
k
0
;
% Undo regularization
Kw
=
fr
(
C
(
p
)
*
F
(
p
));
Km
=
abs
(
Kw
);
KSm
=
Km
.*
Sm
*
c
0
;
% Undo regularization
cKS
=
KSm
-
Mks
;
% Constraints
...
...
@@ -102,10 +103,10 @@ KF = minreal(K(p)*F(p));
cEq
=
[];
% Gradients
K
F
_pw
=
fr
(
K
F
_p
(
p
));
Sm_p
=
-
mdot
(
Sm
,
real
(
mdot
(
Sw
.*
Pw
,
K
F
_pw
)));
Tm_p
=
mdot
(
Tm
,
real
(
mdot
(
Sw
.^
2.
*
Pw
.
/
Tw
,
K
F
_pw
)));
Qm_p
=
mdot
(
Sm
.
/
K
F
m
,
real
(
mdot
(
conj
(
K
F
w
)
.*
Sw
,
K
F
_pw
)));
K_pw
=
fr
(
K_p
(
p
));
Sm_p
=
-
mdot
(
Sm
,
real
(
mdot
(
Sw
.*
Pw
,
K_pw
)));
Tm_p
=
mdot
(
Tm
,
real
(
mdot
(
Sw
.^
2.
*
Pw
.
/
Tw
,
K_pw
)));
Qm_p
=
mdot
(
Sm
.
/
Km
,
real
(
mdot
(
conj
(
Kw
)
.*
Sw
,
K_pw
)));
c_p
=
[
Sm_p
;
Tm_p
;
Qm_p
]
.'
;
cEq_p
=
[];
end
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment