A-2.1 M-FUNCTIONS
A-2.1.1 Acact21
#define S_FUNCTION_NAME Acact21 #define S_FUNCTION_LEVEL 2 #include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters ssSetNumSFcnParams(S, 11);
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) #define M_PRM(S) ssGetSFcnParam(S, 0) #define g_PRM(S) ssGetSFcnParam(S, 1) #define P_c_N1_PRM(S) ssGetSFcnParam(S, 2) #define P_c_N2_PRM(S) ssGetSFcnParam(S, 3) #define P_c_N3_PRM(S) ssGetSFcnParam(S, 4) #define P_c_L1_PRM(S) ssGetSFcnParam(S, 5) #define P_c_L2_PRM(S) ssGetSFcnParam(S, 6) #define P_c_L3_PRM(S) ssGetSFcnParam(S, 7) #define P_c_R1_PRM(S) ssGetSFcnParam(S, 8) #define P_c_R2_PRM(S) ssGetSFcnParam(S, 9) #define P_c_R3_PRM(S) ssGetSFcnParam(S, 10) //Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 33);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 42);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T Fa1 = (*uPtrs[0]);
real_T Fa2 = (*uPtrs[1]); real_T Fa3 = (*uPtrs[2]); real_T Ma1 = (*uPtrs[3]); real_T Ma2 = (*uPtrs[4]); real_T Ma3 = (*uPtrs[5]); real_T F_LG_R1 = (*uPtrs[6]); real_T F_LG_R2 = (*uPtrs[7]); real_T F_LG_R3 = (*uPtrs[8]); real_T M_LG_R1 = (*uPtrs[9]); real_T M_LG_R2 = (*uPtrs[10]); real_T M_LG_R3 = (*uPtrs[11]); real_T F_LG_N1 = (*uPtrs[12]); real_T F_LG_N2 = (*uPtrs[13]); real_T F_LG_N3 = (*uPtrs[14]); real_T M_LG_N1 = (*uPtrs[15]); real_T M_LG_N2 = (*uPtrs[16]); real_T M_LG_N3 = (*uPtrs[17]); real_T F_LG_L1 = (*uPtrs[18]); real_T F_LG_L2 = (*uPtrs[19]); real_T F_LG_L3 = (*uPtrs[20]); real_T M_LG_L1 = (*uPtrs[21]); real_T M_LG_L2 = (*uPtrs[22]); real_T M_LG_L3 = (*uPtrs[23]); real_T Ft1 = (*uPtrs[24]); real_T Ft2 = (*uPtrs[25]); real_T Ft3 = (*uPtrs[26]); real_T Mt1 = (*uPtrs[27]); real_T Mt2 = (*uPtrs[28]); real_T Mt3 = (*uPtrs[29]); real_T u31 = (*uPtrs[30]); real_T u32 = (*uPtrs[31]); real_T u33 = (*uPtrs[32]);
real_T M = (mxGetPr(M_PRM(S))[0]); real_T g = (mxGetPr(g_PRM(S))[0]); real_T P_c_N1 = {(mxGetPr(P_c_N1_PRM(S))[0])}; real_T P_c_N2 = {(mxGetPr(P_c_N2_PRM(S))[0])}; real_T P_c_N3 = {(mxGetPr(P_c_N3_PRM(S))[0])}; real_T P_c_L1 = {(mxGetPr(P_c_L1_PRM(S))[0])}; real_T P_c_L2 = {(mxGetPr(P_c_L2_PRM(S))[0])}; real_T P_c_L3 = {(mxGetPr(P_c_L3_PRM(S))[0])}; real_T P_c_R1 = {(mxGetPr(P_c_R1_PRM(S))[0])}; real_T P_c_R2 = {(mxGetPr(P_c_R2_PRM(S))[0])}; real_T P_c_R3 = {(mxGetPr(P_c_R3_PRM(S))[0])}; real_T sphi,cphi,sthe,cthe,spsi,cpsi,Gb_i[3][3],F_LG_R[3],M_LG_R[3],F_LG_N[3],M_LG_N[3],F_LG_L[3],M_LG_L[3], W[3],Fa_w_t[3],F_LG[3],F_A[3],Mright[3],Mnose[3],Mleft[3],Ma_w_t[3],M_LG[3],M_A[3],Faeri[3],Fa_w_ti[3],F_LGi[3], F_Ai[3],Maeri[3],Ma_w_ti[3],M_LGi[3],M_Ai[3];
//Defining aerodynamic forces L, D (wind axes) and pitch moment Ms ("stability axes") sphi = sin(u31); cphi = cos(u31); sthe = sin(u32); cthe = cos(u32); spsi = sin(u33); cpsi = cos(u33); Gb_i[0][0] = cthe*cpsi; Gb_i[0][1] = sphi*sthe*cpsi-cphi*spsi; Gb_i[0][2] = cphi*sthe*cpsi+sphi*spsi; Gb_i[1][0] = -cthe*cpsi; Gb_i[1][1] = -(sphi*sthe*spsi+cphi*cpsi); Gb_i[1][2] = -(cphi*sthe*spsi-sphi*cpsi); Gb_i[2][0] = +sthe; Gb_i[2][1] = -sphi*cthe; Gb_i[2][2] = -cphi*cthe; F_LG_R[0] = Gb_i[0][0]*F_LG_R1+Gb_i[0][1]*F_LG_R2+Gb_i[0][2]*F_LG_R3; F_LG_R[1] = Gb_i[1][0]*F_LG_R1+Gb_i[1][1]*F_LG_R2+Gb_i[1][2]*F_LG_R3; F_LG_R[2] = Gb_i[2][0]*F_LG_R1+Gb_i[2][1]*F_LG_R2+Gb_i[2][2]*F_LG_R3; M_LG_R[0] = Gb_i[0][0]*M_LG_R1+Gb_i[0][1]*M_LG_R2+Gb_i[0][2]*M_LG_R3; M_LG_R[1] = Gb_i[1][0]*M_LG_R1+Gb_i[1][1]*M_LG_R2+Gb_i[1][2]*M_LG_R3; M_LG_R[2] = Gb_i[2][0]*M_LG_R1+Gb_i[2][1]*M_LG_R2+Gb_i[2][2]*M_LG_R3; F_LG_N[0] = Gb_i[0][0]*F_LG_N1+Gb_i[0][1]*F_LG_N2+Gb_i[0][2]*F_LG_N3;
F_LG_N[1] = Gb_i[1][0]*F_LG_N1+Gb_i[1][1]*F_LG_N2+Gb_i[1][2]*F_LG_N3; F_LG_N[2] = Gb_i[2][0]*F_LG_N1+Gb_i[2][1]*F_LG_N2+Gb_i[2][2]*F_LG_N3; M_LG_N[0] = Gb_i[0][0]*M_LG_N1+Gb_i[0][1]*M_LG_N2+Gb_i[0][2]*M_LG_N3; M_LG_N[1] = Gb_i[1][0]*M_LG_N1+Gb_i[1][1]*M_LG_N2+Gb_i[1][2]*M_LG_N3; M_LG_N[2] = Gb_i[2][0]*M_LG_N1+Gb_i[2][1]*M_LG_N2+Gb_i[2][2]*M_LG_N3; F_LG_L[0] = Gb_i[0][0]*F_LG_L1+Gb_i[0][1]*F_LG_L2+Gb_i[0][2]*F_LG_L3; F_LG_L[1] = Gb_i[1][0]*F_LG_L1+Gb_i[1][1]*F_LG_L2+Gb_i[1][2]*F_LG_L3; F_LG_L[2] = Gb_i[2][0]*F_LG_L1+Gb_i[2][1]*F_LG_L2+Gb_i[2][2]*F_LG_L3; M_LG_L[0] = Gb_i[0][0]*M_LG_L1+Gb_i[0][1]*M_LG_L2+Gb_i[0][2]*M_LG_L3; M_LG_L[1] = Gb_i[1][0]*M_LG_L1+Gb_i[1][1]*M_LG_L2+Gb_i[1][2]*M_LG_L3; M_LG_L[2] = Gb_i[2][0]*M_LG_L1+Gb_i[2][1]*M_LG_L2+Gb_i[2][2]*M_LG_L3; W[0] = Gb_i[0][0]*0+Gb_i[0][1]*0-Gb_i[0][2]*M*g; W[1] = Gb_i[1][0]*0+Gb_i[1][1]*0-Gb_i[1][2]*M*g; W[2] = Gb_i[2][0]*0+Gb_i[2][1]*0-Gb_i[2][2]*M*g; Fa_w_t[0] = Fa1+Ft1+W[0]; Fa_w_t[1] = Fa2+Ft2+W[1]; Fa_w_t[2] = Fa3+Ft3+W[2]; F_LG[0] = F_LG_R[0]+F_LG_N[0]+F_LG_L[0]; F_LG[1] = F_LG_R[1]+F_LG_N[1]+F_LG_L[1]; F_LG[2] = F_LG_R[2]+F_LG_N[2]+F_LG_L[2]; F_A[0] = F_LG[0]+Fa_w_t[0]; F_A[1] = F_LG[1]+Fa_w_t[1]; F_A[2] = F_LG[2]+Fa_w_t[2]; Mright[0] = P_c_R2*F_LG_R[2]-P_c_R3*F_LG_R[1]; Mright[1] = -(P_c_R1*F_LG_R[2]-P_c_R3*F_LG_R[0]); Mright[2] = P_c_R1*F_LG_R[1]-P_c_R2*F_LG_R[0]; Mnose[0] = P_c_N2*F_LG_N[2]-P_c_N3*F_LG_N[1]; Mnose[1] = -(P_c_N1*F_LG_N[2]-P_c_N3*F_LG_N[0]); Mnose[2] = P_c_N1*F_LG_N[1]-P_c_N2*F_LG_N[0]; Mleft[0] = P_c_L2*F_LG_L[2]-P_c_L3*F_LG_L[1]; Mleft[1] = -(P_c_L1*F_LG_L[2]-P_c_L3*F_LG_L[0]); Mleft[2] = P_c_L1*F_LG_L[1]-P_c_L2*F_LG_L[0]; Ma_w_t[0] = Ma1+Mt1; Ma_w_t[1] = Ma2+Mt2; Ma_w_t[2] = Ma3+Mt3; M_LG[0]=M_LG_R[0]+M_LG_N[0]+M_LG_L[0]+Mright[0]+Mnose[0]+Mleft[0]; M_LG[1]=M_LG_R[1]+M_LG_N[1]+M_LG_L[1]+Mright[1]+Mnose[1]+Mleft[1]; M_LG[2]=M_LG_R[2]+M_LG_N[2]+M_LG_L[2]+Mright[2]+Mnose[2]+Mleft[2]; M_A[0] = M_LG[0]+Ma_w_t[0]; M_A[1] = M_LG[1]+Ma_w_t[1]; M_A[2] = M_LG[2]+Ma_w_t[2]; Faeri[0] = Gb_i[0][0]*Fa1+Gb_i[1][0]*Fa2+Gb_i[2][0]*Fa3; Faeri[1] = Gb_i[0][1]*Fa1+Gb_i[1][1]*Fa2+Gb_i[2][1]*Fa3; Faeri[2] = Gb_i[0][2]*Fa1+Gb_i[1][2]*Fa2+Gb_i[2][2]*Fa3; Fa_w_ti[0] = Gb_i[0][0]*Fa_w_t[0]+Gb_i[1][0]*Fa_w_t[1]+Gb_i[2][0]*Fa_w_t[2]; Fa_w_ti[1] = Gb_i[0][1]*Fa_w_t[0]+Gb_i[1][1]*Fa_w_t[1]+Gb_i[2][1]*Fa_w_t[2]; Fa_w_ti[2] = Gb_i[0][2]*Fa_w_t[0]+Gb_i[1][2]*Fa_w_t[1]+Gb_i[2][2]*Fa_w_t[2]; F_LGi[0] = Gb_i[0][0]*F_LG[0]+Gb_i[1][0]*F_LG[1]+Gb_i[2][0]*F_LG[2]; F_LGi[1] = Gb_i[0][1]*F_LG[0]+Gb_i[1][1]*F_LG[1]+Gb_i[2][1]*F_LG[2]; F_LGi[2] = Gb_i[0][2]*F_LG[0]+Gb_i[1][2]*F_LG[1]+Gb_i[2][2]*F_LG[2]; F_Ai[0] = Gb_i[0][0]*F_A[0]+Gb_i[1][0]*F_A[1]+Gb_i[2][0]*F_A[2]; F_Ai[1] = Gb_i[0][1]*F_A[0]+Gb_i[1][1]*F_A[1]+Gb_i[2][1]*F_A[2]; F_Ai[2] = Gb_i[0][2]*F_A[0]+Gb_i[1][2]*F_A[1]+Gb_i[2][2]*F_A[2]; Maeri[0] = Gb_i[0][0]*Ma1+Gb_i[1][0]*Ma2+Gb_i[2][0]*Ma3; Maeri[1] = Gb_i[0][1]*Ma1+Gb_i[1][1]*Ma2+Gb_i[2][1]*Ma3; Maeri[2] = Gb_i[0][2]*Ma1+Gb_i[1][2]*Ma2+Gb_i[2][2]*Ma3; Ma_w_ti[0] = Gb_i[0][0]*Ma_w_t[0]+Gb_i[1][0]*Ma_w_t[1]+Gb_i[2][0]*Ma_w_t[2]; Ma_w_ti[1] = Gb_i[0][1]*Ma_w_t[0]+Gb_i[1][1]*Ma_w_t[1]+Gb_i[2][1]*Ma_w_t[2];
Ma_w_ti[2] = Gb_i[0][2]*Ma_w_t[0]+Gb_i[1][2]*Ma_w_t[1]+Gb_i[2][2]*Ma_w_t[2]; M_LGi[0] = Gb_i[0][0]*M_LG[0]+Gb_i[1][0]*M_LG[1]+Gb_i[2][0]*M_LG[2]; M_LGi[1] = Gb_i[0][1]*M_LG[0]+Gb_i[1][1]*M_LG[1]+Gb_i[2][1]*M_LG[2]; M_LGi[2] = Gb_i[0][2]*M_LG[0]+Gb_i[1][2]*M_LG[1]+Gb_i[2][2]*M_LG[2]; M_Ai[0] = Gb_i[0][0]*M_A[0]+Gb_i[1][0]*M_A[1]+Gb_i[2][0]*M_A[2]; M_Ai[1] = Gb_i[0][1]*M_A[0]+Gb_i[1][1]*M_A[1]+Gb_i[2][1]*M_A[2]; M_Ai[2] = Gb_i[0][2]*M_A[0]+Gb_i[1][2]*M_A[1]+Gb_i[2][2]*M_A[2]; //outputs y[0] = Fa_w_t[0]; y[1] = Fa_w_t[1];; y[2] = Fa_w_t[2]; y[3] = F_LG[0]; y[4] = F_LG[1]; y[5] = F_LG[2]; y[6] = F_A[0]; y[7] = F_A[1]; y[8] = F_A[2]; y[9] = Ma_w_t[0]; y[10] = Ma_w_t[1]; y[11] = Ma_w_t[2]; y[12] = M_LG[0]; y[13] = M_LG[1]; y[14] = M_LG[2]; y[15] = M_A[0]; y[16] = M_A[1];; y[17] = M_A[2];; y[18] = Faeri[0]; y[19] = Faeri[1]; y[20] = Faeri[2]; y[21] = Fa_w_ti[0]; y[22] = Fa_w_ti[1]; y[23] = Fa_w_ti[2]; y[24] = F_LGi[0]; y[25] = F_LGi[1]; y[26] = F_LGi[2]; y[27] = F_Ai[0]; y[28] = F_Ai[1]; y[29] = F_Ai[2]; y[30] = Maeri[0]; y[31] = Maeri[1]; y[32] = Maeri[2]; y[33] = Ma_w_ti[0]; y[34] = Ma_w_ti[1]; y[35] = Ma_w_ti[2]; y[36] = M_LGi[0]; y[37] = M_LGi[1]; y[38] = M_LGi[2]; y[39] = M_Ai[0]; y[40] = M_Ai[1]; y[41] = M_Ai[2]; } /* end mdlOutputs */ /* 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 */ #endif
A2.1.2 Ackyn2_4
#define S_FUNCTION_NAME ACKYN2_4 #define S_FUNCTION_LEVEL 2
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S,9); /* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) #define P_c_L1_PRM(S) ssGetSFcnParam(S, 0) #define P_c_L2_PRM(S) ssGetSFcnParam(S, 1) #define P_c_L3_PRM(S) ssGetSFcnParam(S, 2) #define P_c_N1_PRM(S) ssGetSFcnParam(S, 3) #define P_c_N2_PRM(S) ssGetSFcnParam(S, 4) #define P_c_N3_PRM(S) ssGetSFcnParam(S, 5) #define P_c_R1_PRM(S) ssGetSFcnParam(S, 6) #define P_c_R2_PRM(S) ssGetSFcnParam(S, 7) #define P_c_R3_PRM(S) ssGetSFcnParam(S, 8) //Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 18);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 27);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T u = (*uPtrs[0]); real_T v = (*uPtrs[1]); real_T w = (*uPtrs[2]); real_T p = (*uPtrs[3]); real_T q = (*uPtrs[4]); real_T r = (*uPtrs[5]); real_T up = (*uPtrs[6]); real_T vp = (*uPtrs[7]); real_T wp = (*uPtrs[8]); real_T pp = (*uPtrs[9]); real_T qp = (*uPtrs[10]); real_T rp = (*uPtrs[11]);
real_T phi = (*uPtrs[12]); real_T the = (*uPtrs[13]); real_T psi = (*uPtrs[14]); real_T xcg = (*uPtrs[15]); real_T ycg = (*uPtrs[16]); real_T zcg = (*uPtrs[17]); real_T P_c_L1 = {(mxGetPr(P_c_L1_PRM(S))[0])}; real_T P_c_L2 = {(mxGetPr(P_c_L2_PRM(S))[0])}; real_T P_c_L3 = {(mxGetPr(P_c_L3_PRM(S))[0])}; real_T P_c_N1 = {(mxGetPr(P_c_N1_PRM(S))[0])}; real_T P_c_N2 = {(mxGetPr(P_c_N2_PRM(S))[0])}; real_T P_c_N3 = {(mxGetPr(P_c_N3_PRM(S))[0])}; real_T P_c_R1 = {(mxGetPr(P_c_R1_PRM(S))[0])}; real_T P_c_R2 = {(mxGetPr(P_c_R2_PRM(S))[0])}; real_T P_c_R3 = {(mxGetPr(P_c_R3_PRM(S))[0])}; real_T b_L[3],b_N[3],b_R[3],sphi,cphi,sthe,cthe,spsi,cpsi,Gb_i[3][3],Pright[3],Pnose[3],Pleft[3],omega_b_R1,omega_b_R2,omega_b_R3, omega_b_N1,omega_b_N2,omega_b_N3,omega_b_L1,omega_b_L2,omega_b_L3,Ppright[3],Ppnose[3],Ppleft[3],omega_V1,omega_V 2,omega_V3, omega2_b_R1,omega2_b_R2,omega2_b_R3,omega2_b_N1,omega2_b_N2,omega2_b_N3,omega2_b_L1,omega2_b_L2,omega2_b_L3, pomega_b_R1,pomega_b_R2, pomega_b_R3,pomega_b_N1,pomega_b_N2,pomega_b_N3,pomega_b_L1,pomega_b_L2,pomega_b_L3,sommaR[3],Pppright[3],somm aN[3],Pppnose[3],sommaL[3],Pppleft[3]; //calcoli b_L[0] = P_c_L1; b_L[1] = P_c_L2; b_L[2] = P_c_L3; b_N[0] = P_c_N1; b_N[1] = P_c_N2; b_N[2] = P_c_N3; b_R[0] = P_c_R1; b_R[1] = P_c_R2; b_R[2] = P_c_R3; sphi = sin(phi); cphi = cos(phi); sthe = sin(the); cthe = cos(the); spsi = sin(psi); cpsi = cos(psi);
/*real_T Gb_i[3][3] = { { cthe*cpsi , sphi*sthe*cpsi-cphi*spsi , cphi*sthe*cpsi+sphi*spsi }, { -cthe*spsi , -(sphi*sthe*spsi+cphi*cpsi) , -(cphi*sthe*spsi-sphi*cpsi) }, { +sthe , -sphi*cthe , -cphi*cthe } } ; */
Gb_i[0][0] = cthe*cpsi; Gb_i[1][0] = sphi*sthe*cpsi-cphi*spsi; Gb_i[2][0] = cphi*sthe*cpsi+sphi*spsi; Gb_i[0][1] = -cthe*spsi; Gb_i[1][1] = -(sphi*sthe*spsi+cphi*cpsi); Gb_i[2][1] = -(cphi*sthe*spsi-sphi*cpsi); Gb_i[0][2] = sthe; Gb_i[1][2] = -sphi*cthe; Gb_i[2][2] = -cphi*cthe; /*Gb_i[0][0] = cthe*cpsi; Gb_i[0][1] = sphi*sthe*cpsi-cphi*spsi; Gb_i[0][2] = cphi*sthe*cpsi+sphi*spsi; Gb_i[1][0] = -cthe*spsi; Gb_i[1][1] = -(sphi*sthe*spsi+cphi*cpsi); Gb_i[1][2] = -(cphi*sthe*spsi-sphi*cpsi); Gb_i[2][0] = sthe; Gb_i[2][1] = -sphi*cthe; Gb_i[2][2] = -cphi*cthe;*/ Pright[0] = xcg+Gb_i[0][0]*b_R[0]+Gb_i[1][0]*b_R[1]+Gb_i[2][0]*b_R[2]; Pright[1] = ycg+Gb_i[0][1]*b_R[0]+Gb_i[1][1]*b_R[1]+Gb_i[2][1]*b_R[2];
Pright[2] = zcg+Gb_i[0][2]*b_R[0]+Gb_i[1][2]*b_R[1]+Gb_i[2][2]*b_R[2]; Pnose[0] = xcg+Gb_i[0][0]*b_N[0]+Gb_i[1][0]*b_N[1]+Gb_i[2][0]*b_N[2]; Pnose[1] = ycg+Gb_i[0][1]*b_N[0]+Gb_i[1][1]*b_N[1]+Gb_i[2][1]*b_N[2]; Pnose[2] = zcg+Gb_i[0][2]*b_N[0]+Gb_i[1][2]*b_N[1]+Gb_i[2][2]*b_N[2]; Pleft[0] = xcg+Gb_i[0][0]*b_L[0]+Gb_i[1][0]*b_L[1]+Gb_i[2][0]*b_L[2]; Pleft[1] = ycg+Gb_i[0][1]*b_L[0]+Gb_i[1][1]*b_L[1]+Gb_i[2][1]*b_L[2]; Pleft[2] = zcg+Gb_i[0][2]*b_L[0]+Gb_i[1][2]*b_L[1]+Gb_i[2][2]*b_L[2]; omega_b_R1 = q*b_R[2]-r*b_R[1]; omega_b_R2 = -(p*b_R[2]-r*b_R[0]); omega_b_R3= p*b_R[1]-q*b_R[0]; omega_b_N1 = q*b_N[2]-r*b_N[1]; omega_b_N2 = -(p*b_N[2]-r*b_N[0]); omega_b_N3= p*b_N[1]-q*b_N[0]; omega_b_L1 = q*b_L[2]-r*b_L[1]; omega_b_L2 = -(p*b_L[2]-r*b_L[0]); omega_b_L3= p*b_L[1]-q*b_L[0]; Ppright[0] = (Gb_i[0][0]*(u+omega_b_R1)+Gb_i[1][0]*(v+omega_b_R2)+Gb_i[2][0]*(w+omega_b_R3)); Ppright[1] = (Gb_i[0][1]*(u+omega_b_R1)+Gb_i[1][1]*(v+omega_b_R2)+Gb_i[2][1]*(w+omega_b_R3)); Ppright[2] = (Gb_i[0][2]*(u+omega_b_R1)+Gb_i[1][2]*(v+omega_b_R2)+Gb_i[2][2]*(w+omega_b_R3)); Ppnose[0] = (Gb_i[0][0]*(u+omega_b_N1)+Gb_i[1][0]*(v+omega_b_N2)+Gb_i[2][0]*(w+omega_b_N3)); Ppnose[1] = (Gb_i[0][1]*(u+omega_b_N1)+Gb_i[1][1]*(v+omega_b_N2)+Gb_i[2][1]*(w+omega_b_N3)); Ppnose[2] = (Gb_i[0][2]*(u+omega_b_N1)+Gb_i[1][2]*(v+omega_b_N2)+Gb_i[2][2]*(w+omega_b_N3)); Ppleft[0] = (Gb_i[0][0]*(u+omega_b_L1)+Gb_i[1][0]*(v+omega_b_L2)+Gb_i[2][0]*(w+omega_b_L3)); Ppleft[1] = (Gb_i[0][1]*(u+omega_b_L1)+Gb_i[1][1]*(v+omega_b_L2)+Gb_i[2][1]*(w+omega_b_L3)); Ppleft[2] = (Gb_i[0][2]*(u+omega_b_L1)+Gb_i[1][2]*(v+omega_b_L2)+Gb_i[2][2]*(w+omega_b_L3)); omega_V1 = q*w-r*v; omega_V2 = -(p*w-r*u); omega_V3 = p*v-q*u; omega2_b_R1 = q*omega_b_R3-r*omega_b_R2; omega2_b_R2 = -(p*omega_b_R3-r*omega_b_R1); omega2_b_R3 = p*omega_b_R2-q*omega_b_R1; omega2_b_N1 = q*omega_b_N3-r*omega_b_N2; omega2_b_N2 = -(p*omega_b_N3-r*omega_b_N1); omega2_b_N3 = p*omega_b_N2-q*omega_b_N1; omega2_b_L1 = q*omega_b_L3-r*omega_b_L2; omega2_b_L2 = -(p*omega_b_L3-r*omega_b_L1); omega2_b_L3 = p*omega_b_L2-q*omega_b_L1; pomega_b_R1 = qp*b_R[2]-rp*b_R[1]; pomega_b_R2 = -(pp*b_R[2]-rp*b_R[0]); pomega_b_R3= pp*b_R[1]-qp*b_R[0]; pomega_b_N1 = qp*b_N[2]-rp*b_N[1]; pomega_b_N2 = -(pp*b_N[2]-rp*b_N[0]); pomega_b_N3= pp*b_N[1]-qp*b_N[0]; pomega_b_L1 = qp*b_L[2]-rp*b_L[1]; pomega_b_L2 = -(pp*b_L[2]-rp*b_L[0]); pomega_b_L3= pp*b_L[1]-qp*b_L[0]; sommaR[0] = up+omega_V1+omega2_b_R1+pomega_b_R1; sommaR[1] = vp+omega_V2+omega2_b_R2+pomega_b_R2; sommaR[2] = wp+omega_V3+omega2_b_R3+pomega_b_R3; Pppright[0] = Gb_i[0][0]*sommaR[0]+Gb_i[1][0]*sommaR[1]+Gb_i[2][0]*sommaR[2]; Pppright[1] = Gb_i[0][1]*sommaR[0]+Gb_i[1][1]*sommaR[1]+Gb_i[2][1]*sommaR[2]; Pppright[2] = Gb_i[0][2]*sommaR[0]+Gb_i[1][2]*sommaR[1]+Gb_i[2][2]*sommaR[2]; sommaN[0] = up+omega_V1+omega2_b_N1+pomega_b_N1; sommaN[1] = vp+omega_V2+omega2_b_N2+pomega_b_N2; sommaN[2] = wp+omega_V3+omega2_b_N3+pomega_b_N3; Pppnose[0] = Gb_i[0][0]*sommaN[0]+Gb_i[1][0]*sommaN[1]+Gb_i[2][0]*sommaN[2]; Pppnose[1] = Gb_i[0][1]*sommaN[0]+Gb_i[1][1]*sommaN[1]+Gb_i[2][1]*sommaN[2]; Pppnose[2] = Gb_i[0][2]*sommaN[0]+Gb_i[1][2]*sommaN[1]+Gb_i[2][2]*sommaN[2];
sommaL[0] = up+omega_V1+omega2_b_L1+pomega_b_L1; sommaL[1] = vp+omega_V2+omega2_b_L2+pomega_b_L2; sommaL[2] = wp+omega_V3+omega2_b_L3+pomega_b_L3; Pppleft[0] = Gb_i[0][0]*sommaL[0]+Gb_i[1][0]*sommaL[1]+Gb_i[2][0]*sommaL[2]; Pppleft[1] = Gb_i[0][1]*sommaL[0]+Gb_i[1][1]*sommaL[1]+Gb_i[2][1]*sommaL[2]; Pppleft[2] = Gb_i[0][2]*sommaL[0]+Gb_i[1][2]*sommaL[1]+Gb_i[2][2]*sommaL[2]; //outputs y[0] = Pppright[0]; y[1] = Pppright[1]; y[2] = Pppright[2]; y[3] = Ppright[0]; y[4] = Ppright[1]; y[5] = Ppright[2]; y[6] = Pright[0]; y[7] = Pright[1]; y[8] = Pright[2]; y[9] = Pppnose[0]; y[10] = Pppnose[1]; y[11] = Pppnose[2]; y[12] = Ppnose[0]; y[13] = Ppnose[1]; y[14] = Ppnose[2]; y[15] = Pnose[0]; y[16] = Pnose[1]; y[17] = Pnose[2]; y[18] = Pppleft[0]; y[19] = Pppleft[1]; y[20] = Pppleft[2]; y[21] = Ppleft[0]; y[22] = Ppleft[1]; y[23] = Ppleft[2]; y[24] = Pleft[0]; y[25] = Pleft[1];
y[26] = Pleft[2]; //se non gira bene fare attenzione agli indici delle matrici e degli output } /* end mdlOutputs */
/* 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 */ #endif
A-2.1.3 Aerod2_2
#define S_FUNCTION_NAME AEROD2_2 #define S_FUNCTION_LEVEL 2
#include <stdio.h> #include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters ssSetNumSFcnParams(S, 32);
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) #define ro_PRM(S) ssGetSFcnParam(S, 0) #define b_PRM(S) ssGetSFcnParam(S, 1) #define cmean_PRM(S) ssGetSFcnParam(S, 2)
#define WINGREFSURF_PRM(S) ssGetSFcnParam(S, 3) #define CLo_PRM(S) ssGetSFcnParam(S, 4)
#define CLalfa_PRM(S) ssGetSFcnParam(S, 5) #define CLq_PRM(S) ssGetSFcnParam(S, 6) #define CLde_PRM(S) ssGetSFcnParam(S, 7) #define CDo_PRM(S) ssGetSFcnParam(S, 8) #define k_PRM(S) ssGetSFcnParam(S, 9) #define CDalfa_PRM(S) ssGetSFcnParam(S, 10) #define CDq_PRM(S) ssGetSFcnParam(S, 11) #define Cmo_PRM(S) ssGetSFcnParam(S, 12) #define Cmalfa_PRM(S) ssGetSFcnParam(S, 13) #define Cmalfap_PRM(S) ssGetSFcnParam(S, 14) #define Cmq_PRM(S) ssGetSFcnParam(S, 15) #define Cmde_PRM(S) ssGetSFcnParam(S, 16)///// #define CYbeta_PRM(S) ssGetSFcnParam(S, 17) #define CYp_PRM(S) ssGetSFcnParam(S, 18) #define CYr_PRM(S) ssGetSFcnParam(S, 19) #define CYda_PRM(S) ssGetSFcnParam(S, 20) #define CYdr_PRM(S) ssGetSFcnParam(S, 21) #define Clbeta_PRM(S) ssGetSFcnParam(S, 22) #define Clp_PRM(S) ssGetSFcnParam(S, 23) #define CLr_PRM(S) ssGetSFcnParam(S, 24) #define Clda_PRM(S) ssGetSFcnParam(S, 25) #define Cldr_PRM(S) ssGetSFcnParam(S, 26) #define Cnbeta_PRM(S) ssGetSFcnParam(S, 27) #define Cnp_PRM(S) ssGetSFcnParam(S, 28) #define Cnr_PRM(S) ssGetSFcnParam(S, 29) #define Cnda_PRM(S) ssGetSFcnParam(S, 30) #define Cndr_PRM(S) ssGetSFcnParam(S, 31) //Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 15);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 6);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
real_T de = (*uPtrs[0]); real_T df = (*uPtrs[1]); real_T da = (*uPtrs[2]); real_T dr = (*uPtrs[3]);
real_T alfa = (*uPtrs[4]); real_T beta = (*uPtrs[5]); real_T u = (*uPtrs[6]); real_T v = (*uPtrs[7]); real_T w = (*uPtrs[8]); real_T p = (*uPtrs[9]); real_T q = (*uPtrs[10]); real_T r = (*uPtrs[11]); real_T up = (*uPtrs[12]); real_T vp = (*uPtrs[13]); real_T wp = (*uPtrs[14]); real_T ro = (mxGetPr(ro_PRM(S))[0]); real_T b = (mxGetPr(b_PRM(S))[0]); real_T cmean = (mxGetPr(cmean_PRM(S))[0]);
real_T WINGREFSURF = (mxGetPr(WINGREFSURF_PRM(S))[0]); real_T CLo = (mxGetPr(CLo_PRM(S))[0]);
real_T CLalfa = (mxGetPr(CLalfa_PRM(S))[0]); real_T CLq = (mxGetPr(CLq_PRM(S))[0]); real_T CLde = (mxGetPr(CLde_PRM(S))[0]); real_T CDo = (mxGetPr(CDo_PRM(S))[0]); real_T k = (mxGetPr(k_PRM(S))[0]);
real_T CDalfa = (mxGetPr(CDalfa_PRM(S))[0]); real_T CDq = (mxGetPr(CDq_PRM(S))[0]); real_T Cmo = (mxGetPr(Cmo_PRM(S))[0]); real_T Cmalfa = (mxGetPr(Cmalfa_PRM(S))[0]); real_T Cmalfap = (mxGetPr(Cmalfap_PRM(S))[0]); real_T Cmq = (mxGetPr(Cmq_PRM(S))[0]); real_T Cmde = (mxGetPr(Cmde_PRM(S))[0]); real_T CYbeta = (mxGetPr(CYbeta_PRM(S))[0]); real_T CYp = (mxGetPr(CYp_PRM(S))[0]); real_T CYr = (mxGetPr(CYr_PRM(S))[0]); real_T CYda = (mxGetPr(CYda_PRM(S))[0]); real_T CYdr = (mxGetPr(CYdr_PRM(S))[0]); real_T Clbeta = (mxGetPr(Clbeta_PRM(S))[0]); real_T Clp = (mxGetPr(Clp_PRM(S))[0]); real_T Clr = (mxGetPr(CLr_PRM(S))[0]); real_T Clda = (mxGetPr(Clda_PRM(S))[0]); real_T Cldr = (mxGetPr(Cldr_PRM(S))[0]); real_T Cnbeta = (mxGetPr(Cnbeta_PRM(S))[0]); real_T Cnp = (mxGetPr(Cnp_PRM(S))[0]); real_T Cnr = (mxGetPr(Cnr_PRM(S))[0]); real_T Cnda = (mxGetPr(Cnda_PRM(S))[0]); real_T Cndr = (mxGetPr(Cndr_PRM(S))[0]);
real_T CL,CD,alfap,Cm,CY,Cl,Cn,V2,D,Y,L,l,m,n,salfa,calfa; //Calcoli della M function
CL = CLo+CLalfa*alfa+CLq*q+CLde*de; CD = CDo+k*CL*CL; // if (u=0.0) // { // alfap=0.0; // } // else // { // alfap=0.0; // wp=0.1; // up=0.1;
// alfap=( 1 / ( 1+(w/u)*(w/u) ) )*(wp/u-w*up/(u*u)); // } da controllare la posizione esatta della parentesi // Cm = Cmo+Cmalfa*alfa+Cmalfap*alfap+Cmq*q+Cmde*de; Cm = Cmo+Cmalfa*alfa+Cmq*q+Cmde*de; CY = CYbeta*beta+CYp*p+CYr*r+CYda*da+CYdr*dr; Cl = Clbeta*beta+Clp*p+Clr*r+Clda*da+Cldr*dr; Cn = Cnbeta*beta+Cnp*p+Cnr*r+Cnda*da+Cndr*dr; V2 = u*u+v*v+w*w; D = 0.5*ro*WINGREFSURF*V2*CD; Y = 0.5*ro*WINGREFSURF*V2*CY; L = 0.5*ro*WINGREFSURF*V2*CL;
l = 0.5*ro*WINGREFSURF*V2*b*Cl; m = 0.5*ro*WINGREFSURF*V2*cmean*Cm; n = 0.5*ro*WINGREFSURF*V2*b*Cn; salfa = sin(alfa); calfa = cos(alfa); //outputs y[0] = -D*calfa+L*salfa; y[1] = Y; y[2] = -D*salfa-L*calfa; y[3] = l; y[4] = m; y[5] = n; } /* 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 */ #endif
A-2.1.4 Dz34L
#define S_FUNCTION_NAME DZ34L #define S_FUNCTION_LEVEL 2 #include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 1);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) #define Ro_LR_PRM(S) ssGetSFcnParam(S, 0) //Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 1);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 1);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0);
ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0);
ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T zh = (*uPtrs[0]);
real_T Ro_LR = (mxGetPr(Ro_LR_PRM(S))[0]); real_T stop,def,dz,delta;
//calcoli della funzione if (zh > Ro_LR*(1+0.005)) {stop = 0; dz = 0;} else {stop=0; def=Ro_LR-zh; dz = def;} delta = dz; y[0]=delta; } /* end mdlOutputs */ /* 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 */ #endif
A-2.1.5 Dz34R
#define S_FUNCTION_NAME DZ34R #define S_FUNCTION_LEVEL 2 #include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 1);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) #define Ro_LR_PRM(S) ssGetSFcnParam(S, 0) //Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 1);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 1);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T zh = (*uPtrs[0]);
real_T Ro_LR = (mxGetPr(Ro_LR_PRM(S))[0]); real_T stop,def,dz,delta;
//calcoli della funzione if (zh > Ro_LR*(1+0.005)) {stop = 0; dz = 0;} else {stop=0; def=Ro_LR-zh; dz = def;} delta = dz; y[0]=delta; } /* end mdlOutputs */ /* 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 */ #endif
A-2.1.6 Dz34N
#define S_FUNCTION_NAME DZ34N #define S_FUNCTION_LEVEL 2 #include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters ssSetNumSFcnParams(S, 1);
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { /*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) #define Ro_N_PRM(S) ssGetSFcnParam(S, 0) //Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 1);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 1);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T zh = (*uPtrs[0]);
real_T Ro_N = (mxGetPr(Ro_N_PRM(S))[0]); real_T def,stop,dz,delta;
//calcoli della funzione
if (zh > Ro_N*(1+0.005)) {stop = 0; dz = 0;} else
{stop=0; def=Ro_N-zh; dz = def;} delta = dz; y[0] = delta; } /* end mdlOutputs */ /* 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 */ #endif
A-2.1.7 Eng2_3
#define S_FUNCTION_NAME ENG2_3 #define S_FUNCTION_LEVEL 2 #include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 2);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) #define Tmax_PRM(S) ssGetSFcnParam(S, 0) #define h_thr_PRM(S) ssGetSFcnParam(S, 1) //Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 4);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 6);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T dt = (*uPtrs[0]);
real_T phi = (*uPtrs[1]); real_T the = (*uPtrs[2]); real_T psi = (*uPtrs[3]);
real_T Tmax = (mxGetPr(Tmax_PRM(S))[0]); real_T h_thr = (mxGetPr(h_thr_PRM(S))[0]); real_T sphi,cphi,sthe,cthe,spsi,cpsi,Gb_i11,Gb_i21,Gb_i31,Gb_i12,Gb_i22,Gb_i32,Gb_i13,Gb_i23,Gb_i33,Ftb1,Ftb2,Ftb3,Mtx,Mty,Mtz; //calcoli sphi = sin(phi); cphi = cos(phi); sthe = sin(the); cthe = cos(the); spsi = sin(psi); cpsi = cos(psi);
/* real_T Gb_i[3][3] = { { cthe*cpsi , sphi*sthe*cpsi-cphi*spsi , cphi*sthe*cpsi+sphi*spsi }, { -cthe*spsi , -(sphi*sthe*spsi+cphi*cpsi) , -(cphi*sthe*spsi-sphi*cpsi) }, { +sthe , -sphi*cthe , -cphi*cthe } } ;*/
Gb_i11 = cthe*cpsi; Gb_i21 = sphi*sthe*cpsi-cphi*spsi; Gb_i31 = cphi*sthe*cpsi+sphi*spsi; Gb_i12 = -cthe*cpsi; Gb_i22 = -(sphi*sthe*spsi+cphi*cpsi); Gb_i32 = -(cphi*sthe*spsi-sphi*cpsi); Gb_i13 = +sthe; Gb_i23 = -sphi*cthe; Gb_i33 = -cphi*cthe;
/* real_T Spinta[3]={ {Tmax*dt},{0},{0}}; real_T Ftb[3] = { {Gb_i[0][0]*Spinta[0]+Gb_i[0][1]*Spinta[1]+Gb_i[0][2]*Spinta[2]}, {Gb_i[1][0]*Spinta[0]+Gb_i[1][1]*Spinta[1]+Gb_i[1][2]*Spinta[2]}, {Gb_i[2][0]*Spinta[0]+Gb_i[2][1]*Spinta[1]+Gb_i[2][2]*Spinta[2]} };*/ Ftb1 = Gb_i11*Tmax*dt; Ftb2 = Gb_i21*Tmax*dt; Ftb3 = Gb_i31*Tmax*dt; Mtx = 0; Mty = -dt*Tmax*h_thr; Mtz = 0; //outputs y[0]=Ftb1; y[1]=Ftb2; y[2]=Ftb3; y[3]=Mtx; y[4]=Mty; y[5]=Mtz; } /* end mdlOutputs */ /* Function: mdlTerminate ==================================================== * Abstract:
* No termination needed, but we are required to have this routine. */
{ }
#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 */ #endif
A-2.1.8 Hubin37L
#define S_FUNCTION_NAME HUBIN37L #define S_FUNCTION_LEVEL 2
#include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 0);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) //no parameters
//Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 9);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 5);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T gamma = (*uPtrs[0]);
real_T Fx = (*uPtrs[1]); real_T Fy = (*uPtrs[2]); real_T My = (*uPtrs[3]); real_T Mx = (*uPtrs[4]);
real_T Fz = (*uPtrs[5]); real_T phi = (*uPtrs[6]); real_T the = (*uPtrs[7]); real_T psi = (*uPtrs[8]); //calcoli
real_T spsigam = sin(psi+gamma); real_T cpsigam = cos(psi+gamma); real_T gi_h11 = cpsigam; real_T gi_h21 = -spsigam; real_T gi_h31 = 0; real_T gi_h12 = spsigam; real_T gi_h22 = cpsigam; real_T gi_h32 = 0; real_T gi_h13 = 0; real_T gi_h23 = 0; real_T gi_h33 = 1;
real_T det = cpsigam*cpsigam+spsigam*spsigam; real_T gi_hA11 = gi_h22*gi_h33-gi_h32*gi_h23; real_T gi_hA21 = -(gi_h12*gi_h33-gi_h13*gi_h32); real_T gi_hA31 = gi_h12*gi_h23-gi_h13*gi_h22; real_T gi_hA12 = -(gi_h21*gi_h33-gi_h23*gi_h31); real_T gi_hA22 = gi_h11*gi_h33-gi_h31*gi_h13; real_T gi_hA32 = -(gi_h11*gi_h23-gi_h13*gi_h21); real_T gi_hA13 = gi_h21*gi_h32-gi_h22*gi_h31; real_T gi_hA23 = -(gi_h11*gi_h32-gi_h12*gi_h31); real_T gi_hA33 = gi_h11*gi_h22-gi_h12*gi_h21; real_T gi_hAT11 = gi_hA11;
real_T gi_hAT21 = gi_hA12; real_T gi_hAT31 = gi_hA13; real_T gi_hAT12 = gi_hA21; real_T gi_hAT22 = gi_hA22; real_T gi_hAT32 = gi_hA23; real_T gi_hAT13 = gi_hA31; real_T gi_hAT23 = gi_hA32; real_T gi_hAT33 = gi_hA33; real_T gh_i11 = (1/det)*gi_hAT11; real_T gh_i21 = (1/det)*gi_hAT21; real_T gh_i31 = (1/det)*gi_hAT31; real_T gh_i12 = (1/det)*gi_hAT12; real_T gh_i22 = (1/det)*gi_hAT22; real_T gh_i32 = (1/det)*gi_hAT32; real_T gh_i13 = (1/det)*gi_hAT13; real_T gh_i23 = (1/det)*gi_hAT23; real_T gh_i33 = (1/det)*gi_hAT33;
real_T F1 = gh_i11*Fx+gh_i21*Fy+gh_i31*Fz; real_T F2 = gh_i12*Fx+gh_i22*Fy+gh_i32*Fz; real_T F3 = gh_i13*Fx+gh_i23*Fy+gh_i33*Fz; real_T M1 = gh_i11*Mx+gh_i21*My; real_T M2 = gh_i12*Mx+gh_i22*My; real_T M3 = gh_i13*Mx+gh_i23*My; //outputs y[0] = F1; y[1] = F2; y[2] = F3; y[3] = M1; y[4] = M2; } /* end mdlOutputs */ /* 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 */ #endif
A-2.1.9 Hubin37R
#define S_FUNCTION_NAME HUBIN37R #define S_FUNCTION_LEVEL 2
#include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 0);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) //no parameters
//Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 9);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 5);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T gamma = (*uPtrs[0]);
real_T Fx = (*uPtrs[1]); real_T Fy = (*uPtrs[2]); real_T My = (*uPtrs[3]); real_T Mx = (*uPtrs[4]); real_T Fz = (*uPtrs[5]);
real_T phi = (*uPtrs[6]); real_T the = (*uPtrs[7]); real_T psi = (*uPtrs[8]); //calcoli
real_T spsigam = sin(psi+gamma); real_T cpsigam = cos(psi+gamma); real_T gi_h11 = cpsigam; real_T gi_h21 = -spsigam; real_T gi_h31 = 0; real_T gi_h12 = spsigam; real_T gi_h22 = cpsigam; real_T gi_h32 = 0; real_T gi_h13 = 0; real_T gi_h23 = 0; real_T gi_h33 = 1;
real_T det = cpsigam*cpsigam+spsigam*spsigam; real_T gi_hA11 = gi_h22*gi_h33-gi_h32*gi_h23; real_T gi_hA21 = -(gi_h12*gi_h33-gi_h13*gi_h32); real_T gi_hA31 = gi_h12*gi_h23-gi_h13*gi_h22; real_T gi_hA12 = -(gi_h21*gi_h33-gi_h23*gi_h31); real_T gi_hA22 = gi_h11*gi_h33-gi_h31*gi_h13; real_T gi_hA32 = -(gi_h11*gi_h23-gi_h13*gi_h21); real_T gi_hA13 = gi_h21*gi_h32-gi_h22*gi_h31; real_T gi_hA23 = -(gi_h11*gi_h32-gi_h12*gi_h31); real_T gi_hA33 = gi_h11*gi_h22-gi_h12*gi_h21; real_T gi_hAT11 = gi_hA11;
real_T gi_hAT21 = gi_hA12; real_T gi_hAT31 = gi_hA13; real_T gi_hAT12 = gi_hA21; real_T gi_hAT22 = gi_hA22; real_T gi_hAT32 = gi_hA23; real_T gi_hAT13 = gi_hA31; real_T gi_hAT23 = gi_hA32; real_T gi_hAT33 = gi_hA33; real_T gh_i11 = (1/det)*gi_hAT11; real_T gh_i21 = (1/det)*gi_hAT21; real_T gh_i31 = (1/det)*gi_hAT31; real_T gh_i12 = (1/det)*gi_hAT12; real_T gh_i22 = (1/det)*gi_hAT22; real_T gh_i32 = (1/det)*gi_hAT32; real_T gh_i13 = (1/det)*gi_hAT13; real_T gh_i23 = (1/det)*gi_hAT23; real_T gh_i33 = (1/det)*gi_hAT33;
real_T F1 = gh_i11*Fx+gh_i21*Fy+gh_i31*Fz; real_T F2 = gh_i12*Fx+gh_i22*Fy+gh_i32*Fz; real_T F3 = gh_i13*Fx+gh_i23*Fy+gh_i33*Fz; real_T M1 = gh_i11*Mx+gh_i21*My; real_T M2 = gh_i12*Mx+gh_i22*My; real_T M3 = gh_i13*Mx+gh_i23*My; //outputs y[0] = F1; y[1] = F2; y[2] = F3; y[3] = M1; y[4] = M2; } /* end mdlOutputs */ /* Function: mdlTerminate ==================================================== * Abstract:
* No termination needed, but we are required to have this routine. */
static void mdlTerminate(SimStruct *S) {
}
#include "simulink.c" /* MEX-file interface mechanism */ #else
#include "cg_sfun.h" /* Code generation registration function */ #endif
A-2.1.10 Hubin37N
#define S_FUNCTION_NAME HUBIN37N #define S_FUNCTION_LEVEL 2
#include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 0);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) //no parameters
//Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 9);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 5);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T gamma = (*uPtrs[0]);
real_T Fx = (*uPtrs[1]); real_T Fy = (*uPtrs[2]); real_T My = (*uPtrs[3]); real_T Mx = (*uPtrs[4]); real_T Fz = (*uPtrs[5]); real_T phi = (*uPtrs[6]); real_T the = (*uPtrs[7]);
real_T psi = (*uPtrs[8]); //calcoli
real_T spsigam = sin(psi+gamma); real_T cpsigam = cos(psi+gamma);
real_T gi_h11 = cpsigam; real_T gi_h21 = -spsigam; real_T gi_h31 = 0; real_T gi_h12 = spsigam; real_T gi_h22 = cpsigam; real_T gi_h32 = 0; real_T gi_h13 = 0; real_T gi_h23 = 0; real_T gi_h33 = 1;
real_T det = cpsigam*cpsigam+spsigam*spsigam; real_T gi_hA11 = gi_h22*gi_h33-gi_h32*gi_h23; real_T gi_hA21 = -(gi_h12*gi_h33-gi_h13*gi_h32); real_T gi_hA31 = gi_h12*gi_h23-gi_h13*gi_h22; real_T gi_hA12 = -(gi_h21*gi_h33-gi_h23*gi_h31); real_T gi_hA22 = gi_h11*gi_h33-gi_h31*gi_h13; real_T gi_hA32 = -(gi_h11*gi_h23-gi_h13*gi_h21); real_T gi_hA13 = gi_h21*gi_h32-gi_h22*gi_h31; real_T gi_hA23 = -(gi_h11*gi_h32-gi_h12*gi_h31); real_T gi_hA33 = gi_h11*gi_h22-gi_h12*gi_h21; real_T gi_hAT11 = gi_hA11;
real_T gi_hAT21 = gi_hA12; real_T gi_hAT31 = gi_hA13; real_T gi_hAT12 = gi_hA21; real_T gi_hAT22 = gi_hA22; real_T gi_hAT32 = gi_hA23; real_T gi_hAT13 = gi_hA31; real_T gi_hAT23 = gi_hA32; real_T gi_hAT33 = gi_hA33; real_T gh_i11 = (1/det)*gi_hAT11; real_T gh_i21 = (1/det)*gi_hAT21; real_T gh_i31 = (1/det)*gi_hAT31; real_T gh_i12 = (1/det)*gi_hAT12; real_T gh_i22 = (1/det)*gi_hAT22; real_T gh_i32 = (1/det)*gi_hAT32; real_T gh_i13 = (1/det)*gi_hAT13; real_T gh_i23 = (1/det)*gi_hAT23; real_T gh_i33 = (1/det)*gi_hAT33;
real_T F1 = gh_i11*Fx+gh_i21*Fy+gh_i31*Fz; real_T F2 = gh_i12*Fx+gh_i22*Fy+gh_i32*Fz; real_T F3 = gh_i13*Fx+gh_i23*Fy+gh_i33*Fz; real_T M1 = gh_i11*Mx+gh_i21*My; real_T M2 = gh_i12*Mx+gh_i22*My; real_T M3 = gh_i13*Mx+gh_i23*My; //outputs y[0] = F1; y[1] = F2; y[2] = F3; y[3] = M1; y[4] = M2; } /* end mdlOutputs */ /* 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 */
#include "cg_sfun.h" /* Code generation registration function */ #endif
A-2.1.11 Inhub36L
#define S_FUNCTION_NAME INHUB36L #define S_FUNCTION_LEVEL 2
#include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 0);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) //no parameters
//Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 7);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 3);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T gamma = (*uPtrs[0]);
real_T xp_hub_in = (*uPtrs[1]); real_T yp_hub_in = (*uPtrs[2]); real_T zp_hub_in = (*uPtrs[3]); real_T phi = (*uPtrs[4]); real_T the = (*uPtrs[5]); real_T psi = (*uPtrs[6]); //calcoli
real_T cpsigam = cos(psi+gamma); /* gi_h = [cpsigam -spsigam 0
spsigam cpsigam 0 0 0 1];
v_hub_hub=Gi_h*[xp_hub_in; yp_hub_in; zp_hub_in]; % hub velocity in the hub */ real_T v_hub_hub1 = cpsigam*xp_hub_in-spsigam*yp_hub_in;
real_T v_hub_hub2 = spsigam*xp_hub_in+cpsigam*yp_hub_in; real_T v_hub_hub3 = zp_hub_in;
//outputs y[0] = v_hub_hub1; y[1] = v_hub_hub2; y[2] = v_hub_hub3; } /* end mdlOutputs */ /* 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 */ #endif
A-2.1.12 Inhub36R
#define S_FUNCTION_NAME INHUB36R #define S_FUNCTION_LEVEL 2
#include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 0);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) //no parameters
//Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 7);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 3);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE);
} /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T gamma = (*uPtrs[0]);
real_T xp_hub_in = (*uPtrs[1]); real_T yp_hub_in = (*uPtrs[2]); real_T zp_hub_in = (*uPtrs[3]); real_T phi = (*uPtrs[4]); real_T the = (*uPtrs[5]); real_T psi = (*uPtrs[6]); //calcoli
real_T spsigam = sin(psi+gamma); real_T cpsigam = cos(psi+gamma); /* gi_h = [cpsigam -spsigam 0
spsigam cpsigam 0 0 0 1];
v_hub_hub=Gi_h*[xp_hub_in; yp_hub_in; zp_hub_in]; % hub velocity in the hub */ real_T v_hub_hub1 = cpsigam*xp_hub_in-spsigam*yp_hub_in;
real_T v_hub_hub2 = spsigam*xp_hub_in+cpsigam*yp_hub_in; real_T v_hub_hub3 = zp_hub_in;
//outputs y[0] = v_hub_hub1; y[1] = v_hub_hub2; y[2] = v_hub_hub3; } /* end mdlOutputs */ /* 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 */ #endif
A-2.1.13 Inhub36N
#define S_FUNCTION_NAME INHUB36N #define S_FUNCTION_LEVEL 2
#include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 0);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a
* parameter mismatch. */
return; }
//Defining parameters (in the same order) //no parameters
//Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 7);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 3);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T gamma = (*uPtrs[0]);
real_T xp_hub_in = (*uPtrs[1]); real_T yp_hub_in = (*uPtrs[2]); real_T zp_hub_in = (*uPtrs[3]); real_T phi = (*uPtrs[4]); real_T the = (*uPtrs[5]); real_T psi = (*uPtrs[6]); //calcoli
real_T spsigam = sin(psi+gamma); real_T cpsigam = cos(psi+gamma); /* gi_h = [cpsigam -spsigam 0
spsigam cpsigam 0 0 0 1];
v_hub_hub=Gi_h*[xp_hub_in; yp_hub_in; zp_hub_in]; % hub velocity in the hub */ real_T v_hub_hub1 = cpsigam*xp_hub_in-spsigam*yp_hub_in;
real_T v_hub_hub2 = spsigam*xp_hub_in+cpsigam*yp_hub_in; real_T v_hub_hub3 = zp_hub_in;
//outputs y[0] = v_hub_hub1; y[1] = v_hub_hub2; y[2] = v_hub_hub3; } /* end mdlOutputs */ /* 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 */ #endif
A-2.1.14 Inhub8L
#define S_FUNCTION_NAME INHUB8L #define S_FUNCTION_LEVEL 2 #include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 0);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) //no parameters
//Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 7);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 3);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T gamma = (*uPtrs[0]);
real_T xp_hub_in = (*uPtrs[1]); real_T yp_hub_in = (*uPtrs[2]); real_T zp_hub_in = (*uPtrs[3]); real_T phi = (*uPtrs[4]); real_T the = (*uPtrs[5]); real_T psi = (*uPtrs[6]); //calcoli
real_T spsigam = sin(psi+gamma); real_T cpsigam = cos(psi+gamma); /* gi_h = [cpsigam -spsigam 0
spsigam cpsigam 0 0 0 1];
v_hub_hub=Gi_h*[xp_hub_in; yp_hub_in; zp_hub_in]; % hub velocity in the hub */ real_T v_hub_hub1 = cpsigam*xp_hub_in-spsigam*yp_hub_in;
real_T v_hub_hub2 = spsigam*xp_hub_in+cpsigam*yp_hub_in; real_T v_hub_hub3 = zp_hub_in;
//outputs y[0] = v_hub_hub1; y[1] = v_hub_hub2; y[2] = v_hub_hub3; } /* end mdlOutputs */ /* 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 */ #endif
A-2.1.15 Inhub8R
#define S_FUNCTION_NAME INHUB8R #define S_FUNCTION_LEVEL 2 #include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 0);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order) //no parameters
//Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 7);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
ssSetOutputPortWidth(S, 0, 3);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T gamma = (*uPtrs[0]);
real_T xp_hub_in = (*uPtrs[1]); real_T yp_hub_in = (*uPtrs[2]); real_T zp_hub_in = (*uPtrs[3]); real_T phi = (*uPtrs[4]); real_T the = (*uPtrs[5]); real_T psi = (*uPtrs[6]); //calcoli
real_T spsigam = sin(psi+gamma); real_T cpsigam = cos(psi+gamma); /* gi_h = [cpsigam -spsigam 0
spsigam cpsigam 0 0 0 1];
v_hub_hub=Gi_h*[xp_hub_in; yp_hub_in; zp_hub_in]; % hub velocity in the hub */ real_T v_hub_hub1 = cpsigam*xp_hub_in-spsigam*yp_hub_in;
real_T v_hub_hub2 = spsigam*xp_hub_in+cpsigam*yp_hub_in; real_T v_hub_hub3 = zp_hub_in;
//outputs y[0] = v_hub_hub1; y[1] = v_hub_hub2; y[2] = v_hub_hub3; } /* end mdlOutputs */ /* 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 */ #endif
A-2.1.16 Lf321L
#define S_FUNCTION_NAME LF321L #define S_FUNCTION_LEVEL 2 #include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 2);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order)
#define c_w_y_LR_PRM(S) ssGetSFcnParam(S, 0) #define k_w_y_LR_PRM(S) ssGetSFcnParam(S, 1) //Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 4);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 3);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T Fz = (*uPtrs[0]);
real_T zhub = (*uPtrs[1]); real_T dy = (*uPtrs[2]); real_T dyp = (*uPtrs[3]);
real_T c_w_y_LR = (mxGetPr(c_w_y_LR_PRM(S))[0]); real_T k_w_y_LR = (mxGetPr(k_w_y_LR_PRM(S))[0]); //calcoli della funzione
real_T Fy = c_w_y_LR*dyp + k_w_y_LR*dy; real_T miy = -Fy/Fz;
real_T M_xh = Fy*zhub+Fz*dy; //outputs
y[0] = miy; y[1] = Fy; y[2] = M_xh;
} /* end mdlOutputs */
/* 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 */ #endif
A-2.1.17 Lf321R
#define S_FUNCTION_NAME LF321R #define S_FUNCTION_LEVEL 2 #include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 2);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order)
#define c_w_y_LR_PRM(S) ssGetSFcnParam(S, 0) #define k_w_y_LR_PRM(S) ssGetSFcnParam(S, 1) //Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 4);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 3);/* number of output signals */ ssSetNumSampleTimes(S, 1);/* number of sample times */ ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S,SS_OPTION_EXCEPTION_FREE_CODE); } /* end mdlInitializeSizes */
static void mdlInitializeSampleTimes(SimStruct *S) {
/* Register one pair for each sample time */
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
} /* end mdlInitializeSampleTimes */ static void mdlOutputs(SimStruct *S, int_T tid) {
//Defining inputs, parameters
real_T *y = ssGetOutputPortRealSignal(S,0); InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T Fz = (*uPtrs[0]);
real_T zhub = (*uPtrs[1]); real_T dy = (*uPtrs[2]); real_T dyp = (*uPtrs[3]);
real_T c_w_y_LR = (mxGetPr(c_w_y_LR_PRM(S))[0]); real_T k_w_y_LR = (mxGetPr(k_w_y_LR_PRM(S))[0]); //calcoli della funzione
real_T Fy = c_w_y_LR*dyp + k_w_y_LR*dy; real_T miy = -Fy/Fz;
real_T M_xh = Fy*zhub+Fz*dy; //outputs y[0] = miy; y[1] = Fy; y[2] = M_xh; } /* end mdlOutputs */ /* 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 */ #endif
A-2.1.18 Lf321N
#define S_FUNCTION_NAME LF321N #define S_FUNCTION_LEVEL 2 #include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S) {
//Defining number of parameters
ssSetNumSFcnParams(S, 2);/* cambiare!!!!!! number of expected parameters */ if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/*
* If the the number of expected input parameters is not equal * to the number of parameters entered in the dialog box return. * Simulink will generate an error indicating that there is a * parameter mismatch.
*/ return; }
//Defining parameters (in the same order)
#define c_w_y_N_PRM(S) ssGetSFcnParam(S, 0) #define k_w_y_N_PRM(S) ssGetSFcnParam(S, 1) //Defining states, inputs, outputs dimension
ssSetNumContStates( S, 0);/* number of continuous states */ ssSetNumDiscStates( S, 0);/* number of discrete states */ if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 4);/* number of input signals */ ssSetInputPortDirectFeedThrough(S, 0, 1);