The B,C and D arrays are good. I haven't had time to look at the A array.Pandiani said:Since there were not many replies to this thread for a long time, I hope we can conclude few things.
First of all, can you agree with nonlinear model and differential equations in my previous post?
Second, do you agree with the way I linearized the model? I applied Taylor approximation consistently.
Should we proceed further to the LQR controller?
clear
clc
T1 = 65;
T2= 20;
T0 = 40;
F10 = 0.0042*0.4;
F20 = 0.0042*0.5;
L0 = 1;
Area = 1;
Ac = [-(F10+F20)/(Area*L0), (F10*(T0-T1)+F20*(T0-T2))/(Area*L0^2);
0 0];
Bc = [(T1-T0)/(Area*L0), (T2-T0)/(Area*L0);
1/Area, 1/Area];
Cc = [1 0; 0 1];
Dc = [0, 0; 0, 0];
T = 0.001; //Sampling time
Time = 1;
//Discrete state-space representation
I = eye (2,2); //Identity matrix
Ad = I;
for i = 1:5
Ad = Ad + ((Ac*T)^i)/prod(1:i);
end
B = I;
for i = 1:5
B = B + ((Ac*T)^i)/prod(1:i+1);
end
Bd = B*Bc*T;
//Cost matrix
Q = [1/T,0; 0, T];
R = [0.1, 0; 0, 0.1];
N1 = floor(Time/T);
P = Q;
for i = 1:N1
K = inv( Bd'*P*Bd+R)*Bd'*P*Ad;
P = Ad'*P*(Ad-Bd*K)+Q;
end
You shouldn't have T in the Q array. I now I did on sci.engr.control but that was because I was minimizing error for position, velocity and acceleration and the relationship between them is 1/T. In this case there is no time relationship between temperature and level.Pandiani said://Cost matrix
Q = [1/T,0; 0, T];
R = [0.1, 0; 0, 0.1];
I have tried before C2d function and use dlqr (discrete lqr), they return more or less same results. It is interesting that Matlab refuse to calculate K matrix when one eigenvalue is 0, therefore R = [0.1, 0; 0, 0.0] will not work in Matlab. I really wonder why...Peter Nachtwey said:I would
Q = [1,0; 0,1];
R = [0.1, 0; 0, 0.0];
Another method is to simply put a water mixing valve in the design in place of where the mixing tank is now. The mixing valve should have a temperature feedback from the Hot Output Pipe to Dormintory. If that temperature is too hot, it automatically reduces the flow of hot input water. If the output temperature is too cold, it increases the flow of hot input water, keeping the dorm hot water supply at a constant temperature. Isn't hot water at a constant temperature the goal here?So make an indirect system.
Use the hot water direct to the dorm and mix it locally with simple mixing valves. This way everybody can set their own temp.
Yes, yes, that has been noted a couple of times above.Lancie1 said:Another method is to simply put a water mixing valve in the design in place of where the mixing tank is now.
Yes, so you do understand.I think the solution is easy, but it would eliminate all the fun that Peter and Pandiani are having.
Q = [ 1,0,0,0;
0,1,0,0;
0,0,1, 0;
0,0,0,1];
R=[0.1,0;0,0.001];
Aw = [[0,0;0,0;0,0;0,0],[Cc;Ac]];
Bw = [[0,0; 0,0]; Bc]
Because I used the fractional method I don't have four gains to figure out. Just two but I think we can equate the LQR and the fractional method.Pandiani said:Scilab code provided above will return result as 2x2 matrix. This means that control to the system is calculated in the following way:
ut = K11*Temp + K12*Level
ul = K21*Temp + K22*Level
I agree, you end up with a 4x4 array. This greatly complicates things for so little gain. I think the proportional gains can be increased until the desired steady state error is achieved.Since there is no integrator in the model we can conclude that there will always be error in response and that we must use PI control. First thing that comes to my mind is to shape control in the following way:
ut = Kit*inegral(errort) + K11*Temp + K12*Level
ul = Kil*inegral(errorl) + K21*Temp + K22*Level
where errort is difference between actual and setpoint temperature while errorl is same but for the level.
In order to use code above we need to add new poles (integrators in transfer function) which will increase dimension of matrices A and B.
Now the real question is how to add new rows in A and B in such way that Scilab script returns useful results, especially because this is MIMO system. Any ideas?
It doesn't look right. You should get nioce smooth first order responses to changes in demand.I'm not satisfied with the response at all, but at least it's stable
I will be able to look at it now that I have my simulation done. I updated my .pdfPandiani said:Peter, I'll have a look. We're taking different approaches. First off all do you agree with the way I linearized the system around working points 40°C and 1m (what about matrix A)? I think model is right because of compared responses.
That is what I have been thinking too which is why I haven't been much help. Now that I have mine done I will try controlling the hot and cold pumps independently like you.I'll need to fix my own model before I fully focus on yours.