Matlab and Simulink. Matlab and Simulink for Control



Similar documents
PID Controller Tuning: A Short Tutorial

G(s) = Y (s)/u(s) In this representation, the output is always the Transfer function times the input. Y (s) = G(s)U(s).

Control System Definition

Mathematical Modeling and Engineering Problem Solving

EE 402 RECITATION #13 REPORT

Module 2 Introduction to SIMULINK

Dynamic Process Modeling. Process Dynamics and Control

AC : MATHEMATICAL MODELING AND SIMULATION US- ING LABVIEW AND LABVIEW MATHSCRIPT

System Modeling and Control for Mechanical Engineers

MATLAB Control System Toolbox Root Locus Design GUI

Motor Control. Suppose we wish to use a microprocessor to control a motor - (or to control the load attached to the motor!) Power supply.

EDUMECH Mechatronic Instructional Systems. Ball on Beam System

PID Control. Chapter 10

Slide Basic system Models

Proceeding of 5th International Mechanical Engineering Forum 2012 June 20th 2012 June 22nd 2012, Prague, Czech Republic

Stabilizing a Gimbal Platform using Self-Tuning Fuzzy PID Controller

dspace DSP DS-1104 based State Observer Design for Position Control of DC Servo Motor

Time Response Analysis of DC Motor using Armature Control Method and Its Performance Improvement using PID Controller

Introduction to Engineering System Dynamics

Manufacturing Equipment Modeling

General Framework for an Iterative Solution of Ax b. Jacobi s Method

3.2 Sources, Sinks, Saddles, and Spirals

Chapter 9: Controller design

Low Pass Filter Rise Time vs Bandwidth

Understanding Poles and Zeros

Design-Simulation-Optimization Package for a Generic 6-DOF Manipulator with a Spherical Wrist

TEACHING AUTOMATIC CONTROL IN NON-SPECIALIST ENGINEERING SCHOOLS

AP1 Oscillations. 1. Which of the following statements about a spring-block oscillator in simple harmonic motion about its equilibrium point is false?

An Introduction to Applied Mathematics: An Iterative Process

ECE 3510 Final given: Spring 11

Vector Spaces; the Space R n

Active Vibration Isolation of an Unbalanced Machine Spindle

DCMS DC MOTOR SYSTEM User Manual

Lecture 07: Work and Kinetic Energy. Physics 2210 Fall Semester 2014

Motor Modeling and Position Control Lab Week 3: Closed Loop Control

Displacement (x) Velocity (v) Acceleration (a) x = f(t) differentiate v = dx Acceleration Velocity (v) Displacement x

Further Mathematics for Engineering Technicians

Temperature Control Loop Analyzer (TeCLA) Software

Controller Design in Frequency Domain

ECE 516: System Control Engineering

Introduction to LabVIEW for Control Design & Simulation Ricardo Dunia (NI), Eric Dean (NI), and Dr. Thomas Edgar (UT)

Controller and Platform Design for a Three Degree of Freedom Ship Motion Simulator

Power Electronics. Prof. K. Gopakumar. Centre for Electronics Design and Technology. Indian Institute of Science, Bangalore.

CITY UNIVERSITY LONDON. BEng Degree in Computer Systems Engineering Part II BSc Degree in Computer Systems Engineering Part III PART 2 EXAMINATION

W i f(x i ) x. i=1. f(x i ) x = i=1

MODELING FIRST AND SECOND ORDER SYSTEMS IN SIMULINK

Simulink Getting Started Guide

QNET Experiment #06: HVAC Proportional- Integral (PI) Temperature Control Heating, Ventilation, and Air Conditioning Trainer (HVACT)

is identically equal to x 2 +3x +2

Study of Effect of P, PI Controller on Car Cruise Control System and Security

MODELING, SIMULATION AND DESIGN OF CONTROL CIRCUIT FOR FLEXIBLE ENERGY SYSTEM IN MATLAB&SIMULINK

Laboratory 4: Feedback and Compensation

ENERGY TRANSFER SYSTEMS AND THEIR DYNAMIC ANALYSIS

EECE 460 : Control System Design

DAQ in MATLAB HANS-PETTER HALVORSEN,

Introduction to MATLAB Gergely Somlay Application Engineer

SGN-1158 Introduction to Signal Processing Test. Solutions

Students Manual for the Exam. General Engineering and Electrical Civil Engineering Discipline

Lab 2: Vector Analysis

AP Physics C. Oscillations/SHM Review Packet

In order to describe motion you need to describe the following properties.

2.161 Signal Processing: Continuous and Discrete Fall 2008

Implementation of Fuzzy and PID Controller to Water Level System using LabView

Energy transformations

Lecture 5 Rational functions and partial fraction expansion

3.6. Partial Fractions. Introduction. Prerequisites. Learning Outcomes

SECTION 19 CONTROL SYSTEMS

E x p e r i m e n t 5 DC Motor Speed Control

System of First Order Differential Equations

Imag Axis Real Axis

Experiment: Static and Kinetic Friction

Chapter 3: Mathematical Models and Numerical Methods Involving First-Order Differential Equations

Using MATLAB in a Graduate Electrical Engineering Optimal Control Course

ANALYTICAL METHODS FOR ENGINEERS

Chapter 4 One Dimensional Kinematics

Spacecraft Dynamics and Control. An Introduction

LINEAR MOTOR CONTROL IN ACTIVE SUSPENSION SYSTEMS

INTRODUCTION (Syllabus, Numerical Methods & Computational Tools)

Mathematics (MAT) MAT 061 Basic Euclidean Geometry 3 Hours. MAT 051 Pre-Algebra 4 Hours

BSEE Degree Plan Bachelor of Science in Electrical Engineering:

How to program a Zumo Robot with Simulink

APPLIED MATHEMATICS ADVANCED LEVEL

SOLID MECHANICS TUTORIAL MECHANISMS KINEMATICS - VELOCITY AND ACCELERATION DIAGRAMS

VELOCITY, ACCELERATION, FORCE

Basic Op Amp Circuits

Linearly Independent Sets and Linearly Dependent Sets

Kinetic Friction. Experiment #13

Physics 125 Practice Exam #3 Chapters 6-7 Professor Siegel

Control and Simulation. in LabVIEW

An Introduction to Using Simulink

Parameter identification of a linear single track vehicle model

Simple Harmonic Motion

Ch 7 Kinetic Energy and Work. Question: 7 Problems: 3, 7, 11, 17, 23, 27, 35, 37, 41, 43

1 Review of Least Squares Solutions to Overdetermined Systems

Matrix Calculations: Applications of Eigenvalues and Eigenvectors; Inner Products

Design of a Universal Robot End-effector for Straight-line Pick-up Motion

Numerical Methods for Differential Equations

Orbital Mechanics. Angular Momentum

F = ma. F = G m 1m 2 R 2

Cabrillo College Catalog

Transcription:

Matlab and Simulink for Control Automatica I (Laboratorio) 1/78 Matlab and Simulink CACSD 2/78

Matlab and Simulink for Control Matlab introduction Simulink introduction Control Issues Recall Matlab design Example Simulink design Example 3/78 Part I Introduction 4/78

Introduction What is Matlab and Simulink? What is Matlab High-Performance language for technical computing Integrates computation, visualisation and programming Matlab = MATrix LABoratory Features family of add-on, application-specific toolboxes 5/78 Introduction What is Matlab and Simulink? What are Matlab components? Development Environment The Matlab Mathematical Function Library The Matlab language Graphics The Matlab Application Program Interface 6/78

Introduction What is Matlab and Simulink? What is Simulink? Software Package for modelling, simulating and analysing dynamic systems Supports linear & Non-linear systems Supports continuous or discrete time systems Supports multirate systems Allows you to model real-life situations Allows for a top-down and bottom-up approach 7/78 Introduction What is Matlab and Simulink? How Simulink Works? 1. Create a block diagram (model) 2. Simulate the system represented by a block diagram 8/78

Matlab Environment Introduction Matlab&Simulink Getting Started 9/78 The Matlab Language Introduction Matlab&Simulink Getting Started Dürer s Matrix 1 A=[16 3 2 13; 5 10 11 8; 9 6 7 12;4 15 14 1]; 2 sum(a) %ans = 34 34 34 34 3 sum(a ) %ans = 34 34 34 34 4 sum( diag(a)) %ans = 34 Operators 1 100: 7:50 % 100 93 86 79 72 65 58 51 2 sum(a(1:4,4)) % ans = 34 10 / 78

Introduction Matlab&Simulink Getting Started The Matlab API You can use C or FORTRAN Pipes on UNIX, COM on Windows You can call Matlab routines from C/FORTRAN programs and vice versa You can call Java from Matlab 11 / 78 Introduction Matlab&Simulink Getting Started Simulink Environment 12 / 78

Starting Simulink Introduction Matlab&Simulink Getting Started Just type in Matlab 1 simulink 13 / 78 Part II Matlab Background 14 / 78

Laplace Transform Matlab Background Transfer Functions and Laplace Transforms Definition The Laplace Transform is an integral transform perhaps second only to the Fourier transform in its utility in solving physical problems. The Laplace transform is defined by: L [f (t)] (s) 0 f (t)e st dt Source: [1, Abramowitz and Stegun 1972] 15 / 78 Laplace Transform Matlab Background Transfer Functions and Laplace Transforms Several Laplace Transforms and properties f L [f (t)] (s) range 1 1 1 t t n n! e at 1 s a s s > 0 s > 0 s 2 n Z > 0 s n+1 s > a ] L t [f (n) (t) (s) =s n L t [f (t)] s n 1 f (0) s n 2 f (0)... f (n 1) (0) (1) This property can be used to transform differential equations into algebraic ones. This is called Heaviside calculus 16 / 78

Matlab Background Transfer Functions and Laplace Transforms Heaviside Calculus Example Let us apply the Laplace transform to the following equation: f (t)+a 1 f (t)+a 0 f (t) =0 which should give us: { s 2 L t [f (t)] (s) sf (0) f (0) } + +a 1 {sl t [f (t)] (s) f (0)} + +a 0 L t [f (t)] (s) =0 which can be rearranged to: L t [f (t)] (s) = sf (0) + f (0) + a 1 f (0) s 2 + a 1 s + a 0 17 / 78 Matlab Background Transfer Functions and Laplace Transforms Transfer Functions For Matlab modelling we need Transfer Functions To find the Transfer Function of a given system we need to take the Laplace transform of the system modelling equations (2) & (3) System modelling equations F = m v + bv (2) y = v (3) Laplace Transform: F (s) =msv (s)+bv (s) Y (s) =V (s) 18 / 78

Matlab Background Transfer Functions and Laplace Transforms Transfer Functions cntd. Assuming that our output is velocity we can substitute it from equation (5) Transfer Function Laplace Transform: Transfer Function: F (s) =msv (s)+bv (s) (4) Y (s) =V (s) (5) Y (s) F (s) = 1 ms + b (6) 19 / 78 Matlab Background Matlab Functions Matlab Functions Transfer Function I What is tf? Specifies a SISO transfer function for model h(s) =n(s)/d(s) 1 h = tf(num, den ) What are num & den? row vectors listing the coefficients of the polynomials n(s) and d(s) ordered in descending powers of s Source: Matlab Help 20 / 78

Matlab Background Matlab Functions Matlab Functions Transfer Function II tf Example T (s) = 2s 3 s+1 h=tf([2-3], [1 1]) T (s) = 2s+1 4s 2 +s+1 h=tf([2 1], [4 1 1]) 21 / 78 Matlab Background Matlab Functions Feedback I Matlab Functions Matlab code 1 sys = feedback( forward, backward ); Source: [2, Angermann et al. 2004] 22 / 78

Matlab Background Matlab Functions Feedback II Matlab Functions obtains a closed-loop transfer function directly from the open-loop transfer function no need to compute by hand Example Forward = 1 st i (7) Backward = V (8) T (s) = C(s) 1 R(s) = st i 1+V 1 st i feedback(tf(1,[ti 0]), tf(v, 1)) (9) Matlab Functions Step Response 23 / 78 Matlab Background Matlab Functions system=tf ([2 1],[4 1 1]); t =0:0.1:50; step(100 system) axis ([0 30 60 180]) 24 / 78

Matlab Background Steady-State Error Definition Steady-State Error Figure 1: Unity Feedback System Steady-State Error The difference between the input and output of a system in the limit as time goes to infinity 25 / 78 Steady-State Error Matlab Background Steady-State Error Steady-State Error e( ) = lim s 0 sr(s) 1+G(s) (10) e( ) = lim s 0 sr(s) 1 T (s) (11) 26 / 78

Matlab Background Proportional, Integral and Derivative Controllers Feedback controller How does it work I? Figure 2: System controller e represents the tracking error e difference between desired input (R) an actual output (Y) e is sent to controller which computes: derivative of e integral of e u controller output is equal to... 27 / 78 Matlab Background Proportional, Integral and Derivative Controllers Feedback controller How does it work II? u controller output is equal to: K p (proportional gain) times the magnitude of the error + Ki (integral gain) times the integral of the error + K d (derivative gain) times the derivative of the error Controller s Output u = K p e + K i edt + K d de dt Controller s Transfer Function K p + K i s + K ds = K ds 2 + K p s + K i s 28 / 78

Matlab Background Characteristics of PID Controllers Proportional, Integral and Derivative Controllers Proportional Controller K p reduces the rise time reduces but never eliminates steady-state error Integral Controller K i eliminates steady-state error worsens transient response Derivative Controller K d increases the stability of the system reduces overshoot improves transient response 29 / 78 Example Problem Matlab Background Proportional, Integral and Derivative Controllers Figure 3: Mass spring and damper problem Modelling Equation mẍ + bẋ + kx = F (12) 30 / 78

Matlab Background Proportional, Integral and Derivative Controllers Example Problem Laplace & Transfer Functions mẍ + bẋ + kx = F ms 2 X (s)+bsx (s)+kx (s) =F (s) (13) X (s) F (s) = 1 ms 2 + bs + k (14) 31 / 78 Matlab Background Proportional, Integral and Derivative Controllers Matlab System Response Assumptions Let: m =1[kg], b = 10[Ns/m], k = 20[N/m] Matlab code 1 %{ Set up variables%} 2 m=1; b=10; k=20; 3 %{ Calculate response%} 4 num=1; 5 den=[m, b, k ] ; 6 plant=tf(num, den ) ; 7 step(plant) 32 / 78

Matlab Background Proportional, Integral and Derivative Controllers Matlab System Response Figure 4: Amplitude Displacement 33 / 78 Matlab Background Proportional, Integral and Derivative Controllers Problems The steady-state error is equal to 0.95 equation (11) Therisetimeisabout1second The settling time is about 1.5 seconds The PID controller should influence (reduce) all those parameters 34 / 78

Matlab Background Proportional, Integral and Derivative Controllers Controllers Characteristics Type Rise time Overshoot Settling time S-S Error K p decrease increase small change decrease K i decrease increase increase eliminate K d small change decrease decrease small change These correlations may not be exactly accurate, because K p, K i,andk d are dependent on each other. In fact, changing one of these variables can change the effect of the other two. 35 / 78 Matlab Background Proportional, Integral and Derivative Controllers Proportional Controller P Transfer Function Matlab code X (s) F (s) = K p s 2 + bs +(k + K p ) 1 %{ Set up proportional gain%} 2 Kp=300; 3 %{ Calculate controller%} 4 sys ctl=feedback(kp plant, 1); 5 %{ Plot results%} 6 t=0:0.01:2; 7 step(sys ctl, t) 36 / 78

Matlab Background Proportional Controller Plot Proportional, Integral and Derivative Controllers Figure 5: Improved rise time & steady-state error 37 / 78 Matlab Background Proportional Derivative Controller Proportional, Integral and Derivative Controllers PD Transfer Function Matlab code X (s) F (s) = K d s + K p s 2 +(b + K d )s +(k + K p ) 1 %{ Set up proportional and derivative gain%} 2 Kp=300; Kd=10; 3 %{ Calculate controller%} 4 contr=tf ([Kd, Kp],1); 5 sys ctl=feedback(contr plant, 1); 6 %{ Plot results%} 7 t=0:0.01:2; 8 step(sys ctl, t) 38 / 78

Matlab Background Proportional Derivative Controller Plot Proportional, Integral and Derivative Controllers Figure 6: Reduced over-shoot and settling time 39 / 78 Matlab Background Proportional Integral Controller Proportional, Integral and Derivative Controllers PI Transfer Function X (s) F (s) = K p s + K i s 3 + bs 2 +(k + K p )s + K i Matlab code 1 %{ Set up proportional and integral gain%} 2 Kp=30; Ki=70; 3 %{ Calculate controller%} 4 contr=tf ([Kp, Ki],[1, 0]); 5 sys ctl=feedback(contr plant, 1); 6 %{ Plot results%} 7 t=0:0.01:2; 8 step(sys ctl, t) 40 / 78

Matlab Background Proportional Integral Controller Plot Proportional, Integral and Derivative Controllers Figure 7: Eliminated steady-state error, decreased over-shoot 41 / 78 Matlab Background Proportional, Integral and Derivative Controllers Proportional Integral Derivative Controller PID Transfer Function X (s) F (s) = K d s 2 + K p s + K i s 3 +(b + K d )s 2 +(k + K p )s + K i Matlab code 1 %{ Set up proportional and integral gain%} 2 Kp=350; Ki=300; Kd=50; 3 %{ Calculate controller%} 4 contr=tf ([Kd, Kp, Ki],[1, 0]); 5 sys ctl=feedback(contr plant, 1); 6 %{ Plot results%} 7 t=0:0.01:2; 8 step(sys ctl, t) 42 / 78

Matlab Background Proportional, Integral and Derivative Controllers Proportional Integral Derivative Controller Plot Figure 8: Eliminated steady-state error, decreased over-shoot 43 / 78 Part III Matlab Cruise Control System 44 / 78

Matlab Cruise Control System Design Criteria How does Cruise Control for Poor work? Figure 9: Forces taking part in car s movement Based on Carnegie Mellon University Library Control Tutorials for Matlab and Simulink 45 / 78 Matlab Cruise Control System Design Criteria Building the Model Using Newton s law we derive Where: m = 1200[kg], b = 50[ Ns m ], F = 500[N] F = m v + bv (15) y = v (16) 46 / 78

Matlab Cruise Control System Design Criteria Design Criteria ForthegivendataV max = 10[m/s] = 36[km/h] The car should accelerate to V max within 6[s] 10% tolerance on the initial velocity 2% of a steady-state error 47 / 78 Matlab Cruise Control System Matlab Representation Transfer Function System Equations: F = m v + bv y = v Laplace Transform: F (s) =msv (s)+bv (s) (17) Y (s) =V (s) (18) Transfer Function: Y (s) F (s) = 1 ms + b (19) 48 / 78

Matlab Cruise Control System Matlab Representation Matlab Representation Now in Matlab we need to type Matlab code 1 m=1200; 2 b=50; 3 num = [ 1 ] ; 4 den=[m,b ] ; 5 cruise=tf(num, den ) ; 6 step = (500 cruise ); 49 / 78 Results Matlab Cruise Control System Matlab Representation Figure 10: Car velocity diagram mind the design criteria 50 / 78

Matlab Cruise Control System Matlab Representation Design criteria revisited Our model needs over 100[s] to reach the steady-state The design criteria mentioned 5 seconds 51 / 78 Matlab Cruise Control System PID Controller Feedback controller To adjust the car speed within the limits of specification We need the feedback controller Figure 11: System controller 52 / 78

Matlab Cruise Control System Decreasing the rise time PID Controller Proportional Controller Y (s) R(s) = K p ms +(b + K p ) (20) Matlab code 1 Kp=100; m=1200; b=50; 2 num = [ 1 ] ; den =[m, b ] ; 3 cruise=tf(num, den ) ; 4 sys ctl=feedback(kp cruise, 1); 5 t=0:0.1:20; 6 step(10 sys cl,t) 7 axis ([0 20 0 10]) 53 / 78 Matlab Cruise Control System Under- and Overcontrol PID Controller Figure 12: K p =100 Figure 13: K p = 10000 54 / 78

Matlab Cruise Control System PID Controller Making Rise Time Reasonable Proportional Integral Controller Y (s) R(s) = K p s + K i ms 2 +(b + K p )s + K i (21) Matlab code 1 Kp=800; Ki=40; m=1200; b=50; 2 num = [ 1 ] ; den =[m, b ] ; 3 cruise=tf(num, den ) ; 4 contr=tf ([Kp Ki],[1 0]) 5 sys ctl=feedback(contr cruise, 1); 6 t=0:0.1:20; 7 step(10 sys cl,t) 8 axis ([0 20 0 10]) 55 / 78 Results Matlab Cruise Control System PID Controller Figure 14: Car velocity diagram meeting the design criteria 56 / 78

Part IV Simulink Cruise Control System 57 / 78 Simulink Cruise Control System Building the Model How does Cruise Control for Poor work? Figure 15: Forces taking part in car s movement Based on Carnegie Mellon University Library Control Tutorials for Matlab and Simulink 58 / 78

Physical Description Simulink Cruise Control System Building the Model Summing up all the forces acting on the mass Forces acting on the mass F = m dv dt + bv (22) Where: m=1200[kg], b=50[ Nsec m ], F=500[N] 59 / 78 Simulink Cruise Control System Physical Description cntd. Building the Model Integrating the acceleration to obtain the velocity Integral of acceleration a = dv dt dv dt = v (23) 60 / 78

Simulink Cruise Control System Building the Model in Simulink Building the Model Figure 16: Integrator block from Continuous block library 61 / 78 Simulink Cruise Control System Building the Model in Simulink Building the Model Obtaining acceleration Acceleration a = dv dt = F bv m (24) 62 / 78

Simulink Cruise Control System Building the Model Building the Model in Simulink Figure 17: Gain block from Math operators block library 63 / 78 Simulink Cruise Control System Building the Model Elements used in Simulink Model Friction (Gain block) Subtract (from Math Operators) Input (Step block from Sources) Output (Scope from Sinks) 64 / 78

Complete Model Simulink Cruise Control System Building the Model 65 / 78 Simulink Cruise Control System Building the Model Mapping Physical Equation to Simulink Model 66 / 78

Simulink Cruise Control System Setting up the Variables Simulating the Model Now it is time to use our input values in Simulink... F=500[N] In Step block set: Step time = 0 and Final value = 500...and adjust simulation parameters... Simulation Configuration Parameters... Stop time = 120...and set up variables in Matlab 1 m=1200; 2 b=50; 67 / 78 Running Simulation Simulink Cruise Control System Simulating the Model Choose Simulation Start Double-click on the Scope block... 68 / 78

Simulink Cruise Control System Extracting Model into Matlab Simulating the Model Replace the Step and Scope Blocks with In and Out Connection Blocks 69 / 78 Simulink Cruise Control System Verifying Extracted Model Simulating the Model We can convert extracted model into set of linear equations into transfer function Matlab code 1 [A, B, C, D]=linmod( cc2mtlb ); 2 [ num, den ]= ss2tf(a, B, C, D); 3 step(500 tf(num, den ) ) ; 70 / 78

Simulink Cruise Control System Simulating the Model Matlab vs Simulink Figure 18: Matlab Figure 19: Simulink 71 / 78 Simulink Cruise Control System Implementing the PI Control The open-loop system In Matlab section we have designed a PI Controller Kp = 800 Ki =40 We will do the same in Simulik First we need to contain our previous system in a Sybsystem block Choose a Subsystem block from the Ports&Subsystems Library Copy in the model we used with Matlab 72 / 78

Subsystem Simulink Cruise Control System Implementing the PI Control Figure 20: Subsystem Block and its Contents 73 / 78 PI Controller I Simulink Cruise Control System Implementing the PI Control Figure 21: Step: final value=10, time=0 74 / 78

PI Controller II Simulink Cruise Control System Implementing the PI Control Figure 22: We use Transfer Fcn block from Continuous-Time Linear Systems Library 75 / 78 Results Simulink Cruise Control System Implementing the PI Control Runnig simulation with time set to 15[s] 76 / 78

References Course basic references 77/78 Textbooks Digital Control of Dynamic Systems (3rd Edition) by Gene F. Franklin, J. David Powell, Michael L. Workman Publisher: Prentice Hall; 3 edition (December 29, 1997) ISBN: 0201820544 Lecture slides Computer Lab Exercises 78/78