estimate control gains and use utility functions
perform control parameter tuning for the speed and the torque control loops that are part of the field-oriented control (foc) algorithm. motor control blockset™ provides you with multiple methods to compute the control loop gains from the system or block transfer functions that are available for the motors, inverter, and controller:
use the field oriented control autotuner block.
use simulink® control design™.
use the model initialization script.
field-oriented control autotuner
the field-oriented control autotuner block of motor control blockset enables you to automatically tune the pid control loops in your field-oriented control (foc) application in real time. you can automatically tune the pid controllers associated with the following loops (for more details, see ):
direct-axis (d-axis) current loop
quadrature-axis (q-axis) current loop
speed loop
for each loop that the block tunes, the field-oriented control autotuner block performs autotuning experiment in a closed-loop manner without using a parametric model associated with that loop. the block enables you to specify the order in which the block tunes the control loops. when the tuning experiment runs for one loop, the block has no effect on the other loops. for more details about foc autotuner, see field oriented control autotuner and tune pi controllers using field oriented control autotuner.
simulink control design
simulink control design enables you to design and analyze the control systems modeled in simulink. you can automatically tune the arbitrary siso and mimo control architectures, including the pid controllers. you can deploy pid autotuning to the embedded software to automatically compute the pid gains in real time.
you can find the operating points and compute the exact linearizations of the simulink models at different operating conditions. simulink control design provides tools that let you compute the simulation-based frequency responses without modifying your model. for details, see .
model initialization script
this section explains how the motor control blockset examples estimate the control gains needed to implement field-oriented control. for example, for a pmsm that is connected to a quadrature encoder, these steps describe the procedure to compute the control loop gain values from the system details by using the initialization script:
open the initialization script (
.m
) file of the example in matlab®. to find the associated script file name:select modeling > model settings > model properties to open the model properties dialog box.
in the model properties dialog box, navigate to the callbacks tab > initfcn to find the name of the script file that simulink opens before running the example.
this figure shows an example of the initialization script (
.m
) file.use the workspace to edit the control variables values. for example, to update stator resistance (
rs
), use the variablepmsm
to add the parameter value to thers
field.the model initialization script associated with a target model calls these functions and sets up the workspace with the necessary variables.
model initialization script function called by model initialization script description script associated with a target model mcb_setpmsmmotorparameters
input to the function is the type of pmsm (for example, bly171d).
the function populates a structure named
pmsm
in the matlab workspace, which is used by the model.it also computes the permanent magnet flux and rated torque for the selected motor.
you can extend the function by adding an additional switch-case for a new motor.
this function also loads the structure
motorparam
, obtained by running parameter estimation, to the structurepmsm
. if the structuremotorparam
is not available in the matlab workspace, the function loads the default parameters.mcb_setacimmotorparameters
input to the function is the type of ac induction motor (for example, em_synergy).
the function populates a structure named
acim
in the matlab workspace, which is used by the model.you can extend the function by adding an additional switch-case for a new motor.
this function also loads the structure
motorparam
, obtained by running parameter estimation, to the structureacim
. if the structuremotorparam
is not available in the matlab workspace, the function loads the default parameters.mcb_setinverterparameters
input to the function is inverter type (for example, boostxl-drv8305).
the function populates a structure named
inverter
in the matlab workspace, which is used by the model.the function also computes the inverter resistance for the selected inverter.
you can extend the function by adding an additional switch-case for a new inverter.
mcb_setprocessordetails
inputs to the function are processor type (for example, f28379d) and the pulse-width modulation (pwm) switching frequency.
the function populates a structure named
target
in the matlab workspace, which is used by the model.the function also computes the pwm counter period that is a parameter for the epwm block in the target model.
you can extend the function by adding an additional switch-case for a new processor.
mcb_getbasespeed
inputs to the function are motor and inverter parameters.
the function computes the base speed for pmsm.
type
help mcb_getbasespeed
at the matlab command window or see section obtain base speed for more details.mcb_setpusystem
inputs to the function are motor and inverter parameters.
the function sets the base values of the per-unit system for voltage, current, speed, torque, and power.
the function populates a structure named
pu_system
in the matlab workspace, which is used by the model.mcb_setcontrollerparameters
inputs to the function are motor and inverter parameters, per-unit system base values, pwm switching time period, sample time for the control system, and sample time for the speed controller.
the function computes the proportional integral (pi) parameters (kp, ki) for the field-oriented control implementation.
the function populates a structure named
pi_params
in the matlab workspace, which is used by the model.see section obtain controller gains for more details.
mcb_updateinverterparameters
inputs to the function are motor and inverter parameters.
the function updates the inverter parameters based on the selected hardware and motor.
this table explains the useful variables for each control parameter that you can update.
note
you can try starting matlab in the administrator mode on windows® system, if you are unable to update the model initialization scripts associated with the example models.
control parameter category | control parameter name | matlab workspace variable |
---|---|---|
motor parameters | manufacturer’s model number | pmsm.model |
manufacturer’s serial number | pmsm.sn | |
pole pairs | pmsm.p | |
stator resistance (ohm) | pmsm.rs | |
d-axis stator winding inductance (henry) | pmsm.ld | |
q-axis stator winding inductance (henry) | pmsm.lq | |
back emf constant (v_line(peak)/krpm) | pmsm.ke | |
motor inertia (kg.m2) | pmsm.j | |
friction constant (n.m.s) | pmsm.f | |
permanent magnet flux (wb) | pmsm.fluxpm | |
trated | pmsm.t_rated | |
nbase | pmsm.n_base | |
maximum motor speed used in the
| pmsm.n_max | |
irated | pmsm.i_rated | |
position decoders | qep index and hall position offset correction | pmsm.positionoffset |
quadrature encoder slits per revolution | pmsm.qepslits | |
inverter parameters | manufacturer’s model number | inverter.model |
manufacturer’s serial number | inverter.sn | |
dc link voltage of the inverter (v) | inverter.v_dc | |
maximum permissible currents by inverter (a) | inverter.i_trip | |
on-state resistance of mosfets (ohm) | inverter.rds_on | |
shunt resistance for current sensing (ohm) | inverter.rshunt | |
per-phase board resistance seen by motor (ohm) | inverter.r_board | |
adc offsets for current sensor (ia and ib) |
| |
maximum limit of automatically calibrated adc offsets for current sensor (ia and ib) | inverter.ctsensoffsetmax | |
minimum limit of automatically calibrated adc offsets for current sensor (ia and ib) | inverter.ctsensoffsetmin | |
enable auto-calibration for current sense adcs | inverter.adcoffsetcalibenable | |
adc gain factor configured by spi | inverter.adcgain | |
type of inverter: 1 — active high-enabled inverter 0 — active low-enabled inverter | inverter.enablelogic | |
convention for current entering motor: 1 — current entering motor sensed as positive by current sense amplifier –1 — current entering motor sensed as negative by current sense amplifier | inverter.invertingamp | |
reference voltage for the inverter current sensing circuit (v) | inverter.isensevref | |
output voltage of the inverter current sensing circuit corresponding to 1 ampere current (v/a) you can
compute this parameter using the datasheet values of current
shunt resistance (
| inverter.isensevoltperamp | |
maximum measurable peak-neutral current by the inverter current sensing circuit (a) | inverter.isensemax | |
processor | manufacturer’s model number | target.model |
manufacturer’s serial number | target.sn | |
cpu frequency | target.cpu_frequency | |
pwm frequency | target.pwm_frequency | |
pwm counter period | target.pwm_counter_period | |
reference voltage for adc (v) | target.adc_vref | |
maximum count output for 12-bit adc | target.adc_maxcount | |
baud rate for serial communication | target.sci_baud_rate | |
per-unit system | base voltage (v) | pu_system.v_base |
base current (a) | pu_system.i_base | |
base speed (rpm) | pu_system.n_base | |
base torque (nm) | pu_system.t_base | |
base power (watts) | pu_system.p_base | |
data-type for target device | data-type (fixed-point or floating-point) selection | datatype |
sample time values | switching frequency for converter | pwm_frequency |
pwm switching time period | t_pwm | |
sample time for current controllers | ts | |
sample time for speed controller | ts_speed | |
simulation sample time | ts_simulink | |
simulation sample time for motor | ts_motor | |
simulation sample time for inverter | ts_inverter | |
controller parameters | proportional gain for iq controller | pi_params.kp_i |
integral gain for iq controller | pi_params.ki_i | |
proportional gain for id controller | pi_params.kp_id | |
integral gain for id controller | pi_params.ki_id | |
proportional gain for speed controller | pi_params.kp_speed | |
integral gain for speed controller | pi_params.ki_speed | |
proportional gain for field weakening controller | pi_params.kp_fwc | |
integral gain for field weakening controller | pi_params.ki_fwc | |
sensor delay parameters | current sensor delay | delays.current_sensor |
speed sensor delay | delays.speed_sensor | |
delay for low-pass speed filter | delays.speed_filter | |
controller delay parameters | damping factor (ζ) of the current control loop | delays.om_damping_factor |
symmetrical optimum factor of the speed control loop | delays.so_factor_speed |
note
for the predefined processors and drivers, the model initialization script uses the default values.
the model initialization script uses these functions for performing the computations:
control parameter category | function | functionality |
---|---|---|
base speed of the motor | mcb_getbasespeed | calculates the base speed of pmsm at the rated voltage and rated load. for details, type |
motor characteristics for the given motor and inverter | mcb_getcharacteristics | obtain these drive characteristics of a pmsm motor.
for details, type for details, see section obtain motor characteristics. |
mcb_getcharacteristicsacim | obtain these motor characteristics of an induction motor.
obtain these drive characteristics of an induction motor.
for details, type for details, see section obtain motor characteristics. | |
control algorithm parameters | mcb_setcontrollerparameters | compute the gains for these pi controllers:
for details, see section obtain controller gains. |
control analysis for the motor and inverter you are using | mcb_getcontrolanalysis | performs frequency domain analysis for the computed gains of pi controllers used in the field-oriented motor control system. note this feature requires control system toolbox™. for details, type |
obtain base speed
the function mcb_getbasespeed
computes the base speed of
the pmsm at the given supply voltage. base speed is the maximum motor speed at
the rated voltage and rated load, outside the field-weakening region.
when you call this function (for example, base_speed =
mcb_getbasespeed(pmsm,inverter)
), it returns the base speed (in
rpm) for the given combination of pmsm and inverter. the function accepts the
following inputs:
pmsm parameter structure.
inverter parameter structure.
these equations describe the computations that the function performs:
the inverter voltage constraint is defined by computing the d-axis and q-axis voltages:
the current limit circle defines the current constraint which can be considered as:
in the preceding equation, is zero for surface pmsms. for interior pmsms, values of and corresponding to mtpa are considered.
using the preceding relationships, we can compute the base speed as:
where:
is the electrical speed corresponding to frequency of stator voltages (radians/ sec).
is the mechanical base speed of the motor (radians/ sec).
is the d-axis current (amperes).
is the q-axis current (amperes).
is the d-axis voltage when is zero (volts).
is the q-axis voltage when is zero (volts).
is the d-axis winding inductance (henry).
is the q-axis winding inductance (henry).
is the stator phase winding resistance (ohms).
is the permanent magnet flux linkage (weber).
is the d-axis voltage (volts).
is the q-axis voltage (volts).
is the maximum fundamental line to neutral voltage (peak) supplied to the motor (volts).
is the dc voltage supplied to the inverter (volts).
is the maximum phase current (peak) of the motor (amperes).
is the number of motor pole pairs.
obtain motor characteristics
the function mcb_getcharacteristics
calculates the torque,
power, and current characteristics of a pmsm, which helps you to develop the
control algorithm for the motor.
the function returns these characteristics for the given pmsm:
torque as opposed to speed
power as opposed to speed
idq as opposed to speed
ipeak as opposed to speed
the function mcb_getcharacteristicsacim
calculates the motor
and drive characteristics of an induction motor, which helps you to develop the
control algorithm for the motor.
the function returns these motor characteristics for the given induction motor:
torque as opposed to speed
power as opposed to speed
the function returns these drive characteristics for the given induction motor:
torque as opposed to speed
power as opposed to speed
idq as opposed to speed
ipeak as opposed to speed
obtain controller gains
the function mcb_setcontrollerparameters
computes the gains
for the pi controllers used in the field-oriented motor control systems.
you can use this command to call the function
mcb_setcontrollerparameters
:
pi_params = mcb_setcontrollerparameters(pmsm,inverter,pu_system,t_pwm,ts,ts_speed);
the function returns the gains of these pi controllers used in the foc algorithm:
direct-axis (d-axis) current loop
quadrature-axis (q-axis) current loop
speed loop
field-weakening control loop
the function accepts these inputs:
pmsm object
inverter object
pu system params
t_pwm
ts_control
ts_speed
the function does not plot any characteristic.
the design of compensators depends on the classical frequency response analysis applied to the motor control systems. we used the modulus optimum (mo) based design for the current controllers and the symmetrical optimum (so) based design for the speed controller.
the function automatically computes the other required parameters (for example, delays, damping factor) based on the input arguments.
you can modify the default system responses by an optional input to the function that specifies the system delays, damping factor, and symmetrical optimum factor:
pi_params = mcb_setcontrollerparameters(pmsm,inverter,pu_system,t_pwm,ts,ts_speed,delays);
damping factor (ζ) defines the dynamic behavior of the
standard form of a second-order system, where 0
<
ζ < 1
[1]. an underdamped system
gets close to the final value more quickly than a critically damped or an
overdamped system. among the systems that respond without oscillations, a
critically damped system shows the quickest response. an overdamped system is
always slow in responding to any inputs. this parameter has a default value of .
symmetrical optimum factor (a) defines the placement of the
cross-over frequency at the geometric mean of the two corner frequencies, to
obtain maximum phase margin that results in optimum damping of the speed loop,
where a > 1
[2]. this parameter has a
default value of 1.2
.
this example explains how to customize the parameters:
% sensor delays delays.current_sensor = 2*ts; %current sensor delay delays.speed_sensor = ts; %speed sensor delay delays.speed_filter = 20e-3; �lay for speed filter (lpf) % controller delays delays.om_damping_factor = 1/sqrt(2); �mping factor for current control loop delays.so_factor_speed = 1.5; %symmetrical optimum factor 1 < x < 20 % controller design pi_params = mcb_setcontrollerparameters(pmsm,inverter,pu_system,t_pwm,ts,ts_speed,delays);
perform control analysis
the function mcb_getcontrolanalysis
performs the basic
control analysis of the pmsm foc current control system. the function performs
frequency domain analysis for the computed pi controller gains used in the
field-oriented motor control systems.
note
this function requires the control system toolbox.
when you call this function (for example,
mcb_getcontrolanalysis(pmsm,inverter,pu_system,pi_params,ts,ts_speed)
),
it performs the following functions for the current control loop or
subsystem:
transfer function for the closed-loop current control system
root locus
bode diagram
stability margins (pm & gm)
step response
pz map
the function plots the corresponding plots:
references
[1] ogata, k. (2010). modern control engineering. prentice hall.
[2] leonhard, w. (2001). control of electrical drives. springer science & business media. pp. 86.