Consider the basic control scheme for a water tank in Figure 1, where the objective is to maintain the level between a maximum and a minimum measured by two level switches. The tank is fed by an on-off pump that allows a inflow of and the outflow at the bottom is a function on the difference between the hydro static pressure and the pressure in the outlet pipe.

Figure 1.

The state of the pump will be changed when the maximum level is reached and the pump is on or when the minimum level is reached and the pump is off .

This simple system can be represented as an Hybrid System, as follows:

The state of the system is:

where Tank level [m] and State of the pump, where pump off and pump on.

where : gravitational constant, : flow coefficient.

Simulation instructions for Hybrid Equations Toolbox

Simulation results for are shown in Figure 2 a) and b)

a) b)

Figure 2. a) Tank Level. b) Pump State

Source code for Simulation:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Matlab M-file Project: HyEQ Toolbox @ Hybrid Dynamics and Control % Lab, http://www.u.arizona.edu/~sricardo/index.php?n=Main.Software % % Filename: run_tank % % Version 1.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function run_tank %constants hmin=0.8; hmax=1.2; Qi=0.4; kv=0.05; A=0.5^2*pi; global hmin hmax Qi kv A; % clear all % initial conditions x0 = [1.8;1]; % simulation horizon TSPAN=[0 20]; JSPAN = [0 20]; % rule for jumps % rule = 1 -> priority for jumps % rule = 2 -> priority for flows rule = 1; options = odeset('RelTol',1e-6,'MaxStep',1e-3); % simulate [t j x] = HyEQsolver( @f,@g,@C,@D,... x0,TSPAN,JSPAN,rule,options); % state x1 = x(:,1); x2 = x(:,2); % plot solutions figure(1) clf subplot(2,1,1),plotflows(t,j,x(:,1)) grid on ylabel('Tank level') subplot(2,1,2),plotjumps(t,j,x(:,1)) grid on ylabel('x1') figure(2) clf subplot(2,1,1),plotflows(t,j,x(:,2)) grid on ylabel('Pump State') subplot(2,1,2),plotjumps(t,j,x(:,2)) grid on ylabel('x2') % plot hybrid arc plotHybridArc(t,j,x(:,1)) xlabel('j') ylabel('t') zlabel('x1')

Flow map (f.m)

function xdot = f(x) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Matlab M-file Project: HyEQ Toolbox @ Hybrid Dynamics and Control % Lab, http://www.u.arizona.edu/~sricardo/index.php?n=Main.Software % % Project: Simulation of a hybrid system % % Name: f.m % % Description: Flow map % % Version 1.0 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % flow map: xdot=f(x,u,parameters); % Constants: global Qi; global kv; global A; % State xi1 = x(1); % Tank level h xi2 = x(2); % Pump state % flow map %xdot=f(x,u); xi1dot = 1/A*(xi2*Qi-kv*sqrt(9.81*xi1)); xi2dot = 0; xdot = [xi1dot;xi2dot];

Flow set (C.m)

function v = C(x) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Matlab M-file Project: HyEQ Toolbox @ Hybrid Dynamics and Control % Lab, http://www.u.arizona.edu/~sricardo/index.php?n=Main.Software % % Project: Simulation of a hybrid system % % Name: C.m % % Description: Flow set % % Version: 1.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Constants global hmin; global hmax; % State xi1 = x(1); xi2 = x(2); % flow condition if (((xi1 <= hmin ) && (xi2 == 1)) || ((xi1 >= hmax ) && (xi2 == 0))) % flow condition v = 1; % report flow elseif (xi1 < hmax ) v = 1; % report flow else v = 0; % do not report flow end

Jump map (g.m)

function xplus = g(x) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Matlab M-file Project: HyEQ Toolbox @ Hybrid Dynamics and Control % Lab, http://www.u.arizona.edu/~sricardo/index.php?n=Main.Software % % Project: Simulation of a hybrid system % % Name: g.m % % Description: Jump map % % Version: 1.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % jump map: xplus = g(x,u,parameters); % state xi1 = x(1); xi2 = x(2); xi1plus=xi1; xi2plus=1-xi2; xplus = [xi1plus;xi2plus];

Jump set (D.m)

function v = D(x) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Matlab M-file Project: HyEQ Toolbox @ Hybrid Dynamics and Control % Lab, http://www.u.arizona.edu/~sricardo/index.php?n=Main.Software % % Project: Simulation of a hybrid system % % Name: D.m % % Description: Jump set % % Version: 1.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Check on flow conditions % % E.g., % if (x(1) <= u(1)) && (x(2) <= 0) % jump condition % v = 1; % report jump % else % v = 0; % do not report jump % end % Constants global hmin; global hmax; % state xi1 = x(1); xi2 = x(2); % Jump conditions if ((xi1 >= hmax) && ( xi2 == 1)) v = 1; % report jump elseif ((xi1 <= hmin) && ( xi2 == 0)) % jump condition v = 1; % report jump else v = 0; % do not report jump end