How to model the amount of state space is now used in the PID control method and is implemented by the M language:
To understand these two problems, deepen the understanding of the PID controller:
U = Kp * (x_last-x (i)) +
Ki * (x_last-2 * x (I-1) + x (i-2)) +
Kd * X_last
U is the control amount and the X_last is the target value. X (i) for the current value (formula specifically how to write forgot, but the form should be right)
1 scale adjustment cannot adjust the actual value to the target value!
Reason: We only look at the proportional portion, U = Kp * (x_last-x (i)), when the actual value toward the target value, the equal right to the 0,u is approaching 0, if the actual system of friction, air resistance, and so on, such phenomena are more obvious;
2 Why the integral link can control the actual value to the target value!
Cause: Ki * (x_last-2 * x (I-1) + x (i-2)), when the actual value approaching the target value, the integration content toward 0, and a constant derivative of 0, so the integral part of the final calculation is a fixed value, just to compensate for the proportion of the lack of regulation;
3 system may be limited by the physical limit to achieve the desired target value, such as the speed of the car to stabilize the 500m/s, the actual life of the current car is impossible to achieve;
For an example, consider the question of order:
Known: a= [ -2-1;1 0], B = [1; 0], is now using the P controller to control the system (to understand the P-control, integral differential content is also the same)
The Matlab script is as follows:
A = [ -2-1;1 0];
B = [1;0];
C = [0 0];%c value should be related to the order of AB
D = 0;
SYS = SS (a,b,c,d);% constituent space amount
Sys1 = c2d (sys,0.1),% to discrete, sample time 0.1s
x = [1;0];% System initial State
X_last = [0;0];% The ultimate goal we expect
Kp = [0.001 0.001];% coefficient can not be too large, the following will explain why the 2*1
%ki
%kd
% starts to adjust P
For i = 1:100
U = Kp * (x_last-x (:, i)), the amount of control calculated by the%u controller
X (:, i+1) = Sys1 (in). A * x (:, i) + sys1 (in). B * u;% in order to ensure consistency of the Matrix dimension, u must be 1*1, so KP needs to be 1*2
End
To this end of the program, here are a few points to note:
1 must pay attention to the matrix dimension problem, the dimension is prone to error;
2 cycle to ensure that each state can be recycled to;
Implementation of PID controller based on state space model in M language