Index: mttroot/mtt/lib/rep/sfun_rep/Makefile ================================================================== --- mttroot/mtt/lib/rep/sfun_rep/Makefile +++ mttroot/mtt/lib/rep/sfun_rep/Makefile @@ -98,6 +98,6 @@ useful-functions.hh:: ${MTT_CC}/include/useful-functions.hh echo Copying $@ cp $^ $@ %:: - mtt -q $(MTT_OPTS) `echo $* | sed 's/\(.*\)_\(.*\)\.\(.*\)/\1 \2 \3/'` + mtt -cc -q $(MTT_OPTS) `echo $* | sed 's/\(.*\)_\(.*\)\.\(.*\)/\1 \2 \3/'` Index: mttroot/mtt/lib/rep/sfun_rep/sfun_interface.c.tmpl ================================================================== --- mttroot/mtt/lib/rep/sfun_rep/sfun_interface.c.tmpl +++ mttroot/mtt/lib/rep/sfun_rep/sfun_interface.c.tmpl @@ -20,19 +20,19 @@ static double *mttpar; /* pointer to parameters */ static double *mttx; /* pointer to states */ static double *mtty; /* pointer to outputs */ static double mttt; /* time */ -static double *controller_inputs; -static double *controller_outputs; +static double *MTT_outputs; +static double *MTT_inputs; static unsigned int i; /* loop counter */ /* Start EDIT */ -/* Edit this block to define the number of controller inputs, outputs and parameters */ -const int NumberOfControllerInputs = 1; /* inputs TO controller */ -const int NumberOfControllerOutputs = 1; /* outputs FROM controller */ +/* Edit this block to define the number of simulink inputs, outputs and parameters */ +#define NumberOfSimulinkInputs MTTNY /* MTT outputs */ +#define NumberOfSimulinkOutputs MTTNU /* MTT inputs */ /* End EDIT */ static void _process_inputs (SimStruct *S) { @@ -39,23 +39,25 @@ /* insert _struc.c */ /* Start EDIT */ /* Edit this block to process the model inputs and outputs */ - /* Remove the following line */ - ssSetErrorStatus (S, "_sfun_interface.c has not been customised!\n"); - - /* simple example follows */ - - /* Get total of all outputs and input to controller */ - controller_inputs[0] = 0.0; - for (i = 0; i < MTTNY; i++) { - controller_inputs[0] += mtty[i]; + /* Error messages can be set using the following line */ + /* ssSetErrorStatus (S, "_some error message!\n"); */ + + /* Default is to expose all MTT inputs, outputs and states */ + + /* Get all the MTT model outputs and pass them to simulink */ + for (i = 0; i < NumberOfSimulinkInputs; i++) { + MTT_outputs[i] = mtty[i]; } - /* overwrite first model input with output from controller */ - mttu[0] = controller_outputs[0]; + /* Get all inputs from Simulink and pass them to the MTT model */ + /* Any inputs not over-written here will be read from _input.c */ + for (i = 0; i < NumberOfSimulinkOutputs; i++) { + mttu[i] = MTT_inputs[i]; + } /* End EDIT */ } @@ -98,14 +100,14 @@ array_name = "mttu"; } else if (array == mttx) { array_name = "mttx"; } else if (array == mtty) { array_name = "mtty"; - } else if (array == controller_inputs) { - array_name = "controller_inputs"; - } else if (array == controller_outputs) { - array_name = "controller_outputs"; + } else if (array == MTT_outputs) { + array_name = "MTT_outputs"; + } else if (array == MTT_inputs) { + array_name = "MTT_inputs"; } else { array_name = "unknown_array"; } sprintf(warning, "(time %f) Non-finite array element: %s[%d]\n", mttt, array_name, index); ssWarning(S, warning); @@ -120,12 +122,12 @@ mttpar = array_of_double (MTTNPAR); mttu = array_of_double (MTTNU + MTTNYZ); mttx = array_of_double (MTTNX); mtty = array_of_double (MTTNY); - controller_inputs = array_of_double (NumberOfControllerInputs); - controller_outputs = array_of_double (NumberOfControllerOutputs); + MTT_outputs = array_of_double (NumberOfSimulinkInputs); + MTT_inputs = array_of_double (NumberOfSimulinkOutputs); PRINT_LEAVE; } static void @@ -142,13 +144,13 @@ } for (i = 0; i < MTTNY; i++) { mtty[i] = *ssGetInputPortRealSignalPtrs (S, 2)[i]; check_finite(S, mtty, i); } - for (i = 0; i < NumberOfControllerOutputs; i++) { - controller_outputs[i] = *ssGetInputPortRealSignalPtrs (S, 3)[i]; - check_finite(S, controller_outputs, i); + for (i = 0; i < NumberOfSimulinkOutputs; i++) { + MTT_inputs[i] = *ssGetInputPortRealSignalPtrs (S, 3)[i]; + check_finite(S, MTT_inputs, i); } PRINT_LEAVE; } static void @@ -176,19 +178,19 @@ if (!ssSetNumInputPorts(S, 4)) return; ssSetInputPortWidth(S, 0, MTTNU); ssSetInputPortWidth(S, 1, MTTNX); ssSetInputPortWidth(S, 2, MTTNY); - ssSetInputPortWidth(S, 3, NumberOfControllerOutputs); /* inputs from controller */ + ssSetInputPortWidth(S, 3, NumberOfSimulinkOutputs); /* inputs from simulink */ ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortDirectFeedThrough(S, 1, 1); ssSetInputPortDirectFeedThrough(S, 2, 1); ssSetInputPortDirectFeedThrough(S, 3, 1); if (!ssSetNumOutputPorts(S, 2)) return; ssSetOutputPortWidth(S, 0, MTTNU); /* altered inputs */ - ssSetOutputPortWidth(S, 1, NumberOfControllerInputs); /* outputs to controller */ + ssSetOutputPortWidth(S, 1, NumberOfSimulinkInputs); /* outputs to simulink */ ssSetNumSampleTimes(S, 1); ssSetNumRWork(S, 0); ssSetNumIWork(S, 0); ssSetNumPWork(S, 0); @@ -232,13 +234,13 @@ for (i = 0; i < MTTNU; i++) { check_finite(S, mttu, i); ssGetOutputPortRealSignal (S, 0)[i] = mttu[i]; } - for (i = 0; i < NumberOfControllerInputs; i++) { - check_finite(S, controller_inputs, i); - ssGetOutputPortRealSignal (S, 1)[i] = controller_inputs[i]; + for (i = 0; i < NumberOfSimulinkInputs; i++) { + check_finite(S, MTT_outputs, i); + ssGetOutputPortRealSignal (S, 1)[i] = MTT_outputs[i]; } PRINT_LEAVE; } @@ -258,16 +260,16 @@ free (mttpar); free (mttu); free (mttx); free (mtty); - free (controller_inputs); - free (controller_outputs); + free (MTT_outputs); + free (MTT_inputs); 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