Professional Documents
Culture Documents
11/2/2013
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
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
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
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
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
Solution
Call it objfun.m
Use fminunc
11/2/2013
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
11/2/2013
And
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
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
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
11
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
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
13
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
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
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
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
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
tracklsq.m
11/2/2013
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
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
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
23
Try it!
This should converge in 10 iterations and give final values of pid = 2.9108 0.1443 12.8161
11/2/2013
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
0.00122 DAC
2 AMP
11/2/2013
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
26
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
28
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
29
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);
11/2/2013
Optimization results
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
31
Any questions?
11/2/2013
32