tune pi controllers using field oriented control autotuner -凯发k8网页登录
this example computes the gain values of pi controllers available in the speed and current control loops by using the field oriented control autotuner block. for details about this block, see field oriented control autotuner. for details about field-oriented control, see .
use the code-generation capability of the example to deploy the gain-tuning algorithm to the target hardware. this enables you to run the algorithm by using hardware connected to a motor and to compute accurate pi controller gains by processing motor feedback in real-time on the target hardware. the example uses a quadrature encoder sensor to measure the rotor position.
note: this example uses the field-oriented control algorithm as a reference. you can refer this example and use a similar approach to add the field oriented control autotuner block and the gain-tuning algorithm to the foc logic available in your model.
model
the example includes the target model .
you can use this model for both simulation and code generation. use the open_system command to open the model.
open_system('mcb_pmsm_foc_autotuner_f28379d.slx');
the field oriented control autotuner block iteratively tunes the d
- and q
-axis current control and speed control loops and computes the gains of the current and speed pi controllers. use this command to locate the field oriented control autotuner block available inside the model:
open_system('mcb_pmsm_foc_autotuner_f28379d/current control/control_system/closed loop control/foc_autotuner/foc_autotuner');
the block processes the current and speed feedback from the plant. it also processes the voltage output of the d
- and q
-axis current pi controllers to compute the pi controller gains (kp
and ki
).
for more details on the foc architecture, see .
required mathworks® products
to simulate model:
motor control blockset™
simulink control design™
stateflow® (needed only if you modify the example model)
to generate code and deploy model:
motor control blockset
simulink control design
embedded coder®
c2000™ microcontroller blockset
stateflow (needed only if you modify the example model)
prerequisites for simulation and hardware deployment
1. open the model initialization script for the target model. check and update the motor, inverter, and other control system and hardware parameters available in the script. for instructions on locating and editing the model initialization script associated with a target model, see estimate control gains and use utility functions.
2. in the inverter & target parameters section of the model initialization script, verify that the mcb_setinverterparameters
function uses the argument boostxl-drv8305
. this enables the script to use the preprogrammed parameters for the boostxl-drv8305 inverter.
3. configure these parameters correctly in the model initialization script. these variables are essential for the gain-tuning algorithm to compute the pi controller gains. if the values of these variables are incorrect, the model may fail to bring the motor to the steady speed state.
pmsm.p
pmsm.i_rated
pmsm.positionoffset
pmsm.qepslits
4. if you are using a motor that is not listed in the mcb_setpmsmmotorparameters
function (used in the system parameters // hardware parameters section of the model initialization script), tune the default values of the following initial gains available in the initial pi parameters section of the model initialization script. this ensures that the motor reaches the steady state of speed-control operation:
pi_params.kp_id
pi_params.ki_id
pi_params.kp_iq
pi_params.ki_iq
pi_params.kp_speed
pi_params.ki_speed
when you either simulate or run the example on a target hardware, the example uses crude values of the pi controller gains to achieve the steady state of speed-control operation.
note: when using this example, if the motor (whether it is listed or not in the mcb_setpmsmmotorparameters
function) does not run, try tuning the default values of these parameters.
5. in the foc autotuner parameters section of the model initialization script, check and update the parameters of the field oriented control autotuner block. this sets the reference bandwidth and phase margin values for both the speed and the current pi controllers.
simulate the target model
simulating the example is optional. follow these steps to simulate the target model:
1. open the target model.
2. click run on the simulation tab to simulate the target model.
3. observe the computed pi controller gain values in the display blocks available in the mcb_pmsm_foc_autotuner_f28379d/current control/pi_params_display_and_logging
subsystem.
the computed gains might not be accurate because step 3 in the prerequisites for simulation and hardware deployment section checks the accuracy of only four motor parameters.
if you want to compute and test the pi controller gains using simulation, follow these steps before clicking run on the simulation tab of the target model.
in the system parameters // hardware parameters section of the model initialization script, verify that the
mcb_setpmsmmotorparameters
function uses an argument that represents your motor (for example,teknic2310p
). open themcb_setpmsmmotorparameters
function to see the preprogrammed cases that store the motor parameters of commonly used pmsms.
if the mcb_setpmsmmotorparameters
function does not list your pmsm, determine the parameters for your motor using these steps:
if you have motor control hardware, you can estimate the parameters for your motor, by using the motor control blockset parameter estimation tool. for instructions, see estimate pmsm parameters using recommended hardware and estimate pmsm parameters using custom hardware.
the parameter estimation tool updates the motorparam
variable (in the matlab® workspace) with the estimated motor parameters.
if you obtain the motor parameters from the datasheet or other sources, add and configure the motor parameters in the model initialization script. these parameter values override the selected pre-programmed case in the function
mcb_setpmsmmotorparameters
.
if you use the parameter estimation tool, do not update the motor parameters directly in the model initialization script. the script automatically extracts the motor parameters from the updated motorparam
variable in the workspace.
after you simulate the target model and determine the gains, update your model (that implements foc) with the computed gain values to quickly bring the motor to a steady speed state.
deploy the example to the target hardware to tune the pi controller gains more accurately by using an actual hardware connected to a motor. for more details, see the generate code and deploy model to target hardware section.
generate code and deploy model to target hardware
this section shows how to generate code and run the algorithm for tuning the pi controller gains on the target hardware. running the example on the hardware enables you to compute the pi controller gains more accurately by processing the feedback from an actual plant in real-time.
this example uses a host and a target model. the host model is a user interface to the controller hardware board. you can run the host model on the host computer. before you run the host model on the host computer, deploy the target model to the controller hardware board. the host model uses serial communication to command the target model and run the motor in closed-loop control.
required hardware
the example supports the following hardware configuration. you can also use the target model name to open the model from the matlab® command prompt.
launchxl-f28379d controller boostxl-drv8305 inverter:
for more information on connections related to this hardware configuration, see launchxl-f28069m and launchxl-f28379d configurations.
generate code and run model on target hardware
1. complete the hardware connections.
2. the model automatically computes the analog to digital converter (adc) offset (also known as current offset). to disable this functionality (enabled by default), update the value of the inverter.adcoffsetcalibenable
variable in the model initialization script to 0
.
alternatively, you can compute the adc offset values and update them manually in the model initialization script. for instructions, see .
3. compute the quadrature encoder index offset value and update it in the pmsm.positionoffset
variable in the model initialization script of the target model. for instructions, see .
4. open the target model. if you want to change the default hardware configurations of the model, see .
5. load a sample program to the cpu2 of the launchxl-f28379d board. for example, load the program that operates the cpu2 blue led by using gpio31 (c28379d_cpu2_blink.slx
). this ensures that cpu2 is not mistakenly configured to use the board peripherals intended for cpu1.
6. click build, deploy & start on the hardware tab to deploy the target model to the hardware.
7. click the host model hyperlink in the target model to open the associated host model. you can also use the open_system
command to open the host model.
open_system('mcb_host_autotuner_f28379d.slx');
for details on serial communication between the host and target models, see .
8. in the model initialization script associated with the target model, specify the communication port using the variable target.comport. the example uses this variable to update the port parameter of the host serial setup, host serial receive, and host serial transmit blocks available in the host model.
9. turn the motor slider switch to the start position to start running the motor.
10. update the reference speed value in the speed ref [rpm] field. it is recommended that you use a value that is approximately half the rated speed of the motor.
11. in the debug signals section, select speed_ref & speed_feedback and monitor the speed signals in the selectedsignals time scope. wait until the motor reaches a steady speed.
the example can begin tuning only in the steady speed state.
12. check that the pi parameters slider switch is in the autotuner position.
13. turn the autotuner slider switch to the start position to start autotuning the pi controller gains. the tuning process introduces perturbations depending on the controller goals (bandwidth and phase margin) in the controller output. the example uses the system response to the perturbations to calculate the optimal controller gain values.
the model performs these tests iteratively on the motor and determines an accurate set of kp
and ki
gains for the current and speed pi controllers.
the tuning status display changes status from tuning not started
to tuning in progress
.
note: when tuning is in progress, ensure that the pi parameters slider switch remains in the autotuner position.
14. when the tuning process successfully completes, the tuning status display changes status from tuning in progress
to tuning complete
.
the target model updates the speed and current pi controllers running on the target hardware with the computed kp
and ki
gains. in addition, the host model displays these values.
15. if the gain-tuning algorithm encounters an error during the tuning process, the tuning status display shows tuning failed
. turn the autotuner slider switch to the stop position and see the troubleshooting section for the troubleshooting instructions.
16. if you have successfully completed the tuning process, turn the autotuner slider switch to the stop position.
17. validate the computed gain values. for instructions, see the validate computed pi controller gains section.
validate computed pi controller gains
1. check that the motor is running and that the pi parameters slider switch is in the autotuner position.
2. select the speed_ref & speed_feedback debug signal in the debug signals section of the host model.
3. open the selectedsignals time scope to monitor the reference speed and speed feedback signals.
4. update the reference speed (for your motor control application) in the speed ref [rpm] field and monitor the signals in the time scope.
5. in the selectedsignals window, navigate to tools > measurements and select cursor measurements to display the cursor measurements area.
6. drag cursor-1 to a position that indicates zero speed_ref
(just before speed_ref rises). drag cursor-2 to a position where speed_feedback
meets speed_ref
for the first time.
δt indicates the actual response time of the foc algorithm (time taken by the motor to reach 100% of the reference speed from zero reference speed).
7. for the speed pi controller, use the pi_params.speedbw
variable available in the model initialization script to determine the bandwidth of the speed pi controller. compute the theoretical response time using this relation:
compare the theoretical response_time
with the actual response time δt to validate the speed pi controller gains.
similarly, you can validate the current pi controller gains by analyzing the step responses of the d
and q
current pi controllers.
troubleshooting
follow these steps to troubleshoot failed gain-tuning instances.
1. identify the loop (either d
current, q
current, or speed) for which the tuning process failed.
the target model tunes the pi controllers in this sequence:
d
current controller → q
current controller → speed controller
tuning failure of one controller in this sequence results in incorrect gain-tuning for the subsequent controllers.
check the computed gains for the three controllers using the display blocks available in the host model. a zero kp
or ki
controller gain value indicates that the tuning process failed for the respective controller.
follow the subsequent steps for the first pi controller in the preceding sequence for which the tuning failed.
2. select the controller reference and feedback signals for the controller identified in step 1, in the debug signals section (for example, iq_ref & iq_feedback for the q
current controller) and open the selectedsignals time scope.
3. check that the pi parameters slider switch is in the autotuner position.
4. turn the autotuner slider switch to the start position to run the tuning process again.
5. monitor the feedback signal for the controller identified in step 1 (for example, iq_feedback
) in the selectedsignals time scope.
case 1: follow these steps if the peak value of the controller feedback signal satisfies one of these conditions:
value is too high (greater than 1)
value is too low (less than
pi_params.currentsineamp
for the current controllers or less thanpi_params.speedsineamp
for the speed controller)
note: the pi_params.currentsineamp
and pi_params.speedsineamp
variables are defined in the model initialization script.
a. if the controller identified in step 1 is the d
or the q
current controller, modify the pi_params.currentsineamp
variable such that it is less than the peak value of the controller feedback signal.
b. if the controller identified in step 1 is the speed controller, modify the pi_params.speedsineamp
variable such that it is less than the peak value of the controller feedback signal.
c. turn the autotuner slider switch to the stop position and then to the start position to run the tuning process again.
case 2: follow these steps if the peak value of the controller feedback signal lies in the range:
(for the current controllers)
(for the speed controller)
note: the pi_params.currentsineamp
and pi_params.speedsineamp
variables are defined in the model initialization script.
a. update the parameters of the field oriented control autotuner block (that set the reference bandwidth and phase margin values) available in the foc autotuner parameters section of the model initialization script.
b. turn the autotuner slider switch to the stop position and then to the start position to run the tuning process again.