| Attribute | Value |
|---|---|
| Goal | Build a discrete PID speed controller with production data types |
| Plant | First-order vehicle: v_dot = (F_drive - F_drag) / m |
| Controller | Discrete PID: Kp=10, Ki=2, Kd=0.5, Ts=10ms |
| Types | All controller signals: single; lookup tables: int16 |
| Target | Step response 0-30 m/s in < 5s; steady-state error < 0.1 m/s |
| Deliverable | Simulated response plot + named signals + code-gen ready |
Lab: Discrete PID Speed Controller
Exercise 1: PID Model in MATLAB
% Build PID speed controller model
model = "SpeedController";
new_system(model); open_system(model);
% Solver: Fixed-step, ode4, 10ms
set_param(model,"SolverType","Fixed-step","Solver","ode4","FixedStep","0.01");
set_param(model,"ProdHWDeviceType","ARM Compatible->ARM Cortex");
% Plant subsystem: v_dot = (u - 0.01*v^2) / 1500
% Blocks: Add(-F_drag) -> Gain(1/1500) -> Discrete Integrator -> v
% F_drag = Gain(0.01) * Product(v*v)
% PID Controller subsystem:
% Error = SpeedRef - VehicleSpeed
% P: Gain(Kp) output P_term
% I: Discrete-Time Integrator(Ki, Ts=0.01) output I_term
% AntiWindup: Saturation(-100,100) before integrator input
% D: Unit Delay + Subtract (discrete difference) * Gain(Kd)
% Sum: Add(P_term + I_term + D_term)
% Clamp: Saturation(0, 100) -- pedal 0-100%
% Step input: 0 to 30 m/s at t=1s
sim(model, 20);
figure; plot(logsout{"VehicleSpeed"}.Values); grid on;
title("Vehicle Speed Response"); xlabel("s"); ylabel("m/s");Exercise 2: Signal Objects for Code Gen
% Signal objects: set types, min, max, description
SpeedRef = Simulink.Signal;
SpeedRef.DataType = "single"; SpeedRef.Min = 0; SpeedRef.Max = 40;
SpeedRef.Description = "Reference speed (m/s)";
VehicleSpeed = Simulink.Signal;
VehicleSpeed.DataType = "single"; VehicleSpeed.Min = 0; VehicleSpeed.Max = 40;
SpeedError = Simulink.Signal;
SpeedError.DataType = "single"; SpeedError.Min = -40; SpeedError.Max = 40;
% Parameter objects (appear in A2L for calibration)
Kp = Simulink.Parameter; Kp.Value = 10.0; Kp.DataType = "single";
Kp.Min = 0; Kp.Max = 100;
Kp.CoderInfo.StorageClass = "ExportedGlobal";
Ki = Simulink.Parameter; Ki.Value = 2.0; Ki.DataType = "single";
Ki.Min = 0; Ki.Max = 50;
Ki.CoderInfo.StorageClass = "ExportedGlobal";
% Verify: no untyped signals
% Analysis > Model Advisor > jc_0021 check
ma = ModelAdvisor.run(model, {"mathworks.maab.jc_0021"});
disp(ma.getResult("mathworks.maab.jc_0021"));Summary
Building the first complete MBD model reveals what production-grade modelling demands: every signal needs a name, a type, and Min/Max bounds. These are not optional - signal names become C variable names, types determine memory layout, and Min/Max enable Design Verifier property checking and Model Advisor range analysis. The PID controller also demonstrates anti-windup handling: the integrator must be clamped or the integral term will wind up to its maximum during periods of high error (like a long stretch at maximum pedal) and then resist returning to zero, causing overshoot. Anti-windup is invisible in a simple Simulink model without the clamping logic - which is why the model is the correct place to implement and document it.
🔬 Deep Dive — Core Concepts Expanded
This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.
Key principles to reinforce:
- Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
- Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
- Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.
🏭 How This Topic Appears in Production Projects
- Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
- Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
- Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.
⚠️ Common Mistakes and How to Avoid Them
- Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
- Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
- Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
- Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.
📊 Industry Note
Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.