How to initialize outpt of a matlab function block in simulink to zero

15 vues (au cours des 30 derniers jours)
lady bird
lady bird le 19 Juin 2019
Modifié(e) : Gert Kruger le 27 Juin 2019
Hello all;
I have designed a control system for a robot manipulator using simulink which includes several matlab function blocks.
My question how is it possible to initialize the input of the controller τ to zero at the start of the simulink simulation
Thank you in advance for your help
Regards

Réponses (1)

Gert Kruger
Gert Kruger le 19 Juin 2019
Modifié(e) : Gert Kruger le 27 Juin 2019
You can add a persistent variable and check if it is empty. If it is empty, then it means it is the first time the Matlab function block is being executed, in which case you can set the output to be zero.
Example code:
function y = fcn(u)
persistent x
if isempty(x)
x = 1;
end
if (x==1)
y = 0; %y is 0 on the first simulation time step
else
y = 1; %y is 1 on for the rest
end
  2 commentaires
lady bird
lady bird le 20 Juin 2019
Thank you for your answer , i created this function just after the block that computes the τ, but it didn't initialize it to zero.
Gert Kruger
Gert Kruger le 27 Juin 2019
Modifié(e) : Gert Kruger le 27 Juin 2019
lady bird,
perhaps you can upload your model if you are still having problems.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with Simulink dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by