Output Size of Simulink Block set to constant input variable..Is this possible?

2 vues (au cours des 30 derniers jours)
Grazzle
Grazzle le 8 Avr 2020
Commenté : Grazzle le 9 Avr 2020
Hi everyone, first time poster here but I am at a wall!
I have a unique problem in Simulink and I have not been able to find anyone that has had a similar issue.
Here is an ovierview of the code:
I have a buffer block in my simulink model. Essentially this just takes measurments and collects them at a high frequency to spit them out at a slower frequecny than they are recieved. For example, If we get a 3 channel (let's say x,y,z) signal at 100hz into the buffer, and want to send out info from the buffer at 50hz, we would pass a [meas x size] vector, in this case 3x2, out of the buffer every .02 seconds. The code looks something like this:
function [3_axis_meas_out] = myBuffer(3_axis_meas_in)
size=2;
if isempty(3_axis_meas_out)
3_axis_meas_out = zeros(3,size); %Set Vec to 3xn where n is size
end
%% Buffer Data (Most Recent Data on Right)
temp = [3_axis_meas_out(:,2:end),3_axis_meas_in]; %Update Buffer: shift buffer left, meas replaces 3x1 on far right of buffer
%% Output
3_axis_meas_out = temp; %Output the current state of the buffer
end
end
Here is the Problem:
So the code above works. The problem is the flag "size" must be hard coded every time the sim is recompiled, which is not ideal when you have to change the frequencies often. Ideally, "size" would be defined in a start up script by dividng the two frequncies (.02/.01), and the code would be changed to take an input of "size" from a contant block linked to a variable- see below:
function [3_axis_meas_out] = myBuffer(3_axis_meas_in,INPUT_SIZE_CONSTANT_BLOCK)
size=INPUT_SIZE_CONSTANT_BLOCK;
if isempty(3_axis_meas_out)
3_axis_meas_out = zeros(3,size); %Set Vec to 3xn where n is size
end
%% Buffer Data (Most Recent Data on Right)
temp = [3_axis_meas_out(:,2:end),3_axis_meas_in]; %Update Buffer: shift buffer left, acc meas replaces 3x1 on far right of buffer
%% Output
3_axis_meas_out = temp; %Output the current state of the buffer
end
end
But when I try to run it, it gets the following error:
Simulink cannot determine sizes and/or types of the outputs for block 'myBuffer' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
So it appears that simulink wants you to specify the size every time with a scalar, so it knows how big to make the output before running. I get it. BUT...there must be another way to have this automated. Please Help!!
Other notes: I am using rapid accelerator
Thanks, I appreciate it!

Réponses (1)

Jonas
Jonas le 9 Avr 2020
Does this help?
  3 commentaires
Jonas
Jonas le 9 Avr 2020
Can't you use your variable for defining the size in the setting where it defines the input variable size for the MATLAB Function block?
Grazzle
Grazzle le 9 Avr 2020
Nope. I can use that variable everywhere else to establish port sizes in my sim- except in that one spot. For some reason simulink wants a scalar there. I almost feel like it is more related to memory than port sizing. for example, I have [3,size] set throught my sim in other spots down stream of the buffer, but I can not seem to do that there. Even if I do, simulink will still give me that error saying not enough info

Connectez-vous pour commenter.

Catégories

En savoir plus sur Physical Units dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by