Overview
Comment: | Code for Simulink S-function target written direct to sfun.cc instead of calling .mexglx files. This eliminates the sfun dependency on Octave ColumnVectors. sys_sfun.cc should build directly on a MS Windows machine (can't test this yet). added sfun.zip target to create source code to export. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
d60ad9b171d62145110c8baf3fb9ec79 |
User & Date: | geraint@users.sourceforge.net on 2002-05-15 14:22:26 |
Other Links: | branch diff | manifest | tags |
Context
2002-05-15
| ||
16:32:35 | Now notices changes in numpar state input and simpar check-in: 117a204ebb user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
14:22:26 |
Code for Simulink S-function target written direct to sfun.cc instead of calling .mexglx files. This eliminates the sfun dependency on Octave ColumnVectors. sys_sfun.cc should build directly on a MS Windows machine (can't test this yet). added sfun.zip target to create source code to export. check-in: d60ad9b171 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
11:01:24 | New PI controller component check-in: d2e6dc7890 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
Changes
Modified mttroot/mtt/bin/mtt from [2e04af1961] to [af644c2eee].
︙ | ︙ | |||
13 14 15 16 17 18 19 20 21 22 23 24 25 26 | # Copyright (C) 2001 by Peter J. Gawthrop ############################################################### ## Version control history ############################################################### ## $Header$ ## $Log$ ## Revision 1.343 2002/05/10 14:07:16 geraint ## Preserve .cc files. ## ## Revision 1.342 2002/05/10 13:24:58 geraint ## Added initial support for building Simulink S-functions. ## Rates do not update properly yet. ## Inertial switches do not work yet. | > > > > | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # Copyright (C) 2001 by Peter J. Gawthrop ############################################################### ## Version control history ############################################################### ## $Header$ ## $Log$ ## Revision 1.344 2002/05/11 01:14:17 geraint ## Fix for [ 553218 ] simpar.oct and simpar.m different. ## Translation added between ColumnVector in base .cc and Octave_map in .oct. ## ## Revision 1.343 2002/05/10 14:07:16 geraint ## Preserve .cc files. ## ## Revision 1.342 2002/05/10 13:24:58 geraint ## Added initial support for building Simulink S-functions. ## Rates do not update properly yet. ## Inertial switches do not work yet. |
︙ | ︙ | |||
2156 2157 2158 2159 2160 2161 2162 | ${MTT_MATLAB_FLAGS} -DCODEGENTARGET=MATLABMEX \ ${MTT_CXXINCS} ${MTT_CXXLIBS} ${MTT_CXXFLAGS} mtt_kpathsea.cc mtt_matlab_octave.cc ## .cc files .PRECIOUS: %.cc # Don't let mtt delete them .PRECIOUS: $1_%.cc # Don't let mtt delete them $1_%.cc: $1_%.m | | | 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 | ${MTT_MATLAB_FLAGS} -DCODEGENTARGET=MATLABMEX \ ${MTT_CXXINCS} ${MTT_CXXLIBS} ${MTT_CXXFLAGS} mtt_kpathsea.cc mtt_matlab_octave.cc ## .cc files .PRECIOUS: %.cc # Don't let mtt delete them .PRECIOUS: $1_%.cc # Don't let mtt delete them $1_%.cc: $1_%.m mtt_m2cc.sh $1 \$* cc cat mtt_%.cc: ${MTT_LIB}/cc/mtt_%.cc cp ${MTT_LIB}/cc/mtt_\$*.cc mtt_\$*.cc mtt_%.hh: ${MTT_LIB}/cc/mtt_%.hh cp ${MTT_LIB}/cc/mtt_\$*.hh mtt_\$*.hh |
︙ | ︙ |
Modified mttroot/mtt/bin/trans/mtt_header from [83d0d37bdc] to [c5cc8a3a52].
︙ | ︙ | |||
8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # Copyright (C) 2000 by Peter J. Gawthrop ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ ## Revision 1.48 2002/05/08 14:51:03 geraint ## Moved matlab/octave data type conversion functions to a separate file. ## ## Revision 1.47 2002/05/07 23:50:34 geraint ## Preliminary support for Matlab dynamically linked shared objects: ## invoke with: mtt -cc sys rep mexglx ## ode2odes support is not yet included. | > > > > | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # Copyright (C) 2000 by Peter J. Gawthrop ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ ## Revision 1.49 2002/05/11 01:14:17 geraint ## Fix for [ 553218 ] simpar.oct and simpar.m different. ## Translation added between ColumnVector in base .cc and Octave_map in .oct. ## ## Revision 1.48 2002/05/08 14:51:03 geraint ## Moved matlab/octave data type conversion functions to a separate file. ## ## Revision 1.47 2002/05/07 23:50:34 geraint ## Preliminary support for Matlab dynamically linked shared objects: ## invoke with: mtt -cc sys rep mexglx ## ode2odes support is not yet included. |
︙ | ︙ | |||
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | declarestates=no declareinputs=no declareswitches=no ;; oct) modeline="// -*-c++-*- Put Emacs into c++-mode"; Lc='//'; oct_header=yes; constant_declaration="const double " var_declaration="double " minusone="-1" map="_map" declaredummies=yes ;; *) echo Language $language not supported - sorry; exit 1 esac if [ "$rep" = "simpar" ]; then output=${output}${map} # Output is simpar_map in this case fi | > > > > > > > > > > > > > > | 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | declarestates=no declareinputs=no declareswitches=no ;; oct) modeline="// -*-c++-*- Put Emacs into c++-mode"; Lc='//'; Lb='('; Rb=')'; oct_header=yes; constant_declaration="const double " var_declaration="double " minusone="-1" map="_map" declaredummies=yes ;; sfun) modeline="// -*-c++-*- Put Emacs into c++-mode"; Lc='//' Rc='' Lb='[' Rb=']' start="## BEGIN Code" finish="## END Code" constant_declaration="const double " var_declaration="double " minusone="-1" ;; *) echo Language $language not supported - sorry; exit 1 esac if [ "$rep" = "simpar" ]; then output=${output}${map} # Output is simpar_map in this case fi |
︙ | ︙ | |||
582 583 584 585 586 587 588 | { # Parameters if [ "$parameters" = "yes" ]; then cat <<EOF $Lc Parameters $Rc EOF | | | | | | 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | { # Parameters if [ "$parameters" = "yes" ]; then cat <<EOF $Lc Parameters $Rc EOF sympar2par_txt2m ${system} "" "$var_declaration" "$minusone" "$Lb" "$Rb" fi # States if [ "$states" = "yes" ]; then cat <<EOF $Lc States $Rc EOF N=`n2m 1 $Nx` for i in $N; do echo $constant_declaration 'mttx'$i' = mttx'$Lb$i$minusone$Rb ';' done fi if [ "$declarestates" = "yes" ]; then declare_vars state fi # Inputs if [ "$inputs" = "yes" ]; then cat <<EOF $Lc Inputs $Rc EOF N=`n2m 1 $Nu` for i in $N; do echo $constant_declaration 'mttu'$i' = mttu'$Lb$i$minusone$Rb';' done cat <<EOF $Lc Unknown Inputs $Rc EOF Ni=`n2m 1 $Nyz` for i in $Ni; do echo $constant_declaration 'mttui'$i' = mttu'$Lb$Nu+$i$minusone$Rb';' done fi if [ "$declareinputs" = "yes" ]; then declare_vars input fi |
︙ | ︙ |
Modified mttroot/mtt/bin/trans/sympar2par_txt2m from [c3e5676656] to [ea07b68f51].
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 | #! /bin/sh ###################################### ##### Model Transformation Tools ##### ###################################### # Bourne shell script: sympar2par_txt2m # Symbolic parameters parameter conversion # Used in lang_header # Copyright (C) 2000 by Peter J. Gawthrop case $2 in zero) strip_comments <$1_sympar.txt |\ gawk '{ i++; printf(" %s %s = 0.0;\n", tolower($1)); }' ;; set) strip_comments <$1_sympar.txt |\ gawk '{ i++; printf(" %s mttpar(%i) \t= %s;\n", i, tolower($1)); }' ;; *) strip_comments <$1_sympar.txt |\ gawk '{ | > > > | | | 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 | #! /bin/sh ###################################### ##### Model Transformation Tools ##### ###################################### # Bourne shell script: sympar2par_txt2m # Symbolic parameters parameter conversion # Used in lang_header # Copyright (C) 2000 by Peter J. Gawthrop Lb=${5:-'('} Rb=${6:-')'} case $2 in zero) strip_comments <$1_sympar.txt |\ gawk '{ i++; printf(" %s %s = 0.0;\n", tolower($1)); }' ;; set) strip_comments <$1_sympar.txt |\ gawk '{ i++; printf(" %s mttpar(%i) \t= %s;\n", i, tolower($1)); }' ;; *) strip_comments <$1_sympar.txt |\ gawk '{ i++; printf(" %s %s \t= mttpar%c%i%s%c;\n", decl, tolower($1), Lb, i, minusone, Rb); }' decl="$3" minusone="$4" Lb=$Lb Rb=$Rb ;; esac |
Modified mttroot/mtt/cc/def_m2h.sh from [78c95b87eb] to [8879414d17].
1 2 3 4 5 6 7 8 9 10 | #! /bin/sh # $Id$ # $Log$ # Revision 1.1 2000/12/28 09:46:05 peterg # put under RCS # # Revision 1.3 2000/12/05 12:13:52 peterg # Changed function name to name() # # Revision 1.2 2000/12/04 12:04:46 peterg | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #! /bin/sh # $Id$ # $Log$ # Revision 1.2 2002/04/28 18:58:06 geraint # Fixed [ 549658 ] awk should be gawk. # Replaced calls to awk with call to gawk. # # Revision 1.1 2000/12/28 09:46:05 peterg # put under RCS # # Revision 1.3 2000/12/05 12:13:52 peterg # Changed function name to name() # # Revision 1.2 2000/12/04 12:04:46 peterg |
︙ | ︙ | |||
24 25 26 27 28 29 30 | get_array_size () { vec=$1 gawk -v vec=${vec} '($1 == vec && $2 == "=") { print $3 }' | sed s/\;// } | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | get_array_size () { vec=$1 gawk -v vec=${vec} '($1 == vec && $2 == "=") { print $3 }' | sed s/\;// } echo "/* ${SYS}_def.h, generated by MTT on `date` */" > ${OUT} echo "" >> ${OUT} echo "const int MTTNU = `cat ${IN} | get_array_size nu`;" >> ${OUT} echo "const int MTTNX = `cat ${IN} | get_array_size nx`;" >> ${OUT} echo "const int MTTNY = `cat ${IN} | get_array_size ny`;" >> ${OUT} echo "const int MTTNZ = `cat ${IN} | get_array_size nz`;" >> ${OUT} echo "const int MTTNYZ = `cat ${IN} | get_array_size nyz`;" >> ${OUT} echo "const int MTTNPAR = `wc -l ${SYM} | gawk '{ print $1 }'`;" >> ${OUT} |
Modified mttroot/mtt/cc/mtt_m2cc.sh from [d5b350ce6a] to [7e5ae6afba].
1 2 3 4 | #! /bin/sh SYS=$1 REP=$2 | > | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #! /bin/sh SYS=$1 REP=$2 TARGET=${3:-cc} PARSER=${4:-indent} IN=${SYS}_${REP}.m OUT=${SYS}_${REP}.${TARGET} TMP=${SYS}_${REP}_m2cc.tmp rep_declarations () { (case ${REP} in simpar) cat <<EOF |
︙ | ︙ | |||
105 106 107 108 109 110 111 | }; decrement_indices () { # first section appends '-1' to container indices # to convert from FORTRAN-type numbering to C-type numbering | | | | | | | | | | | | | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | }; decrement_indices () { # first section appends '-1' to container indices # to convert from FORTRAN-type numbering to C-type numbering sed 's/mtta(\([0-9][0-9]*\),\([0-9][0-9]*\))/mtta[\1-1,\2-1]/g' |\ sed 's/mttax(\([0-9][0-9]*\))/mttax[\1-1]/g' |\ sed 's/mttdx(\([0-9][0-9]*\))/mttdx[\1-1]/g' |\ sed 's/mttedx(\([0-9][0-9]*\))/mttedx[\1-1]/g' |\ sed 's/mttpar(\([0-9][0-9]*\))/mttpar[\1-1]/g' |\ sed 's/mttu(\([0-9][0-9]*\))/mttu[\1-1]/g' |\ sed 's/mttx(\([0-9][0-9]*\))/mttx[\1-1]/g' |\ sed 's/mtty(\([0-9][0-9]*\))/mtty[\1-1]/g' |\ sed 's/mttyz(\([0-9][0-9]*\))/mttyz[\1-1]/g' |\ sed 's/mttz(\([0-9][0-9]*\))/mttz[\1-1]/g' |\ sed 's/mttopen(\([0-9][0-9]*\))/mttopen[\1-1]/g' |\ \ # next sections tidy the code up a bit, but are not necessary sed 's/1\-1\([\,\)]\)/0\1/g' |\ sed 's/2\-1\([\,\)]\)/1\1/g' |\ sed 's/3\-1\([\,\)]\)/2\1/g' |\ sed 's/4\-1\([\,\)]\)/3\1/g' |\ sed 's/5\-1\([\,\)]\)/4\1/g' |\ |
︙ | ︙ | |||
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | sed 's/600\-1\([\,\)]\)/599\1/g' |\ sed 's/700\-1\([\,\)]\)/699\1/g' |\ sed 's/800\-1\([\,\)]\)/799\1/g' |\ sed 's/900\-1\([\,\)]\)/899\1/g' |\ sed 's/\([(,]\)0\([0-9]\)/\1\2/g' }; fix_pow () { # matches number^number where number is one or more digits and one or zero decimal points # converts to pow (number, number) sed 's/\([0-9]*\)\(\.\)\{0,1\}\([0-9]*\)\^\([0-9]*\)\(\.\)\{0,1\}\([0-9]*\)/pow \(\1\2\3,\4\5\6\)/g' }; echo Creating ${OUT} | > > > > > > > > > > > > > > > > > > > > > | | | | | > | | | | | | | > > > | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 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 | sed 's/600\-1\([\,\)]\)/599\1/g' |\ sed 's/700\-1\([\,\)]\)/699\1/g' |\ sed 's/800\-1\([\,\)]\)/799\1/g' |\ sed 's/900\-1\([\,\)]\)/899\1/g' |\ sed 's/\([(,]\)0\([0-9]\)/\1\2/g' }; fortran_to_c_paren () { # converts [i] to (i) sed 's/\[\([^[]*\)\]/(\1)/g' } fix_pow () { # matches number^number where number is one or more digits and one or zero decimal points # converts to pow (number, number) sed 's/\([0-9]*\)\(\.\)\{0,1\}\([0-9]*\)\^\([0-9]*\)\(\.\)\{0,1\}\([0-9]*\)/pow \(\1\2\3,\4\5\6\)/g' }; echo Creating ${OUT} case ${TARGET} in sfun) mtt_header ${SYS} ${REP} "sfun" > ${TMP} echo "## END Code" >> ${TMP} find_code ${TMP} head > ${OUT} find_code ${IN} body |\ decrement_indices |\ fix_comment_delimiter |\ fix_pow |\ strip_junk |\ ${PARSER} >> ${OUT} find_code ${TMP} foot >> ${OUT} rm ${TMP} ;; cc | *) mtt_header ${SYS} ${REP} "oct" > ${TMP} find_code ${TMP} head > ${OUT} rep_declarations >> ${OUT} find_code ${IN} body |\ decrement_indices |\ fortran_to_c_paren |\ fix_comment_delimiter |\ fix_pow |\ strip_junk |\ ${PARSER} >> ${OUT} rep_footer >> ${OUT} find_code ${TMP} foot >> ${OUT} rm ${TMP} ;; esac |
Modified mttroot/mtt/lib/rep/sfun_rep/Makefile from [0703d3d39e] to [f2177a72f4].
1 2 | #! /usr/bin/make -f | | | | | > > > > > > > > > > > > > > > > | 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 | #! /usr/bin/make -f SRC = $(SYS)_sfun.cc $(SYS)_def.h $(SYS)_ae.sfun $(SYS)_ode.sfun $(SYS)_odeo.sfun $(SYS)_state.sfun all: $(SYS)_sfun.mexglx $(SYS)_sfun.mexglx: $(SRC) mex $(SYS)_sfun.cc $(SYS)_sfun.cc:: ${MTT_REP}/sfun_rep/sfun.cc.tmpl cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@ $(SYS)_sfun.zip: $(SRC) zip $@ $^ $(SYS)_ae.sfun: $(SYS)_ae.m ${MTT_CC}/mtt_m2cc.sh $(SYS) ae sfun cat $(SYS)_ode.sfun: $(SYS)_ode.m ${MTT_CC}/mtt_m2cc.sh $(SYS) ode sfun cat $(SYS)_odeo.sfun: $(SYS)_odeo.m ${MTT_CC}/mtt_m2cc.sh $(SYS) odeo sfun cat $(SYS)_state.sfun: $(SYS)_state.m ${MTT_CC}/mtt_m2cc.sh $(SYS) state sfun cat %:: mtt -q $(OPTS) `echo $* | sed 's/\(.*\)_\(.*\)\.\(.*\)/\1 \2 \3/'` |
Modified mttroot/mtt/lib/rep/sfun_rep/sfun.cc.tmpl from [3d56d803b8] to [cc87f430f2].
1 | // -*-c++-*- | | < > > > | | > | | > > | | | | | 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 | // -*-c++-*- // <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 "simstruc.h" #include "<mtt_model_name>_def.h" static mxArray *dX = mxCreateDoubleMatrix (MTTNX , 1, mxREAL); static mxArray *P = mxCreateDoubleMatrix (MTTNPAR , 1, mxREAL); static mxArray *T = mxCreateDoubleMatrix (1 , 1, mxREAL); static mxArray *U = mxCreateDoubleMatrix (MTTNU , 1, mxREAL); static mxArray *X = mxCreateDoubleMatrix (MTTNX , 1, mxREAL); static mxArray *Y = mxCreateDoubleMatrix (MTTNY , 1, mxREAL); static mxArray *YZ = mxCreateDoubleMatrix (MTTNYZ , 1, mxREAL); static double *mttdx = mxGetPr (dX); static double *mttu = mxGetPr (U); static double *mttpar = mxGetPr (P); static double *mttx = mxGetPr (X); static double *mtty = mxGetPr (Y); static double *mttyz = mxGetPr (YZ); static double *mtttp = mxGetPr (T); void update_parameters_from_simulink (SimStruct *S) { for (int i = 0; i < MTTNPAR; i++) { mttpar [i] = *mxGetPr (ssGetSFcnParam (S, i)); } } void update_states_from_simulink (SimStruct *S) { static double *x; x = ssGetContStates (S); for (int i = 0; i < MTTNX; i++) { mttx [i] = x [i]; } } void update_inputs_from_simulink (SimStruct *S) { for (int i = 0; i < MTTNU; i++) { mttu [i] = *ssGetInputPortRealSignalPtrs (S, i)[0]; } } void update_simtime_from_simulink (SimStruct *S) { mtttp [0] = ssGetT (S); } // S-function methods static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, MTTNPAR); |
︙ | ︙ | |||
89 90 91 92 93 94 95 | ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); } #define MDL_INITIALIZE_CONDITIONS static void mdlInitializeConditions(SimStruct *S) { | < < < < < < | | | < | > | > > > > | > | > | > > > > | > > | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < | | < < | 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); } #define MDL_INITIALIZE_CONDITIONS static void mdlInitializeConditions(SimStruct *S) { update_parameters_from_simulink (S); #include "<mtt_model_name>_state.sfun" for (int i = 0; i < MTTNX; i++) { ssGetContStates (S)[i] = mttx [i]; } } static void mdlOutputs(SimStruct *S, int_T tid) { update_states_from_simulink (S); update_inputs_from_simulink (S); update_simtime_from_simulink (S); update_parameters_from_simulink (S); UNUSED_ARG(tid); // not used in single tasking mode #include "<mtt_model_name>_odeo.sfun" for (int i = 0; i < MTTNY; i++) { ssGetOutputPortRealSignal (S,i)[0] = mtty [i]; } } #define MDL_DERIVATIVES static void mdlDerivatives(SimStruct *S) { update_states_from_simulink (S); update_inputs_from_simulink (S); update_simtime_from_simulink (S); update_parameters_from_simulink (S); #include "<mtt_model_name>_ode.sfun" for (int i = 0; i < MTTNX; i++) { ssGetdX (S)[i] = mttdx [i]; } } static void mdlTerminate(SimStruct *S) { UNUSED_ARG(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 |