- https://www.mathworks.com/matlabcentral/answers/108567-how-to-use-lqr-and-code-generation
- https://www.mathworks.com/matlabcentral/answers/508844-lqr-and-c2d-not-available-with-matlab-coder
State feedback in Simulink for code generation
7 views (last 30 days)
Show older comments
Is it possible to design state feedback matrices (either with pole placement or the LQR method) in Simulink, such that it supports code generation? The code will run in an embedded environment without access to the Matlab engine at runtime (so declaring functions as external is not an option). The calculations have to take place at regular intervals, so importing the result from a pre-run Matlab script also doesn't work. I have a general MIMO system, for which implementing this for myself seems a huge amount of work, which I'd like to avoid...
0 Comments
Answers (1)
Ashok
on 28 Oct 2024
Edited: Ashok
on 28 Oct 2024
The Control System Designer app is useful for designing single-input, single-output (SISO) controllers for feedback systems modeled in MATLAB or Simulink. Here's an example of designing an LQR controller using the app:
Currently, there's no direct way to generate code for the controller design procedures used by the app. For state-space control design, a list of MATLAB functions can be found here:
However, these functions do not support code generation, as they are not listed on this page, which lists the MATLAB functions that support code generation:
Additionally, the following MATLAB Answers also state that these functions do not support code generation. Staff have mentioned that internal requests have been made to enable this in future releases:
The only workaround mentioned is to write a custom Riccati equation solver. For linear time-invariant (LTI) systems, it's recommended to compute the gain matrix separately and use it directly in the model.
I hope this answers your query!
0 Comments
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!