Use Arduino as controller (HIL) for a simulink modelled physical system
33 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello Everyone,
I've been searching for an answer to this question and haven't found anything quite applicable in past items from this forum. Would appreciate any guidance you all can give. I have modelled a system (inverted pendulum) in Simulink and tuned a PID controller for support. My next step is to convert my current continuous controller into a discreet form and write that in the Arduino programming environment then upload to the board. That part is not an issue. What I need help with is to replace the controller sub system I have in simulink with controls sent to/from the actual Arduino itself.
What I need to do is simulate the system in Simulink and send the various state information via USB to the Arduino for processing then read that information back in to update the simulated system. Is this possible and does anyone have ideas for where to start? I have already downloaded the Arduino support module but that seems more for laying out a full system to upload onto the Arduino board and run separate from the computer. (While a useful function, it's not applicable to the project I want. I do want to program the controller separately using the standard c-based language for the arduino.)
Thank you in advance for any help!
EDIT: I forgot to mention that I'm using the Arduino Uno (Makezine version)
0 comentarios
Respuestas (3)
Ubaldo
el 14 de En. de 2022
I think this could be a solution (I haven't tried myself though).
1 comentario
Reily
el 13 de En. de 2025
Editada: Reily
el 13 de En. de 2025
Thanks for this comment, I found this guide helpful.
I followed this guide and made a primitive controller hardware in the loop (CHIL) test on an arduino: I made a buck converter in SimScape, made a PI controller for arduino, and allowed the arduino to control the plant over serial. I don't have much experience with Arduino, but I found it quite clear and painless.
Norehsa
el 4 de Abr. de 2015
1 comentario
Henk Argeloos
el 15 de Jun. de 2015
Dear Norehsa,
I've been trying to accomplish the exact same thing for a school project. My goal is to simulate a cruise control system with an Arduino Uno in the loop as controller, while the 'plant' (i.e. the car dynamics) runs as a Simulink model. Also, i'm using Simulink as the way to program my Arduino.
Could you maybe share a bit more on how you've turned your Arduino into an 'external' controller. For instance, how are you dealing with the limitations of uint8 giving you only the values 0 - 255 to work with?
Thank you in advance!
Emanuel Feru
el 20 de En. de 2019
Editada: Emanuel Feru
el 20 de En. de 2019
I tryied also something similar. Basically a kind of HIL system, where the controller runs on Arduino while the plant model (built with Simscape) runs on my laptop. All the comminication back and forth (closed loop) I want to do via the Serial Communication via USB (Port 0).
After spending almost 2 days, it seems that Simulink Arduino Serial Read/Write blocks are limited. They cannot be easily customized. In other words, it does not allow easy customization of the message to be transmitted.
What I was looking is to send a message like:
"u1 u2 u3 u4 \r\n"
where u1, u2, u3, u4 are values (single, int, boolean, etc.) sent as text with maximum 2 decimals.
Then decode this message with the blocks 'Input stream' or 'Serial Read' from the Instrumentation Toolbox. However, I cannot create the message above.
What is suprizing that in External mode, the arduino board communicates with Simulink via Port 0. So, Matworks must have a solution for running Closed loop systems. I wonder why is this not included as a library block, to be able to do closed loop or HiL type of simulations? Mathworks should respond.
PS: It would be really powerful to be able to do HIL simulations. It would make Arduino and Simulink a complete platform for HIL symulations.
0 comentarios
Ver también
Categorías
Más información sobre Modeling en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!