0
0
SimulinkHow-ToIntermediate · 4 min read

Implement Agile with Model Based Design in Simulink

To implement agile with model based design in Simulink, break your system into small, testable components and develop them in short iterations. Use Simulink's version control, model referencing, and automated testing tools to continuously integrate and validate changes quickly.
📐

Syntax

Agile with model based design in Simulink involves these key steps:

  • Model decomposition: Split your system into smaller models using Model References.
  • Iteration cycles: Develop and test each model in short cycles.
  • Version control: Use Simulink Projects with Git or SVN integration.
  • Automated testing: Use Simulink Test to create and run test cases automatically.
  • Continuous integration: Integrate models frequently using tools like Simulink Check and Simulink Design Verifier.
matlab
%% Example syntax for model referencing and testing
% Create a model reference block in your main model
add_block('built-in/ModelReference', 'MainModel/SubsystemRef', 'ModelName', 'SubsystemModel')

% Run automated test using Simulink Test
results = sltest.testmanager.run('TestFile.mldatx');
disp(results);
Output
[Test run results displayed in MATLAB command window]
💻

Example

This example shows how to create a simple model reference and run an automated test in Simulink to support agile development.

matlab
% Create a simple subsystem model
new_system('SubsystemModel');
open_system('SubsystemModel');
add_block('simulink/Commonly Used Blocks/Gain', 'SubsystemModel/Gain');
set_param('SubsystemModel/Gain', 'Gain', '2');
save_system('SubsystemModel');

% Create main model and add model reference block
new_system('MainModel');
open_system('MainModel');
add_block('built-in/ModelReference', 'MainModel/SubsystemRef', 'ModelName', 'SubsystemModel');
save_system('MainModel');

% Create a simple test harness
new_system('TestHarness');
open_system('TestHarness');
add_block('simulink/Commonly Used Blocks/Step', 'TestHarness/Step');
add_block('simulink/Commonly Used Blocks/Scope', 'TestHarness/Scope');
add_block('built-in/ModelReference', 'TestHarness/SubsystemRef', 'ModelName', 'SubsystemModel');
add_line('TestHarness', 'Step/1', 'SubsystemRef/1');
add_line('TestHarness', 'SubsystemRef/1', 'Scope/1');
save_system('TestHarness');

% Run simulation to validate
sim('TestHarness');
Output
Simulation completed successfully with output visible in Scope block.
⚠️

Common Pitfalls

  • Not modularizing models: Large monolithic models slow down iteration and testing.
  • Skipping automated tests: Manual testing delays feedback and increases errors.
  • Poor version control: Without proper branching and commits, integration conflicts arise.
  • Ignoring model consistency checks: Leads to errors during integration and deployment.
matlab
% Wrong approach: Single large model without references
new_system('BigModel');
open_system('BigModel');
add_block('simulink/Commonly Used Blocks/Gain', 'BigModel/Gain');
set_param('BigModel/Gain', 'Gain', '2');
save_system('BigModel');

% Right approach: Use model references for modularity
new_system('ModularModel');
open_system('ModularModel');
add_block('built-in/ModelReference', 'ModularModel/SubsystemRef', 'ModelName', 'SubsystemModel');
save_system('ModularModel');
📊

Quick Reference

  • Use Model References to break down complex systems.
  • Develop in short iterations with frequent commits.
  • Automate tests with Simulink Test for fast feedback.
  • Integrate models regularly to catch errors early.
  • Use version control tools integrated in Simulink Projects.

Key Takeaways

Break your system into small models using Model References for easier iteration.
Use automated testing in Simulink Test to validate changes quickly.
Integrate and commit changes frequently with version control to avoid conflicts.
Keep models modular and consistent to support agile workflows.
Leverage Simulink Projects to manage files, tests, and version control together.