main content

tune field-凯发k8网页登录

this example shows how to use the systune command to tune field-oriented control (foc) for a permanent magnet synchronous machine (pmsm) based on a frequency response estimation (fre) result.

field-oriented control

in this example, field-oriented control (foc) for a permanent magnet synchronous machine (pmsm) is modeled in simulink® using simscape™ electrical™ components.

mdl = 'scdfocmotorsystune';
open_system(mdl)
signaleditorpath = [mdl,'/system_inputs/reference_system_inputs'];

field-oriented control controls 3-phase stator currents as a vector. foc is based on projections, which transform a 3-phase time-dependent 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 controller_algorithm 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 controller_algorithm 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.

before tuning controllers, examine the speed responses with the original controllers, and save the simulation results to a mat-file, systunedspeed.mat. the existing speed pi controller has gains of p = 0.08655 and i = 0.1997. the current pi controllers both have gains of p = 1 and i = 200.

scdfocmotorsystuneoriginalresponse

plot the speed response with the original controllers. the plots exhibit steady-state errors and relatively slow transient behavior. you can tune the controllers to achieve a better performance.

figure
plot(logsout_original_oneside{2}.values);
hold on
plot(logsout_original_oneside{1}.values);
legend('original controller','speed reference','location','southeast');
grid on
hold off
figure
plot(logsout_original_twoside{2}.values);
hold on
plot(logsout_original_twoside{1}.values);
legend('original controller','speed reference','location','northeast');
grid on
hold off

collect frequency response data

to collect frequency response data, find an operating point at a speed of 150 rad/sec, specify linear analysis points, define input signals, and estimate the frequency response.

disconnect the original controllers, and simulate the open-loop system model with vd and vq commands. to reach the operating point, specify initial voltages of -0.1 v for vd and 3.465 v for vq using the ctrlinivalues structure. constant voltage command blocks are connected by setting switch signals in the switchinivalue structure.

switchinivalue.openloopd = 1;
switchinivalue.openloopq = 1;
ctrlinivalues.voltaged = -0.1;
ctrlinivalues.voltageq = 3.465;

capture a simulation snapshot at 3 sec as the operating point for frequency response estimation.

set_param(signaleditorpath,'activescenario',...
    'test_case_150_rad_sec_steady_state');
op = findop(mdl,3);

use the simulation snapshot operating point as the initial condition of the model. change the model initial values in the ctrlinivalues structure to be at this steady state. for the d-axis current controller, the current id is 0 a. for the q-axis current controller, the current iq is 0.1 a. for the outer-loop speed controller, the reference current is 0.122 a and the speed is at 150 rad/s. for the pmsm plant, set the rotor velocity in the pmsm structure to 150 rad/s.

set_param(mdl,'loadinitialstate','on');
set_param(mdl,'initialstate','getstatestruct(op)');
ctrlinivalues.currentdic = 0;
ctrlinivalues.currentqic = 0.1;
ctrlinivalues.speedic = 150;
ctrlinivalues.speedcurrent = 0.122;
pmsm.rotorvelocityinit = 150;

add linear analysis points to the model for frequency response estimation. add open-loop input points to vd and vq. add open-loop output points to id, iq, and speed. in addition, add a loop break analysis point to the speed measurement.

io = getlinio(mdl);

define input sinestream signal from 10 to 10,000 rad/s with a fixed sample time of 4e-6 s, that is, the sample time of the current control loop sampletime.currentcontrol. the sinestream signal magnitude is 0.25 v. this magnitude ensures that the plant is properly excited within the saturation limit. if the excitation amplitude is either too large or too small, it produces inaccurate frequency response estimation results.

in = frest.createfixedtssinestream(sampletime.currentcontrol,{10,1e4});
in.amplitude = 0.5;

estimate the frequency response at the specified steady state operating point op, using the linear analysis points in io and the input signals in in. after finishing the frequency response estimation, modify the input and output channel names in the resulting model, and plot the frequency response.

estsys = frestimate(mdl,op,io,in);
estsys.inputname = {'vd','vq'};
estsys.outputname = {'id','iq','speed'};
figure
bode(estsys,'.')

tune control system using systune

obtain a state-space linear system model from the frequency response estimation result. using an option set for the ssest function, set the numerical search method used for this iterative parameter estimation as the levenberg-marquardt least-squares search. estimate a state-space model with four states and a period of 4e-6 seconds. this step requires system identification toolbox™ software.

optssest = ssestoptions('searchmethod','lm');
optssest.regularization.lambda = 0.1;
sys_singletune = ssest(estsys,4,'ts',sampletime.currentcontrol,optssest);

in order to tune all three pi controllers in the pmsm foc model, construct a control system as shown in the following block diagram.

define three tunable discrete-time pid blocks and their i/os for d-axis current control, q-axis current control, and speed control. the sample times of these discrete-time pid controllers must be consistent, which is the same as the current control loop sample time. to ensure a better approximation of faster controllers as compared to the original slower controllers, set the discrete integrator formula for each pid controller to 'trapezoidal'.

cd = tunablepid('cd','pi',sampletime.currentcontrol);
cd.iformula = 'trapezoidal';
cd.u = 'id_e';
cd.y = 'vd';
cq = tunablepid('cq','pi',sampletime.currentcontrol);
cq.iformula = 'trapezoidal';
cq.u = 'iq_e';
cq.y = 'vq';
cspeed = tunablepid('cspeed','pi',sampletime.currentcontrol);
cspeed.iformula = 'trapezoidal';
cspeed.u = 'speed_e';
cspeed.y = 'iq_ref';

create three summing junctions for the inner and outer feedback loops.

sum_speed = sumblk('speed_e = speed_ref - speed');
sum_id = sumblk('id_e = id_ref - id');
sum_iq = sumblk('iq_e = iq_ref - iq');

define inputs, outputs, and analysis points for controller tuning.

input = {'id_ref','speed_ref'};
output = {'id','iq','speed'};
aps = {'iq_ref','vd','vq','id','iq','speed'};

finally, assemble the complete control system, st0, using these components.

st0 = connect(sys_singletune,cd,cq,cspeed,sum_speed,sum_id,sum_iq,input,output,aps);

define tuning goals, including tracking and loop shape goals to ensure command tracking, as well as gain goals to prevent saturations. for the speed controller, set the tracking bandwidth to 150 rad/s. this bandwidth is used in both the tracking and loop shape goals. additionally, set the dc error to 0.001 to reflect a maximum steady-state error of 0.1%. set the peak error to 10. for the d-axis current controller, set the tracking bandwidth to 2500 rad/s, which is much faster than the outer-loop speed controller. to prevent saturating controllers, specify goals to constrain the gains for all three controllers.

tr1 = tuninggoal.tracking('speed_ref','speed',2/150,0.001,10);
tr2 = tuninggoal.tracking('id_ref','id',2/2500);
ls1 = tuninggoal.loopshape('id',2500);
ls2 = tuninggoal.loopshape('speed',150);
mg1 = tuninggoal.gain('speed_ref','iq_ref',2);
mg2 = tuninggoal.gain('speed_ref','vq',50);
mg3 = tuninggoal.gain('id_ref','vd',20);

tune all three pi controllers using systune with all tuning goals based on the constructed model st0. to increase the likelihood of finding parameter values that meet all design requirements, set options for systune to run five additional optimizations starting from five randomly generated parameter values.

opt = systuneoptions('randomstart',5);
rng(2)
[st1,fsoft] = systune(st0,[tr1,tr2,ls1,ls2,mg1,mg2,mg3],opt);
final: soft = 1.01, hard = -inf, iterations = 62
final: soft = 497, hard = -inf, iterations = 71
       some closed-loop poles are marginally stable (decay rate near 1e-07)
final: soft = 1.01, hard = -inf, iterations = 55
       some closed-loop poles are marginally stable (decay rate near 1e-07)
final: soft = 1.01, hard = -inf, iterations = 54
final: soft = 1.01, hard = -inf, iterations = 51
final: soft = 1.01, hard = -inf, iterations = 47

after finding a solution using systune, show how tuning goals are met in the tuned model st1. show the tracking, loop shape, and gain tuning goals separately. dashed lines in the following figures represent tuning goals and solid lines are the result of the tuned controllers.

figure
viewgoal([tr1,tr2],st1)
figure
viewgoal([ls1,ls2],st1)
figure
viewgoal([mg1,mg2,mg3],st1)

after verifying tuning goals, extract controller parameters from the tuned model st1. use tuned pi controller parameters to update the workspace parameters for the pi controller blocks.

cd = getblockvalue(st1,'cd');
cq = getblockvalue(st1,'cq');
cspeed = getblockvalue(st1,'cspeed');

the d-axis current pi controller has tuned gains:

paramcurrentcontrolpd = cd.kp
paramcurrentcontrolid = cd.ki
paramcurrentcontrolpd =
    2.5952
paramcurrentcontrolid =
   2.4166e 03

the q-axis current pi controller has tuned gains:

paramcurrentcontrolpq = cq.kp
paramcurrentcontroliq = cq.ki
paramcurrentcontrolpq =
    5.5948
paramcurrentcontroliq =
  707.6873

the speed pi controller has tuned gains:

paramvelocitycontroltunep = cspeed.kp
paramvelocitycontroltunei = cspeed.ki
paramvelocitycontroltunep =
    0.3643
paramvelocitycontroltunei =
    0.4932

after tuning all three controllers together using systune, the controller gains are significantly different from the original values. the pid controller in the speed control loop has a different sample time, which is 0.001 second. the tuned result uses a different sample time of 4e-6 second but the controller gains are the same. to make sure controller performances are identical with different sample times, the discrete integrator format of the pid controllers is 'trapezoidal' in this example.

validate tuned controller

examine the performances using the tuned controller gains. first, initialize the model to its zero initial conditions using ctrlinivalues. connect the pid controller blocks by setting switch signals in the switchinivalue and set proper initial conditions for the pmsm plant model.

switchinivalue.openloopq = 0;
switchinivalue.openloopd = 0;
ctrlinivalues.currentdic = 0;
ctrlinivalues.voltaged = 0;
ctrlinivalues.currentqic = 0;
ctrlinivalues.voltageq = 0;
ctrlinivalues.speedic = 0;
ctrlinivalues.speedcurrent = 0;
pmsm.rotorvelocityinit = 0;
set_param(mdl,'loadinitialstate','off')

configure the model to use a one-sided speed command signal and simulate the model. show the speed response of the model to the one-sided speed command that rises from 0 rad/s to 150 rad/s at 0.05 s, and then to 200 rad/s at 0.8 s. save the simulation result to logsout_tuned_oneside in the mat-file, systunedspeed.mat.

set_param(signaleditorpath,'activescenario','test_case_150_rad_sec_no_load');
sim(mdl);
logsout_tuned_oneside = logsout;
save('systunedspeed','logsout_tuned_oneside','-append')

configure the model to use a two-sided speed command signal and simulate the model. show the speed response of the model to the two-sided speed command that rises from 0 rad/s to 150 rad/s at 0.05 s, reverses direction at 0.5 s and then back to 0 rad/s at 0.8 s. save the simulation result to logsout_tuned_twoside in the mat-file, systunedspeed.mat.

set_param(signaleditorpath,'activescenario','test_case_1_150_rad_sec_no_load');
sim(mdl);
logsout_tuned_twoside = logsout;
save('systunedspeed','logsout_tuned_twoside','-append')

compare the motor speed responses between the existing controller gains and the tuned result. the speed responses are shown side-by-side over the one-second simulation. the speed response follows more closely to the step command. the steady-state error also decreases after the pi controllers are tuned with systune.

scdfocmotorsystuneplotspeed

after tuning the controllers, the motor response improves with faster transient response and smaller steady-state error under both types of speed commands.

bdclose(mdl)

see also

related topics

    网站地图