Main Content

Tune Field-Oriented Controllers for a PMSM Using Closed-Loop PID Autotuner Block

This example shows how to tune a field-oriented controller for a PMSM-based electrical-traction drive in just one simulation using the Closed-Loop PID Autotuner block.

Field-Oriented Control

In this example, a field-oriented controller for a permanent magnet synchronous machine (PMSM) based electrical-traction drive is modeled in Simulink® using Simscape™ Electrical™ components. The model is based on the Simscape example Three-Phase PMSM Traction Drive (Simscape Electrical).

mdl = 'scdfocpmsmPIDTuning';
open_system(mdl)

Field-oriented control (FOC) controls three-phase stator currents as a vector. FOC is based on projections, which transform a three-phase time- and speed-dependent system into a two-coordinate time-invariant system. These transformations are the Clarke Transformation, Park Transformation, and their respective inverse transforms. These transformations are implemented as blocks within the PMSM controller subsystem.

The advantages of using FOC to control AC motors include:

  • Torque and flux controlled directly and separately

  • Accurate transient and steady-state management

  • Similar performance compared to DC motors

The PMSM controller subsystem contains all three PI controllers. The outer-loop PI controller regulates the speed of the motor. The two inner-loop PI controllers control the d-axis and q-axis currents separately. The command from the outer-loop PI controller directly feeds to the q-axis to control torque. The command for the d-axis is zero for PMSM because the rotor flux is fixed with a permanent magnet for this type of AC motor.

The existing PI controllers have the following gains:

  • Speed PI controller has gains of P = 20 and I = 500.

  • D-axis PI controller has gains of P = 0.8779 and I = 710.3.

  • Q-axis PI controller has gains of P = 1.0744 and I = 1061.5.

The controller gains are stored in a Data Store Memory block and provided externally to each PID block. When the tuning process for a controller is complete, the new tuned gains are written to the Data Store Memory block. This configuration allows you to update your controller gains in real-time during the simulation.

Closed-Loop PID Autotuner Block

The Closed-Loop PID Autotuner block allows you to tune one PID controller at a time. It injects sinusoidal perturbation signals at the plant input and measures the plant output during a closed-loop experiment. When the experiment stops, the block computes PID gains based on the plant frequency responses estimated at a small number of points near the desired bandwidth. For this PMSM-based electrical-traction drive model, the Closed-Loop PID Autotuner block can be used for each of the three PI controllers.

This workflow applies when you have initial controllers that you want to retune using the Closed-Loop PID Autotuner block. The benefits of this approach are:

  1. If there is an unexpected disturbance during the experiment, it will be rejected by the existing controllers to ensure safe operation.

  2. The existing controllers will keep the plant running near its nominal operating point by suppressing the perturbation signals.

When using the Closed-Loop PID Autotuner block for both simulations and real-time applications:

  • The plant must be either asymptotically stable (all the poles are strictly stable) or integrating. The autotuner block does not work with an unstable plant.

  • The feedback loop with the existing controller must be stable.

  • To estimate plant frequency responses more accurately in real time, minimize the occurrence of any disturbance in the PMSM based electrical-traction drive model during the experiment. The autotuner block expects the plant output to be the response to the injected perturbation signals only.

  • Because the feedback loop is closed during the experiment, the existing controller suppresses the injected perturbation signals as well. The advantage of using closed-loop experiment is that the controller keeps the plant running near the nominal operating point and maintains safe operation. The disadvantage is that it reduces the accuracy of frequency response estimation if your target bandwidth is far away from the current bandwidth.

Connect Autotuner with Plant and Controller

Insert the Closed-Loop PID Autotuner block between the PID block and the plant for all three PI controllers, as shown in the PMSM-based electrical-traction drive model. The start/stop signal starts and stops the closed-loop experiment. When no experiment is running, the Closed-Loop PID Autotuner block behaves like a unity gain block, where the $u$ signal directly passes to $u + \Delta u$.

To view the modified outer-loop control structure, open the Outer loop control subsystem in the PMSM controller subsystem.

controlSubsystem = [mdl '/PMSM controller'];
open_system([controlSubsystem '/Outer loop control'])

View the modified current controllers in the Inner loop control subsystem.

open_system([controlSubsystem '/Inner loop control'])

Configure Autotuner Block

After connecting the Closed-Loop PID Autotuner block with the plant model and PID block, configure the tuning and experiment settings.

On the Tuning tab, there are two main tuning settings:

  • Target bandwidth - Determines how fast you want the controller to respond. In this example, choose 300 rad/s for speed control, 2500 rad/s for d-axis current control and 2200 rad/s for q-axis current control.

  • Target phase margin - Determines how robust you want the controller to be. In this example, choose 60 degrees for inner-loop current control and 70 degrees for outer-loop control.

On the Experiment tab, there are three main experiment settings:

  • Plant Type - Specifies whether the plant is asymptotically stable or integrating. In this example, the PMSM-based electrical-traction drive model is stable.

  • Plant Sign - Specifies whether the plant has a positive or negative sign. The plant sign is positive if a positive change in the plant input at the nominal operating point results in a positive change in the plant output when the plant reaches a new steady state. Otherwise, the plant sign is negative. If a plant is stable, the plant sign is equivalent to the sign of its dc gain. If a plant is integrating, the plant sign is positive (or negative) if the plant output keeps increasing (or decreasing). In this example, the PMSM-based electrical-traction drive model has a positive plant sign.

  • Sine Amplitudes - Specifies the amplitudes of the injected sine waves. In this example, choose 5 for the inner-loop controllers and 5 for the outer-loop controller to ensure the plant is properly excited within the saturation limit. If the excitation amplitude is either too large or too small, it will produce inaccurate frequency response estimation results.

Tuning Cascaded Feedback Loops

Because the Closed-Loop PID Autotuner block only tunes one PI controller at a time, the three controllers must be tuned separately in the PMSM-based electrical-traction drive model. Tune the inner-loop controllers first, and then tune the outer-loop controller.

  • The d-axis current controller is tuned between 1.0 and 1.2 sec.

  • The q-axis current controller is tuned between 1.3 and 1.5 sec.

  • The speed controller is tuned between 1.8 and 2.6 sec.

After tuning each PI controller, the controller gains are updated through the Data Store Memory block.

Simulating Autotuner Block in Normal Mode

In this example, the PMSM-based electrical-traction drive model is built in Simulink. All three PI controllers are tuned in one simulation. In addition, speed responses are compared before and after tuning the controllers during acceleration processes.

Simulation of the PMSM-based electrical-traction drive model usually takes a few minutes on your computer due to the small sample time of the power electronics controller of the motor.

sim(mdl);
save('AutotunedSpeed','SpeedData');

During the autotuning process from 1.0 to 2.6 seconds, the changes in current and in motor speed are very small. The motor speed reaches the nominal 1000 rpm before the autotuning process begins.

The three PI controllers are tuned with new gains.

  • The d-axis PI controller has gains of P = 0.6332 and I = 331.7.

  • The q-axis PI controller has gains of P = 0.937 and I = 351.1.

  • The speed PI controller has gains of P = 32.35 and I = 1322.

The same rotor speed reference is applied before and after the autotuning process. Plot the rotor speed responses with respect to the nominal 1000 rpm before and after tuning the controllers. The speed response curves are aligned in time to compare controller performances side-by-side.

scdfocpmsmPIDTuningPlotSpeed

After tuning the controllers, the speed response of the PMSM has a faster transient response during acceleration.

bdclose(mdl)

See Also

Related Topics