PID Controller - non-adjustable parameters
30 views (last 30 days)
Show older comments
Hello,
I am using PI controller (original library name "PID Controller") component.
Customized, it looks like on the following picture:
Project requirements are that all the "parameters" are customizable, and changeable during the runtime.
Most of them, I succeeded to configure as "inputs", and that works.
Issue comes with certain parameters, which become hardcoded in the model, and therefore hardcoded also in the generated C code. These parameters are: Integrator saturation limits (Upper limit, Lower limit)
Is there a way to feed these parameters also externally? Or, is there a better common practice to handle these situations? Reason for doing so is the project maintenance. Different users could code their parameters in external memory regions, without need to reflash an MCU and touch the control-loop algorithms.
4 Comments
Aquatris
on 23 Oct 2024 at 12:24
Then my next question is there a specific reasong to set the integrator saturation level independently then the output saturation value?
The output saturation value already disables the integrator via clamping (as selected by the drop down menu). So unless you put an integrator saturation value that is lower than the output saturation value (which I cannot think of a solid reason), the integrator saturation value would not do anything.
More Answers (1)
Aravind
on 29 Oct 2024 at 5:07
It seems like you want to configure the saturation limits of the integrator externally during code generation. You can accomplish this by setting the storage class of the parameters representing the saturation limits to "ImportedExtern." This approach will make the generated code declare the parameter as a global variable using the "extern" keyword in C. You can then define the value of this variable in a separate header file, allowing users to adjust the parameters without altering the MCU firmware or control algorithms.
To change the storage class of a parameter in Simulink, you can follow these steps:
- Open your Simulink model, go to the "Modeling" tab, and click on "Model Explorer."
- In "Model Explorer," navigate to the "Base Workspace" or the specific model workspace. Find and select the parameter you want to modify.
- Double-click on the parameter to open its properties dialog. Locate the "Storage Class" field and select the needed storage class from the dropdown menu.
- Click "OK" or "Apply" to save the changes. Update your model by clicking the "Update Model" button or pressing Ctrl+D.
- Regenerate the code to ensure the changes are applied.
You can also use the "Code Mappings Editor" to achieve this. For more details, you can refer to the documentation here: https://www.mathworks.com/help/releases/R2024a/rtw/ref/codemappingseditorc.html.
Here are some additional resources to help you with choosing storage classes for parameters in your Simulink model:
- Choosing storage class for controlling data representation in generated code: https://www.mathworks.com/help/releases/R2024a/rtw/ug/choose-a-built-in-storage-class-for-controlling-data-representation-in-the-generated-code.html
- Configuring parameters for Code generation: https://www.mathworks.com/help/releases/R2024a/rtw/ug/configure-parameters-for-code-generation.html
- Different storage classes available for code generation: https://www.mathworks.com/help/releases/R2024a/ecoder/ug/storage-classes-for-code-generation-from-matlab-code.html
- An example on changing storage classes and their effect on the generated code: https://www.mathworks.com/help/releases/R2024a/rtw/ug/configure-model-data-for-c-code-generation.html
I hope this helps resolve your query!
0 Comments
See Also
Categories
Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!