From Zero to Embedded Code Deployment — 25 Hands-On Lessons
Classical, Modern, Robust, Nonlinear, MPC, Adaptive, Fuzzy, Physical Modeling, and Code Generation
中文版请见 README.md
- Preview
- Quick Start
- Prerequisites
- Tutorial Overview
- Learning Path
- What You'll Learn
- Project Structure
- Companion Projects
- Contributing
- License
All figures auto-generated by run_all_tutorials. See docs/images for the full set.
| PID Control (t05) | LQR Optimal Control (t10) |
![]() |
![]() |
| Kalman Filter (t12) | PMSM FOC (t14) |
![]() |
![]() |
git clone https://github.com/xingd5478-ctrl/simulink-control-tutorial.gitIn MATLAB, navigate to the project folder and run:
>> check_setup>> t00_main_guide % Course overview (25 lessons)
>> t01_signal_basics % Lesson 1: Sine wave + Gain + Scope% Phase 1 (t01-t08) — Simulink fundamentals, no extra toolboxes needed
% Phase 2 (t16, t17, t22) — Classical control design
% Phase 3 (t09-t12) — Modern control theory
% Phase 4 (t18-t21, t23, t24) — Advanced control topics
% Phase 5 (t13, t14, t25, t15) — Applications & deployment
% Or run everything at once:
>> run_all_tutorialsEach script auto-creates a Simulink model (.slx) → configures blocks → runs simulation → generates result plots. No manual model-building required.
- Double-click the Scope block — view the waveform
- Double-click other blocks — see how parameters are set
- Tweak a parameter — change Gain from 2 to 5, re-run, observe the change
- Look at the MATLAB Figure — comparison plots help you understand concepts
| Dependency | Notes | Phase |
|---|---|---|
| MATLAB R2020a+ | Core runtime | All |
| Simulink | Model building and simulation | All |
| Control System Toolbox | State-space, LQR, Kalman, freq analysis | Phase 2-5 |
| Robust Control Toolbox | H∞ / μ analysis | t19 (optional) |
| Model Predictive Control Toolbox | MPC design | t20 (optional) |
| Fuzzy Logic Toolbox | Fuzzy inference system | t24 (optional) |
| Simscape | Physical modeling | t25 (optional) |
Beginner tip: t01-t08 need only MATLAB + Simulink. Run
check_setupto verify your environment.
Q: I have zero control theory background. Can I follow?
Yes. Phase 1 (t01-t08) teaches only Simulink operations, no control theory. Later lessons explain control concepts as needed.
Q: "Undefined function or variable" error?
Make sure MATLAB's Current Folder is the project root (simulink-control-tutorial/). Use the folder panel in MATLAB to navigate there.
Q: No waveform in Scope?
Double-click the Scope block. If the line is flat, check the Step block's Step time parameter — it jumps at 0.5s, not 0s.
Q: Too many model windows open?
>> bdclose all % Close all Simulink models
>> close all % Close all FiguresQ: How do I regenerate a tutorial model?
Simply re-run the script — it overwrites the old .slx:
>> t05_pid_control25 lessons, 5 phases — progressive learning path from fundamentals to industrial applications.
| # | Tutorial | Content | Model |
|---|---|---|---|
| t01 | Signal Basics | Signals, gain blocks, scopes | ✅ |
| t02 | Math Operations | Sum, product, Mux/Demux routing | ✅ |
| t03 | First-Order Systems | Transfer functions, time constants | ✅ |
| t04 | Second-Order Systems | Damping ratio, overshoot, natural frequency | ✅ |
| t05 | PID Control | P/I/D effects, feedback loop tuning | ✅ |
| t06 | Sources & Sinks | Data import/export, signal generators | ✅ |
| t07 | Subsystems | Hierarchical model packaging | ✅ |
| t08 | Masking | Parameterized block design | ✅ |
| # | Tutorial | Core Theory | Engineering Value |
|---|---|---|---|
| t16 | Frequency Domain | Bode, Nyquist, Nichols, gain/phase margin | Stability analysis |
| t17 | Lead-Lag Compensator | Lead/Lag compensation, frequency shaping | Classical control design |
| t22 | Root Locus | rlocus(), pole trajectories, compensator design | Classical design visualization |
| # | Tutorial | Core Theory | Engineering Value |
|---|---|---|---|
| t09 | State-Space Models | ẋ=Ax+Bu, y=Cx+Du | Modern control foundation |
| t10 | LQR Optimal Control | Pole placement, Riccati equation, Q/R tuning | MIMO system design |
| t11 | State Observer | Luenberger Observer, duality, (A-LC) | Sensorless control |
| t12 | Kalman Filter | lqe(), Q/R noise modeling, Luenberger comparison | Optimal estimation under noise |
| # | Tutorial | Core Theory | Engineering Value |
|---|---|---|---|
| t18 | System Identification | Step response, least-squares, model validation | From data to transfer function |
| t19 | H∞ Robust Control | Mixed sensitivity, hinfsyn, μ analysis | Optimal control under uncertainty |
| t20 | MPC | Receding horizon, QP constraints, explicit MPC | Constrained multivariable control |
| t21 | Sliding Mode Control | Sliding surface, chattering suppression, STSMC | Nonlinear robust control |
| t23 | MRAC Adaptive Control | MIT rule, reference model, parameter adaptation | Online tuning for time-varying systems |
| t24 | Fuzzy Logic Control | Sugeno FIS, membership functions, control surface | Model-free expert knowledge control |
| # | Tutorial | Core Theory | Engineering Value |
|---|---|---|---|
| t13 | DC Motor Control | Electromagnetic + mechanical coupling, cascaded PI, LQR | Actuator modeling |
| t14 | PMSM + FOC | d-q transform, Clarke/Park, vector control | Brushless motor control |
| t25 | Simscape Physical Modeling | Physical components, multi-domain, auto-derived equations | Formula-free modeling approach |
| t15 | Code Generation | c2d discretization, dlqr, C code, FreeRTOS | Embedded deployment |
Phase 1 (Basics) Phase 2 (Classical) Phase 3 (Modern) Phase 4 (Advanced) Phase 5 (Apps)
t01-t08 Basics ──→ t16 Freq Domain ──→ t09 State-Space ──→ t18 System ID ──→ t13 DC Motor
│ │ │ │
├── t17 Lead-Lag ├── t10 LQR ├── t19 H∞ ├── t14 FOC
│ │ │ │
└── t22 Root Locus ├── t11 Observer ├── t20 MPC ├── t25 Simscape
│ │ │
└── t12 Kalman ├── t21 SMC └── t15 Code Gen
│
├── t23 MRAC
│
└── t24 Fuzzy
After completing all 25 lessons, you will be able to:
- Derive state-space models from physical laws
- Design LQR/Kalman optimal controllers and observers
- Analyze stability in the frequency domain (Bode/Nyquist) and design compensators
- Identify system models from experimental data
- Handle parameter uncertainty with H∞ robust control
- Design MPC controllers for constrained systems
- Implement sliding mode control for nonlinear/high-disturbance systems
- Analyze pole trajectories with root locus and design compensators
- Design MRAC adaptive controllers for time-varying systems
- Build fuzzy logic control systems without precise mathematical models
- Model physical systems in Simscape without deriving equations
- Go from continuous → discrete → C code, deploy to STM32 and other embedded platforms
- Understand cascaded PI and FOC vector control in industrial practice
.
├── check_setup.m # Environment checker (run this first)
├── t00_main_guide.m # Tutorial index
├── t01-t25_*.m # 25 tutorial scripts
├── models/ # Simulink models (auto-generated)
│ └── tutorial01-tutorial25.slx
├── utils/ # Shared utilities
│ └── getSimData.m
├── run_all_tutorials.m # Batch runner for all tutorials
├── docs/images/ # Auto-generated simulation figures
├── .github/ # Issue/PR templates
├── README.md # 中文版
├── README_EN.md # This file (English)
├── CHANGELOG.md # Changelog
├── CONTRIBUTING.md # Contribution guide
├── CODE_OF_CONDUCT.md # Code of conduct
├── SECURITY.md # Security policy
└── LICENSE # MIT
- STM32-MPU6050-System — MEMS gyroscope Allan variance + adaptive Kalman on real hardware
- ebpf-robot-safety — eBPF real-time control safety monitoring
Issues and PRs are welcome! Bug reports, new tutorial ideas, and documentation improvements all count.
- Bug → use Bug Report template
- New topic → use Tutorial Request template
- Code/doc improvements → Fork → Modify → PR
See CONTRIBUTING.md for details.
MIT — Free to use, modify, and distribute. See LICENSE.
If this tutorial helps you, a ⭐ Star would be greatly appreciated!
Xing Dong · 2026



