Simulink sample time error
31 views (last 30 days)
Show older comments
I am using Simulink to run drive cycle simulations. I am using a Matlab script to automatically cycle between drive cycles, some using a From Spreadsheet block and some a From Workspace. The drive cycles have different sample times, so I tried using the Matlab script to assign a value to variable "dt" before running each cycle, and using this variable in the model's sample time. The model will return the following error for this setup:
% The sample time period (0.1) of 'p1_model/From Workspace' is
% not an integer multiple of the fixed step size (1.0) specified
% for model.
I believe this error has something to do with the fact that the "sim()" function compiles all drive cycles as if they were all being run, even if they are not selected as active in the multiport switch. How can I keep Simulink from doing this? Or how can I better setup the sample time parameter? I've attached examples of how this is implemented in both my Matlab script and Simulink model. Thank you!
Here is an example of how the simulation is called in the script:
%% HwFET
HwFET_drive = xlsread('HwFET.xlsx');
dt = 1; % seconds
t_end = dt*length(HwFET_drive);
clear sim_out;
pick = 4;
sim_out = sim('p1_model');
HwFET_info.PosPropEnergy = max(sim_out.PosPropEnergy);
HwFET_info.NegPropEnergy = min(sim_out.NegPropEnergy);
HwFET_info.NetPropEnergy = sim_out.NetPropEnergy(end);
HwFET_info.PeakPosPower = max(sim_out.PeakPosPower);
HwFET_info.PeakNegPower = min(sim_out.PeakNegPower);
HwFET_info.MaxTractForce = max(sim_out.MaxTractForce);
HwFET_info.MaxSpeed = max(sim_out.MaxSpeed);
HwFET_info = cell2mat(struct2cell(HwFET_info));
0 Comments
Answers (1)
Fangjun Jiang
on 3 Feb 2020
The error has nothing to do with the script. According to the error message, your simulation step size is fixed, 1 second. However, the sample time of the "From Workspace" block 'p1_model/From Workspace' is 0.1 second. This is the error. Set the sample time as 1 second.
2 Comments
Fangjun Jiang
on 4 Feb 2020
Then you have to figure out what is the best setting, most likely reduce the sample time and fixed step size to a small number such as 0.01 so the derivative block would give reasonalble ouput.
See Also
Categories
Find more on Schedule Model Components in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!