How Fast is Simulink Real Time? Is Simulink Real Time Faster than Rasberry Pi?

21 views (last 30 days)
Dear Community,
Subject: I am looking for help in choosing microcontroller (rasberry pi or another) or platform to implement model predictive controller in real time.
I have designed Model Predictive Controller using simulink MPC toolbox. I want to implement MPC controller in real time to my device (i.e. Atomic Force Microscopy).
My purpose of controller is that it should fast enough to track high speed signal. I have keep my MPC controller sampling time = 3.1309 x 10^-5. My controller in simulations shows better performance in term of speed.
For real time I thought I will use Simulink in real time but my professor told me that it is very slow and you'll not be able to achieve desired results, because simulink is very slower.
One lab mate suggested me to convert simulink block to C/C++ and then use s-function simulink it will be a bit faster, but again i will use simulink and my professor is not agree with that.
I am looking for suggestions which microcontroller (Rasberry Pi, Arduino or any other) will be better for real time experiment? In our lab we have NI RIO FPGA device but I don't know it can be useable with simulink or not, and is it speed is better than above mentioned softwares.
Please help me and suggest some microcontrollers that are faster than simulink and also it should be easy to use them for real time experiment.
Ts = 3.1309x10^-5
Best Regards

Answers (3)

Hassaan
Hassaan on 9 Jan 2024
Implementing a Model Predictive Controller (MPC) in real time, especially with the stringent timing requirements that you've mentioned (sampling time of approximately 31.3 microseconds), requires careful consideration of both the computational platform and the software stack you plan to use.
For such fast control loops, typical microcontrollers like Arduino or even Raspberry Pi might not be suitable due to their limited processing capabilities and non-real-time operating systems. Here are a few options that you might consider:
  1. FPGA (Field-Programmable Gate Array): The NI RIO FPGA device in your lab is likely a good choice for implementing high-speed control systems. FPGAs are known for their ability to execute parallel operations and deterministic timing, which can be crucial for control applications with very fast sampling rates. Simulink has support for FPGA deployment through HDL Coder, which can convert your Simulink models into VHDL or Verilog code that can be synthesized onto an FPGA.
  2. SoC (System on Chip) with an FPGA and CPU: Some platforms like the Xilinx Zynq combine an ARM-based processor with an FPGA. This allows you to run a high-level operating system and perform high-speed operations on the FPGA, all on the same chip. Tools like Xilinx's Vivado HLS can help with the implementation.
  3. Dedicated Real-Time Systems: If you prefer to stick with a CPU-based solution, you might look into dedicated real-time hardware that supports Simulink Real-Time. This hardware is designed to run models developed in Simulink in real time and can meet strict timing requirements.
  4. Real-Time Operating Systems (RTOS) on Embedded Systems: Consider using an RTOS on an embedded platform like BeagleBone Black or even a more powerful ARM Cortex-based microcontroller. An RTOS can provide the deterministic timing you need. You can export the Simulink model to C code using Embedded Coder and then integrate it with the RTOS.
  5. PC-based Real-Time Systems: Some real-time control applications use industrial PCs with real-time operating systems or real-time extensions (like RT-Linux). The Simulink Desktop Real-Time™ toolbox allows you to run Simulink models in real time on your Windows PC.
  6. Speedgoat Real-time Target Machines: These are real-time target machines specifically designed to work with Simulink Real-Time. They are optimized for rapid control prototyping and hardware-in-the-loop (HIL) simulation and are known for high performance.
Here are some steps to guide you further:
  • Assess the Computational Load: Determine how computationally intensive your MPC is. This will influence whether an FPGA or a high-speed processor is necessary.
  • Consider Latency Requirements: Besides the computational speed, also consider the latency from input sensing to actuation. Low-latency is crucial for high-speed tracking.
  • Integration with Hardware: Ensure that the chosen platform can easily interface with your device, the Atomic Force Microscope.
  • Development Time and Resources: Consider the development resources you have available. FPGA programming, for instance, is quite specialized compared to writing C code for microcontrollers.
  • Software Support: Look for platforms that are well-supported by MATLAB/Simulink, since you've developed your controller using these tools.
Your first step should be to look into the capabilities of the NI RIO FPGA device you have and see if you can leverage that for your MPC implementation. National Instruments provides tools to integrate Simulink models with their FPGA devices, which might be a viable solution for you.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

Diego Kuratli
Diego Kuratli on 9 Jan 2024
The answer depends on the complexity of your algorithm, and the required real-time accuracy and I/O connectivity.
When you run your model in your PC, does it run faster or slower than the wall-clock time? If it does not run much slower and you do not need many I/O channels, you might consider Simulink Desktop Real-Time.
For more flexibility and performances, you should look into Simulink Real-Time with Speedgoat real-time test systems.
You may use embedded devices such as Raspberry Pi, Arduino if they can meet your performance and I/O requirements. To learn if your model can run in such devices, a benchmark is recommended.
  3 Comments
Diego Kuratli
Diego Kuratli on 10 Jan 2024
Yes, the MPC controller, and any other components that you have in your controller model.
Muhammad
Muhammad on 15 Jan 2024
Edited: Muhammad on 15 Jan 2024
Hi @Diego Kuratli When I was using MPC Controller Toolbox in Simulink it was running slower like my simulation time was 1 sec but after compiling simulations take atleast 12 sec to complete.
Now I have replaced the MPC block with S-Function Simulink, and it takes less than 1 sec to simulate 10 seconds interval. So in this scenario what you think its faster or slower wall clock time?
I have also found JETSON NANO kit in my lab https://developer.nvidia.com/embedded/jetson-nano-developer-kit does it will work faster for me than Simulink Desktop?
I have also look into JETSON TX2 https://developer.nvidia.com/embedded/jetson-tx2 which I can afford. I want good speed so what you suggest to go with?
My System Specifications are as follows:
I am using Bossmonster Laptop It's Ubuntu and Windows,
I don't have MATLAB Simulink for Ubuntu so I am using Window Bossmonster
Processor: Intel(R) Xeon (R) CPU E3 1231 v3 3.40Ghz 3401 Mhz 4C
16 GB Ram
20 GB virtual memory

Sign in to comment.


Emmanouil Tzorakoleftherakis
Hi,
First of all, how fast (wall clock time) does the Simulink model run with your current MPC implementation? This would be a good way to gauge the feasibility of what you are trying to accomplish. For example, based on what you mentioned, you want to run an MPC controller at 32kHz which is likely not going to be feasible given that MPC solves an optimization problem online.
The suggestion about using C/C++ is towards the right direction: the idea is that if generate C code from your MPC controller and execute this code from within Simulink, that would lead to performance improvement. This is true, but the speed up you will get likely won't get you to 32kHz.
In terms of hw, given what I mentioned before about how expensive MPC is, I don't think you will be successfull with typical low-cost hw.
Based on the above, here are my suggestions:
1) Go over this whitepaper and try to follow some of the recommendations to make sure your MPC design is optimized. For example, make sure parameters such as prediction horizon and control horizon are not larger than needed. Also, try out some of the various solvers available for QP problems in Model Predictive Control Toolbox and pick the fastest solver. You can also reduce optimization iterations by using suboptimal solutions to save time.
2) In terms of hardware I think your best bet would be to run the controller on a Speedgoat machine with Simulink Real-Time that is connected to your target hardware. Another option would be to generate an executable from the controller and run it from your desktop machine assuming it can talk to the target.
3) If the above don't help (and that's very likely), the other option would be to turn your linear implicit MPC controller into an explicit MPC controller. This approach may or may not be practical depending on how big your state space is. If this works, you are much more likely to get the rates you are looking for using the hardware I mentioned in 2).
Hope this helps
  4 Comments
Muhammad
Muhammad on 15 Jan 2024
Hi
When I was using MPC Controller Toolbox in Simulink it was running slower like my simulation time was 1 sec but after compiling simulations take atleast 12 sec to complete.
Now I have replaced the MPC block with S-Function Simulink, and it takes less than 1 sec to simulate 10 seconds interval.
So in this scenario what you think its faster or slower wall clock time?
I have also found JETSON NANO kit in my lab https://developer.nvidia.com/embedded/jetson-nano-developer-kit does it will work faster for me than Simulink Desktop?
I have also look into JETSON TX2 https://developer.nvidia.com/embedded/jetson-tx2 which I can afford. I want good speed so what you suggest to go with?
Secondly I also think LQR will be best solution, but it's so late I think, because I was not aware of LQR i just read about it 2 days ago. Now I am not familiar with LQR. it's equations and also I think there is no toolbox for LQR in simulink.
My System Specifications are as follows:
I am using Bossmonster Laptop It's Ubuntu and Windows,
I don't have MATLAB Simulink for Ubuntu so I am using Window Bossmonster
Processor: Intel(R) Xeon (R) CPU E3 1231 v3 3.40Ghz 3401 Mhz 4C
16 GB Ram
20 GB virtual memory
Emmanouil Tzorakoleftherakis
Edited: Emmanouil Tzorakoleftherakis on 15 Jan 2024
Not sure how you have set up your s function but what I was hinting to is this: Simulink Profiler can tell you exactly how much time it takes for each block to run. So if you generate code from the MPC block or do some kind of SIL test, MPC should be able to run faster than 32kHz on your laptop if you want to run it on less powerful hw after.
Also,on LQR, you can simply use the 'lqr' function and copy over the gains on Simulink to create a state feedback controller.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!