From: Farrukh on 29 Jul 2010 11:10 Hello everyone, I created a a very simple simulink model which has input port, addition and one output port. I successfully compiled the code generated from RTW Embedded coder in eclipse IDE. I used ert.tlc with C++ (Encapsulated), checked the I/O access method in interface pane. Please tell me how to access the output generated by the model in ert_main.cpp. Is there any specific function to access the model output? I set the input value in ert_main.cpp (g,h), ert_main.cpp is as follows * * File: ert_main.cpp * * Real-Time Workshop code generated for Simulink model test_simple. * * Model version : 1.14 * Real-Time Workshop file version : 7.3 (R2009a) 15-Jan-2009 * Real-Time Workshop file generated on : Thu Jul 29 16:15:29 2010 * TLC version : 7.3 (Jan 18 2009) * C/C++ source code generated on : Thu Jul 29 16:15:29 2010 * * Target selection: ert.tlc * Embedded hardware selection: 32-bit Generic * Emulation hardware selection: * Differs from embedded hardware (MATLAB Host) * Code generation objectives: Unspecified * Validation result: Not run */ #include <stdio.h> /* This ert_main.c example uses printf/fflush */ #include "test_simple.h" /* Model's header file */ #include "rtwtypes.h" /* MathWorks types */ static test_simpleModelClass test_simple_Object;/* Instance of model class */ static boolean_T OverrunFlag = 0; /* Associating rt_OneStep with a real-time clock or interrupt service routine * is what makes the generated code "real-time". The function rt_OneStep is * always associated with the base rate of the model. Subrates are managed * by the base rate from inside the generated code. Enabling/disabling * interrupts and floating point context switches are target specific. This * example code indicates where these should take place relative to executing * the generated code step function. Overrun behavior should be tailored to * your application needs. This example simply sets an error status in the * real-time model and returns from rt_OneStep. */ void rt_OneStep(void) { /* Disable interrupts here */ /* Check for overrun */ if (OverrunFlag++) { rtmSetErrorStatus(test_simple_Object.getRTM(), "Overrun"); return; } real_T g=2.0; real_T h=2.0; real_T k; /* Save FPU context here (if necessary) */ /* Re-enable timer or interrupt here */ /* Set model inputs here */ test_simple_Object.setIn1(g); test_simple_Object.setIn2(h); /* Step the model */ test_simple_Object.step(); /* Get model outputs here */ /* Indicate task complete */ OverrunFlag--; /* Disable interrupts here */ /* Restore FPU context here (if necessary) */ /* Enable interrupts here */ } /* The example "main" function illustrates what is required by your * application code to initialize, execute, and terminate the generated code. * Attaching rt_OneStep to a real-time clock is target specific. This example * illustates how you do this relative to initializing the model. */ int_T main(int_T argc, const char_T *argv[]) { /* Initialize model */ test_simple_Object.initialize(); /* The MAT-file logging option selected; therefore, simulating * the model step behavior (in non real-time). Running this * code produces results that can be loaded into MATLAB. */ while (rtmGetErrorStatus(test_simple_Object.getRTM()) == (NULL)) { rt_OneStep(); } /* Disable rt_OneStep() here */ /* Terminate model */ test_simple_Object.terminate(); return 0; } /* File trailer for Real-Time Workshop generated code. * * [EOF] */. Regards, Farrukh
From: Nevine on 30 Jul 2010 14:52 > /* Set model inputs here */ > test_simple_Object.setIn1(g); > test_simple_Object.setIn2(h); > /* Step the model */ > test_simple_Object.step(); > > /* Get model outputs here */ > Similar to root-level input access methods (setIn1, setIn2), you should also find root-level output access methods, for example, getOut1() and getOut2(). - Nevine
From: Farrukh on 5 Aug 2010 11:03 "Nevine" <nevinejacob1981(a)hotmail.com> wrote in message <i2v70k$rus$1(a)fred.mathworks.com>... > > /* Set model inputs here */ > > test_simple_Object.setIn1(g); > > test_simple_Object.setIn2(h); > > /* Step the model */ > > test_simple_Object.step(); > > > > /* Get model outputs here */ > > > > Similar to root-level input access methods (setIn1, setIn2), you should also find root-level output access methods, for example, getOut1() and getOut2(). > > - Nevine Thanks man!
|
Pages: 1 Prev: Report Generator Style Sheet help Next: Highlighting start and endpoints on plots |