Overview
Comment: | MTT input block "sys_sfun_input.mexglx" created to provide inputs from MTT input file to plant model within Simulink. The command "mtt sys sfun zip" now also creates a simple sys.mdl file which connects the input block to the plant block correctly. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
1766067043d01a7809f28fad6677831c |
User & Date: | geraint@users.sourceforge.net on 2002-05-21 11:46:31.000 |
Other Links: | branch diff | manifest | tags |
Context
2002-05-21
| ||
18:50:11 | Customised figures. check-in: 65b5567de9 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
11:46:31 |
MTT input block "sys_sfun_input.mexglx" created to provide inputs from MTT input file to plant model within Simulink. The command "mtt sys sfun zip" now also creates a simple sys.mdl file which connects the input block to the plant block correctly. check-in: 1766067043 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
08:47:41 | Implicit rules check-in: 22eb2b0db5 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
Changes
Modified mttroot/mtt/lib/rep/sfun_rep/Makefile
from [506c1123b2]
to [35509f7ef3].
1 2 3 4 | #! /usr/bin/make -f all: $(SYS)_sfun.mexglx | | | > > > > > > > > | > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #! /usr/bin/make -f all: $(SYS)_sfun.mexglx $(SYS)_sfun.mexglx: $(SYS)_sfun.c sfun_debug.h $(SYS)_def.h $(SYS)_sympar.h $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c $(SYS)_sfun_ae.mexglx $(SYS)_sfun_input.mexglx echo Creating $@ mex $(SYS)_sfun.c cp *_sfun*mexglx .. $(SYS)_sfun.c:: ${MTT_REP}/sfun_rep/sfun.c.tmpl echo Creating $@ cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@ $(SYS)_sfun_ae.mexglx: $(SYS)_sfun_ae.c $(SYS)_def.h $(SYS)_ae.c echo Creating $@ mex $(SYS)_sfun_ae.c $(SYS)_sfun_ae.c:: ${MTT_REP}/sfun_rep/mex_ae.c.tmpl echo Creating $@ cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@ $(SYS)_sfun_input.mexglx: $(SYS)_sfun_input.c sfun_debug.h $(SYS)_def.h $(SYS)_sympar.h $(SYS)_input.c $(SYS)_numpar.c echo Creating $@ mex $(SYS)_sfun_input.c $(SYS)_sfun_input.c:: ${MTT_REP}/sfun_rep/sfun_input.c.tmpl echo Creating $@ cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@ $(SYS)_sfun.zip: $(SYS)_sfun.c sfun_debug.h $(SYS)_sfun_ae.c $(SYS)_sfun_input.c $(SYS)_def.h $(SYS)_sympar.h $(SYS)_ae.c $(SYS)_input.c $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c $(SYS).mdl README echo Creating $@ zip $@ $^ $(SYS).mdl: ${MTT_REP}/sfun_rep/mdl.tmpl echo Creating $@ cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@ README:: ${MTT_REP}/sfun_rep/README.tmpl echo Creating $@ cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@ $(SYS)_ae.c: $(SYS)_ae.m echo Creating $@ ${MTT_CC}/mtt_m2cc.sh $(SYS) ae c cat $(SYS)_input.c: $(SYS)_input.m echo Creating $@ ${MTT_CC}/mtt_m2cc.sh $(SYS) input c cat $(SYS)_numpar.c: $(SYS)_numpar.m echo Creating $@ ${MTT_CC}/mtt_m2cc.sh $(SYS) numpar c cat $(SYS)_ode.c: $(SYS)_ode.m echo Creating $@ ${MTT_CC}/mtt_m2cc.sh $(SYS) ode c cat $(SYS)_odeo.c: $(SYS)_odeo.m echo Creating $@ ${MTT_CC}/mtt_m2cc.sh $(SYS) odeo c cat $(SYS)_state.c: $(SYS)_state.m echo Creating $@ ${MTT_CC}/mtt_m2cc.sh $(SYS) state c cat sfun_debug.h:: ${MTT_REP}/sfun_rep/sfun_debug.h echo Copying $@ cp $^ $@ %:: mtt -q $(OPTS) `echo $* | sed 's/\(.*\)_\(.*\)\.\(.*\)/\1 \2 \3/'` |
Modified mttroot/mtt/lib/rep/sfun_rep/README.tmpl
from [7562840818]
to [ae40a63903].
1 2 3 4 5 6 7 8 | To build a Simulink funtion of the <mtt_model_name> model without using MTT: mex <mtt_model_name>_sfun.c If numerical solution of algebraic equations is also required: mex <mtt_model_name>_sfun_ae.c | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 | To build a Simulink funtion of the <mtt_model_name> model without using MTT: mex <mtt_model_name>_sfun.c The input block can be created with: mex <mtt_model_name>_sfun_input.c If numerical solution of algebraic equations is also required: mex <mtt_model_name>_sfun_ae.c |
Deleted mttroot/mtt/lib/rep/sfun_rep/ae.c.tmpl version [61cef996f8].
Added mttroot/mtt/lib/rep/sfun_rep/mdl.tmpl version [a18037fb99].
Added mttroot/mtt/lib/rep/sfun_rep/mex_ae.c.tmpl version [6767d53ec7].
Modified mttroot/mtt/lib/rep/sfun_rep/sfun.c.tmpl
from [fc7b63a944]
to [dcace679aa].
|
| | < < < < < < < < | | > > > > > | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | /* -*-c-*- Put emacs into c-mode * <mtt_model_name>_sfun.c: * Matlab S-function simulation of <mtt_model_name> */ #define S_FUNCTION_NAME <mtt_model_name>_sfun #define S_FUNCTION_LEVEL 2 #include <stdio.h> #include <stdlib.h> #include "simstruc.h" #include "sfun_debug.h" #include "<mtt_model_name>_def.h" static double *mttdx; /* pointer to rates */ static double *mttu; /* pointer to inputs */ static double *mttpar; /* pointer to parameters */ static double *mttx; /* pointer to states */ static double *mtty; /* pointer to outputs */ static double *mttyz; /* pointer to residuals */ static double mttt; /* time */ static unsigned int i; /* loop counter */ /* system equations */ static void <mtt_model_name>_ae (void) { #include "<mtt_model_name>_ae.c" PRINT_LEAVE; } static void <mtt_model_name>_numpar (void) { #include "<mtt_model_name>_sympar.h" #include "<mtt_model_name>_numpar.c" PRINT_LEAVE; } static void <mtt_model_name>_ode (void) { #include "<mtt_model_name>_ode.c" PRINT_LEAVE; } static void <mtt_model_name>_odeo (void) { #include "<mtt_model_name>_odeo.c" PRINT_LEAVE; } static void <mtt_model_name>_state (void) { #include "<mtt_model_name>_state.c" PRINT_LEAVE; } /* utility procedures */ static double * array_of_double (size_t n) { void *p = calloc (n, sizeof (double)); if (! p) { fprintf (stderr, "*** Error: failed to allocate memory\n"); } return (double *) p; } static void initialise_arrays (void) { PRINT_ENTER; mttdx = array_of_double (MTTNX); mttpar = array_of_double (MTTNPAR); mttu = array_of_double (MTTNU + MTTNYZ); mttx = array_of_double (MTTNX); mtty = array_of_double (MTTNY); mttyz = array_of_double (MTTNYZ); PRINT_LEAVE; } static void update_states_from_simulink (SimStruct *S) { PRINT_ENTER; for (i = 0; i < MTTNX; i++) { mttx[i] = ssGetContStates (S)[i]; } PRINT_LEAVE; } static void update_inputs_from_simulink (SimStruct *S) { PRINT_ENTER; for (i = 0; i < MTTNU; i++) { mttu[i] = *ssGetInputPortRealSignalPtrs (S, 0)[i]; } PRINT_LEAVE; } static void update_inputs_from_solver (void) { mxArray *MTT_MATLAB_P; mxArray *MTT_MATLAB_T; mxArray *MTT_MATLAB_U; mxArray *MTT_MATLAB_Ui; mxArray *MTT_MATLAB_X; double *p; PRINT_ENTER; /* starting value for solver - start with zero */ MTT_MATLAB_Ui = mxCreateDoubleMatrix (MTTNYZ, 1, mxREAL); mxSetName (MTT_MATLAB_Ui, "MTT_Ui"); p = mxGetPr (MTT_MATLAB_Ui); for (i = 0; i < MTTNYZ; i++) { p[i] = 0.0; |
︙ | ︙ | |||
178 179 180 181 182 183 184 | /* free memory */ mxDestroyArray (MTT_MATLAB_P); mxDestroyArray (MTT_MATLAB_T); mxDestroyArray (MTT_MATLAB_U); mxDestroyArray (MTT_MATLAB_Ui); mxDestroyArray (MTT_MATLAB_X); | | | | | > | | < | | | < | | | | < | | | | | | | | | | > | | > > | | | | > > > > | | | | | | | 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | /* free memory */ mxDestroyArray (MTT_MATLAB_P); mxDestroyArray (MTT_MATLAB_T); mxDestroyArray (MTT_MATLAB_U); mxDestroyArray (MTT_MATLAB_Ui); mxDestroyArray (MTT_MATLAB_X); PRINT_LEAVE; } static void update_simtime_from_simulink (SimStruct *S) { PRINT_ENTER; mttt = ssGetT (S); PRINT_LEAVE; } /* S-function methods */ static void mdlInitializeSizes(SimStruct *S) { PRINT_ENTER; ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { PRINT_LEAVE; return; } ssSetNumContStates(S, MTTNX); ssSetNumDiscStates(S, 0); if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, MTTNU); ssSetInputPortDirectFeedThrough(S, 0, 1); if (!ssSetNumOutputPorts(S, 2)) return; ssSetOutputPortWidth(S, 0, MTTNX); ssSetOutputPortWidth(S, 1, MTTNY); ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0); ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE); initialise_arrays (); PRINT_LEAVE; } static void mdlInitializeSampleTimes(SimStruct *S) { PRINT_ENTER; ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); PRINT_LEAVE; } #define MDL_INITIALIZE_CONDITIONS static void mdlInitializeConditions(SimStruct *S) { PRINT_ENTER; <mtt_model_name>_numpar (); <mtt_model_name>_state (); for (i = 0; i < MTTNX; i++) { ssGetContStates (S)[i] = mttx[i]; } PRINT_LEAVE; } static void mdlOutputs(SimStruct *S, int_T tid) { PRINT_ENTER; update_states_from_simulink (S); update_inputs_from_simulink (S); if (MTTNYZ > 0) { update_inputs_from_solver (); } update_simtime_from_simulink (S); UNUSED_ARG(tid); /* not used in single tasking mode */ <mtt_model_name>_odeo (); for (i = 0; i < MTTNX; i++) { ssGetOutputPortRealSignal (S, 0)[i] = mttx[i]; } for (i = 0; i < MTTNY; i++) { ssGetOutputPortRealSignal (S, 1)[i] = mtty[i]; } PRINT_LEAVE; } #define MDL_DERIVATIVES static void mdlDerivatives(SimStruct *S) { PRINT_ENTER; update_states_from_simulink (S); update_inputs_from_simulink (S); if (MTTNYZ > 0) { update_inputs_from_solver (); } update_simtime_from_simulink (S); <mtt_model_name>_ode (); for (i = 0; i < MTTNX; i++) { ssGetdX (S)[i] = mttdx[i]; } PRINT_LEAVE; } static void mdlTerminate(SimStruct *S) { PRINT_ENTER; UNUSED_ARG(S); free (mttdx); free (mttpar); free (mttu); free (mttx); free (mtty); free (mttyz); PRINT_LEAVE; } #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 |
Added mttroot/mtt/lib/rep/sfun_rep/sfun_debug.h version [484e8ce3d6].
Added mttroot/mtt/lib/rep/sfun_rep/sfun_input.c.tmpl version [4e79896f53].