Simulation time in Simulink goes up because of minor changes

13 vues (au cours des 30 derniers jours)
Max E.
Max E. le 1 Sep 2015
Commenté : Max E. le 5 Sep 2015
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!

Réponse acceptée

John Barber
John Barber le 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:
  1. If the function block supports it, try disabling zero crossing detection for that block only.
  2. 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.
  3. Try restructuring the functionality you are implementing to yield a "soft" saturation as the input approaches the saturation limit.
  5 commentaires
John Barber
John Barber le 2 Sep 2015
Another approach would be to implement the calculation as follows:
  1. Calculate F_R_max.^2 - F_ix.^2.
  2. Add a Constant block with the value set to [0;0;0;0]
  3. 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.
  4. Connect the outputs of (1) and (2) to the inputs of the MinMax block.
  5. Connect the output of the MinMax block to a Sqrt block to get the equivalent output to your modified code.
Max E.
Max E. le 5 Sep 2015
sorry for such a late response, but you helped a lot, thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programmatic Model Editing 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