help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

closed loop simulation of A,B,C,D state-space system


From: Beginner1
Subject: closed loop simulation of A,B,C,D state-space system
Date: Tue, 7 Aug 2018 05:42:34 -0500 (CDT)

Hi everyone!

I need help with my code. This is a very simplified version of my real code
but contains the specific issues to solve. The purpose of this code is to
simulate during 3 seconds a system given by its ABCD space-state matrixes
which have been validated and simulated previously without issues in open
loop. Now, I want to simulate it in closed loop. Therefore I need to make a
"for loop" by connecting the outputs idref iqref with the inputs vdc, vac by
means of a sensing gain. (This does not have to have a physical meaning, it
is just for solving the issue with the code). Below you have my code:




/*%Packages call
  pkg control load
  pkg io load 
%Outer Loop parameters
  kv=15;%Constante proporcional del PI de la componente d 
  Tv=0.05;%Constante de tiempo del PI de la componente d 
  kq=0.4;%Constante proporcional del PI de la componente q 
  Tq=0.02;%Constante de tiempo del PI de la componente q 
  kdroop_AC=0;%-3;%Pendiente droop Q/U_AC 
  droop_FSM=0.05;%Pendiente droop P/f 
  FSM_slope=droop_FSM/0.002;%Pendiente droop P/f en p.u.
  enable=0;
%Initial conditions
  xv_0=0.69819;
  xq_0=0;
  x0=[xv_0;xq_0];
%Definition of ABCD matrixes
  A_ol=[0 0;0 0];
  B_ol=[-kv/Tv kv/Tv 0 0 0 0 -kv*FSM_slope*enable/Tv kv*enable/Tv
-kv*enable/Tv kv*enable/Tv;0 0 kq/Tq -kq/Tq -(kq/Tq)*kdroop_AC
(kq/Tq)*kdroop_AC 0 0 0 0];
  C_ol=[1 0;0 1];
  D_ol=[-kv kv 0 0 0 0 -kv*FSM_slope*enable kv*enable -kv*enable kv*enable;0
0 kq -kq -kq*kdroop_AC kq*kdroop_AC 0 0 0 0];
%Definition of state-space equations x.=Ax+Bu; y=Cx+Du 
  stname_ol = {'xv','xq'};
 
inname_ol={'vdcref','vdc','qacref','qac','vacref','vac','fmeas','pdcref','paux','FSMcoordpos'};
  outname_ol={'idref','iqref'};
  sys_ol = ss
(A_ol,B_ol,C_ol,D_ol,'stname',stname_ol,'inname',inname_ol,'outname',outname_ol);
  
%Closed loop  
  Tfinal=3;
  for t=1:0.0001:Tfinal 
    
  if t==1 %first instant
    U = [vdcref(t) vdc(t) qacref(t) qac(t) vacref(t) vac(t) fmeas(t)
pdcref(t) paux(t) FSMcoordpos(t)];
   [y(t),t(t),x(t)] = lsim(sys_ol,U,t(t),x0);
   id_ref(t)=y(t,1);
   iq_ref(t)=y(t,2);
  else  %the rest of the time
    vdc(t)=50*id_ref(t-1);
    vac(t)=50*iq_ref(t-1);
    U = [vdcref(t) vdc(i) qacref(t) qac(t) vacref(t) vac(t) fmeas(t)
pdcref(t) paux(t) FSMcoordpos(t)];
   [y(t),t(t),x(t)] = lsim(sys_ol,U,t(t),x0(t));
   id_ref(t)=y(t,1);
   iq_ref(t)=y(t,2);
   xv_0(t)=x(t,1);
   xq_0(t)=x(t,2);
   x0(t)=[xv_0(t);xq_0(t)];
  endif
 endfor  
 
 %Plot of vdc input and idref,iqref responses
    figure;
    subplot(3,1,1)
    plot(t,vdc)
    ylabel("vdc(p.u)")
    subplot(3,1,2)
    plot(t,y_idref,t,id_ref)
    ylabel("id_r_e_f(p.u)")
    subplot(3,1,3)
    plot(t,y_iqref,t,iq_ref)
    ylabel("iq_r_e_f(p.u)")
    xlabel("t(s)")
*/
   

However, I do obtain illogical answers in the console:

/*error: lsim: input vector 'u' must have 10 columns
error: called from
    lsim>__linear_simulation__ at line 277 column 5
    lsim at line 145 column 10
    Terminal_Master_P2P_closed_loop at line 38 column 20*/

 when it is clear that for each loop u has 10 columns...

Any suggestion to improve the code will be very welcome. 
Thanks folks



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]