- If the function block supports it, try disabling zero crossing detection for that block only.
- Try changing the model's zero crossing behavior in the configuration parameters dialog. Specifically, try adaptive vs. non-adaptive zero crossing detection. You can also globally disable zero crossing detection, but this can impact the accuracy of the simulation results.
- Try restructuring the functionality you are implementing to yield a "soft" saturation as the input approaches the saturation limit.
Simulation time in Simulink goes up because of minor changes
7 views (last 30 days)
Show older comments
Hi guys, I don't know, if you can help with just this little amount of information, but i don't know how to make it more clear, so i thought i might just give it a try: i have a vehicle double-track model implemented in simulink. originally the speed was set by giving a motor torque input. i replaced that with a PID-regulator to be able to set a specific speed. the regulator actually works just fine except you can't make changes in the speed while at the same time having a steering input. This is because the part where the tire forces are limited is implemented like this:
function F_iy_max = KammKreis(F_ix, F_R_max)
%#codegen
F_iy_max = sqrt((F_R_max).^2 - F_ix.^2);
F_R_max is the maximum is calculated as the limit of adhesion, while F_ix and F_iy are the Tireforces in x- and y-direction. So when the regulator sets a high acceleration, the value under the sqrt will be negative and the result is complex, which i don't want it to be. So i tried fixing the issue by replacing the code with this code:
function F_iy_max = KammKreis(F_ix, F_R_max)
F_iy_max=zeros(1, 4)
for i=1:4
if (F_ix(i)^2)<=(F_R_max(i)^2)
F_iy_max(i)=sqrt(F_R_max(i)^2 - F_ix(i)^2)
else
F_iy_max(i)=0
end
end
after all this coede fixes the issue, but the time it takes the modell to simulate for example 300s is like 40s instead of 4s. Does anyone have a clue why this happens? Thanks in advance!
0 Comments
Accepted Answer
John Barber
on 1 Sep 2015
Might be a zero-crossing detection issue. In general, when zero crossings occur, Simulink does a solver reset, which can negate the benefits of a variable-step solver if the resets occur frequently. In your case, I suspect that the implied discontinuity due to the if...else statement is triggering frequent zero crossing events. Here are some suggestions:
5 Comments
John Barber
on 2 Sep 2015
Another approach would be to implement the calculation as follows:
- Calculate F_R_max.^2 - F_ix.^2.
- Add a Constant block with the value set to [0;0;0;0]
- Add a MinMax block. Set the Function parameter to max, the Number of inputs parameter to 2, and uncheck the Enable zero crossing detection box.
- Connect the outputs of (1) and (2) to the inputs of the MinMax block.
- Connect the output of the MinMax block to a Sqrt block to get the equivalent output to your modified code.
More Answers (0)
See Also
Categories
Find more on Sources 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!