Control Tutorials for MATLAB and Simulink (2024)

Related Tutorial Links

  • Digital Control Intro
  • Discrete Poles
  • Sampling Activity

Related External Links

Key MATLAB commands used in this tutorial are: ss , c2d , rank , ctrb , dlqr , lsim , stairs

Contents

  • Discrete state-space
  • Controllability
  • Control design via pole placement
  • Adding precompensation

In this page, we will consider the digital version of the aircraft pitch control problem. A sampled-data version of the airplance pitch dynamics can be obtained from the continuous model, as we will describe. In this example we will apply state-space techniques to design the controller.

From the Aircraft Pitch: System Modeling page, the continous-time state-space model of the aircraft pitch dynamics was derived as

(1)Control Tutorials for MATLAB and Simulink (1)

(2)Control Tutorials for MATLAB and Simulink (2)

where the input is elevator deflection angle Control Tutorials for MATLAB and Simulink (3) and the output is the aircraft pitch angle Control Tutorials for MATLAB and Simulink (4).

For a step reference of 0.2 radians, the design criteria are the following.

  • Overshoot less than 10%
  • Rise time less than 2 seconds
  • Settling time less than 10 seconds
  • Steady-state error less than 2%

Discrete state-space

The first step in the design of a digital control system is to generate a sampled-data model of the plant. MATLAB can be used to generate this model from a continuous-time model using the c2d command. The c2d command requires three arguments: a system model, the sampling time (Ts) and the type of hold circuit. In this example we will assume a zero-order hold (zoh) circuit. Refer to the Introduction: Digital Controller Design page, for further details.

In choosing a sample time, note that it is desired that the sampling frequency be fast compared to the dynamics of the system in order that the sampled output of the system captures the system's full behavior, that is, so that significant inter-sample behavior isn't missed. One measure of a system's "speed" is its closed-loop bandwidth. A good rule of thumb is that the sampling frequency be at least 30 times larger than the closed-loop bandwidth frequency which can be determined from the closed-loop Bode plot.

From the closed-loop Bode plot, the bandwidth frequency can be determined to be approximately 2 rad/sec (0.32 Hz). You may verify this yourself. Thus, to be sure we have a small enough sampling time, we will use a sampling time of 1/100 sec/sample. Now we are ready to use the c2d function. Enter the following commands in an m-file. Running this m-file in the MATLAB command window gives you the following four matrices representing the sampled-data state-space model.

A = [-0.313 56.7 0; -0.0139 -0.426 0; 0 56.7 0];B = [0.232; 0.0203; 0];C = [0 0 1];D = [0];sys_ss = ss(A,B,C,D);Ts = 1/100;sys_d = c2d(sys_ss,Ts,'zoh')
sys_d = A = x1 x2 x3 x1 0.9968 0.5649 0 x2 -0.0001385 0.9957 0 x3 -3.931e-05 0.5658 1 B = u1 x1 0.002374 x2 0.0002024 x3 5.744e-05 C = x1 x2 x3 y1 0 0 1 D = u1 y1 0 Sample time: 0.01 secondsDiscrete-time state-space model.

Now we have obtained the discrete-time state-space model shown below.

Control Tutorials for MATLAB and Simulink (5)

Control Tutorials for MATLAB and Simulink (6)

Controllability

As was the case in the continuous case, before we can design our controller we must verify the controllability of the system. For the system to be completely state controllable the controllability matrix must have rank Control Tutorials for MATLAB and Simulink (7) where the rank of a matrix is the number of linearly independent rows (or columns). The controllability matrix of a discrete-time system has the same form as a continous-time system.

(3)Control Tutorials for MATLAB and Simulink (8)

Since our controllability matrix is 3x3, its rank must be 3. The MATLAB command rank can calculate the rank of a matrix for you. Adding the following additional commands to your m-file and running in the MATLAB command window will produce the following output.

co = ctrb(sys_d);Controllability = rank(co)
Controllability = 3

Therefore, our system is completely state controllable since the controllability matrix has rank 3.

Control design via pole placement

The schematic of a discrete full-state feedback control system is shown below, where Control Tutorials for MATLAB and Simulink (9) is the delay operator (not the aircraft's pitch rate Control Tutorials for MATLAB and Simulink (10)). Note that it is assumed that Control Tutorials for MATLAB and Simulink (11) = 0.

Control Tutorials for MATLAB and Simulink (12)

where

  • Control Tutorials for MATLAB and Simulink (13) = control gain matrix
  • Control Tutorials for MATLAB and Simulink (14) = Control Tutorials for MATLAB and Simulink (15) = state vector
  • Control Tutorials for MATLAB and Simulink (16) = reference (Control Tutorials for MATLAB and Simulink (17))
  • Control Tutorials for MATLAB and Simulink (18) = Control Tutorials for MATLAB and Simulink (19) = control input (Control Tutorials for MATLAB and Simulink (20))
  • Control Tutorials for MATLAB and Simulink (21) = output (Control Tutorials for MATLAB and Simulink (22))

Referring back to the state-space equations at the top of the page, we see that substituting the state-feedback law Control Tutorials for MATLAB and Simulink (23) for Control Tutorials for MATLAB and Simulink (24) leads to the following where we will assume that all of the state variables are measured.

(4)Control Tutorials for MATLAB and Simulink (25)

(5)Control Tutorials for MATLAB and Simulink (26)

In the continuous Aircraft Pitch: State-Space Methods for Controller Design page, the Linear Quadratic Regulator (LQR) method was used to find the control matrix (Control Tutorials for MATLAB and Simulink (27)). In this digital version, we will use the discrete version of the same LQR method. This type of control technique optimally balances the system error and the control effort based on a cost that the designer specifies that defines the relative importance of minimizing errors and minimimizing control effort. In the case of the regulator problem, it is assumed that the reference is zero. Therefore, in this case the magnitude of the error is equal to the magnitude of the state. Please consult your control textbook for details. To use this LQR method, we need to define two parameters: the state-cost weighted matrix (Control Tutorials for MATLAB and Simulink (28)) and the control weighted matrix (Control Tutorials for MATLAB and Simulink (29)). For simplicity, we will choose the control weighted matrix equal to 1 (Control Tutorials for MATLAB and Simulink (30) = 1), and the state-cost matrix (Control Tutorials for MATLAB and Simulink (31)) equal to Control Tutorials for MATLAB and Simulink (32). Employing the vector Control Tutorials for MATLAB and Simulink (33) from the output equation means that we will only consider those states in the output in defining our cost. In this case, Control Tutorials for MATLAB and Simulink (34) is the only state variable in the output. The weighting factor (Control Tutorials for MATLAB and Simulink (35)) will be chosen by trial and error in order to modify the step response to achieve our given requirements. In this case, Control Tutorials for MATLAB and Simulink (36) is a scalar since we have a single input system.

Now we are ready to find the control matrix (Control Tutorials for MATLAB and Simulink (37)) employing the MATLAB command dlqr which is the dicrete-time version of the lqr command. We will choose a weighting factor Control Tutorials for MATLAB and Simulink (38) equal to 50, as determined in the continuous Aircraft Pitch: State-Space Methods for Controller Design page, Add the following commands to your m-file and run it in the MATLAB command window. Note that in the following we are overwriting the values of the state-space matrices Control Tutorials for MATLAB and Simulink (39), Control Tutorials for MATLAB and Simulink (40), Control Tutorials for MATLAB and Simulink (41), and Control Tutorials for MATLAB and Simulink (42) with their discrete-time equivalents using the model derived with the c2d command above.

A = sys_d.a;B = sys_d.b;C = sys_d.c;D = sys_d.d;p = 50;Q = p*C'*CR = 1;[K] = dlqr(A,B,Q,R)
Q = 0 0 0 0 0 0 0 0 50K = -0.6436 168.3611 6.9555

Note the structure of the weighting matrix Control Tutorials for MATLAB and Simulink (43) and the resulting gain matrix Control Tutorials for MATLAB and Simulink (44). Referring to the closed-loop state equations given above assuming a control law with non-zero reference, Control Tutorials for MATLAB and Simulink (45), we can then generate the closed-loop step response by adding the following commands to your m-file and running it in the MATLAB command window. The stairstep response shown below should then be generated.

time = 0:0.01:10;theta_des = 0.2*ones(size(time));sys_cl = ss(A-B*K,B,C,D,Ts);[y,t] = lsim(sys_cl,theta_des);stairs(t,y)xlabel('time (sec)');ylabel('pitch angle (rad)');title('Closed-Loop Step Response: DLQR');

Control Tutorials for MATLAB and Simulink (46)

Examination of the above demonstrates that the rise time, overshoot, and settling time are satisfactory. However, there is a large steady-state error. One way to correct this is by introducing a precompensator (Control Tutorials for MATLAB and Simulink (47)) to scale the overall output.

Adding precompensation

Unlike other design methods, the full-state feedback system does not compare the output to the reference; instead, it compares all states multiplied by the control matrix (Control Tutorials for MATLAB and Simulink (48)) to the reference (see the schematic shown below). Thus, we should not expect the output to equal the commanded reference. To obtain the desired output, we can scale the reference input so that the output does equal the reference in steady state. This can be done by introducing a precompensator scaling factor called Control Tutorials for MATLAB and Simulink (49). The basic schematic of our state-feedback system with scaling factor (Control Tutorials for MATLAB and Simulink (50)) is shown below.

Control Tutorials for MATLAB and Simulink (51)

Unfortunately, we can not use our user-defined function rscale.m to find Control Tutorials for MATLAB and Simulink (52) because it is only defined for continuous systems. We can, however, find the correct scaling by trial and error. After several trials, it was found that Control Tutorials for MATLAB and Simulink (53) equal to 6.95 provided a satisfactory response. Modify your m-file as shown below. Running your m-file at the MATLAB command line will then generate the stairstep response shown below.

Nbar = 6.95;sys_cl = ss(A-B*K,B*Nbar,C,D,Ts);[y,t] = lsim(sys_cl,theta_des);stairs(t,y)xlabel('time (sec)');ylabel('pitch angle (rad)');title('Closed-Loop Step Response: DLQR with Precompensation');

Control Tutorials for MATLAB and Simulink (54)

From this plot, we see that the Control Tutorials for MATLAB and Simulink (55) factor eliminates the steady-state error. Now all design requirements are satisfied.


Published with MATLAB® 9.2

Control Tutorials for MATLAB and Simulink (2024)

FAQs

How do I find answers in MATLAB? ›

To view all of your solutions, go to a Problem page and click View my solutions. You can view your solutions in a list or in the Solution Map. If using the list view, you can review the display by selecting a Sort by option.

Is MATLAB Simulink hard to learn? ›

MATLAB is designed for the way you think and the work you do, so learning is accessible whether you are a novice or an expert. The Help Center is always available to guide you with robust documentation, community answers, and how-to videos. Additionally, online interactive training is a great way to get started.

What is the control model in Simulink? ›

Simulink® Control Design™ lets you design and analyze control systems modeled in Simulink. You can automatically tune arbitrary SISO and MIMO control architectures, including PID controllers.

How long does it take to learn MATLAB? ›

If you're a novice programmer, you can expect it to take a little longer than if you were a more seasoned programmer. Someone who can afford to devote all their time to MATLAB can finish learning the language in two weeks. If you have a lot of other responsibilities, however, it will take you longer to complete.

How do you get a long answer in MATLAB? ›

To format the way numbers display, do one of the following:
  1. On the Home tab, in the Environment section, click Preferences. Select MATLAB > Command Window, and then choose a Numeric format option.
  2. Use the format function, for example: format short format short e format long.

Is MATLAB harder than Python? ›

Learning curve: Python is significantly simpler than Matlab and doesn't require as much background knowledge. Matlab is structured in a very logical and comprehensible way but is aimed at users with a deep knowledge of math.

What is the salary of MATLAB Simulink? ›

Matlab Simulink Developer salary in India ranges between ₹ 2.9 Lakhs to ₹ 15.0 Lakhs with an average annual salary of ₹ 5.0 Lakhs.

Is MATLAB enough for a job? ›

Conclusion. The industry has some familiar buzz that learning MATLAB will not be a good opportunity for a better career. But this is not fully true. Yes, it is an acceptable reason that salary or company structure will never be able to touch available popular jobs on other programming technologies.

Can I learn MATLAB on my own? ›

Get Started with Introductory Videos

See common applications and workflows, and discover new product capabilities. Get started with MATLAB by walking through an example. This video shows you the basics, and it gives you an idea of what working in MATLAB is like.

What should I learn first MATLAB or Python? ›

The OOP in MATLAB is more advanced and complex, which to some can be more confusing. That being said, MATLAB is generally a more advanced language while Python is more of a beginner's language. Therefore, just because MATLAB may be more complex and confusing at first, with practice, it will become easier to grasp.

Is MATLAB or Python better for machine learning? ›

MATLAB may have an edge for computationally intensive tasks, but for general-purpose programming, data manipulation, and machine learning, Python's performance is often deemed satisfactory.

How to understand Simulink model? ›

In Simulink, systems are drawn on screen as block diagrams. Many elements of block diagrams are available, such as transfer functions, summing junctions, etc., as well as virtual input and output devices such as function generators and oscilloscopes.

What is Simulink used for in MATLAB? ›

Simulink is the platform for Model-Based Design that supports system-level design, simulation, automatic code generation, and continuous test and verification of embedded systems. Key capabilities include: A graphical editor for modeling all components of a system.

How to design a controller in MATLAB? ›

To design a controller, first select the controller sample time and horizons, and specify any required constraints. For more information, see Choose Sample Time and Horizons and Specify Constraints. You can then adjust the controller weights to achieve your desired performance.

How do I find Solver in MATLAB? ›

Open the model vdp . To allow the software to select the solver to use for the model, specify the Type parameter as Fixed-step or Variable-step , and set the Solver parameter to auto . For this example, configure the software to select a variable-step solver for the model.

How to check results in MATLAB? ›

View Results in Command Window

The Summary Report link provides access to the Model Advisor Command-Line Summary report. You can review additional results in the Command Window by calling the DisplayResults parameter when you run the Model Advisor.

How do you find the step response in MATLAB? ›

[ y , tOut ] = step( sys , tFinal ) computes the step response from t = 0 to the end time t = tFinal . [ y , tOut ] = step( sys , t ) returns the step response of a dynamic system model sys at the times specified in the vector t .

How do I find something in MATLAB code? ›

Search Using Find Dialog Box

The Find dialog box opens. The search begins at the current cursor position. MATLAB finds the text you specified and highlights it. MATLAB beeps when a search for Find Next reaches the end of the Command Window, or when a search for Find Previous reaches the top of the Command Window.

References

Top Articles
Latest Posts
Article information

Author: Neely Ledner

Last Updated:

Views: 5389

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.