Tank level code in ST

parky

Member
Join Date
Oct 2004
Location
Midlands
Posts
5,748
I seem to remember a number of posts regarding calculation the actual level or volume in a horizontal tank, here is the formula written in ST, note: this assumes the tank ends are flat but tank is round it takes the following parameters:
Tank length
Tank Radius (Not diameter & internal measurement)
Actual level in tank for example 0.0 - 1.0 (1.0 being full).

Horiz tank Calc.png
 
I seem to remember a number of posts regarding calculation the actual level or volume in a horizontal tank, here is the formula written in ST, note: this assumes the tank ends are flat but tank is round it takes the following parameters:
Tank length
Tank Radius (Not diameter & internal measurement)
Actual level in tank for example 0.0 - 1.0 (1.0 being full).
Could you please draw a picture to make the names of the parameters clear?
 
Haven't got the time at the moment, however, Length_L is the length of the tank, Radius is half the tank dia, Part_Fill is the level in the tank (the only dynamic variable).

Here is a little more detail
formula (Radius^2 * ACOS(((Radius) - Part_Fill) / (Radius)) - (Radius - Part_Fill) * (2 * (Radius)*Part_Fill - Part_Fill^2)^(0.5))*Length_L
*)
(* Just for testing Setting values in metres so it does not divide by zero *)
IF SM402 THEN
Length_L:= 1.0; (* Metres*)
Radius := 0.5;
Part_Fill := 0.5;
END_IF;
(* Note: ACOS & Power are Standard FB's here so cannot put them directly into the formula *)
POW(TRUE,Radius, 2.0,Rad_Pow2); (* Radius^2 *)
ACOS(TRUE, ((Radius - Part_Fill) / Radius),Acos_T1); (* ACOS (((Radius)-Part_Fill)/(Radius))) *)
POW(TRUE,Part_Fill,2.0,POW_H_2); (* Part_Fill-Part_Fill^2 *)
POW(TRUE,(2.0*Radius * Part_Fill - Pow_H_2),0.5,Part_F_Part_F_0_5); (*Part_Fill-Part_Fill^2)^(0.5)) *)
Act_Level:= ((Rad_Pow2 * Acos_T1) - (Radius - Part_Fill) * (2.0 * Radius) * Part_F_Part_F_0_5) * Length_L;
Litres := Act_Level * 1000.0; (* convert to litres *)
 
formula for the area of a truncated circle

S = h * (r^2 – h^2)^0.5 + r^2* asin(h/r)+ pi/2 * r^2

h is the distance from the center of the circle to the surface of the water. If the water surface below the center of the circle h is negative, if above h is positive

r – radius

I compared the results of this formula with the recurrent calculation: the results are close
 
Yep, I compared my calculation to that of about 4 on-line calculators & all confirmed the calculation was accurate to 3 decimal places (mainly because some on-line ones were truncated to 3 decimal places).

Tank.jpg
 
Part_Fill is 0.5 i.e. half full.
The fill level goes from 0.0 empty to 1.0 full I chose those values as it is 1m dia by 1m length so for a full tank it would be 785.398 ltrs or 0.785.398 m3
For half a tank then the actual would be 392.699 ltrs
The formula is a standard formular but it's layout is to fit in with the way this IDE has to calculate it. not all PLC's have ACOS (COS-1) so normally has to be a higher spec processor.
It is easy to convert from any type of measurement i.e. inches/ gallons pints whatever, however, US being in the dark ages means the conversion from litres to galls has to be 3.78541178 litres. As I posted, in this IDE cannot put the Poer or Acos functions inside of the formula as these functions return the result into the variable output not as a normal function therefore I calculate the results into temporary vars to use inside the calculation.
The standard calculation uses COS-1 do not have that as a direct function it uses ACos same thing.
 
Last edited:
Radius = 1
Part_Fill = 0.1

[FONT=&quot]Radius^2 * ACOS(((Radius) - Part_Fill) / (Radius)) - (Radius - Part_Fill) * (2 * (Radius)*Part_Fill - Part_Fill^2)^(0.5) =
[/FONT]
[FONT=&quot]1^2 * acos( (1 – 0.1) / 1 ) – ( 1 – 0.1) * 2 * 1 * 0.1 – 0.1^2 )^0.5 = - 0.33357 [/FONT]

[FONT=&quot]What am I doing wrong?[/FONT]
 
Where is your length L or in my case Length_L (1)
d = Diameter (I used radius to shorten the formula) so instead of 1 use 0.5 & do not do the d/2
h = Level (0.1) or in my case 0.5 half full
L = length of tank (Length_L (1) )

((d/2)^2*ACOS(((d/2)-h)/(d/2))-((d/2)-h)*(2*(d/2)*h-h^2)^(0.5))*L

(Radius^2*ACOS((Radius-h)/Radius)-(Radius-h)*(2*Radius*h-h^2)^(0.5))*L

(1^2*ACOS((1-0.1)/1)-(1-0.1)*(2*1*0.1-0.1^2)^(0.5))*1 = 0.0587259069 (* your code should be*)

(0.5^2*ACOS((0.5-0.5)/0.5)-(0.5-0.5)*(2*0.5*0.5-0.5^2)^(0.5))*1 = 0.3926990817 (* Code for half full tank with 0.5 Rad, 0.5 Fill level, Length 1 *)
 
Last edited:
Radius = 1
Part_Fill = 0.1

[FONT=&quot]Radius^2 * ACOS(((Radius) - Part_Fill) / (Radius)) - (Radius - Part_Fill) * (2 * (Radius)*Part_Fill - Part_Fill^2)^(0.5) =
[/FONT]
[FONT=&quot]1^2 * acos( (1 – 0.1) / 1 ) – ( 1 – 0.1) * 2 * 1 * 0.1 – 0.1^2 )^0.5 = - 0.33357 [/FONT]

[FONT=&quot]What am I doing wrong?[/FONT]


Internet have a lot of tank calulators.
One is https://www.calculatorsoup.com/calculators/construction/tank.php which can be used to check own calculations.


It shows 392,7 litres as well as parkys code.




Another page (https://www.omnicalculator.com/construction/tank-volume) shows different equations for tanks.
 
Yes Max forgot multiply by the length of the tank, you need 3 variables to calculate the level.
That is exactly how I checked my calculations by comparing them with the many on-line calculators, only wished the ST functions like POW & ACOS would return result like in C, would have made my ST one line, maybe other ST code in some other PLC's can do that, although it does appear that many functions available in ladder or FBD are not availlable or do not work the same way in ST formula's.
 
Parky's formula works.


I have to apologize to Parky.

I, in turn, wrote it down incorrectly and calculated it accordingly wrong.


I think I understood which integral Parky calculated.
As soon as I have time I will try to calculate and post the result.
 
Hey, no problem, when I realised I had to split the formula up because of the ACOS & POW functions I got in a right mess with the brackets lol, took me an hour or so to get it right.
At some point I might do the formula for convex ends but that one might tax me a bit.
By the way, my one is derived from a standard formula so it's not exactly mine, it's been many years since I did any real maths of any complexity.
 
Here is the latest to allow for the different types of heads i.e. eliptical (3 standard types).
I make no claims about the accuracy of these calculations but they have been checked against a number of on-line calculators and appear to be accurate.
Note: all the calculations are based on metric system i.e. metres & litres, for those dinosaurs out there easily converted to other units.

Partially filled tank.jpg
 
Sweet!

You may want to mention that the 0.2618 formula for elliptical heads assumes a 2:1 ratio between tank radius (also ellipsoid major axes' dimensions) and the ellipse minor axis dimension.

Also, there is a mis(s?)pelling of Elliptical in there.
 

Similar Topics

I want to measure the tank level and get the sensor output to the PLC. Below are the details : Tank Height =0 - 3m, the sensor is stalled 0,2m...
Replies
15
Views
618
Does anyone have RSLogix 5000 ladder diagram program of tank leveling (factory IO). Fill valve, discharge valve, set point, level, etc? I looked...
Replies
2
Views
156
I'm coming from a background of PLC ladderlogic/rockwell products. I am new to blocks. Can you point me in right right direction? What I would...
Replies
5
Views
1,561
Howdy Everyone, We are getting an elliptical water tank for our makeup system in our plant water system. We plan to use an ultrasonic reflective...
Replies
8
Views
2,923
Back
Top Bottom