Main Content

Use the Real-Time Model Data Structure

The code generator uses the real-time model (RT_MODEL) data structure. This structure is also referred to as the rtModel data structure. You can access rtModel data by using a set of macros analogous to the ssSetxxx and ssGetxxx macros that S-functions use to access SimStruct data, including noninlined S-functions compiled by the code generator.

You need to use the set of macros rtmGetxxx and rtmSetxxx to access the real-time model data structure. The rtModel is an optimized data structure that replaces SimStruct as the top level data structure for a model. The rtmGetxxx and rtmSetxxx macros are used in the generated code as well as from the main.c or main.cpp module. If you are customizing main.c or main.cpp (either a static file or a generated file), you need to use rtmGetxxx and rtmSetxxx instead of the ssSetxxx and ssGetxxx macros.

Usage of rtmGetxxx and rtmSetxxx macros is the same as for the ssSetxxx and ssGetxxx versions, except that you replace SimStruct S by real-time model data structure rtM. The following table lists rtmGetxxx and rtmSetxxx macros that are used in grt_main.c and grt_main.cpp.

Macros for Accessing the Real-Time Model Data Structure

rtm Macro Syntax

Description

rtmGetdX(rtm)

Get the derivatives of block continuous states

rtmGetOffsetTimePtr(RT_MDL rtM)

Return the pointer to vector that stores sample time offsets of the model associated with rtM

rtmGetNumSampleTimes(RT_MDL rtM)

Get the number of sample times that a block has

rtmGetPerTaskSampleHitsPtr(RT_MDL)

Return a pointer to NumSampleTime × NumSampleTime matrix

rtmGetRTWExtModeInfo(RT_MDL rtM)

Return an external mode information data structure of the model (used internally for external mode)

rtmGetRTWLogInfo(RT_MDL)

Return a data structure used by code generator logging (internal use only)

rtmGetRTWRTModelMethodsInfo(RT_MDL)

Return a data structure of real-time model methods information (internal use only)

rtmGetRTWSolverInfo(RT_MDL)

Return data structure containing solver information of the model (internal use only)

rtmGetSampleHitPtr(RT_MDL)

Return a pointer to Sample Hit flag vector

rtmGetSampleTime(RT_MDL rtM, int TID)

Get task sample time

rtmGetSampleTimePtr(RT_MDL rtM)

Get pointer to a task sample time

rtmGetSampleTimeTaskIDPtr(RT_MDL rtM)

Get pointer to a task ID

rtmGetSimTimeStep(RT_MDL)

Return simulation step type ID (MINOR_TIME_STEP, MAJOR_TIME_STEP)

rtmGetStepSize(RT_MDL)

Return the fundamental step size of the model

rtmGetT(RT_MDL,t)

Get the current simulation time

rtmSetT(RT_MDL,t)

Set the time of the next sample hit

rtmGetTaskTime(RT_MDL,tid)

Get the current time for the current task

rtmGetTFinal(RT_MDL)

Get the simulation stop time

rtmSetTFinal(RT_MDL,finalT)

Set the simulation stop time

rtmGetTimingData(RT_MDL)

Return a data structure used by timing engine of the model (internal use only)

rtmGetTPtr(RT_MDL)

Return a pointer to the current time

rtmGetTStart(RT_MDL)

Get the simulation start time

rtmIsContinuousTask(rtm)

Determine whether a task is continuous

rtmIsMajorTimeStep(rtm)

Determine whether the simulation is in a major step

rtmIsSampleHit(RT_MDL,tid)

Determine whether the sample time is hit

rtmGetErrorStatus(rtm)

Get the current error status

rtmSetErrorStatus(rtm,val)

Set the current error status

rtmGetErrorStatusPointer(rtm)

Return a pointer to the current error status

rtmGetStopRequested(rtm)

Return whether a stop is requested

rtmGetBlockIO(rtm)

Get the block I/O data structure

rtmSetBlockIO(rtm,val)

Set the block I/O data structure

rtmGetContStates(rtm)

Get the continuous states data structure

rtmSetContStates(rtm,val)

Set the continuous states data structure

rtmGetDefaultParam(rtm)

Get the default parameters data structure

rtmSetDefaultParam(rtm,val)

Set the default parameters data structure

rtmGetPrevZCSigState(rtm)

Get the previous zero-crossing signal state data structure

rtmSetPrevZCSigState(rtm,val)

Set the previous zero-crossing signal state data structure

rtmGetRootDWork(rtm)

Get the DWork data structure

rtmSetRootDWork(rtm,val)

Set the DWork data structure

rtmGetU(rtm)

Get the root inputs data structure (when root inputs are passed as part of the model data structure)

rtmSetU(rtm,val)

Set the root inputs data structure (when root inputs are passed as part of the model data structure)

rtmGetY(rtm)

Get the root outputs data structure (when root outputs are passed as part of the model data structure)

rtmSetY(rtm,val)

Set the root outputs data structure (when root outputs are passed as part of the model data structure)

For additional details on usage, see SimStruct Macros and Functions Listed by Usage.

Related Topics