Here is a summary of the changes (in that order) made to the original Simulink model in
order to make it work in the external mode:
- Have a host computer that runs Simulink and communicates with an Arduino DUE
board via a USB connection. - Install "Simulink Support Package for Arduino Hardware". You need to install a
different hardware support package if your hardware is different. - In the "Configuration Parameters" dialog, choose "Fixed-Step" solver type in the
"Solver" pane and the "Arduino DUE" hardware board in the "Hardware
Implementation" pane. - Replace the engine model section in the original model with two serial interface
blocks. In real time, the Open-Loop PID Autotuner block running on the Arduino board
collects plant output from the "Serial Receive" block (from sensor) and sends the
experiment signals to the engine via the "Serial Transmit" block (to actuator). - For more flexibility in real-time operation, start and stop the tuning process by flipping
a manual "Tuning Switch" instead of based on the simulation clock. Similarly, update
the PI gains by flipping a "Gain Switch" and change the reference signal by flipping a
"Ref Switch". - Choose "External Mode" in the Simulink model and set simulation time to "infinite".
Run simulation. First, Simulink generates code for the whole model and download it to
the Arduino DUE board. After the program starts running on the board, you can monitor
the plant input and output from the scope in real time. When plant reaches the nominal
operating point of 2000 rpm, use the three manual switches to tune, update and validate
the controller.
Reducing Memory and Avoiding Task Overrun in External Mode
The "Reduce memory and avoid task overrun (external mode only)" option in the "Block"
tab can help deploy the generated code on hardware with limited memory resources
and/or very fast sample time.
Tune PID Controller in Real Time Using Open-Loop PID Autotuner Block