Main Content

Generate Current Controller Parameters

Using the Model-Based Calibration Toolbox™, you can generate optimized current tables for flux-based motor controllers. Use the calibration tables for the Powertrain Blockset™ Flux-Based PM Controller current controller block parameters.

Based on nonlinear motor flux data, the calibration tables optimize:

  • Motor efficiency

  • Maximum torque per ampere (MTPA)

  • Flux weakening

To generate optimized current tables, follow these workflow steps.

Workflow StepsDescriptionMathWorks® Tooling

Collect and Post Process Motor Data

Collect the nonlinear motor flux data from dynamometer testing or finite element analysis (FEA). For this example, file PMSMEfficiencyData.xlsx contains the data that you need:

  • Total flux, Ψtotal, in Wb

  • Allowed flux, Ψmax, in Wb

  • d-axis flux, Ψd, in Wb

  • q-axis flux, Ψq, in Wb

  • d-axis current, Id, in A

  • q-axis current, Iq, in A

  • Current magnitude, Is, in A

  • Motor torque, Te, in N·m

  • Motor speed, n, in rpm

N/A

Model Motor Data

Use a one-stage model to fit the data. Specifically:

  • Import data

  • Filter data

  • Fit model

Model-Based Calibration Toolbox

Generate Calibration

Calibrate and optimize the data using objectives and constraints. Specifically:

  • Create functions.

  • Create tables from model.

  • Run an optimization.

  • Generate and fill optimized current controller calibration tables that are functions of motor torque and motor speed.

Model-Based Calibration Toolbox

Set Block Parameters

Use the optimized current controller calibration tables for the Flux-Based PM Controller block current controller parameters.

Powertrain Blockset

Collect and Post Process Motor Data

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

  • d- and q- axis current

  • d- and q- axis flux linkage

  • Electromagnetic motor torque

Use the collected data and motor speed to calculate the total flux, maximum flux, and current magnitude:

ψtotal=ψd2+ψq2is=id2+iq2n=60ωe2πPψmax=Vdc3ωe

The equations use these variables:

id, iq

d- and q- axis current, respectively

is,Current magnitude
Ψd, Ψq

d- and q- axis flux linkage, respectively

Ψtotal, ΨmaxTotal and allowed flux, respectively
ωe

Electrical motor angular speed, rad/s

n

Motor speed, rpm

Vdc

Inverter bus voltage

P

Number of pole pairs

Finally, for each data point, create a file containing:

  • Total flux, Ψtotal, in Wb

  • Allowed flux, Ψmax, in Wb

  • d-axis flux, Ψd, in Wb

  • q-axis flux, Ψq, in Wb

  • d-axis current, Id, in A

  • q-axis current, Iq, in A

  • Current magnitude, Is, in A

  • Motor torque, Te, in N·m

  • Motor speed, n, in rpm

For this example:

  • Pole pairs, P, is 4

  • Inverter bus voltage, Vdc, is 500

the data file matlab\toolbox\mbc\mbctraining\PMSMEfficiencyData.xlsx contains the motor flux data.

Model Motor Data

To model the motor data, use the MBC Model Fitting app to import, filter, and fit the data with a point-by-point model. For this example, the data file PMSMEfficiencyData.xlsx contains a large data set. You could consider using a design of experiment (DOE) to limit the data. However, the data set represents typical FEA analysis results.

Since there is a simple relationship between the d- and q-axis currents for fixed torque-speed operating points, the point-by-point model provides an accurate fit.

For comparison, the PMSM maximum efficiency calibration case study contains the model fit.

Import Data

For this example, PMSMEfficiencyData.xlsx contains this motor controller data:

  • Total flux, Ψtotal, in Wb

  • Allowed flux, Ψmax, in Wb

  • d-axis flux, Ψd, in Wb

  • q-axis flux, Ψq, in Wb

  • d-axis current, Id, in A

  • q-axis current, Iq, in A

  • Current magnitude, Is, in A

  • Motor torque, Te, in N·m

  • Motor speed, n, in rpm

  1. In MATLAB®, on the Apps tab, in the Automotive group, click MBC Model Fitting.

  2. In the Model Browser home page, click Import Data. Click OK to open a data source file.

  3. Navigate to the matlab\toolbox\mbc\mbctraining folder. Open data file PMSMEfficiencyData.xlsx. The Data Editor opens with your data.

Filter Data

You can filter data to exclude records from the model fit. In this example, set up a filter to include only flux and current magnitudes that are less than a specified threshold. Specifically:

  • Current magnitude, Is, less than or equal to 300 A.

  • Total flux, Ψtotal, less than or equal to allowed flux Ψmax

  1. In the Data Editor, select Tools > Filters to open the Filter Editor. Create these filters:

    • Is <= 300

    • Flux <= Flux_allowed

Define Test Groupings

For point-by-point models, you need to define test groups. In the example, define groups for motor torque and speed. Set the tolerances to so that Model-Based Calibration Toolbox groups small variations in torque and speed at the same operating point.

  1. In the Data Editor, select Tools > Test Groups to open the Define Test Groupings dialog box. Create groups for the motor torque and speed.

  2. Set these tolerances:

    • Motor torque, Trq, to 1.000

    • Motor speed, n, to 10.000

  3. In the Data Editor, select File > Save & Close. Accept the changes to the data.

Fit Model

Fit the data to a point-by-point model with these responses, local inputs, and operating points:

  • Responses

    • q-axis current, Iq, in A

  • Local inputs

    • d-axis current, Id, in A

  • Operating points

    • Motor speed, n, in rpm

    • Electromagnetic motor torque, Te, in N·m

  1. In the Model Browser, select Fit Models.

  2. In Fit Models, configure a Point-by-Point model with these responses and inputs.

    ResponsesLocal InputsOperating Points

    Iq

    Id

    Trq

    n

  3. To fit the model, select OK. If prompted, accept changes to data. By default, the fit uses a Gaussian Process Model (GPM) to fit the data.

  4. After the fit completes, examine the response models for Iq. The Model Browser displays information that you can use to determine the accuracy of the model fit.

    • In the Model Browser, select Iq. Examine the response surface and diagnostic statistics. These results indicate a reasonably accurate fit. You can browse through each test to examine the response for each torque-speed operating point.

  5. Save your project. For example, select Files > Save Project. Save gs_example.mat to the work folder.

Generate Calibration

After you fit the model, create functions and tables, run the optimization, and fill the calibration tables.

For comparison, the PMSM maximum efficiency calibration case study contains the calibration results.

Import Models and Create Functions

Import models and create the functions to use when you optimize the calibration. In this example, set up functions for:

  • Current magnitude, Is

  • Torque per amp, TPA

  1. In MATLAB, on the Apps tab, in the Automotive group, click MBC Optimization.

  2. In the Cage Browser, select Models. If it is not already opened, in the MBC Model Fitting browser, open the gs_example.mat project.

  3. In Import Models, click OK. Close the CAGE Import Tool.

  4. In the Cage Browser toolbar, use New Function Model wizard to create these functions:

    • Is = sqrt(Id^2 + Iq^2)

    • TPA = Trq/Is

  5. In the Cage Browser, verify that the function models for Is and TPA have these descriptions.

  6. Select File > Save Project. Save gs_example.cag to the work folder.

Create Lookup Tables from Model

Create tables that the Model-Based Calibration Toolbox optimizers uses to store the optimized parameters. For this example, the tables are:

  • d-axis current, Id, as a function of motor torque, Trq, and motor speed, n.

  • q-axis current, Iq, as a function of motor torque, Trq, and motor speed, n.

  1. In the Cage Browser, select Lookup Tables and Tradeoff. In Create Lookup Tables from Model, select Iq. Click Next.

  2. In the Create Lookup Tables from Model wizard:

    • Clear Use model operating points.

    • Set Table rows to 31.

    • Set Table columns to 29.

    • Click Next.

  3. In Create Lookup Tables from Model:

    • Select Id and Iq.

    • Click Finish.

  4. In the CAGE Browser, examine the tables.

Run Optimization

In this example, run an optimization with these specifications:

  • Current magnitude, Is, less than or equal to 300 A.

  • Maximizes torque per ampere, TPA.

  1. On the Cage Browser home, select Optimization.

  2. In Create Optimization from Model, select TPA and Next.

  3. In Create Optimization from Model:

    • Select Id.

    • Set Objective type to Maximize.

    • Click Finish.

  4. Add the optimization constraint for the current magnitude, Is. In the CAGE Browser, select Optimization > Constraints > Add Constraints to open Edit Constraint. Use the dialog box to create a constraint on the current.

    • Is <= 300

  5. In the Cage Browser, carefully verify the Objectives and Constraints.

  6. In the Cage Browser, select Run.

    The optimization results are similar to these.

Fill Lookup Tables

  1. In the CAGE Browser, select Fill Lookup Tables.

  2. Use the Lookup Table Filling from Optimization Results Wizard to fill the Id_Table and Iq_Table tables.

    • For the Id_Table, fill with Id.

    • For the Iq_Table, fill with Iq.

    Click Next. For the Fill Method, select Clip Fill (column-based).

    Click Finish.

  3. Review results for Iq_Table. The results are similar to these.

  4. Review results for Id_Table. The results are similar to these.

  5. Select File > Save Project. Save gs_example.cag to work folder.

Export Results

  1. Select File > Export > Calibration.

  2. Use Export Calibration Data to select the items to export and format. For example, export the Id and Iq tables and breakpoints to MATLAB file gs_example.m.

Set Block Parameters

The optimized current controller calibration tables are functions of motor torque and motor speed. Use the tables for these Flux-Based PM Controller block parameters:

  • Corresponding d-axis current reference, id_ref

  • Corresponding q-axis current reference, iq_ref

  • Vector of speed breakpoints, wbp

  • Vector of torque breakpoints, tbp

To set the block parameters:

  1. Run the .m file that contains the Model-Based Calibration Toolbox calibration results for the current controller. For example, in the MATLAB command line, run gs_example.m:

    % Access data from MBC current controller calibration
    gs_example

  2. Assign the breakpoint parameters to the data contained in the .m file. In this example, the speed data is in rpm. To use the calibration data for the block parameters, convert the speed breakpoints from rpm to rad/s.

    ParameterMATLAB Commands
    Vector of speed breakpoints, wbp
    tbp=Trq_norm.X;
    Vector of speed breakpoints, wbp
    % MBC data for speed is in rpm.  
    % For the block parameter, use rad/s
    nbp=n_norm.X;
    conversion=(2*pi/60.);
    wbp=conversion.*nbp;
    Corresponding d-axis current reference, id_ref
    id_table=Id_Table.Z;
    id_ref=id_table';
    Corresponding q-axis current reference, iq_ref
    iq_table=Iq_Table.Z;
    iq_ref=iq_table';