Hello!
I'm trying to perform a calculation based on some simulation parameters in Simulink before the simulation runs but after it's loaded. Basically, I need some constraints evaluated at run-time and I'd rather not have them eval'd inside the block diagram.
For compactness and portability I'd like to keep the constraints as simulink parameters defined in the Model Workspace, and I'm running into a few problems understanding the scope of the callback functions.
At the moment I have the following (simplified) code sitting in the InitFcn:
hws = get_param(bdroot,'modelworkspace');
SPEED_MIN = evalin(hws,'SPEED_MIN');
FLOW_RATIO_MIN = evalin(hws,'RATIO_MIN');
V_MIN = evalin(hws,'V_MIN');
FLYWHEEL_R = evalin(hws,'FLYWHEEL_R');
minspeed_rad = SPEED_MIN.Value*(2*pi/60);
w_min = minspeed_rad * RATIO_MIN.Value;
V_MIN.Value = 1/2 * minspeed_rad * FLYWHEEL_R.Value;
My questions:
- Is this the "right" way to do it? If it's one of the right ways, what are the other ones? I'm not super comfortable with the idea of using "evalin" to grab handles to the workspace vars. Also, it's leaving all of the junk in the MATLAB base workspace when it's through, so it's clearly not evaluating in the scope I would like (model-level). Is there a way to import an M-File to the model file for evaluation like you can import MAT-files to the model workspace?
- Why does pasting the above code in the StartFcn callback cause Simulink to throw an "Attempted to Access Read only workspace" error while the InitFcn runs fine?
Thanks, Peter