You are on page 1of 32

Manufacturing Controls

FALL 2001 Lecture 19

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

Syllabus

DATE TOPIC 1. Sep. 20 2. Sep. 25 3. Sep. 27 4. Oct. 2 5. Oct. 4 6. Oct. 9 7. Oct. 11 8. Oct. 16 9. Oct. 18 10. Oct. 23

Mechatronics Design Process System Modeling and Simulation Laplace Transforms and Transfer Functions Electrical Examples Mechanical Examples More Examples, Thermal and Fluid Examples, QUIZ 1 (Take Home) Sensors and Transducers Digital control, Advanced MATLAB Analog and Digital Sensing Ch. 3, Notes Actuating Devices, time and frequency response

NOTES Ch. 1 Ch. 2 Ch. 2 Ch.2, Notes Ch.2, Notes Ch. 3

Ch. 4

11. Oct. 25
12. Oct. 30 13. Nov. 1 14. Nov. 6 15. Nov. 8 16. Nov. 13 17. Nov. 15 18. Nov. 20 19. Nov. 22 20. Nov. 27 21. Nov. 29 22. Dec.

DC Motor Model,
Examples
Boolean Logic ,Programmable Logic Controllers

Ch. 4, Notes Ch. 5


Ch. 5, Notes Ch. 6 Ch. 7 Ch. 8 Ch. 9, Notes Ch. 9, Notes Ch. 9, Notes Comprehensive

Stability and Compensators, P, PI and PD PID Controllers - Review QUIZ 2 (In Class - Open Book) Practical and Optimal Compensator Design Frequency Response Methods THANKSGIVING HOLIDAY Optimal Design of a Motion Control System REVIEW QUIZ 3 (In Class - Closed Book) FINAL EXAM (In Class - Closed Book)

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

Todays objective

To test the accomplishment of our objective of understanding systems theory by solving problems related to the concepts of optimal control systems for feedback control lets try some practice problems.

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

1. Medium-Scale Unconstrained Example


Unconstrained example Consider the problem of finding a set of values[x1,x2] that solves
x1 2 1 2 2

min f ( x) (2 x 4 x 2 x1 x2 4 x2 2)
x

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

Solution

Write an M-file that returns the function value

Call it objfun.m

Then invoke the unconstrained minimization routine

Use fminunc

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

Function

function f = objfun(x)
f=exp(x(1))*(2*x(1)^2+4*x(2)^2+2*x(1)*x(2)+4*x(2)+2);

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

Step 2 Invoke one of the optimization routines


x0 = [-1,1]; % Starting guess options = optimset(LargeScale,off);


[x,fval,exitflag,output]=fminunc(objfun,x0,options); Try this. After 40 iterations, it should produce the solution X= 0.50000 -1.0000
(C) 2001, Ernest L. Hall, University of Cincinnati 7

11/2/2013

And

The function at the solution x is returned in fval:

fval =

1.3030e-10

The exitflag tells if the algorithm converged. An exitflag > 0 means than a local minimum was found. exitflag = 1
11/2/2013 (C) 2001, Ernest L. Hall, University of Cincinnati 8

Output structure gives more details

For fminunc, it includes the number of iterations, the number of function elaluations, the final step size, a measure of first-order optimality, and the type algorithm used. output =

iterations: 7 funcCount: 40 stepsize: 1 firstorderopt: 9.280e-004 algorithm: medium-scale: Quasi-Newton line search
(C) 2001, Ernest L. Hall, University of Cincinnati 9

11/2/2013

Simulink Example

Suppose we want to optimize the control parameters in the Simulink model


optsim.mdl Look in directory X:\matlabR12/toolbox\optim\optsim.mdl

This model may be found in the Optimization Toolbox directory. Lets look for it. Try it. This will also check that Simulink is installed.
(C) 2001, Ernest L. Hall, University of Cincinnati 10

11/2/2013

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

11

Simulink mdl file

The model is a nonlinear process plant

Limit amplifier Rate amplifier Under-damped third-order system

The actuator limits are a saturation limit and a slew rate limit. The saturation limit cuts off input values greater than 2 units and less than -2 units The slew rate limit is 0.8 units/sec.
(C) 2001, Ernest L. Hall, University of Cincinnati 12

11/2/2013

Examine the response

At the Matlab command prompt, type

optsim

Open the Scope block by double clicking on it. Run the simulation. The output is oscillatory. The problem is to design a feedback control law that tracks a unit step input function.

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

13

Closed loop plant

The closed-loop plant is entered in terms of the blocks where the plant and actuator have been placed in a hierarchical Subsystem block. A Scope block displays output trajectories during the design process. A PID controller is used.

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

14

Optimization approach

One way to solve the problem is to minimize the error between the output and input signals. The variables are the parameters of the PID controller. If you need to minimize the error at one time value, the problem would require a single objective function. However, let us set the goal to minimize the error for all time steps from 0 to 100. This produces a multiobjective function with one function per time step.
(C) 2001, Ernest L. Hall, University of Cincinnati 15

11/2/2013

Use the routine lsqnonlin

lsqnonlin is used to perform a least squares fit on tracking the output. This is defined by a Matlab function in the file

tracklsq.m It defines the error signal, yout. The output is computed by calling sim, minus the input signal 1

Error =yout-1

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

16

tracklsq

tracklsq must run the simulation. The simulation may be run either in the base workspace or the current workspace, i.e, the workspace of the function calling sim which in this case is the tracklsqs workspace. In this example, the simset command is used to tell sim to run the simulation in the current workspace by setting SrcWorkspace to current.
(C) 2001, Ernest L. Hall, University of Cincinnati 17

11/2/2013

Running the simulation

To run the simulation in optsim, the variables

Kp, Kd and Ki And a1 and a2 that are variables in the plant block Must all be defined.

You can initialize a1 and a2 before calling lsqnonlin and then pass these two variables as additional arguments. lsqnonlin will then pass a1 and a2 to tracklsq each time it is called so you do not have to use global variables.
(C) 2001, Ernest L. Hall, University of Cincinnati 18

11/2/2013

Choosing a solver

After choosing a solver using the simset function, the simulation is run using sim. The simulation is performed using a fixed-step fifthorder method to 100 seconds. When the simulation completes, the variables tout, xout and your are now in the current workspace (the workspace of tracklsq). The Outport block is used in the block diagram model to put yout into the current workspace at the end of the simulation.
(C) 2001, Ernest L. Hall, University of Cincinnati 19

11/2/2013

Procedure

Step 1- Write an M-file

tracklsq.m

Step 2 Invoke optimization routine

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

20

tracklsq.m

Function F = tracklsq(pid,a1,a2)

Kp = pid(1); % Move variables into model parameters Ki = pid(2); Kd = pid(3); % choose solver and set model workspace to this function opt = simset('solver', 'ode5', 'SrcWorkspace', 'Current'); [tout, xout, yout] = sim('optsim', [0 100], opt); F = yout-1; % compute error signal

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

21

optsim

Step 2: The second file invokes the model and the optimizing routine
optsim % load the model pid0 = [0.63 0.0504 1.9688] % setting initial values a1 = 3; a2 = 43;% initialize Plant variables in model options = optimset('LargeScale', 'off', 'Display', 'iter', 'TolX', 0.001, 'TolFun', 0.001); pid = lsqnonlin(tracklsq', pid0, [], [], options, a1, a2) % put variables back into the base workspace Kp = pid(1); Ki = pid(2); Kd = pid(3);

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

22

Options

The variable options passed to lsqnonlin define the criteria and display characteristics. In this case you ask for output, use the medium-scale algorithm, and give termination tolerances for the step and objective function on the order of 0.001.

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

23

Try it!

This should converge in 10 iterations and give final values of pid = 2.9108 0.1443 12.8161

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

24

Challenge-Given the Simulink model of the motor system- select the optimum values of the digital PID controller (a,b,g,f).

Step Input

+ Sum

gs 2+(g*a+f)s+f*b s 2+bs The PID controller

1 .0005s+1 Zero Order Hold

0.00122 DAC

2 AMP

.54 .0003773s2 Motor and Load

-KGain2 Auto-Scale Graph Auto-Scale Graph1

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

25

Model explanation

Step input signal fed to a summation block Constant values to be used are calculated using a separate M-file Analog values in the Mat lab kernel Zero order hold DAC Amplifier Encoder feedback fed to the summation block for correction

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

26

Optimization of the parameters


11/2/2013

Non-linear model Enables the system to track a unit step input into the system Two methods are used lsqnonlin is the non-linear least squares method. It minimizes the error between the output and input fminmax minimizes the maximum value of the output at anytime. The first method is chosen It is a multi-objective function because the error needs to be minimized for all time steps
(C) 2001, Ernest L. Hall, University of Cincinnati 27

lsqnonlin method
Least square fit on the tracking of output E = input-output Objective is Minimize

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

28

Mat lab optimizing files

Step 1: the first file defines the function

function F = lsq(pid, a1, a2) Kp = pid(1); % Move variables into model parameters Ki = pid(2); Kd = pid(3); % choose solver and set model workspace to this function opt = simset('solver', 'ode5', 'SrcWorkspace', 'Current'); [tout, xout, yout] = sim('optsim', [0 100], opt); F = yout-1; % compute error signal

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

29

Mat lab optimizing files contd.

Step 2: The second file invokes the model and the optimizing routine
kolmodel % loads the model pid0 = [1 10 12] % setting initial values a1 = 0; a2 = 0.0005; options = optimset('LargeScale', 'off', 'Display', 'iter', 'TolX', 0.001, 'TolFun', 0.001); pid = lsqnonlin('lsq', pid0, [], [], options, a1, a2) % put variables back into the base workspace Kp = pid(1); Ki = pid(2); Kd = pid(3);

Initial values of the parameters are defined


(C) 2001, Ernest L. Hall, University of Cincinnati 30

11/2/2013

Optimization results

Kp, Ki, Kd values after 55 function evaluations


pid0 = 1 5 10 Step-size 1 0.375 0.253 0.293 0.0868 0.119 3.28e-007 Directional derivative -4.91e+012 -1.51e+011 -2.33e+011 -8.38e+010 -8.32e+010 -1.63e+011 -3.27e+011 Lambda 1.32032e+012 8.77204e+011 1.68981e+012 2.02202e+012 2.60576e+012 1.07078e+018

Iteration Func-count Residual 1 3 4.76719e+012 2 10 4.70723e+012 3 17 4.65431e+012 4 24 4.58281e+012 5 31 4.56367e+012 6 39 4.53102e+012 7 55 4.53102e+012 Optimization terminated successfully: Search direction less than tolX pid = 0.7234

4.9399 10.0233

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

31

Any questions?

11/2/2013

(C) 2001, Ernest L. Hall, University of Cincinnati

32

You might also like