# Implementation of PID controller based on state space model in M language

Source: Internet
Author: User
Tags time 0

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

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

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.