How can I keep the quaternion state normalized at every step in a MATLAB S-function, not just at the output?
Afficher commentaires plus anciens
Hello,
I am simulating the dynamics of a quadrotor using a MATLAB S-function. The attitude is represented with a quaternion. I normalize it in mdlOutputs. However, I also need the quaternion to be normalized after each integration/update step, because the internal state vector x (which contains the quaternion) is what gets fed back into the dynamics.
I'm searching for something like "mdlUpdate", but it's used for discrete states.
Can you please advice me on how should I proceed?
Thanks in advance!
1 commentaire
Sam Chak
le 3 Sep 2025
You may need to use the normalized quaternion differential equations. However, I would suggest testing the basic integration code in MATLAB using the ode45 solver before implementing it in the Simulink S-function.
Could you provide the MATLAB code for basic attitude dynamics using the normalized quaternion differential equations? You can click the "play" icon
to run the code in this forum.
function dx = normAttitude(t, x)
dx = [];
end
[t, x] = ode45(@normAttitude, tspan, x0);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Simulink Coder dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!