www.gusucode.com > control 案例程序 matlab源码代码 > control/DiscretizeAContinuousTimePIDControllerExample.m

    %% Discretize a Continuous-Time PID Controller
% Discretize a continuous-time PID controller and set integral and
% derivative filter formulas.
%%
% Create a continuous-time controller and discretize it using the
% zero-order-hold method of the |c2d| command.

% Copyright 2015 The MathWorks, Inc.

Ccon = pid(1,2,3,4);  % continuous-time PIDF controller
Cdis1 = c2d(Ccon,0.1,'zoh')
%%
% The display shows that |c2d| computes new PID gains for the
% discrete-time controller. 
%
% The discrete integrator formulas of the discretized controller depend on
% the |c2d| discretization method, as described in
% <docid:control_ref.bsmdmvx-4>.  For the |zoh| method, both |IFormula| and
% |DFormula| are |ForwardEuler|.
Cdis1.IFormula
Cdis1.DFormula
%%
% If you want to use different formulas from the ones returned by |c2d|,
% then you can directly set the |Ts|, |IFormula|, and |DFormula| properties
% of the controller to the desired values.
Cdis2 = Ccon;
Cdis2.Ts = 0.1; 
Cdis2.IFormula = 'BackwardEuler';
Cdis2.DFormula = 'BackwardEuler';
%%
% However, these commands do not compute new PID gains for the discretized
% controller.  To see this, examine |Cdis2| and compare the coefficients to
% |Ccon| and |Cdis1|.
Cdis2