AKC SE Plan
MEI PROPRIETARY
Automated Generation Of Code From Simulink To An Event-Based Simulation Framework
Jonathan Maram
Isela Villanueva
Millennium Engineering And Integration
16 March 2010
SSCGI2
MEI PROPRIETARY
Simulation Environments Used By MEI
• Simulink
–Dynamic System Modeling/Simulations
–Graphical Block-Diagramming Tool
–Tightly Integrated With Matlab Command Library
–Means To Generate Time-Driven Code
• Event-based Framework (EBF)
–Discrete Event Messaging
–Models created with compiled code
–Componentized Simulation Layers
• Middleware, Controller Layers
• User Components; Simulation Engine & Model Layers
Benefit Derived From Porting Simulink-Developed Models
Into EBF Simulations
SSCGI3
MEI PROPRIETARY
Required Information Flow From Simulink To EBF During Code Generation
Model1Out1 In2
Model1 Constructor
Simulink
EBF
Code
Elements
Model1 Initializer
Model1 Event1 Constructor
Model1 Self-Schedule Event Handler
Model Logic
Model Traits
Model2
Model Logic
Model Traits
Model2 Initializer
Model1 Event1 Handler
Model2 Constructor
SSCGI4
MEI PROPRIETARY
Time-consuming Manual Approach Initially Used
• User
• XML
• Graphic
• File
• Database
Controller
Simulation Engine
OutputInput
Functional Model (Code Generated from Simulink or other sources)
Implements Methods in the Model API
Model Base Class
Interface CodeProcess Events, Call Functional ModelPublish and Subscribe to Attributes, Output StreamsImplements Methods in the Inline Functionality API
Inline Functionality APIModel API
•Functional model code generated from Simulink
•Other components hand-written
SSCGI5
MEI PROPRIETARY
Tasks For Automation
• Extract Information About Targeted Models And Their I/O
• Store Information In A .MAT file
• Generate Functional Model Code From Simulink Using Standard Templates
• Generate Additional Interface Code Using Custom Code Templates– Model classes, including Event Handling Methods
– Attribute classes
– Event classes
• Generate Makefile Or Visual Studio Projects/Solution
• Compile & Build EBF code
• Generate Prototype Run-Time Configuration Files– Incorporate Simulink Tunable Parameters
SSCGI6
MEI PROPRIETARY
Automated EBF Code Generation Implemented
Reusable Code Templates Matlab Scripts
Develop ETE
Simulink Model Generate Code
Generate Custom Code Templates VS Solution
VS Projects
C++ files
Build EBF Simulation
Model DLLs
Simitar Executable
Run EBF Simulations
Baseline Config Files
Automated Code Generation
Model Development
Run Simulink
Simulations
Compare Results
Configure For CG
Extracted Model Data
Tunable Parameters
(Customizations)
EBF API
SSCGI7
MEI PROPRIETARY
Testing Performed To Verify Fidelity Of Generated Code
• 4 Synthetic Test Cases
– varied I/O schemes
– varied feedback schemes
– multiple rates
• 4 Simulink Models Developed In-House or By MEI Partners
– Representation of Sensors, Association, State Estimation, Control, Actuators, and Flight Dynamics
• Output data from Simulink & EBF Simulations Compared
SSCGI8
MEI PROPRIETARY
Example Scenario Targeted For Code Generation
SSCGI9
MEI PROPRIETARY
Example Parameter Compared: Pointing Error
SSCGI10
MEI PROPRIETARY
Pointing Error Time Plots Compared
SSCGI11
MEI PROPRIETARY
Pointing Errors Compare Well
SSCGI12
MEI PROPRIETARY
Summary
•Customized scripts and templates used to generate EBF scenario
– Inputs/Outputs Characterized and Adapted
–Model Traits Captured And Incorporated
•Templates Structured With EBF-Specific Code
–Model, Event, Attribute Classes
–Model Initialization and Event Handling Methods
– Communication, Event Scheduling, Data Handling
•Code Generation Interface Tested and Validated With Several Scenarios