I am looking for a tool or Simulink project that is already complete where I can enter my motor parameters (and possibly inverter) and do some testing with PID tuning in the case of Field Oriented Control.
I found this: https://it.mathworks.com/help/mcb/gs/tune-pi-controllers-using-foc-autotuner.html?s_eid=PSM_15028 but I don't understand if I can use it only via software without having to buy that motor and inveter.
Again, I am interested in doing PID tuning tests for my motor in the case of FOC, nothing more.
There is a lot of Simulink material online, so I ask for your help since I have little experience with Matlab
Thank you.

 Accepted Answer

Shivam Gothi
Shivam Gothi on 29 Jan 2025

1 vote

I analysed both the models as attached by you in the comments. I found the following differences:
  • Model1 uses gain scheduling mechanism to change the gains of PI controller, as the speed varies from zero to its rated vaue. Model2 uses constant gain PI controllers
  • Model1 is meant only for simulation purposes. You cannot deploy it on embedded targets. Whereas, model2 has simulink/codegen variant blocks that are capable of generating code to be deployed on embedded targets.
  • In Model2, a sensorless observer is employed to estimate the rotor's position, eliminating the need for an encoder. Conversely, Model1 takes a different approach: the "motor position" output from the "Surface Mount PMSM" block is initially converted into Quadrature Encoder Pulse (QEP) signals, which are then used to estimate both speed and position.
From what I understand, you've developed your own controllers and are looking to evaluate their performance using a Simulink model. You plan to adjust the controller parameters to observe how these changes affect the output. Your goal is to fine-tune the parameters until the desired response is achieved.
Please correct me if I understood it incorrectly.
Based on the above understanding, I can suggest the following:
For you purpose, It is better to go with Model1, as you want only the simulation model. But, you can remove the gain scheduling algorithm and replace them with constant gains (which you have calculated for your controller). This will help you to test the performance of the PI controller designed by you.
I hope it helps !

6 Comments

Perfect! Thank you.
I'll take the opportunity to ask you one more general thing about the model.
Where do I find these parameters? (I want to change them)
When you run the model, you will see that some variables are loaded into the base workspace. These are loaded from the .MAT file attached with the example (scd_fre_mcb_double.mat).
When you run the model, the following line of code automatically gets executed:
load('scd_fre_mcb_double.mat');
This is coded inside the "InitFcn" callbacks found inside Model properties.
You can directly change the value of parameters from the base workspace. For example, if you want to change resistance to 10 ohms, simply type the following in the command window:
pmsm.Rs=10;
Note: please save the modified workspace data with the same name (scd_fre_mcb_double.mat) in the same directory. Because, each time you run the model, it will load parameters from (scd_fre_mcb_double.mat) file. Therefore it is necessary to save the changes you made in the parameters.
I hope it helps!
Thank you for the clear and comprehensive answer.
When you say "remove the gain scheduling algorithm and replace them with constant gains" do you mean to remove the whole green PID block and replace it with a classic PID block ??
Also, since I have to make changes to the simulink, I would like to avoid the original project files (located in C:\Users\lucad\Documents\MATLAB\Examples\R2023b\slcontrol\TuneGainScheduledControllerForPMSMUsingPIDAutotunerExample).
So I copied all the files inside that folder to a new folder on the desktop and renamed inside the project what needed to be renamed, resolving the errors Matlab was giving (still pointing to the original directory):
Here the actual error:
I'm afraid it means I can't copy/rename a project ... so I have to necessarily edit the original (?)
Yes ! You interpreted the below statement correctly.
"remove the gain scheduling algorithm and replace them with constant gains":
The procedure followed by you is correct. Actually, I will recommend you to copy the entire folder "slcontrol" at the below given location instead of placing it at desktop.
C:\Users\lucad\Documents\MATLAB\Examples
Note one important point:
Change the current working directory of MATLAB to the path: C:\Users\lucad\Documents\MATLAB\Examples\slcontrol\TuneGainScheduledControllerForPMSMUsingPIDAutotunerExample
In this way, your original model will be at :
C:\Users\lucad\Documents\MATLAB\Examples\R2023b\slcontrol
and the modified model will be at:
C:\Users\lucad\Documents\MATLAB\Examples
IMPORTANT: Make sure to set the current working directory in MATLAB to the folder containing the project you wish to work on.
For an example, if you want to run the original model, change the current working directory of MATLAB to:
C:\Users\lucad\Documents\MATLAB\Examples\R2023b\slcontrol\TuneGainScheduledControllerForPMSMUsingPIDAutotunerExample
if you want to work at your own model, change the current working directory of MATLAB to:
C:\Users\lucad\Documents\MATLAB\Examples\slcontrol\TuneGainScheduledControllerForPMSMUsingPIDAutotunerExample
Feel free to reply back if you face any difficulty in following this approach !

Sign in to comment.

More Answers (1)

Shivam Gothi
Shivam Gothi on 29 Jan 2025

0 votes

The model referred by you is for online tuning of motor control parameters. It requires actual motor and inverter setup. As per my understanding, you want a Simulation model for field oriented control of PMSM motor, so that you can simulate the performance of the controllers designed by you, by changing motor or inverter parameters.
In this case, I will recommend the below given shipped examples from motor control blockset:
These model are build using the simulation and codegen variants blocks. That is, the same model can be used to generate the code and deploy on hardware and it can also be used for simulating the plant without involving any hardware.
To run the model in simulation (without the hardware), just press "Run button" as shown below:
You can change the motor and inverter parameters from the MATLAB script, located in the same folder where the simulink model is found. Using that script, you can also replace the default controller parameters with your own designed parameters and simulate its performance.
I hope this answers the question !

3 Comments

Thanks for the detailed answer!
I take this opportunity to ask you one more thing:
What is the difference between what you sent me and this one ?? .. which one do you recommend given my request? (in the main post)
Another thing, I don't want the simulink to generate embeeded code, I just want a PID simulation depending on the engine etc..
In the examples you sent me it is always required to microrpocessor TI etc.
The examples I suggested do not require microprocessor to run. You can run them as a normal simulation, without any microcontroller/launchpad.
That's why I noted that the Simulink model is using Codegen/simulink variant blocks. It allows you to run standard simulations while also providing the option to generate code if needed.
The microcontroller is not mandatory to run the simulation

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!