## Generate Parameters for Flux-Based PMSM Block

Using MathWorks tools, you can create lookup tables for an interior permanent magnet synchronous motor (PMSM) controller that characterizes the d-axis and q-axis current as a function of d-axis and q-axis flux.

To generate the flux parameters for the Flux-Based PMSM block, follow these workflow steps. Example script CreatingIdqTable.m calls gridfit to model the current surface using scattered or semi-scattered flux data.

WorkflowDescription

Step 1: Load and Preprocess Data

Load and preprocess this nonlinear motor flux data from dynamometer testing or finite element analysis (FEA):

• d- and q- axis current

• d- and q- axis flux

• Electromagnetic motor torque

Step 2: Generate Evenly Spaced Table Data From Scattered Data

Use the gridfit function to generate evenly spaced data. Visualize the flux surface plots.

Step 3: Set Block Parameters

Set workspace variables that you can use for the Flux-Based PM Controller block parameters.

### Step 1: Load and Preprocess Data

Load and preprocess this nonlinear motor flux data from dynamometer testing or finite element analysis (FEA):

• d- and q- axis current

• d- and q- axis flux

• Electromagnetic motor torque

1. Open the example script CreatingIdqTable.m.

2. Load and preprocess the data.

% Load the data from a |mat| file captured from a dynamometer or % another CAE tool. load FEAdata.mat; 

3. Determine the minimum and maximum flux values.

flux_d_min = min(min(FEAdata.flux.d)) ; flux_d_max = max(max(FEAdata.flux.d)) ; flux_q_min = min(min(FEAdata.flux.q)) ; flux_q_max = max(max(FEAdata.flux.q)) ;

4. Plot the sweeping current points used to collect the data.

for i = 1:length(FEAdata.current.d) for j = 1:1:length(FEAdata.current.q) plot(FEAdata.current.d(i),FEAdata.current.q(j),'b*'); hold on end end

5. Plot the current limit sweeping points and circle.

for angle_theta = pi/2:(pi/2/200):(3*pi/2) plot(300*cos(angle_theta),300*sin(angle_theta),'r.'); hold on end xlabel('I_d [A]') ylabel('I_q [A]') title('Sweeping Points'); grid on; xlim([-300,0]); ylim([-300,300]); hold off ### Step 2: Generate Evenly Spaced Table Data From Scattered Data

The flux tables and can have different step sizes for the currents. Evenly spacing the rows and columns helps improve interpolation accuracy. This script uses spline interpolation.

1. Set the spacing for the table rows and columns.

% Set the spacing for the table rows and columns flux_d_size = 50; flux_q_size = 50;

2. Generate linear spaced vectors for the breakpoints.

% Generate linear spaced vectors for the breakpoints ParamFluxDIndex = linspace(flux_d_min,flux_d_max,flux_d_size); ParamFluxQIndex = linspace(flux_q_min,flux_q_max,flux_q_size);

3. Create 2-D grid coordinates based on the d-axis and q-axis currents.

% Create 2-D grid coordinates based on the d-axis and q-axis currents [id_m,iq_m] = meshgrid(FEAdata.current.d,FEAdata.current.q);

4. Create the table for the d-axis current.

% Create the table for the d-axis current id_fit = gridfit(FEAdata.flux.d,FEAdata.flux.q,id_m,ParamFluxDIndex,ParamFluxQIndex); ParamIdLookupTable = id_fit'; figure; surf(ParamFluxDIndex,ParamFluxQIndex,ParamIdLookupTable'); xlabel('\lambda_d [v.s]');ylabel('\lambda_q [v.s]');zlabel('id [A]');title('id Table'); grid on; shading flat;

d-axis current, Id, as a function of q-axis flux, λq, and d-axis flux, λd. 5. Create the table for the q-axis current.

% Create the table for the q-axis current iq_fit = gridfit(FEAdata.flux.d,FEAdata.flux.q,iq_m,ParamFluxDIndex,ParamFluxQIndex); ParamIqLookupTable = iq_fit'; figure; surf(ParamFluxDIndex,ParamFluxQIndex,ParamIqLookupTable'); xlabel('\lambda_d [v.s]');ylabel('\lambda_q [v.s]');zlabel('iq [A]'); title('iq Table'); grid on; shading flat;

q-axis current, Iq, as a function of q-axis flux, λq, and d-axis flux, λd. ### Step 3: Set Block Parameters

Set the block parameters to these values assigned in the example script.

ParameterMATLAB® Commands

Vector of d-axis flux, flux_d

flux_d=ParamFluxDIndex;

Vector of q-axis flux, flux_q

flux_q=ParamFluxQIndex;
Corresponding d-axis current, id
id=ParamIdLookupTable;

Corresponding q-axis current, iq

iq=ParamIqLookupTable;

 Hu, Dakai, Yazan Alsmadi, and Longya Xu. “High fidelity nonlinear IPM modeling based on measured stator winding flux linkage.” IEEE® Transactions on Industry Applications, Vol. 51, No. 4, July/August 2015.

 Chen, Xiao, Jiabin Wang, Bhaskar Sen, Panagiotis Lasari, Tianfu Sun. “A High-Fidelity and Computationally Efficient Model for Interior Permanent-Magnet Machines Considering the Magnetic Saturation, Spatial Harmonics, and Iron Loss Effect.” IEEE Transactions on Industrial Electronics, Vol. 62, No. 7, July 2015.

 Ottosson, J., M. Alakula. “A compact field weakening controller implementation.” International Symposium on Power Electronics, Electrical Drives, Automation and Motion, July, 2006.