Global declaration not resolved to a Data Store Memory block registered via the Ports and Data Manager.
36 次查看(过去 30 天)
显示 更早的评论
i was trying to make a predictive code algorithm however i recieve the same error every time .
code below.
function [Sa,Sb,Sc] = control(T_ref,sflux_ref,wm,i_meas)
% Variables defined in the parameters file
global Ts Rs Lr Lm Ls p tr kr r_sigma t_sigma lambda v states
persistent x_opt Fs %Fsp1 Tp1 g
if isempty(x_opt), x_opt = 1; end
if isempty(Fs), Fs = 0 + 0i*1; end
T_ref = T_ref(1) + 1j*T_ref(2);
sflux_ref = sflux_ref(1) + 1j*sflux(2);
i_meas = i_meas(1) + 1j*i_meas(2);
wm = wm(1) + 1j*wm(2);
% Stator flux estimate
Fs = Fs + Ts*(v(x_opt) - Rs*i_meas);
% Rotor flux estimate
Fr = Lr/Lm*Fs+i_meas*(Lm-Lr*Ls/Lm);
g_opt = 1e10;
for i = 1:8
% i-th voltage vector for current prediction
v_o1 = v(i);
% Stator flux prediction at instant k+1
Fsp1 = Fs + Ts*v_o1 - Rs*Ts*i_meas;
% Stator current prediction at instant k+1
Isp1 = (1+Ts/t_sigma)*i_meas+Ts/(t_sigma+Ts)*(1/r_sigma*((kr/tr-kr*1i*wm)*Fr+v_o1));
% Torque prediction at instant k+1
Tp1 = 3/2*p*imag(conj(Fsp1)*Isp1);
% Cost function
g = abs(T_ref - Tp1)+ lambda*abs(sflux_ref-abs(Fsp1));
if (g<g_opt)
g_opt = g;
x_opt = i;
end
end
17 个评论
Walter Roberson
2022-5-19
okay, and did you register each of the global variables as a datastore using the Port Manager?
amr makhlouf
2022-5-22
i have tried couple of things one of which to use the data store memory block , and i have tried to register the variables in the port manager but it's not shown @Walter Roberso@Walter Roberson
Walter Roberson
2022-5-22
You might be interested in my discussion at https://www.mathworks.com/matlabcentral/answers/1653710-global-variable-in-simulink#comment_2009495
amr makhlouf
2022-5-24
i have read the full discussion over there but there are some point that i don't understand :-
1- where i shoud add the first part of the code starting from % Variables required by the control algorithm
% Sampling time of the predictive algorithm [s]
Ts_value = 4e-5; till
SS.InitialValue = mat2str(value);
end .. i quite belive this should be in the intial function call backs .
2- in the main function function [sa,sb,sc] = control(T_ref,sflux_ref,wm,i_meas,kr,Lm,p,r_sigma,t_sigma,tr) you have included multiple of inputs starting from Kr to tr which is not included in the refrence paramters from the induction motor paramters
Walter Roberson
2022-5-24
That code all involved a specific model the user provided, in which that script was responsible for initializing variables and parameters, and then using sim() to run the model.
Adding additional parameters to the function was the cleanest way of importing Simulink parameters.
amr makhlouf
2022-5-24
well fourtunately , am trying the same exact model that the user was trying to do actually the full model is being illustrated in the predictive control book . i mean have you tried to run the model and it worked ? am using matlab version 2016a so idon't know if there's a comptability problem.
so my question is does the first part of the code has to be implment in the call backs and i have to change all the given variables to somthing_value e.g. sf_nom has to be sf_nom_value to work with the code ??
and when i add the additional paramters to the model it has to get a signal from somewhere which i don't know ?
i have alos attached my model so you can see we are working almost on the same thing. . i even have tried the data store memory thing which you mentioned in your explantion then i find our that Simulink.Signal Object is better for multiple global data but still recieve no result .
Walter Roberson
2022-5-24
I got the parameters and global variables working when I was helping the person. The overall code could not be run because of the unexpected 2x1 vector that I discussed in that Answer. (There is a bus that is being split into two entities instead of into three, so one ends up as a vector.)
amr makhlouf
2022-5-24
alright so my question is i have to make a simulink signal to all global variables that includes : Ts Rs Lr Lm Ls p tr kr r_sigma t_sigma lambda v states ?? in the model explorer >> model workspace.
then i have to intialize the model variables till sim () in the call backs then rest of the codes in the matlab function , please correct me if am wrong ?
Walter Roberson
2022-5-26
I have attached the editted models I created in that linked Question.
When you run this, you will quickly get an error. It will say
Error using run_MPC (line 67)
Errors occurred during parsing of MATLAB function 'MPC_DTC_IM/MATLAB Function'
This is because
Incorrect dimensions for matrix multiplication.
Check that the number of columns in the first matrix matches the number of rows in the second matrix.
To perform elementwise multiplication, use '.*'.
Function 'MATLAB Function' (#64.1097.1116), line 38, column 18: "(kr/tr-kr*1i*wm)*Fr"
The reason for this is what I explained in the previous question, about the bus with 3 elements being split into two locations, leading to a vector in an unexpected place. Which is outside of the domain of the question about how to set parameters and global variables.
amr makhlouf
2022-5-27
unfourtantely i have matlab 2016a , i cannot run it . i understand the matrix problem but my question is do i have to put the first part of the code in the intial function in call backs or just put all of the code in the m file , excuse me am way to new to matlab and am trying to learn
Walter Roberson
2022-5-27
This is specifically about using matlab to set up parameters and globals, and then use sim() to run the model. This code is not designed to be put into initfcn. It is potentially possible that some of it could be moved to initfcn callbacks, but it was not designed around that possibility.
amr makhlouf
2022-5-28
i have attached the final matlab file i have made following all the steps in this thread :
1- define a signal and data store memory for global variables.
2- defining all the code inside the m file and the intial function in call backs
3- checked that every blocks work just fine sattrting from the induction motor model to lc filter that i have made
4- i even get an outside space vector modulation controller to make sure that my model is working . however i still recieve errors regarding data type could you plese let me know how can i fix this . thank you so much
akram amri
2024-2-8
Hello, I have the same problem Did you solve the code? Could you please give me the corrected code?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)