00001 #include <math.h>
00002 #include <trgen.h>
00003 #include <balet.h>
00004
00005 #ifdef __cplusplus
00006 extern "C" {
00007 #endif // defined within this scope
00008
00009 #define S_FUNCTION_LEVEL 2
00010 #define S_FUNCTION_NAME sf_posreg
00011
00012
00013
00014
00015
00016 #include "simstruc.h"
00017
00018
00019
00020 #define INPUT_REF_POS 0
00021 #define INPUT_EST_POS 1
00022
00023 #define DP_K_IDX 0
00024 #define K_PARAM(S) (ssGetSFcnParam(S,DP_K_IDX))
00025
00026
00027
00028
00029
00030 #define MDL_CHECK_PARAMETERS
00031 #if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
00032
00033
00034
00035 static void mdlCheckParameters(SimStruct *S)
00036 {
00037 const mxArray *k = K_PARAM(S);
00038
00039 if (mxGetM(k) * mxGetN(k) != 3) {
00040 ssSetErrorStatus(S, "Parameter must bu 3 element vector");
00041 return;
00042 }
00043 }
00044 #endif
00045
00046
00047
00048
00049
00050
00051
00052 static void mdlInitializeSizes(SimStruct *S)
00053 {
00054
00055 ssSetNumSFcnParams(S, 1);
00056
00057 #if defined(MATLAB_MEX_FILE)
00058 if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {
00059 mdlCheckParameters(S);
00060 if (ssGetErrorStatus(S) != NULL) {
00061 return;
00062 }
00063 } else {
00064 return;
00065 }
00066 #endif
00067
00068 ssSetSFcnParamTunable(S, DP_K_IDX, 1);
00069
00070 ssSetNumContStates(S, 0);
00071 ssSetNumDiscStates(S, 0);
00072
00073 if (!ssSetNumInputPorts(S, 2)) return;
00074
00075 ssSetInputPortWidth(S, INPUT_REF_POS, 5);
00076 ssSetInputPortDirectFeedThrough(S, INPUT_REF_POS, 1);
00077 ssSetInputPortRequiredContiguous(S, INPUT_REF_POS, 1);
00078
00079 ssSetInputPortWidth(S, INPUT_EST_POS, 3);
00080 ssSetInputPortDirectFeedThrough(S, INPUT_EST_POS, 1);
00081 ssSetInputPortRequiredContiguous(S, INPUT_EST_POS, 1);
00082
00083 if (!ssSetNumOutputPorts(S, 1)) return;
00084 ssSetOutputPortWidth(S, 0, 2);
00085
00086
00087 ssSetNumSampleTimes(S, 1);
00088 ssSetNumRWork(S, 0);
00089 ssSetNumIWork(S, 0);
00090 ssSetNumPWork(S, 0);
00091 ssSetNumModes(S, 0);
00092 ssSetNumNonsampledZCs(S, 0);
00093
00094 ssSetOptions(S, 0);
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 static void mdlInitializeSampleTimes(SimStruct *S)
00106 {
00107 ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
00108 ssSetOffsetTime(S, 0, 0.0);
00109 ssSetModelReferenceSampleTimeDefaultInheritance(S);
00110 }
00111
00112
00113 #if defined(MDL_START)
00114
00115
00116
00117
00118
00119
00120 static void mdlStart(SimStruct *S)
00121 {
00122 }
00123 #endif
00124
00125
00126
00127
00128
00129
00130 static void mdlOutputs(SimStruct *S, int_T tid)
00131 {
00132 const real_T *y = ssGetInputPortRealSignal(S,INPUT_EST_POS);
00133 const real_T *r = ssGetInputPortRealSignal(S,INPUT_REF_POS);
00134 double *u = ssGetOutputPortRealSignal(S,0);
00135 const double *k = mxGetPr(K_PARAM(S));
00136 Pos rp;
00137 rp.x = r[0];
00138 rp.y = r[1];
00139 rp.phi = r[2];
00140 rp.v = r[3];
00141 rp.omega = r[4];
00142
00143 balet(rp, y, u, k);
00144
00145 UNUSED_ARG(tid);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154 static void mdlTerminate(SimStruct *S)
00155 {
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165 #ifdef MATLAB_MEX_FILE
00166 #include "simulink.c"
00167 #else
00168 #include "cg_sfun.h"
00169 #endif
00170
00171 #ifdef __cplusplus
00172 }
00173 #endif