# Day 3: Model-Based Design with Simulink: Code Gen and V\&V

## Code Generation and Targeting - Pete Szpak

### Maximizing Component Reuse in Code Generation - Xiaocang Lin

* Improving encapsulation in generated code
  * Minimize public interface dependecny (R2017a)
  * Keep local function truly local (R2017b)
    * Eliminates name collisions
    * cset: Preserve static keyword in function declarations
* Simulink Library -> Reusable Code Parts
  * Reuse a function within a model (since 2002)
  * Reuse a function across multiple models (since R2012b)

### Responding to the Ever-Increasing Demands on Code Efficiency - Partha Biswas

* Traditional MBD Workflow in pure control applications
  * RAM and Data minimization/efficiency is critical
* Increasing design complexity (i.e. vision application domain)
  * High demand for performance
    * Zero tolerance for unnecessary copies
  * Tareting heterogeneous platforms
    * Leverage concurrency
* Improvements
  * No unnecessary data copies for bus element assignment (R2017a)
    * TODO: Investigate
  * Favor buffer reuse in a chain of blocks (R2017b)
    * 11% RAM reduction
  * RAM and Data Copy Reduction (R2017b)
    * Reusable CSC
    * Inout arguments in MATLAB/Simulink function & MATLAB system blocks
  * Exploiting parallelism
    * Data-level parallelism
    * Task-level parallelism

### Reusing Generated Code Across MATLAB Releases - Jon Fielder

* Addressing the challenge of manual code integration
  * Difficulties
    * Duplicate utilities across releases
    * Non-functional changes
    * Perhaps a large number of utilities to handle
  * Approaches
    * Reduce number of utilities generated (R2016b)
  * Automatically integrate shared code (R2016b)
    * Associate model components with existing shared code
  * Automatically integrate model code (R2016b)
    * Directly import model code and shared code
      * Utilizes SIL and PIL using the previously generated and verified code
        * As far back as R2010a
    * Cross-relese system simulation
  * Generate efficient integrated code (R2016b)
    * Call to the previous releases are fully inline, without wrapper code
  * Easily reuse model reference components
    * Import model refreence component (R2017a)
    * Import model reference hierearchy (R2017b)

### Real-Time Simulation and Testing - Marc Schafer

* Simulink Desktop Real-Time integration to ThingSpeak (R2017b)
* Logging improvements (R2017b)
  * Works just like you would for desktop simulations
* Simulink Test and Simulink Real-Time can interoperate
* Baseline Real-Time Target Machine (R2017a)
* Mission: If you know how to use Simulink, you know how to use Simulink Real-Time

### Advances in C++ Code Generation  - Pengcheng Wu

* An object-oriented, C++ code realization is more natural sometimes
* Separation of concerns
  * Publish-Subscribe
  * Discovery
  * Communication
  * Quality of Service
* Since R2016a, more production code use-cases
* Multi-instantiable Simulink Functions: Natural way to map models to classes (R2017b)
  * Can utilizie dot notation, similar to C++ code

### Advances in HDL Code Generation - Kiran Kintali

* Advanced algorithms require hardware acceleartion
* FPGA/SoC are key to meet the growing performance needs
* HDL Code Generation workflows help manage complexity
* Hardships of fixed-point conversion (with high dynamic range math models)
  * New support for floating-point and fixed-point algorithms
    * Directly target floating-point on the hardware
      * Misconception that fixed-point is always more efficient than floating-point
* Math more accessible for FPGA
  * Single (R2016a)
  * Double (R2017b)

### Generating GPU Code for Acceleration - Girish Venkataramani

* New Product in R2017b
  * GPU Coder
    * Take MATLAB and generate CUDA code for NVIDIA GPUs
    * Accelerated implementation of parallel algorithms on GPUs
      * Neural Networks
        * Deep Neural Network
      * Image processing and computer vision
      * Signal processing and communications

## Autonomous Systems Design - Don Orofino

* Robotic Autonmous Systems are a MEGATREND
  * Fixed-location robotics (eg, robotic arm)
  * Wheeled vehicles
  * UAV/Drone/Quadcopters
* Automated driving is a high priority for TMW
  * Directing all possible development teams to this area

### Delivering Autonomous Systems using Model-Based Design - David Koh

* Need to combine many diverse technologies
* Managing complexity is a key to developing autonomous systems
  * High-level abstraction using MATLAB, Simulink, & Stateflow
  * Parallel Simulations (R2017a)
    * `parsim`
      * Multicore
      * Data center on the cloud
  * Code generation
    * C/C++/HDL/PLC generators
  * GPU Coder (R2017b)
    * Translate MATLAB to optimized CUDA
  * Closed-loop testing & real time hardware-in-the-loop
    * Vehicle blockset toolbox (R2017b)

### Automated Driving - Witek Jachimczyk

* Automated Driving System Toolbox (R2017a)
  * Emphasis on perception and algorithm validation
    * Vehicle detection with distance estimation using a monocular camera
      * Parabolic lane boundary model
      * Bird's eye projection
    * Ground Truth Labeler
      * API for custom automation algorithm
* Direction
  * Simulink support for tracking and sensor fusion (R2017b)

### Deep Learning and Computer Vision for Environment Perception - Birju Patel

* Deep Learning Algorithms
  * R2016a
    * Neural Network Toolbox
    * Computer Vision System Toolbox
  * R2017a
    * Computer vision System Toolbox
      * Train faster R-CNN Dector
    * Automated Driving System Toolbox
  * R2017b
    * Computer Vision System Toolbox
      * Semantic Segmentation
    * Automated Driving System Toolbox
      * Labeling Training Data
* Deployment
  * Code generation
    * GPU (R2017b)

### Sensor Fusion and Tracking - Vincent Pellissier

* Fuse detections with multi-object tracker (R2017a)
  * Vision & radar
    * Fused detector
    * Fused tracker
* Synthesize scenario to test tracker (R2017a)
* Sensor fusion in Simulink (R2017b)
  * Adaptive cruise control example will be shipped

### Localization, Mapping, and Planning - Remo Pillat

* Robotics System Toolbox
  * Plan manpulator motion (R2017a)
  * UAV localization & Control (R2017a)

### Replay Simulation of Recorded Sensor Data - David Koh

* Why?
  * To develop robust algorithms, need lots of real-world data collected under varying conditions
* Robotics System Toolbox

## Test and Verification - Bill Aldrich

### Work with Requirements in Simulink - Yasumitsu Ito

* New interface
  * Bring in requirements into MATLAB
  * Tracing is simplified
  * RMI will still be available
  * Bi-directional linking with DOORS isn't initially supported

### Use Quality Measures to Improve Your Design - Sai Avula

* Access Model Quality Metrics Dashboard (R2017b)
* Clone detection (R2017b)
  * Cloned component
    * Subsystem that matches any other subsystem in the model hierarchy
    * Convert all cloned components to library link subsystem
    * Size of generated code was reduced by 50% in one industry test model

### Author Tests with Spreadsheets - Khoo Yit Phang

* Leverages Simulink Test
  * Excel file are input and baseline options (R2017b)
    * Supports boolean, enumeration, and numeric data types
    * Utilize multiple sheets to define multiple tests
    * Test results can be captured effortlessly to Excel files

### Eliminate Defects Using Regression Testing - A. Abhishek

* Use Simulink Project impact analysis to identify tests to be re-run
* Focus on sandbox testing
  * Local machine testing
  * Simulink Test Manager
    * Run tests, fetch results
* Model coverage

### Address Missing Coverage - Anjali Joshi

* Simulink Design Verifier
  * Detect dead logic
    * Newly integrated in coverage results explorer (R2017a)
    * Fix design to eliminate dead logic
    * Add justification for dead logic
    * Automatically add tests for missing coverage (R2017a)
* Coverage Results Explorer (R2016b)
  * TODO: Investigate

### Test Across Releases - Gregg Smith

* Approaches
  * Use SIL replacement blocks to host older code in newer release (R2017b)
  * `crossReleaseExport()`
  * `crossReleaseImport()`
* Test Manager (R2017b)
  * Multi-release testing
    * Automatically spawns older releases of MATLAB and tests on those

## Breakout Sessions

### Streamlining Certification Workflows with Model-Based Designa - Eric Dillaber

* Model Advisor
  * Modeling Standard Checks
    * Security (eg, CERT-C) added
  * Design error detection is now exposed in Model Advisor (R2017a)
* Code coverage
  * Bill recommends running code coverage in SIL mode, then running PIL mode with code coverage disabled
    * Code coverage instruments the code
* Qual/Cert Kit Updates
  * R2017a
    * Qualification of
      * Simulink Design Error Detection
      * Polyspace Report
      * Simulink Block Execution Coverage
  * R2017b
    * Qualification of
      * New MathWorks High-Integrity Guideline Checks
      * MAAB Guideline Checks
      * MISRA Checks
    * Improvements to Simulink Coverage Qual kit
    * Guidance on Qaulifying Custom Checks
    * Menu Access to Kit artifacts, trace matrix and tests

### Customizing Embedded Coder to Generate Perfect Code for Your Environment - Xiaocang Lin
