Documentation Center |
Create a PID controller in standard form, convert to standard-form PID controller
C = pidstd(Kp,Ti,Td,N)
C = pidstd(Kp,Ti,Td,N,Ts)
C = pidstd(sys)
C = pidstd(Kp)
C = pidstd(Kp,Ti)
C = pidstd(Kp,Ti,Td)
C = pidstd(...,Name,Value)
C = pidstd
C = pidstd(Kp,Ti,Td,N) creates a continuous-time PIDF (PID with first-order derivative filter) controller object in standard form. The controller has proportional gain Kp, integral and derivative times Ti and Td, and first-order derivative filter divisor N:
C = pidstd(Kp,Ti,Td,N,Ts) creates a discrete-time controller with sampling time Ts. The discrete-time controller is:
IF(z) and DF(z) are the discrete integrator formulas for the integrator and derivative filter. By default, IF(z) = DF(z) = T_{s}z/(z – 1). To choose different discrete integrator formulas, use the IFormula and DFormula inputs. (See Properties for more information about IFormula and DFormula). If DFormula = 'ForwardEuler' (the default value) and N ≠ Inf, then Ts, Td, and N must satisfy Td/N > Ts/2. This requirement ensures a stable derivative filter pole.
C = pidstd(sys) converts the dynamic system sys to a standard form pidstd controller object.
C = pidstd(Kp) creates a continuous-time proportional (P) controller with Ti = Inf, Td = 0, and N = Inf.
C = pidstd(Kp,Ti) creates a proportional and integral (PI) controller with Td = 0 and N = Inf.
C = pidstd(Kp,Ti,Td) creates a proportional, integral, and derivative (PID) controller with N = Inf.
C = pidstd(...,Name,Value) creates a controller or converts a dynamic system to a pidstd controller object with additional options specified by one or more Name,Value pair arguments.
Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
Use Name,Value syntax to set the numerical integration formulas IFormula and DFormula of a discrete-time pidstd controller, or to set other object properties such as InputName and OutputName. For information about available properties of pidstd controller objects, see Properties.
C |
pidstd object representing a single-input, single-output PID controller in standard form. The controller type (P, PI, PD, PDF, PID, PIDF) depends upon the values of Kp, Ti, Td, and N. For example, when Td = Inf and Kp and Ti are finite and nonzero, C is a PI controller. Enter getType(C) to obtain the controller type. When the inputs Kp,Ti, Td, and N or the input sys are arrays, C is an array of pidstd objects. |
pidstd controller objects have the following properties:
Kp |
Proportional gain. Kp must be real and finite. |
Ti |
Integral time. Ti must be real, finite, and greater than or equal to zero. |
Td |
Derivative time. Td must be real, finite, and greater than or equal to zero. |
N |
Derivative time. N must be real, and greater than or equal to zero. |
IFormula |
Discrete integrator formula IF(z) for the integrator of the discrete-time pidstd controller C:
IFormula can take the following values:
When C is a continuous-time controller, IFormula is ''. Default: 'ForwardEuler' |
DFormula |
Discrete integrator formula DF(z) for the derivative filter of the discrete-time pidstd controller C:
DFormula can take the following values:
When C is a continuous-time controller, DFormula is ''. Default: 'ForwardEuler' |
InputDelay |
Time delay on the system input. InputDelay is always 0 for a pidstd controller object. |
OutputDelay |
Time delay on the system Output. OutputDelay is always 0 for a pidstd controller object. |
Ts |
Sampling time. For continuous-time models, Ts = 0. For discrete-time models, Ts is a positive scalar representing the sampling period. This value is expressed in the unit specified by the TimeUnit property of the model. To denote a discrete-time model with unspecified sampling time, set Ts = -1. Changing this property does not discretize or resample the model. Use c2d and d2c to convert between continuous- and discrete-time representations. Use d2d to change the sampling time of a discrete-time system. Default: 0 (continuous time) |
TimeUnit |
String representing the unit of the time variable. For continuous-time models, this property represents any time delays in the model. For discrete-time models, it represents the sampling time Ts. Use any of the following values:
Changing this property changes the overall system behavior. Use chgTimeUnit to convert between time units without modifying system behavior. Default: 'seconds' |
InputName |
Input channel names. Set InputName to a string for single-input model. For a multi-input model, set InputName to a cell array of strings. Alternatively, use automatic vector expansion to assign input names for multi-input models. For example, if sys is a two-input model, enter: sys.InputName = 'controls'; The input names automatically expand to {'controls(1)';'controls(2)'}. You can use the shorthand notation u to refer to the InputName property. For example, sys.u is equivalent to sys.InputName. Input channel names have several uses, including:
Default: Empty string '' for all input channels |
InputUnit |
Input channel units. Use InputUnit to keep track of input signal units. For a single-input model, set InputUnit to a string. For a multi-input model, set InputUnit to a cell array of strings. InputUnit has no effect on system behavior. Default: Empty string '' for all input channels |
InputGroup |
Input channel groups. The InputGroup property lets you assign the input channels of MIMO systems into groups and refer to each group by name. Specify input groups as a structure. In this structure, field names are the group names, and field values are the input channels belonging to each group. For example: sys.InputGroup.controls = [1 2]; sys.InputGroup.noise = [3 5]; creates input groups named controls and noise that include input channels 1, 2 and 3, 5, respectively. You can then extract the subsystem from the controls inputs to all outputs using: sys(:,'controls') Default: Struct with no fields |
OutputName |
Output channel names. Set OutputName to a string for single-output model. For a multi-output model, set OutputName to a cell array of strings. Alternatively, use automatic vector expansion to assign output names for multi-output models. For example, if sys is a two-output model, enter: sys.OutputName = 'measurements'; The output names to automatically expand to {'measurements(1)';'measurements(2)'}. You can use the shorthand notation y to refer to the OutputName property. For example, sys.y is equivalent to sys.OutputName. Output channel names have several uses, including:
Default: Empty string '' for all input channels |
OutputUnit |
Output channel units. Use OutputUnit to keep track of output signal units. For a single-output model, set OutputUnit to a string. For a multi-output model, set OutputUnit to a cell array of strings. OutputUnit has no effect on system behavior. Default: Empty string '' for all input channels |
OutputGroup |
Output channel groups. The OutputGroup property lets you assign the output channels of MIMO systems into groups and refer to each group by name. Specify output groups as a structure. In this structure, field names are the group names, and field values are the output channels belonging to each group. For example: sys.OutputGroup.temperature = [1]; sys.InputGroup.measurement = [3 5]; creates output groups named temperature and measurement that include output channels 1, and 3, 5, respectively. You can then extract the subsystem from all inputs to the measurement outputs using: sys('measurement',:) Default: Struct with no fields |
Name |
System name. Set Name to a string to label the system. Default: '' |
Notes |
Any text that you want to associate with the system. Set Notes to a string or a cell array of strings. Default: {} |
UserData |
Any type of data you wish to associate with system. Set UserData to any MATLAB^{®} data type. Default: [] |
SamplingGrid |
Sampling grid for model arrays, specified as a data structure. For model arrays that are derived by sampling one or more independent variables, this property tracks the variable values associated with each model in the array. This information appears when you display or plot the model array. Use this information to trace results back to the independent variables. Set the field names of the data structure to the names of the sampling variables. Set the field values to the sampled variable values associated with each model in the array. All sampling variables should be numeric and scalar valued, and all arrays of sampled values should match the dimensions of the model array. For example, suppose you create a 11-by-1 array of linear models, sysarr, by taking snapshots of a linear time-varying system at times t = 0:10. The following code stores the time samples with the linear models. sysarr.SamplingGrid = struct('time',0:10)
Similarly, suppose you create a 6-by-9 model array, M, by independently sampling two variables, zeta and w. The following code attaches the (zeta,w) values to M. [zeta,w] = ndgrid(<6 values of zeta>,<9 values of w>) M.SamplingGrid = struct('zeta',zeta,'w',w) When you display M, each entry in the array includes the corresponding zeta and w values. M M(:,:,1,1) [zeta=0.3, w=5] = 25 -------------- s^2 + 3 s + 25 M(:,:,2,1) [zeta=0.35, w=5] = 25 ---------------- s^2 + 3.5 s + 25 ... Default: [] |
Create a continuous-time standard-form PDF controller with proportional gain 1, derivative time 3, and a filter divisor of 6.
C = pidstd(1,Inf,3,6);
C = s Kp * (1 + Td * ------------) (Td/N)*s+1 with Kp = 1, Td = 3, N = 6 Continuous-time PDF controller in standard form
The display shows the controller type, formula, and coefficient values.
Create a discrete-time PI controller with trapezoidal discretization formula.
To create a discrete-time controller, set the value of Ts using Name,Value syntax.
C = pidstd(1,0.5,'Ts',0.1,'IFormula','Trapezoidal') % Ts = 0.1s
This command produces the result:
Discrete-time PI controller in standard form: 1 Ts*(z+1) Kp * (1 + ---- * --------) Ti 2*(z-1) with Kp = 1, Ti = 0.5, Ts = 0.1
Alternatively, you can create the same discrete-time controller by supplying Ts as the fifth argument after all four PID parameters Kp, Ti, Td, and N.
C = pidstd(5,2.4,0,Inf,0.1,'IFormula','Trapezoidal');
Create a PID controller and set dynamic system properties InputName and OutputName.
C = pidstd(1,0.5,3,'InputName','e','OutputName','u')
Create a 2-by-3 grid of PI controllers with proportional gain ranging from 1–2 and integral time ranging from 5–9.
Create a grid of PI controllers with proportional gain varying row to row and integral time varying column to column. To do so, start with arrays representing the gains.
Kp = [1 1 1;2 2 2]; Ti = [5:2:9;5:2:9]; pi_array = pidstd(Kp,Ti,'Ts',0.1,'IFormula','BackwardEuler');
These commands produce a 2-by-3 array of discrete-time pidstd objects. All pidstd objects in an array must have the same sample time, discrete integrator formulas, and dynamic system properties (such as InputName and OutputName).
Alternatively, you can use the stack command to build arrays of pidstd objects.
C = pidstd(1,5,0.1) % PID controller Cf = pidstd(1,5,0.1,0.5) % PID controller with filter pid_array = stack(2,C,Cf); % stack along 2nd array dimension
These commands produce a 1-by-2 array of controllers. Enter the command:
size(pid_array)
to see the result
1x2 array of PID controller. Each PID has 1 output and 1 input.
Convert a standard form pid controller to parallel form.
Parallel PID form expresses the controller actions in terms of an proportional, integral, and derivative gains K_{p}, K_{i}, and K_{d}, and a filter time constant T_{f}. You can convert a parallel form controller parsys to standard form using pidstd, provided that:
parsys is not a pure integrator (I) controller.
The gains Kp, Ki, and Kd of parsys all have the same sign.
parsys = pid(2,3,4,5); % Standard-form controller stdsys = pidstd(parsys)
These commands produce a parallel-form controller:
Continuous-time PIDF controller in standard form: 1 1 s Kp * (1 + ---- * --- + Td * ------------) Ti s (Td/N)*s+1 with Kp = 2, Ti = 0.66667, Td = 2, N = 0.4
Convert a continuous-time dynamic system that represents a PID controller to parallel pid form.
The dynamic system
represents a PID controller. Use pidstd to obtain H(s) to in terms of the standard-form PID parameters K_{p}, T_{i}, and T_{d}.
H = zpk([-1,-2],0,3); C = pidstd(H)
These commands produce the result:
Continuous-time PID controller in standard form: 1 1 Kp * (1 + ---- * --- + Td * s) Ti s with Kp = 9, Ti = 1.5, Td = 0.33333
Convert a discrete-time dynamic system that represents a PID controller with derivative filter to standard pidstd form.
% PIDF controller expressed in zpk form sys = zpk([-0.5,-0.6],[1 -0.2],3,'Ts',0.1)
The resulting pidstd object depends upon the discrete integrator formula you specify for IFormula and DFormula.
For example, if you use the default ForwardEuler for both formulas:
C = pidstd(sys)
you obtain the result:
Discrete-time PIDF controller in standard form: 1 Ts 1 Kp * (1 + ---- * ------ + Td * ---------------) Ti z-1 (Td/N)+Ts/(z-1) with Kp = 2.75, Ti = 0.045833, Td = 0.0075758, N = 0.090909, Ts = 0.1
For this particular sys, you cannot write sys in standard PID form using the BackwardEuler formula for the DFormula. Doing so would result in N < 0, which is not permitted. In that case, pidstd returns an error.
Similarly, you cannot write sys in standard form using the Trapezoidal formula for both integrators. Doing so would result in negative Ti and Td, which also returns an error.
Discretize a continuous-time pidstd controller.
First, discretize the controller using the 'zoh' method of c2d.
Cc = pidstd(1,2,3,4) % continuous-time pidf controller Cd1 = c2d(Cc,0.1,'zoh')
c2d computes new parameters for the discrete-time controller:
Discrete-time PIDF controller in standard form: 1 Ts 1 Kp * (1 + ---- * ------ + Td * ---------------) Ti z-1 (Td/N)+Ts/(z-1) with Kp = 1, Ti = 2, Td = 3.2044, N = 4, Ts = 0.1
The resulting discrete-time controller uses ForwardEuler (T_{s}/(z–1)) for both IFormula and DFormula.
The discrete integrator formulas of the discretized controller depend upon the c2d discretization method, as described in Tips. To use a different IFormula and DFormula, directly set Ts, IFormula, and DFormula to the desired values:
Cd2 = Cc; Cd2.Ts = 0.1; Cd2.IFormula = 'BackwardEuler'; Cd2.DFormula = 'BackwardEuler';
These commands do not compute new parameter values for the discretized controller. To see this, enter:
Cd2
to obtain the result:
Discrete-time PIDF controller in standard form: 1 Ts*z 1 Kp * (1 + ---- * ------ + Td * -----------------) Ti z-1 (Td/N)+Ts*z/(z-1) with Kp = 1, Ti = 2, Td = 3, N = 4, Ts = 0.1
pid | piddata | pidtool | pidtune