custom state estimation -凯发k8网页登录
model predictive control toolbox™ software allows you to override the default controller state estimation method.
to do so, you can use the following methods:
you can override the default kalman gains, and , using the function. to obtain the default values from the controller use . these commands assume that the columns of and are in the engineering units of the measured plant outputs. internally, the software converts them to dimensionless form.
you can use the custom estimation option, which skips all kalman gain calculations within the controller. when the controller operates, at each control interval you must use an external procedure to estimate the controller states and provide these state estimates to the controller.
custom state estimation is not supported in mpc designer. for more information see controller state estimation and .
define plant model
consider the case of a double integrator plant for which all of the plant states are measurable. in such a case, you can provide the measured states to the mpc controller rather than have the controller estimate the states.
the linear open-loop plant model is a double integrator.
plant = tf(1,[1 0 0]);
design mpc controller
create the controller object with a sample time of 0.1
seconds, a prediction horizon of 10
steps, and control horizon of 3
steps.
ts=0.1; mpcobj = mpc(plant,ts,10,3);
-->"weights.manipulatedvariables" is empty. assuming default 0.00000. -->"weights.manipulatedvariablesrate" is empty. assuming default 0.10000. -->"weights.outputvariables" is empty. assuming default 1.00000.
specify actuator saturation limits as manipulated variable constraints.
mpcobj.mv = struct('min',-1,'max',1);
configure the controller to use custom state estimation.
setestimator(mpcobj,'custom');
simulate controller
initialize variables to store the closed-loop responses.
tf = round(5/ts); yy = zeros(tf,1); uu = zeros(tf,1);
prepare the plant used in the simulation by converting it to a discrete-time model and setting the initial state.
sys = c2d(ss(plant),ts); xsys = [0;0];
get an handle to the object that is used to store the controller states.
xmpc = mpcstate(mpcobj);
-->converting the "model.plant" property to state-space. -->converting model to discrete time. assuming no disturbance added to measured output #1. -->"model.noise" is empty. assuming white noise on each measured output.
iteratively simulate the closed-loop response using the function.
for each simulation step:
obtain the plant output,
y
, from the current state.store the plant output.
set the plant state in the
mpcstate
object to the current measured state values,xsys
, using the handlexmpc
. for plants in which the state is not measurable, a state estimation must be provided by an observer. when using the built-in estimator, this is not needed.compute the mpc control action,
u
, passing in thempcstate
object and the output reference,1
.store the control signal.
update the plant state.
for t = 0:tf y = sys.c*xsys; % plant equations: output yy(t 1) = y; xmpc.plant = xsys; % state estimation u = mpcmove(mpcobj,xmpc,[],1); % y is not needed uu(t 1) = u; xsys = sys.a*xsys sys.b*u; % plant equations: next state end
plot the simulation results.
figure subplot(2,1,1) plot(0:ts:5,yy) title('y') subplot(2,1,2) plot(0:ts:5,uu) title('u')
simulate closed-loop control of the linear plant model in simulink. for this model, the controller mpcobj
is specified in the mpc controller block.
mdl = 'mpc_customestimation';
open_system(mdl)
sim(mdl)
the closed-loop responses for the matlab and simulink simulations are identical.
fprintf('\ndifference between simulations in matlab and simulink is %g\n',norm(uu-u));
difference between simulations in matlab and simulink is 5.92777e-14
close the simulink model.
bdclose(mdl)
see also
functions
- | |