Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics State Estimation with Observers HANS-PETTER HALVORSEN, 2012.08.20 Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01
Preface In this Lab we will implement an Observer in LabVIEW and MathScript. An Observer is an alternative to Kalman Filter. LabVIEW and LabVIEW Control Design and Simulation Module have advanced features for State Estimation. LabVIEW has a built-in Observer algorithm we will use, but we will also implement our own Observer algorithm from scratch. We will use the USB-6008 DAQ device and the Level Tank in this assignment. Go to the following website for more background information about the Lab Work: http://home.hit.no/~hansha/?lab=state_estimator_observer ii
Table of Contents Preface...ii Table of Contents... iii 1 Introduction... 4 1.1 Lab Equipment... 4 2 Modelling... 5 2.1 Introduction... 5 2.2 Tasks... 7 Task 1: Model parameter adjustment Trial and Error... 7 Task 2: State-space Model... 8 Task 3: Discretization... 8 3 Observers... 10 3.1 Introduction... 10 3.2 Tasks... 15 Task 4: Observer Gain... 15 Task 5: Built-in Observer Algorithm... 15 Task 6: Implement an Observer from scratch... 16 4 Control System... 17 Task 7: PI(D) Control... 17 iii
1 Introduction 1.1 Lab Equipment The LM-900 Level Tank equipment will be used in this Lab Work: You will also need the USB-6008 DAQ device. 4
2 Modelling 2.1 Introduction The LM-900 Level Tank equipment will be used in this Lab Work: A very simple (linear) model of the water tank is as follows: or [ ] Where: is the level in the water tank is the pump control signal to the pump is the cross-sectional area is the pump gain 5
6 Modelling [cm3/s] is the outflow through the valve (this outflow can be modeled more accurately taking into account the valve characteristic expressing the relation between pressure drop across the valve and the flow through the valve). In your application the sampling time can be set to 0.1 s. A more complicated/accurate and nonlinear model can be found here: http://home.hit.no/~finnh/dok_tankmodell/ Control Signal: A pump fills the tank with water from the reservoir. The pump speed can be controlled by a voltage signal in the range 0-5V. The pump can be controlled by an external voltage signal at the FROM PC connector. Measurement Signal: The measurement is a voltage signal in the range 0-5V available at the TO PC connector. This voltage range corresponds to a level range of 0-20 cm, approximately (unless you need a more accurate relation, you can assume this range in your applications). Scaling: You need to scale the signal to. The following linear relationship applies: You have to find (slope) and (intercept). The following formulas may be used:
7 Modelling This gives: where 2.2 Tasks Task 1: Model parameter adjustment Trial and Error Adjust the model parameters, from experiments on the real process. You need to use the LM-900 Level Tank equipment and the USB-6008 DAQ for this task. Show by simulations where you run the real process in parallel with the simulated model that you have found proper values. Note! can be found directly if you measure the radius in the tank ( ). Note! [End of Task]
8 Modelling Task 2: State-space Model For the real system, only the level ( ) is measured, so we want to use Kalman Filter and Observers for estimating the outflow ( ) of the tank. Set up the system on the following form ( pen and paper ): Set and Assume that is constant, i.e., Find the matrices. MathScript: Implement the state-space model in MathScript LabVIEW: Implement the state-space model in LabVIEW. [End of Task] Task 3: Discretization Find the discrete linear state-space model on the following form: Use the Euler Forward discretization method. Where is the sampling time. Find the matrices. LabVIEW: Use LabVIEW to convert the continuous model to a discrete state-space model from the previous task. Compare the results with your calculations.
9 Modelling MathScript: Find the discrete state-space model in MathScript. Compare the results. [End of Task]
3 Observers 3.1 Introduction An alternative to Kalman Filters are Observers. Observers have the same structure as the Kalman Filter, but they are calculated from specified estimator error dynamics, or in other words: how fast and stable you want the estimates to converge to the real values. A necessary condition when using Observers is that the system needs be observable. Given the following linear system: The Observability matrix is defined as: [ ] Where is the system order, i.e., number of states. A system is observable if the Observability matrix has full rank: The rank is given by the determinant. If the determinant is not equal zero, then the Observability matrix has full rank and the system is observable. The Observer Gain is given by the eigenvalues for : Example: Given the following system: ( ) [ ] [ ] [ ] [ ] 10
11 Observers [ ] Observability matrix: The Observability matrix is given by: [ ] This gives: [ ] Finally: [ ] [ ] [ ] Determinant: We find the determinant: For a 2x2 system we have: [ ] Then we get: ([ ]) MathScript: In MathScript we can write the following code: clear, clc % Define system A = [0, 1; 0, 0]; B = [0; 1]; C = [1, 0]; D = [0]; ssmodel = ss(a, B, C, D); O = obsvmx(ssmodel)
12 Observers rank(o) det(o) Observer Gain: Next we want to find the Observer Gain: A 2.ordens Butterworth polynomial is defined as: Where. This gives: The Observer Gain is: [ ] The Observer system matrix ( ) becomes: [ ] [ ] [ ] [ ] [ ] The characteristic equation becomes: ( ) ([ ] [ ]) ([ ]) A 2.order Butterworth filter has the following polynomial: This gives: ( ) We compare and get:
13 Observers This gives: [ ] [ ] Then we have: For simplicity we set This gives: Finally: MathScript: We use the roots() and acker() functions: A = [0, 1; 0, 0]; B = [0; 1]; C = [1, 0]; D = [0]; n=2; Tr=2; T=Tr/n; B2=[T*T, 1.4142*T, 1]; eigenvalues=roots(b2); K=acker(A,C,eigenvalues,'o') %o for observer This gives: K = 1.4142 1 LabVIEW:
14 Observers In LabVIEW we define the polynomial like this: We use the CD Ackermann.vi in order to find the Observer Gain K. Block Diagram: Front Panel: As you see, we get the same results either we use pen and paper, MathScript or LabVIEW.
15 Observers [End of Example] LabVIEW have several built-in algorithms. Below we see the Estimation palette in LabVIEW (Control Design & Simulation Simulation Estimation): LabVIEW have built-in algorithms, both for continuous systems and discrete systems. 3.2 Tasks Do the following tasks: Task 4: Observer Gain Check for Observability and find the Observer Gain using Pen and Paper. Check your answer by using MathScript. Use the Ackermann (acker() function). You may set, e.g.,. [End of Task] Task 5: Built-in Observer Algorithm Estimate the process variables using Observer on the simulated tank. Use one of the built-in functions in LabVIEW. LabVIEW have several built-in algorithms, but in this task you can use the CD Continuous Observer.vi function.
16 Observers Add noise in the simulated model to make it more realistic. You can use, e.g., the Gaussian White Noise PtByPt.vi. Extend your application and use the Observer on Real Process. With the real tank, use your state estimators (simultaneuously, i.e. in parallel) to estimate. Change the outflow by adjusting manually the outlet valve. Discuss the results. [End of Task] Task 6: Implement an Observer from scratch I this task you shall implement your own Observer algorithm from scratch in LabVIEW. The general Observer algorithm is as follows: Step 1: Find Measurement Estimate For linear systems: Step 2: Find estimator error: Step 3: Find corrected and predicted state estimate: For linear systems: K is the Observer Gain. Use Ackermann to find the Observer Gain ( CD Ackermann.vi ). [End of Task]
4 Control System Here you will control the system using a standard PI(D) controller. Task 7: PI(D) Control Implement a PI(D) Control System for your system. You shall control the level in the water tank. Use the built-in PID controller in LabVIEW. The Observer Estimator shall be running in parallel (use either the built-in or your own algorithm). Find proper PI(D) parameters using the Skogestad's method. You cannot use the Good Gain method or the Ziegler-Nichols' method because the process has almost no time-delay. A reasonable process model is a time-constant (with zero time-delay, ): You need to apply a step on the input and then observe the response and the output, as shown below: Here are the Skogestad s formulas for finding the PID parameters: 17
18 Control System In this task we can set sec and. For more details about the Skogestads method, please read this article: Model-based PID tuning with Skogestad s method. Discuss the results. Create the application so that you can use the estimated level instead of the measured level if the measurement for some reason is not available. Try it out by removing the cables from the DAQ device. Discuss the results. [End of Task]
Telemark University College Faculty of Technology Kjølnes Ring 56 N-3918 Porsgrunn, Norway www.hit.no Hans-Petter Halvorsen, M.Sc. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics E-mail: hans.p.halvorsen@hit.no Blog: http://home.hit.no/~hansha/