How to adjust internal sample time of MPC?
17 次查看(过去 30 天)
显示 更早的评论
In Simulink I'm using an MPC Controller block. As a parameter in this block, I'm using an mpc object from my workspace, which I then design using the MPC Designer.
My goal is to generate C++ code for this MPC Controller for an embedded system.
When I set the sample time in the MPC Designer to 0.1 (seconds) and generate C++ code of this MPC Controller, generated comments in the code tell me to call the step() function every 0.1 seconds.
But I want these two sample times to be different from each other. For example:
I want the MPC Controller to simulate his internal plant using a sample time of 0.1 seconds, but I want to call the step() function in the generated C++ code every 0.005 seconds.
Why do I want this?
The rest of my system has a sample time of 0.005 seconds, so I would like to use the MPC Controller every 0.005 seconds as well. But setting the MPC internal sample time to 0.005 seconds forces me to set a really large prediction horizon. That's why I want to have a rather rough sampling time inside the MPC just for his simulation activities.
So how can I decouple the internal MPC simulation sample time and the actual sample time of calling the step() function in the C++ code?
Thank you for your effort in helping me here:)
0 个评论
采纳的回答
Emmanouil Tzorakoleftherakis
2023-1-26
There is a way to do that, but first you need to consider whether you actually need to run your MPC controller that fast. As you noticed, small sample time with long time horizon makes the underlying optimization problem very large and slower to solve. Just because the rest of the system has a small sample time, it does not mean that the controller needs to do the same. The rule of thumb is that the sample time should be small enough to give you reasonable control bandwidth based on the control objective and dynamics, not smaller than that.
If you are not sure how to have multi-rate systems in your generated code, the code generation process should be able to take care of that for you. For example, if in the same Simulink model you have an MPC controller than runs every 0.1 seconds and some other algorithm to-be-deployed that runs every 0.005 seconds, there generated code will call these routines at their specified rates.
If the above were not enough to convince you and you still want to decouple prediction and control sample time, first make sure that the MPC optimization problem can be solved sufficiently fast (ts=0.005 is pretty small after all). If that's the case, you can specify Ts = 0.1 is the mpc object (this will be your prediction sample time) and then put the MPC block inside a triggered subsystem with the desired control sample time sample time (ts = 0.005). This doc page provides useful information. Note that this process however would require you to create a custom state estimator instead of the built-in Kalman filter.
Hope this helps
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Controller Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!