From: <par...@us...> - 2010-09-05 07:00:48
|
Revision: 7660 http://octave.svn.sourceforge.net/octave/?rev=7660&view=rev Author: paramaniac Date: 2010-09-05 07:00:41 +0000 (Sun, 05 Sep 2010) Log Message: ----------- control: reformat example Modified Paths: -------------- trunk/octave-forge/main/control/inst/optiPID.m Added Paths: ----------- trunk/octave-forge/main/control/inst/optiPIDfun.m Removed Paths: ------------- trunk/octave-forge/main/control/inst/optiPIDfunction.m Modified: trunk/octave-forge/main/control/inst/optiPID.m =================================================================== --- trunk/octave-forge/main/control/inst/optiPID.m 2010-09-05 06:42:21 UTC (rev 7659) +++ trunk/octave-forge/main/control/inst/optiPID.m 2010-09-05 07:00:41 UTC (rev 7660) @@ -1,12 +1,13 @@ +% =================================================================================== +% optiPID Lukas Reichlin July 2009 +% =================================================================================== % Numerical Optimization of an A/H PID Controller -% Written by Lukas Reichlin July 2009 % Required OCTAVE Packages: control, miscellaneous, optim % Required MATLAB Toolboxes: Control, Optimization +% =================================================================================== % Tabula Rasa -clear all; -close all; -clc; +clear all, close all, clc; % Global Variables global P t dt mu_1 mu_2 mu_3 @@ -18,8 +19,8 @@ % Relative Weighting Factors: PLAY AROUND WITH THESE! mu_1 = 1; % Minimize ITAE Criterion -mu_2 = 1; % Minimize Max Overshoot -mu_3 = 1; % Minimize Sensitivity Ms +mu_2 = 10; % Minimize Max Overshoot +mu_3 = 20; % Minimize Sensitivity Ms % Simulation Settings: PLANT-DEPENDENT! t_sim = 30; % Simulation Time [s] @@ -53,7 +54,7 @@ error ('optiPID: please install optim package to proceed'); end -C_par_opt = fminsearch (@optiPIDfunction, C_par_0); +C_par_opt = fminsearch (@optiPIDfun, C_par_0); % Optimized Controller disp ('optiPID: optimized PID controller parameters:'); @@ -95,3 +96,5 @@ xlabel ('Time [s]') ylabel ('Output [-]') legend ('A/H', 'Optimized', 'Location', 'SouthEast') + +% =================================================================================== Added: trunk/octave-forge/main/control/inst/optiPIDfun.m =================================================================== --- trunk/octave-forge/main/control/inst/optiPIDfun.m (rev 0) +++ trunk/octave-forge/main/control/inst/optiPIDfun.m 2010-09-05 07:00:41 UTC (rev 7660) @@ -0,0 +1,59 @@ +% =================================================================================== +% optiPIDfun Lukas Reichlin July 2009 +% =================================================================================== +% Objective Function +% See "Analysis and Synthesis of SISO Control Systems" +% by Lino Guzzella for further details +% =================================================================================== + +function J = optiPIDfun (C_par) + + % Global Variables + global P t dt mu_1 mu_2 mu_3 + + % Function Argument -> Controller Parameters + kp = C_par(1); + Ti = C_par(2); + Td = C_par(3); + tau = Td / 10; + + % PID Controller with Roll-Off + numC = kp * [Ti * Td, Ti, 1]; + denC = conv ([Ti, 0], [tau^2, 2 * tau, 1]); + C = tf (numC, denC); + + % Open Loop + L = P * C; + + % Sum Block: e = r - y + SUM = ss ([1, -1]); % Matlab converts to SS (and back) for MIMO TF connections + + % Group Sum Block and Open Loop + SUML = append (SUM, L); + + % Build System Interconnections + CM = [3, 1; % Controller Input with Sum Block Output + 2, 2]; % Sum Block Negative Input with Plant Output + + inputs = [1]; % Input 1: reference r(t) + outputs = [1, 2]; % Output 1: error e(t), Output 2: output y(t) + + SUML = connect (SUML, CM, inputs, outputs); + + % Simulation + [y, t_y] = step (SUML, t); + + % ITAE Criterion + itae = dt * (t_y.' * abs (y(:, 1))); + + % Sensitivity + S = inv (1 + L); + Ms = norm (S, inf); + + % Objective Function + J = mu_1 * itae + mu_2 * (max (y(:, 2)) - 1) + mu_3 * Ms; + +end % function + +% =================================================================================== + Deleted: trunk/octave-forge/main/control/inst/optiPIDfunction.m =================================================================== --- trunk/octave-forge/main/control/inst/optiPIDfunction.m 2010-09-05 06:42:21 UTC (rev 7659) +++ trunk/octave-forge/main/control/inst/optiPIDfunction.m 2010-09-05 07:00:41 UTC (rev 7660) @@ -1,50 +0,0 @@ -function J = optiPIDfunction (C_par) - -% Objective Function -% written by Lukas Reichlin -% See "Analysis and Synthesis of SISO Control Systems" -% by Lino Guzzella for further details - -global P t dt mu_1 mu_2 mu_3 - -% Function Argument -> Controller Parameters -kp = C_par(1); -Ti = C_par(2); -Td = C_par(3); -tau = Td / 10; - -% PID Controller with Roll-Off -numC = kp * [Ti * Td, Ti, 1]; -denC = conv ([Ti, 0], [tau^2, 2 * tau, 1]); -C = tf (numC, denC); - -% Open Loop -L = P * C; - -% Sum Block: e = r - y -SUM = ss ([1, -1]); % Matlab converts to SS (and back) for MIMO TF connections - -% Group Sum Block and Open Loop -SUML = append (SUM, L); - -% Build System Interconnections -CM = [3, 1; % Controller Input with Sum Block Output - 2, 2]; % Sum Block Negative Input with Plant Output - -inputs = [1]; % Input 1: reference r(t) -outputs = [1, 2]; % Output 1: error e(t), Output 2: output y(t) - -SUML = connect (SUML, CM, inputs, outputs); - -% Simulation -[y, t_y] = step (SUML, t); - -% ITAE Criterion -itae = dt * (t_y.' * abs (y(:, 1))); - -% Sensitivity -S = inv (1 + L); -Ms = norm (S, inf); - -% Objective Function -J = mu_1 * itae + mu_2 * (max (y(:, 2)) - 1) + mu_3 * Ms; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |