13.07.2015 Views

An Integrated, Modular Simulation System for Education ... - Cal Poly

An Integrated, Modular Simulation System for Education ... - Cal Poly

An Integrated, Modular Simulation System for Education ... - Cal Poly

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

* calulate the trig functions first */sAlpha=sin(alpha);cAlpha=cos(alpha);sBeta=sin(beta);cBeta=cos(beta);/* coordinate trans<strong>for</strong>m <strong>for</strong> the velocity and positionfrom airspeed body axis to world axis */uWind = u*cAlpha*cBeta+v*sBeta+w*sAlpha*cBeta;vWind = -u*cAlpha*sBeta+v*cBeta-w*sAlpha*sBeta;wWind = -u*sAlpha+w*cAlpha;xDot = uWind*CTheta*CPsi+vWind*(SPhi*STheta*CPsi-CPhi*SPsi)+wWind*(CPhi*STheta*CPsi+SPhi*SPsi);yDot = uWind*CTheta*SPsi+vWind*(SPhi*STheta*SPsi+CPhi*CPsi)+wWind*(CPhi*STheta*SPsi-SPhi*CPsi);zDot = -uWind*STheta+vWind*SPhi*CTheta+wWind*CPhi*CTheta;Theta +=(3.0*thetaDot-OldThetaDot)/2.0*dt; /***** Pitch Euler angle integration *****/Phi +=(3.0*phiDot-OldPhiDot)/2.0*dt; /* roll */Psi +=(3.0*psiDot-OldPsiDot)/2.0*dt; /* yaw */OldThetaDot=thetaDot;OldPhiDot=phiDot;OldPsiDot=psiDot;y[3]=Psi; /* <strong>An</strong>gle output vector - yaw DEGREES */y[4]=Theta; /* Pitch */y[5]=Phi; /* roll */X +=(3.0*xDot-OldxDot)/2.0*dt; /***** position integration *****/YY +=(3.0*yDot-OldyDot)/2.0*dt;Z +=(3.0*zDot-OldzDot)/2.0*dt;y[0] = X; /* Position output vector */y[1] = YY;y[2] = Z;OldxDot=xDot;OldyDot=yDot;OldzDot=zDot;}/* Function: mdlTerminate =====================================================* Abstract:* No termination needed, but we are required to have this routine.*/static void mdlTerminate(SimStruct *S){}#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */#include "simulink.c" /* MEX-file interface mechanism */#else#include "cg_sfun.h" /* Code generation registration function */164

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!