matlab workflow for tuning the hl-凯发k8网页登录
this is part 5 of the example series on design and tuning of the flight control system for the hl-20 vehicle. this part shows how to perform most of the design in matlab® without interacting with the simulink® model.
background
this example uses the hl-20 model adapted from (aerospace blockset), see part 1 of the series () for details. the autopilot controlling the attitude of the aircraft consists of three inner loops and three outer loops.
in part 2 (angular rate control in the hl-20 autopilot) and part 3 (), we showed how to close the inner loops and tune the gain schedules for the outer loops. these examples made use of the sltuner
interface to interact with the simulink model, obtain linearized models and control system responses, and push tuned values back to simulink.
for simple architectures and rapid design iterations, it can be preferable (and conceptually simpler) to manipulate the linearized models in matlab and use basic commands like feedback
to close loops. this example shows how to perform the design steps of parts 2 and 3 in matlab.
obtaining the plant models
to tune the autopilot, we need linearized models of the transfer function from deflections to angular position and rates. to do this, start from the results from the "trim and linearize" step (see ). recall that g7
is a seven-state linear model of the airframe at 40 different (alpha,beta) conditions, and cs
is the linearization of the controls selector block.
load csthl20_trimdata g7 cs
using the simulink model "csthl20_trim" as reference for selecting i/os, build the desired plant models by connecting g7
and cs
in series. do not forget to convert phi,alpha,beta from radians to degrees.
r2d = 180/pi; g = diag([1 1 1 r2d r2d r2d]) * g7([4:7 31:32],1:6) * cs(:,1:3); g.inputname = {'da','de','dr'}; g.outputname = {'p','q','r','phi_deg','alpha_deg','beta_deg'}; size(g)
8x5 array of state-space models. each model has 6 outputs, 3 inputs, and 7 states.
this gives us an array of plant models over the 8-by-5 grid of (alpha,beta) conditions used for trimming.
closing the inner loops
to close the inner loops, we follow the same procedure as in part 2 (angular rate control in the hl-20 autopilot). this consists of selecting the gain kp,kq,kr to set the crossover frequency of the p,q,r loops to 30, 22.5, and 37.5 rad/s, respectively.
% compute kp,kq,kr for each (alpha,beta) condition. gpqr = g({'p','q','r'},:); kp = 1./abs(evalfr(gpqr(1,1),30i)); kq = -1./abs(evalfr(gpqr(2,2),22.5i)); kr = -1./abs(evalfr(gpqr(3,3),37.5i)); bode(gpqr(1,1)*kp,gpqr(2,2)*kq,gpqr(3,3)*kr,{1e-1,1e3}), grid legend('da to p','de to q','dr to r')
use feedback
to close the three inner loops. insert an analysis point at the plant inputs da,de,dr for later evaluation of the stability margins.
cpqr = append(ss(kp),ss(kq),ss(kr)); apu = analysispoint('u',3); apu.location = {'da','de','dr'}; gpos = feedback(g * apu * cpqr, eye(3), 1:3, 1:3); gpos.inputname = {'p_demand','q_demand','r_demand'}; size(gpos)
8x5 array of generalized state-space models. each model has 6 outputs, 3 inputs, 7 states, and 1 blocks.
note that these commands seamlessly manage the fact that we are dealing with arrays of plants and gains corresponding to the various (alpha,beta) conditions.
tuning the outer loops
next move to the outer loops. we already have an array of linear models gpos
for the "plant" seen by the outer loops. as done in part 3 (), parameterize the six gain schedules as polynomial surfaces in alpha and beta. again we use quadratic surfaces for the proportional gains and multilinear surfaces for the integral gains.
% grid of (alpha,beta) design points alpha_vec = -10:5:25; % alpha range beta_vec = -10:5:10; % beta range [alpha,beta] = ndgrid(alpha_vec,beta_vec); sg = struct('alpha',alpha,'beta',beta); % proportional gains alphabetabasis = polybasis('canonical',2,2); p_phi = tunablesurface('pphi', 0.05, sg, alphabetabasis); p_alpha = tunablesurface('palpha', 0.05, sg, alphabetabasis); p_beta = tunablesurface('pbeta', -0.05, sg, alphabetabasis); % integral gains alphabasis = @(alpha) alpha; betabasis = @(beta) abs(beta); alphabetabasis = ndbasis(alphabasis,betabasis); i_phi = tunablesurface('iphi', 0.05, sg, alphabetabasis); i_alpha = tunablesurface('ialpha', 0.05, sg, alphabetabasis); i_beta = tunablesurface('ibeta', -0.05, sg, alphabetabasis);
the overall controller for the outer loop is a diagonal 3-by-3 pi controller taken the errors on angular positions phi,alpha,beta and calculating the rate demands p_demand,q_demand,r_demand.
kp = append(p_phi,p_alpha,p_beta); ki = append(i_phi,i_alpha,i_beta); cpos = kp ki * tf(1,[1 0]);
finally, use feedback
to obtain a tunable closed-loop model of the outer loops. to enable tuning and closed-loop analysis, insert analysis points at the plant outputs.
rollofffilter = tf(10,[1 10]); apy = analysispoint('y',3); apy.location = {'phi_deg','alpha_deg','beta_deg'}; t0 = feedback(apy * gpos(4:6,:) * rollofffilter * cpos ,eye(3)); t0.inputname = {'phi_demand','alpha_demand','beta_demand'}; t0.outputname = {'phi_deg','alpha_deg','beta_deg'};
you can plot the closed-loop responses for the initial gain surface settings (constant gains of 0.05).
step(t0,6)
tuning goals
use the same tuning goals as in part 3 (). these include "minloopgain" and "maxloopgain" goals to set the gain crossover of the outer loops between 0.5 and 5 rad/s.
r1 = tuninggoal.minloopgain({'phi_deg','alpha_deg','beta_deg'},0.5,1); r1.loopscaling = 'off'; r2 = tuninggoal.maxloopgain({'phi_deg','alpha_deg','beta_deg'},tf(50,[1 10 0])); r2.loopscaling = 'off';
these also include a varying "margins" goal to impose adequate stability margins in each loop and across loops.
% gain margins vs (alpha,beta) gm = [... 6 6 6 6 6 6 6 7 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 6 6 7 6 6 6 6 6 6 6]; % phase margins vs (alpha,beta) pm = [... 40 40 40 40 40 40 40 45 40 40 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 40 40 45 40 40 40 40 40 40 40]; % create varying goal fh = @(gm,pm) tuninggoal.margins({'da','de','dr'},gm,pm); r3 = varyinggoal(fh,gm,pm);
gain schedule tuning
you can now use systune
to shape the six gain surfaces against the tuning goals at all 40 design points.
t = systune(t0,[r1 r2 r3]);
final: soft = 1.03, hard = -inf, iterations = 52
the final objective value is close to 1 so the tuning goals are essentially met. plot the closed-loop angular responses and compare with the initial settings.
step(t0,t,6) legend('baseline','tuned','location','southeast')
the results match those obtained in parts 2 and 3. the tuned gain surfaces are also similar.
clf
% note: setblockvalue updates each gain surface with the tuned coefficients in t
subplot(3,2,1), viewsurf(setblockvalue(p_phi,t))
subplot(3,2,3), viewsurf(setblockvalue(p_alpha,t))
subplot(3,2,5), viewsurf(setblockvalue(p_beta,t))
subplot(3,2,2), viewsurf(setblockvalue(i_phi,t))
subplot(3,2,4), viewsurf(setblockvalue(i_alpha,t))
subplot(3,2,6), viewsurf(setblockvalue(i_beta,t))
you could now use evalsurf
to sample the gain surfaces and update the lookup tables in the simulink model. you could also use the codegen
method to generate code for the gain surface equations. for example
% generate code for "p phi" block mcode = codegen(setblockvalue(p_phi,t)); % get tuned values for the "i phi" lookup table kphi = evalsurf(setblockvalue(i_phi,t),alpha_vec,beta_vec);