How to Use Field Oriented Control Autotuner Block
You can use the Field Oriented Control Autotuner block to automatically tune the PI controllers in your closed-loop field-oriented control (FOC) structure against a machine modeled in Simulink® using Motor Control Blockset™. For instance, you can use the Motor Control Blockset to create an accurate motor model by collecting data directly from hardware and calculating the motor parameters. This parametric model is then used to estimate control gains for your PI controllers in field-oriented control applications. For more information, see Field-Oriented Control (FOC).
This workflow applies when you have an existing FOC structure for a motor with initial set of controllers such that the closed-loop system is stable and the motor model is running at a nominal operating point. Use the Field Oriented Control Autotuner block to automatically tune the existing controllers with specified bandwidths and phase margins.
This block requires Simulink Control Design™ software.
Field Oriented Control Autotuner Block
The block allows you to automatically tune the following control loops in your closed-loop FOC structure:
Direct-axis (d-axis) current loop
Quadrature-axis (q-axis) current loop
The block performs the closed-loop autotuning experiment on the d-axis current, q-axis current, speed, and flux control loops sequentially. During the experiment, for each loop, the block injects sinusoidal perturbation signals at the frequencies [1/10,1/3, 1, 3, 10]ωc, where ωc is your specified target bandwidth for tuning.
When the experiment ends, the block uses the estimated frequency response to compute PID gains. The tuning algorithm aims to balance performance and robustness while achieving the control bandwidth and phase margin that you specify. You can configure your system to automatically update the gains of your existing PID controllers, allowing you to validate closed-loop performance in the same simulation run that is used for tuning.
Connect Autotuner to Existing Model
The following figure shows a simplified block diagram of a field-oriented control structure for a PMSM. The simplified block diagram shows parameters in rotor reference frame and does not include an inverter, Park-Clarke transforms, or sensors. For a detailed model of field-oriented control of a PMSM, see Field-Oriented Control (FOC). For PMSM, there are three control loops in a field-oriented control structure: the direct-axis current control loop, quadrature-axis current control loop, and speed loop. There is no flux loop controller as the rotor flux is fixed and the d-axis current loop reference is typically set to zero. In some applications, you can provide a negative value for the d-axis current reference to implement field weakening control and achieve higher rotor speeds at the cost of a higher current.
In the Field Oriented Control Autotuner block parameters, disable the option Tune flux loop as the rotor flux is fixed with a permanent magnet for this type of AC motor.
To connect the Field Oriented Control Autotuner block and tune the PI controllers in your model, first identify the input and output parameters in your model. You can then connect the block as described below.
For tuning the d-axis current control loop:
Connect the control signal from
PI_daxisto the PIDout daxis input port.
Connect the perturbation daxis by using a sum block with the output of
PI_daxis, which is the d-axis voltage reference
Vd_ref, to modify the input to the plant.
Connect the d-axis current obtained from the measured (sensed or estimated) motor currents to the measured feedback daxis input port.
For tuning the q-axis current control loop:
Connect the control signal from
PI_qaxisto the PIDout qaxis input port.
Connect the perturbation qaxis by using a sum block with the output of
PI_qaxis, which is the q-axis voltage reference
Vq_ref, to modify the input to the plant.
Connect the q-axis current obtained from the measured (sensed or estimated) motor currents to the measured feedback qaxis input port.
For tuning the speed control loop:
Connect the control signal from
PI_speedto the PIDout speed input port.
Connect the perturbation speed by using a sum block with the output of
PI_speed, which is the q-axis current reference
Iq_ref, to modify the input to the plant.
Connect the measured (sensed or estimated) speed from the motor to the measured feedback speed input port.
The following model illustrates generally how the block fits into the FOC structure as shown in the previous block diagram.
During the autotuning process, the block injects perturbation signals at the plant inputs associated with each control loop and measures the responses at measured feedback for each loop. When the experiment ends, the block calculates PI gains and returns them at the pid gains port. When the experiment is not running, the block does not inject any perturbation signals. In this state, the block has no impact on plant or controller behavior.
Specify Controller Parameters and Tuning Goals
Connect the block inputs and outputs for the selected loops as described in the previous section. For each loop you are tuning, you can configure the following controller parameters:
Type – Specify the PID controller actions. If you are using a PI controller from the Motor Control Blockset library, set this parameter to
PIfor all the loops.
Form – Specify the controller form. If you are using a PI controller from the Motor Control Blockset library, set this parameter to
Controller sample time (sec) – Specify the controller sample time.
Integrator method – Specify the discrete integration formula for integrator term. If you are using a PI controller from Motor Control Blockset library, set this parameter to
Filter method – Specify the formula for the discrete derivative filter if your controller includes derivative action with a derivative filter term.
Then, for each loop, specify the target bandwidth and phase margin for tuning with the Target bandwidth (rad/sec) and Target phase margin (degrees) parameters, respectively.
The target bandwidth is the target value for the 0 dB gain crossover frequency of the tuned open-loop response CP, where P is the plant response for a given loop, and C is the controller response associated with that loop. This crossover frequency roughly sets the control bandwidth. For a desired rise time τ, a good guess for the target bandwidth is 2/τ. In order to have effective cascade control, the inner control loops (d-axis and q-axis) respond much faster than the outer control loops (flux and speed).
As a typical rule of thumb, you can set the bandwidth such that:
Current loop bandwidth is at least 10 times faster than the speed loop bandwidth.
Current loop bandwidth is at least 10 times slower than the switching frequency.
The target phase margin reflects your desired robustness for the tuned system. Typically, you can choose a value in the range of about 45°–60°. In general, a higher phase margin reduces overshoot, but can limit the response speed. The default value 60° tends to balance performance and robustness, yielding about 5–10% overshoot, depending on the characteristics of your plant.
To use the same tuning settings for inner control loops, enable Use same settings for current loop controllers (D-axis + Q-axis). Doing so allows you to specify the same controller parameters and tuning goals for the d-axis and q-axis current loops.
For more information about setting these parameters, see the Field Oriented Control Autotuner block reference page.
Set Experiment Parameters
In the block parameters, specify the start time and duration of the autotuning experiment for each loop. The block tunes only one controller at a time, so the start time and duration of the tuning experiment of one loop must not coincide or overlap with another loop. Tune the inner-loop controllers first, and then tune the outer-loop controllers. Consider the following when you specify the experiment start time and duration.
Start the experiment when the motor is at the desired steady-state operating point. Use the initial controller to drive the motor to the operating point.
Avoid any input or output disturbance on the motor during the experiment. If your existing closed-loop system has good disturbance rejection, then the experiment can handle small disturbances. Otherwise, large disturbances can distort the plant output and reduce the accuracy of the frequency-response estimation.
For each loop the block tunes, let the experiment run long enough for the algorithm to collect sufficient data for a good estimate at all frequencies it probes. A conservative estimate for the experiment duration is 200/ωc, where ωc is your target bandwidth for the loop being tuned.
Alternatively, you can configure your start/stop signal by enabling the parameter Use external source for start/stop of experiment.
Then specify the Loop Experiment Settings for each loop to be tuned. Plant Type specifies whether the plant associated with the individual loop is asymptotically stable or integrating. The Plant Sign parameter is positive if a positive change in the plant input at the desired operating point results in a positive change in the plant output. Otherwise, the plant sign is negative. For PMSM FOC tuning, Plant Type is asymptotically stable and Plant Sign is positive for all three loops.
The frequency-response estimation experiment injects a sinusoidal signal into the plant associated with each loop at the frequencies [1/10, 1/3, 1, 3, 10]ωc , where ωc is the target bandwidth for tuning. Use the Sine Amplitudes parameter of the Field Oriented Control Autotuner block to specify the amplitudes of these signals. You can either specify a scalar value to inject the same amplitude at each frequency or a vector of length 5 to specify a different amplitude at each of [1/10, 1/3, 1, 3, 10]ωc .
All the perturbation amplitudes must be:
Large enough that the perturbation overcomes any deadband in the plant actuator and generates a response above the noise level.
Small enough to keep the plant running within the approximately linear region near the nominal operating point, and to avoid saturating the plant input or output.
For more information about setting the experiment parameters, see the Field Oriented Control Autotuner block reference page.
Run Model and Initiate Tuning Experiment
After you have configured all the parameters for tuning, run the model.
If you have configured the start and duration of the experiment in block parameters, allow the simulation to run long enough to begin the experiment, by specifying a simulation length greater than the sum of the largest start time and duration. For instance, if your speed loop experiment start time is 5 seconds and the duration is 3 seconds, then your simulation length must be greater than 8 seconds.
If you have configured an external
start/stopsignal, begin the experiment when the plant has reached steady-state. For more information on how to configure an external start and stop signal, see the input arguments of Field Oriented Control Autotuner block.
Stop Experiment and Examine Tuned Gains
The frequency-response estimation experiment ends when the
start/stop signal registers a falling edge.
If you have configured the start and duration of the experiment in block parameters to begin and end the tuning process at specific times, allow the simulation to run through the end of the experiment.
If you have configured an external
start/stopsignal, end the experiment when the signal at the
convergenceoutput stabilizes near 100% for each loop.
In either case, a conservative estimate for the experiment time is 200/ωc, where ωc is your target bandwidth for the loop being tuned. For instance, if you have a target bandwidth of 5000 rad/sec for tuning the d-axis current controller, the duration of the tuning experiment for the d-axis current loop can be 0.04 seconds.
When you stop the experiment, the block computes new PI gains based on the estimated frequency response of the plant and your specified tuning goals associated with each loop the block tunes. There are several ways to see the tuned gains:
View the output of the
pid gainsport of the autotuner block. One way to view this output is to connect the output to a Simulink Display block.
In the block parameters, on the Block tab, click Export to MATLAB. The block creates a structure in the MATLAB® workspace,
FOCTuningResult. For more information about the contents of this structure, see the block reference page.
Update the PI Controllers with Tuned Gains and Validate the Performance
The Field Oriented Control Autotuner block does not write the gains automatically to your PI controllers. You can transfer the tuned gains to your controllers manually or with your own logic.
To manually update the PI gains, you can view the output of the
pid gainsport of the autotuner block.
pid gainsis a bus signal that contains tuned gains of PI controllers for each loop the block tunes. You can also click Export to MATLAB in the block parameters to get a structure
FOCTuningResultin your MATLAB workspace, which includes the tuned controller gains.
You also can configure your own logic to transfer the tuned PI gains. For instance, you can use signal routing blocks in Simulink to store, read, and write gains to the controllers.
If you are tuning PI Controller from the Motor Control Blockset library, the Field Oriented Control Autotuner block output contains tuned proportional and integral gains. Because the PI controller expects integral gain premultiplied by the controller sample time as input, instead of Ki, use Ki*TS when writing a new integral gain to the controller block.
After you transfer the tuned gains to your PI controllers, you can observe and validate the continued performance of your system with the new gains.