From: freccia on 3 Dec 2009 06:13 Hi Folks I have converted a simulink model to c code by using Real Time Workshop. I used the option “Generate an example main program” and the file ert_main has been created. This model integrates a set of ordinary differential equations. When I compile the source and header files I can’t see the results of the model integration. How can I customize the ert_main to obtain the results? I have read the manual but no example is reported. Thanks in advance. The name of the model is TRIAL whereas the ert_main contains the following code: #include <stdio.h> #include "TRIAL.h" /* Model's header file */ #include "rtwtypes.h" /* MathWorks types */ static boolean_T OverrunFlag = 0; void rt_OneStep(void) { /* Check for overrun */ if (OverrunFlag++) { rtmSetErrorStatus(TRIAL_M, "Overrun"); return; } TRIAL_step(0); /* Get model outputs here */ OverrunFlag--; } int_T main(int_T argc, const char_T *argv[]) { /* Initialize model */ TRIAL_initialize(); while ((rtmGetErrorStatus(TRIAL_M) == NULL) && !rtmGetStopRequested (TRIAL_M)) { rt_OneStep(); } TRIAL_terminate(); return 0; }
From: Arnaud Miege on 4 Dec 2009 10:21 "freccia " <stendardostefano(a)hotmail.com> wrote in message news:hf86gg$36b$1(a)fred.mathworks.com... > Hi Folks > I have converted a simulink model to c code by using Real Time Workshop. I > used the option “Generate an example main program” and the > file ert_main has been created. This model integrates a set of ordinary > differential equations. When I compile the source and header files I > can’t see the results of the model integration. > How can I customize the ert_main to obtain the results? I have read the > manual but no example is reported. > Thanks in advance. > > The name of the model is TRIAL whereas the ert_main contains the following > code: > #include <stdio.h> > #include "TRIAL.h" /* Model's header file */ > #include "rtwtypes.h" /* MathWorks types */ > > static boolean_T OverrunFlag = 0; > > void rt_OneStep(void) > { > /* Check for overrun */ > if (OverrunFlag++) { > rtmSetErrorStatus(TRIAL_M, "Overrun"); > return; > } > TRIAL_step(0); > > /* Get model outputs here */ > OverrunFlag--; > } > int_T main(int_T argc, const char_T *argv[]) > { > /* Initialize model */ > TRIAL_initialize(); > > while ((rtmGetErrorStatus(TRIAL_M) == NULL) && !rtmGetStopRequested > (TRIAL_M)) { > rt_OneStep(); > } > TRIAL_terminate(); > return 0; > } > Not my area of expertise, so I can't answer your question, but you should really go on the training courses: http://www.mathworks.com/services/training/courses/RT01_1.html http://www.mathworks.com/services/training/courses/RT02_1.html Arnaud
From: Riccardo on 7 Dec 2009 04:27 "freccia " <stendardostefano(a)hotmail.com> wrote in message <hf86gg$36b$1(a)fred.mathworks.com>... > Hi Folks > I have converted a simulink model to c code by using Real Time Workshop. I used the option “Generate an example main program” and the file ert_main has been created. This model integrates a set of ordinary differential equations. When I compile the source and header files I can’t see the results of the model integration. > How can I customize the ert_main to obtain the results? I have read the manual but no example is reported. > Thanks in advance. > > The name of the model is TRIAL whereas the ert_main contains the following code: > #include <stdio.h> > #include "TRIAL.h" /* Model's header file */ > #include "rtwtypes.h" /* MathWorks types */ > > static boolean_T OverrunFlag = 0; > > void rt_OneStep(void) > { > /* Check for overrun */ > if (OverrunFlag++) { > rtmSetErrorStatus(TRIAL_M, "Overrun"); > return; > } > TRIAL_step(0); > > /* Get model outputs here */ > OverrunFlag--; > } > int_T main(int_T argc, const char_T *argv[]) > { > /* Initialize model */ > TRIAL_initialize(); > > while ((rtmGetErrorStatus(TRIAL_M) == NULL) && !rtmGetStopRequested > (TRIAL_M)) { > rt_OneStep(); > } > TRIAL_terminate(); > return 0; > } Hi, I'm afraid just posting the source of main.c and saying that you're running some code generation on some model doesn't give any info about your real problem/situation. More to the point: 1) what do you mean by "I can’t see the results of the model integration" ? 2) Does the build process (code generation + compilation + linking) work as expected - i.e. have you checked the source & ancillary files produced - is your model actually described by them or not ? Do you get an executable after the build process ? 3) Can you run the simulation with the exe/or whatever other format produced ? If so, does a run create an output file (check the directory you're working into) ? HTH Riccardo
From: freccia on 10 Dec 2009 08:45 "Riccardo" <nothx(a)nospam.org> wrote in message <hfihp5$fvj$1(a)fred.mathworks.com>... > "freccia " <stendardostefano(a)hotmail.com> wrote in message <hf86gg$36b$1(a)fred.mathworks.com>... > > Hi Folks > > I have converted a simulink model to c code by using Real Time Workshop. I used the option “Generate an example main program” and the file ert_main has been created. This model integrates a set of ordinary differential equations. When I compile the source and header files I can’t see the results of the model integration. > > How can I customize the ert_main to obtain the results? I have read the manual but no example is reported. > > Thanks in advance. > > > > The name of the model is TRIAL whereas the ert_main contains the following code: > > #include <stdio.h> > > #include "TRIAL.h" /* Model's header file */ > > #include "rtwtypes.h" /* MathWorks types */ > > > > static boolean_T OverrunFlag = 0; > > > > void rt_OneStep(void) > > { > > /* Check for overrun */ > > if (OverrunFlag++) { > > rtmSetErrorStatus(TRIAL_M, "Overrun"); > > return; > > } > > TRIAL_step(0); > > > > /* Get model outputs here */ > > OverrunFlag--; > > } > > int_T main(int_T argc, const char_T *argv[]) > > { > > /* Initialize model */ > > TRIAL_initialize(); > > > > while ((rtmGetErrorStatus(TRIAL_M) == NULL) && !rtmGetStopRequested > > (TRIAL_M)) { > > rt_OneStep(); > > } > > TRIAL_terminate(); > > return 0; > > } > > Hi, > I'm afraid just posting the source of main.c and saying that you're running some code generation on some model doesn't give any info about your real problem/situation. > More to the point: > 1) what do you mean by "I can’t see the results of the model integration" ? I am trying to understand which is the function that actually integrates my model and save the numerical results into an output file (e.g. *.txt). For an istance if I run the ert_main.c, the following loop: > > while ((rtmGetErrorStatus(TRIAL_M) == NULL) && !rtmGetStopRequested > > (TRIAL_M)) { > > rt_OneStep(); > > } is infinitely repeated and I have to stop the run. So I want to substitute this loop with another loop which let me to save the numerical results of the integration. > 2) Does the build process (code generation + compilation + linking) work as expected - i.e. have you checked the source & ancillary files produced - is your model actually described by them or not ? Do you get an executable after the build process ? Yes I get an executable file after the building. > 3) Can you run the simulation with the exe/or whatever other format produced ? If so, does a run create an output file (check the directory you're working into) ? Yes I can run the executable but any output is performed. I guess the problem is the aforementioned loop. I should create another loop which perform the integration of the model with the help of the function rtOneStep or something else. Thank you in advance for your response > HTH > Riccardo
From: Riccardo on 15 Dec 2009 03:52
"freccia " <stendardostefano(a)hotmail.com> wrote in message <hfqu15$orf$1(a)fred.mathworks.com>... > "Riccardo" <nothx(a)nospam.org> wrote in message <hfihp5$fvj$1(a)fred.mathworks.com>... > > "freccia " <stendardostefano(a)hotmail.com> wrote in message <hf86gg$36b$1(a)fred.mathworks.com>... > > > Hi Folks > > > I have converted a simulink model to c code by using Real Time Workshop. I used the option “Generate an example main program” and the file ert_main has been created. This model integrates a set of ordinary differential equations. When I compile the source and header files I can’t see the results of the model integration. > > > How can I customize the ert_main to obtain the results? I have read the manual but no example is reported. > > > Thanks in advance. > > > > > > The name of the model is TRIAL whereas the ert_main contains the following code: > > > #include <stdio.h> > > > #include "TRIAL.h" /* Model's header file */ > > > #include "rtwtypes.h" /* MathWorks types */ > > > > > > static boolean_T OverrunFlag = 0; > > > > > > void rt_OneStep(void) > > > { > > > /* Check for overrun */ > > > if (OverrunFlag++) { > > > rtmSetErrorStatus(TRIAL_M, "Overrun"); > > > return; > > > } > > > TRIAL_step(0); > > > > > > /* Get model outputs here */ > > > OverrunFlag--; > > > } > > > int_T main(int_T argc, const char_T *argv[]) > > > { > > > /* Initialize model */ > > > TRIAL_initialize(); > > > > > > while ((rtmGetErrorStatus(TRIAL_M) == NULL) && !rtmGetStopRequested > > > (TRIAL_M)) { > > > rt_OneStep(); > > > } > > > TRIAL_terminate(); > > > return 0; > > > } > > > > Hi, > > I'm afraid just posting the source of main.c and saying that you're running some code generation on some model doesn't give any info about your real problem/situation. > > More to the point: > > > 1) what do you mean by "I can’t see the results of the model integration" ? > > I am trying to understand which is the function that actually integrates my model and save the numerical results into an output file (e.g. *.txt). For an istance if I run the ert_main.c, the following loop: > > > > while ((rtmGetErrorStatus(TRIAL_M) == NULL) && !rtmGetStopRequested > > > (TRIAL_M)) { > > > rt_OneStep(); > > > } > > is infinitely repeated and I have to stop the run. So I want to substitute this loop with another loop which let me to save the numerical results of the integration. > > > > 2) Does the build process (code generation + compilation + linking) work as expected - i.e. have you checked the source & ancillary files produced - is your model actually described by them or not ? Do you get an executable after the build process ? > > Yes I get an executable file after the building. > > > > 3) Can you run the simulation with the exe/or whatever other format produced ? If so, does a run create an output file (check the directory you're working into) ? > > Yes I can run the executable but any output is performed. > > I guess the problem is the aforementioned loop. I should create another loop which perform the integration of the model with the help of the function rtOneStep or something else. > Thank you in advance for your response > > > > HTH > > Riccardo Have you put some output gateway blocks in your model (E.G. - that I remember - to-workspace, global output ports, etc) ? Without those the simulation won't produce an output. |