Discussion:
[Scilab-users] PID tuning with Optimization
Gona
2014-05-16 09:58:35 UTC
Permalink
Hi All,

I was trying to tune my PID controller following this article.
http://wiki.scilab.org/Xcos/Examples/PID

I have setup my environment like this,

<Loading Image...>
<Loading Image...>

And up to the first simulation, the process went well.

<Loading Image...>

I got a warning for the CMSCOPE but I guess it has nothing to do with this
problem.
*CMSCOPE('set'): Wrong size for block parameter 'Refresh period': 2
expected, getting 30 30 30 30 *

But when I tried to start the optimization, I got this error.

*-->[f_opt, x_opt] =
optim(my_optim_pid,'b',Lower,Upper,x0,algo='qn','ar',MaxEvalFunc,MaxEvalFunc,1e-3,1e-3,[1e-3;1e-3]);

CMSCOPE('set'): Wrong size for block parameter 'Refresh period': 2 expecte
d, getting 30 30 30 30
!--error 21
Invalid index.
at line 12 of function f_pid called by :
at line 2 of function my_optim_pid called by :
unc,MaxEvalFunc,1e-3,1e-3,[1e-3;1e-3])*

My f_pid function goes like this.

*function y = f_pid(x)
global Iter;
%scicos_context.l = l
%scicos_context.g = g
%scicos_context.v = v
%scicos_context.phi = phi
%scicos_context.w = w
%scicos_context.P = x(1)*Pfact;
%scicos_context.I = x(2)*Ifact;
Iter = Iter + 1;
Info = scicos_simulate(scs_m,list(),%scicos_context,flag='nw');
y_error = mean(abs((block_output('values')(:,1) -
block_output('values')(:,2))));
y_diff = mean(abs(diff(block_output('values')(:,2))));
y = 0.5*y_error + 0.5*1*y_diff; ...
printf('Evaluation %d - P = %f I = %f y = %f (y_error = %f, y_diff =
%f)\n',Iter,x(1),x(2),y,y_error,y_diff);
endfunction*

I guess the problem lies in the block_output variable.
When I tried to see the content of the block_output('values')(:,2) I got the
same error.

*-->block_output('values')(:,2)
!--error 21
Invalid index.*

I guess in my system the block_output is not in the same dimensions as that
of the example shown in the article. How can I fix this issue.

Anyone please shed some light on this issue ?
and how can I add the D gain in to the optimization ?

any help is highly appreciated.

Thanks
BR
Gona









--
View this message in context: http://mailinglists.scilab.org/PID-tuning-with-Optimization-tp4030508.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Gona
2014-05-16 16:26:16 UTC
Permalink
Hi,

I found out whats wrong basically in my system I have modeled. I hadnt had
the input pushed in to the workspace variable block_output.

I fixed that issue and now the system and output look like this.

Note: I used D gain fixed at 1 as my system is unstable without D

<Loading Image...>
<Loading Image...>

When I initialized the x0 variable to [1;5] (Initial P and I gains), The
optimization routine calculated the optimum gains 1 and 5 for P and I
respectively after 90 iterations.
*
Evaluation 90 - P = 0.999831 I = 4.997351 y = 0.007559 (y_error = 0.015119,
y_diff = 0.000000)
*
and the system response for the square wave looks like this
<Loading Image...>

Then I tried to initialize the x0 variable to [1;1] and started the
optimization routine; after 72 iterations I got 1 for P and 1 for I as
optimal gains.
*
Evaluation 71 - P = 0.999973 I = 1.001996 y = 0.240250 (y_error = 0.446943,
y_diff = 0.033557)
Evaluation 72 - P = 0.999973 I = 0.997996 y = 0.240493 (y_error = 0.447429,
y_diff = 0.033557)
*

1. Why is that the optimization routine seems to take optimal values very
close to the initially given values. ? I am not a pro but I guess it might
have something to do with quasi-Newton method which had been used in this
example as its only possible to find local minima ? In this case do we need
to guess the correct value approximately before running the optimization ?

2. How can I incorporate D gain in to this.

Thanks a lot in advance.





--
View this message in context: http://mailinglists.scilab.org/PID-tuning-with-Optimization-tp4030508p4030515.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Gona
2014-05-17 15:10:41 UTC
Permalink
Hi,

Its none of the guesses I made above. In the example tuning shown in scilab
article initial values are set to [1,1] but final P value comes around 50.

I am posting here my system in SS form and TF form thinking it might give
some insight.
<Loading Image...>

<Loading Image...>

Does the optim function work in the order of my TF ? or do I need to think
about another optimization algorithm. ?

Any feedback is really valuable for me and I do appreciate your time and
effort on this.

Thanks in advance.
BR
Gona.



--
View this message in context: http://mailinglists.scilab.org/PID-tuning-with-Optimization-tp4030508p4030525.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Loading...