View source
From UcgnWiki
for
Simulink UCGN Hello World
Jump to:
navigation
,
search
Up: [[Main Page]] ---- == Overview == The '''SimulinkUcgnDistribution''' contains a "Hello World" example, in the simulink/Examples/HelloWorld subfolder. You will find a simple Simulink model showing how to set up a design and then process it through the stages of model transformation and code-generation. The model is intended to show some of the basic concepts available. The following files are part of the design (located in ./simulink/Examples/HelloWorld) * '''TST_HelloWorldModel.mdl''' - the simulink model * '''GBL_Constants.m''' - showing how workspace parameters are used as "tunable parameters" * '''FCS_FlightControlSystemDefinitions.m''' - showing how to work with bus objects * '''GBL_Definitions.m''' - showing how to emulate enumerated types using workspace parameters The following set of files controls the processing * '''SlcGenExport_TST_HelloWorldModel.m''' - creates the domain-specific XML model from the Simulink model * '''SlcProject.xml''' - project file for the UCGN Simulink model transformation * '''SimulinkUcgn.bat''' - batchfile to run model transformation and code generator All files listed above are located in the ./simulink/Examples/HelloWorld folder. == Prerequisites == * Java JRE 1.6 or newer * Matlab R2009b, Simulink 7.4 == Setup == * Extract '''SimulinkUcgnDistribution.zip''' to a location of your choice<br />We'll refer to that folder location as ''UCGN_SIMULINK_BASE'' * Make a copy of the folder '''work_template''' called '''work''', at the same level * Modify '''SlcGenExport_TST_HelloWorldModel.m''', to point to your <br />UcgnBasePath = '<your UCGN_SIMULINK_BASE>'; * Modify '''SlcProject.xml''', to point to UCGN_SIMULINK_BASE/work as the Working Directory <br /><workingDirectory><your UCGN_SIMULINK_BASE>\work</workingDirectory> * Modify '''SimulinkUcgn.bat''', to point to your UCGN_SIMULINK_BASE<br />set UCGN_SIMULINK_BASE=<your UCGN_SIMULINK_BASE> (enclose in quotes if your path containes spaces!) == Running the example == * In Matlab, run SlcGenExport_TST_HelloWorldModel.m. This will export the model (as well as workspace parameter and bus object definitions) to '''TST_HelloWorldModel.xml'''. The xml file is located in UCGN_SIMULINK_BASE/work/mdl * From a DOS command window run SimulinkUcgn.bat. This will start the java-based model transformation and code generation, using SlcProject.xml as the project file. == The model == [[File:HelloWorld1.jpg|900px]] ---- [[File:HelloWorld2.jpg|950px]] == Generated source code == C-language source code will be generated to '''<UCGN_SIMULINK_BASE>/work/src/lang/c''' Here is an excerpt from the header file '''TST_HelloWorldModel.h''' <source lang="c"> /******************************************************************************/ /* (SubSystem) Declaration of TST_HelloWorldModel.TST_HelloWorldModel */ /******************************************************************************/ void TST_HelloWorldModel_Calculate(FCS_FlightControlSystem_StatusStructuredType *FcsStatus, /* Input */ GBL_Types_Double TerrainElevationM, /* Input */ GBL_Types_UInt32 *PilotRecommendation); /* Output */ </source> And a section from the source file '''TST_HelloWorldModel.c''': <source lang="c"> /* (RelationalOperator) TST_HelloWorldModel.TST_HelloWorldModel.LowAltitude -> inlined (Constant) Constant250 -> inlined (Gain) PressureAltitude_M -> inlined (BusSelector) Selector -> inlined (Sum) AltitudeAboveGround_M */ LowAltitude = ((GBL_Constants_Feet2Meter * FcsStatus->PressureAltitude_Ft) - TerrainElevationM) <= 250.0; /* (Switch) TST_HelloWorldModel.TST_HelloWorldModel.PilotRecommendationSwitch -> inlined (Constant) DontEject -> inlined (BusSelector) Selector -> inlined (Logic) EngineFailure -> inlined (BusSelector) Selector -> inlined (BusSelector) Selector -> inlined (Logic) InTrouble -> inlined (Constant) EjectAsap */ if (FcsStatus->InAir && (FcsStatus->LeftEngFailed || FcsStatus->RightEngFailed) && LowAltitude) { *(PilotRecommendation) = (GBL_Types_UInt32)(GBL_Definitions_EjectionCmd_EjectAsap); } /* end of if */ else { *(PilotRecommendation) = (GBL_Types_UInt32)(GBL_Definitions_EjectionCmd_DontEject); } /* end of else */ </source> This is the type definition resulting from the bus object FCS_FlightControlSystem_Status <source lang="c"> typedef struct FCS_FlightControlSystem_StatusStructuredTypeTag { GBL_Types_Boolean InAir; GBL_Types_Boolean LeftEngFailed; GBL_Types_Boolean RightEngFailed; GBL_Types_Single PressureAltitude_Ft; GBL_Types_Single IndicatedAirspeed_Knots; } FCS_FlightControlSystem_StatusStructuredType; </source> The (emulated) enumerated type definition in GBL_Definitions looks like this <source lang="c"> typedef enum GBL_Definitions_EjectionCmdEnumeratedTypeTag { GBL_Definitions_EjectionCmd_DontEject = 0, GBL_Definitions_EjectionCmd_EjectAsap = 1, GBL_Definitions_EjectionCmd_EjectWarning = 2 } GBL_Definitions_EjectionCmdEnumeratedType; </source>
Return to
Simulink UCGN Hello World
.
Views
Page
Discussion
View source
History
Personal tools
Log in
Navigation
Main page
Community portal
Current events
Recent changes
Random page
Help
Search
Toolbox
What links here
Related changes
Special pages