I am implementing a H2/LQG controller to get the optimum force. In simulink I am using Matlab function block. The error in this block I am getting is
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
function y = fcn(u1,u2) coder.extrinsic('Controlle'); y=0; y=Controlle(u1,u2) end
The code for controlle is as given below:- function OCF=Controlle(M,t) syms s M=M.*(1/s); k=10^5*[12 -6.84 0;-6.84 13.7 -6.84;0 -6.84 6.84]; m=[98.3 0 0;0 98.3 0;0 0 98.3]; c=[175 -50 0;-50 100 -50;0 -50 50]; Ga=50; Gc=[-1;0;0]; Lc=[1;1;1]; Ec=-[0;0;0;Lc]; Ac=[zeros(3,3) eye(3);-inv(m)*k -inv(m)*c]; Bc=[0;0;0;inv(m)*Gc]; Cc=[-inv(m)*k -inv(m)*c;1 0 0 0 0 0]; Dc=[inv(m)*Gc;0]; Qc=[0 0 0 0;0 0 0 0;0 0 1 0;0 0 0 0 ]; r1=1e-17; [P]=care(Ac,Bc,Cc'*Qc*Cc,r1); K=(Bc'*P)/r1; [S]=care(Ac,Cc',Ga*Ec*Ec'); Lr=(Cc*S)'; fc=ilaplace((K*inv(s*eye(6,6)-(Ac-Lr*Cc))*([Lr (Bc-Lr*Dc)])*M),s,t); OCF=vpa(fc,3); end
ERROR:- MATLAB Function Interface Error: MATLAB expression 'Controlle' is not numeric. Block Controller/MATLAB Function1 (#22) While executing: none
1 Commento
Risposte (1)
Ryan Livingston
il 21 Gen 2015
In fcn the output variable is declared to be a real double scalar in:
y=0;
However, the output of the function Controlle is from the vpa function which returns a symbolic value:
>> f = vpa(10)
f =
10.0
>> class(f)
ans =
sym
The data type, size, and complexity in the assignment y=0 needs to match the value returned by the extrinsic function being called ( Controlle in this case).
You can use Symbolic and vpa computations in the function being called extrinsically but:
- If pre-assigning to y, as in y=0, y must be a data type supported for code generation. See data definition doc for more info.
- If y is left without the pre-assignment, y=0, you will be able to pass y to other extrinsic functions but will not be able to return it from the MATLAB Function Block or do many other things with it.
The choice depends upon what you want to do with the output of Controlle.
Lastly, there is more documentation on extrinsic functions that cover what I've said in much more detail.
2 Commenti
Ryan Livingston
il 22 Gen 2015
You could just make sure that the output of Controlle is a double. For example, you could change the last line to:
OCFvpa = vpa(fc,3);
OCF = double(fc);
Then in the MATLAB Function Block use:
function y = fcn(u1,u2)
coder.extrinsic('Controlle');
y=zeros(M,N);
y=Controlle(u1,u2)
where M and N describe the size of the array you expect Controlle to return.
Vedere anche
Categorie
Scopri di più su Code Generation in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!