Calculating Liquid Tank Volume (in gallons or liters) is a common automation task. In a previous webinar, we introduced a variety of User-Defined Function Blocks (UDFBs) that perform this calculation based on common tank geometries. But what if a tank is not a common geometry – but requires that volume be deduced from a manufacturer provided Level vs Volume Table (Dip Chart)? In today’s session we’ll review a new UDFB that takes care of this (also common) use case.




0:12

Hello and welcome to today’s webinar. Today we will look at Tank Volume UDFB from a data table.

0:20

Let’s look at our agenda for today.

0:23

We are going to start with explaining what user defined function blocks are and what they are used for and then we will do a quick review of those previous Tank volume, UDFBs, we are going to be reviewing this new user defined function block that is going to allow you to take that manufacturer data table that has the level and volume listed and figure out based on your level and your tank.

0:46

There will be demonstrations throughout and we will finish with a Q &A session.

0:50

What are UDFBs?

0:52

User defined function blocks are sections of logic that have been transformed into a block with inputs and inputs just like a regular function block that might be native to an instruction seascape or any other logic editor.

1:06

Now UDFBs are saved in a portal file format and they can be imported into your project so if you create a user-defined function block yourself after you have created it and tested it you can then save it in a file format or export and then on a future project you can import that function block back in and you can use one or any instance of that function block in your project.

1:30

So they can be extremely useful.

1:32

Now sometimes you have a user defined function blocks that you have created, other times you have user defined function blocks that are available from others.

1:41

Now let’s take a quick look at the user defined function blocks that allow you to calculate gallons or liters or percent full of a tank based on its geometry.

1:51

And on the screen here, you can see six different tank geometries for which we created user defined function blocks.

1:58

Now what we found out is that not all tanks are of a common geometry, but some manufacturers would do it if they had got a custom geometric shape or a custom tank.

2:07

They will publish the data table and you can see an example of one there on the screen.

2:12

So we have got a tank that has got a column in the level, in this case inches.

2:17

It can also be in centimeters, you can find it both ways and then another column is in gallons.

2:23

In other words, at 1 inch you have got 6 gallons of liquid, all the way up to the end we are at 27 inches.

2:30

When the tank is full you have 275 gallons of liquid and you can see the corresponding levels and their volumes listed in the entire table.

2:41

So what we are going to do is we are going to show you how to take a manufacturer’s table like this and then by using a user defined function block that we have created you can use that and import that into your project and then calculate accurately the amount of liquid in your tank based on the level in terms of gallons or liters or a percent full of the tank.

3:02

What would be involved in doing this exercise if you are going to be doing it from scratch yourself?

3:08

What you would need to do in your logic is you would need to find based on your current level reading.

3:13

You would need to take your current level reading coming from the sensor.

3:17

Convert that over to either inches or centimeters, depending on what units your table is expressed in.

3:23

And then you would need to find on the chart the closest entries that are around your current fill level.

3:29

Once you have done that you would take those entries or the data from those entries and perform linear interpolation to find the closest estimate of the volume based on your level.

3:40

So there in red there on the screen you can see that we have got a theoretical level of 12.5 inches so we would use that readings in the table or the entries in the table that are around 12.5.

3:52

12 is below and 13 is above and you can see that correlates between 119 and 131 and then once we have retrieved that value if we are interested in converting that from gallons to liters we could do that in the case we wanted to provide both readings.

4:10

The other thing we do is we could calculate based on the total capacity of the tank how full it was what percent full it was from 0 to 100. Let’s take a look at the UTFBs that we have created.

4:22

Let’s take a look at the inputs of the user defined function block which are highlighted there on the left.

4:28

You can get data table information into your logic by doing it in the form of two arrays one array for the column of level data in inches or centimeters and another array for the column of volume data, either in gallons or liters for instance.

4:44

You’re going to specify what array as an input represents level, what array as an input represents volume.

4:51

And in this case, this user defined function block, those are the arrays of real values, and we have got three other inputs as well.

4:59

The next input is your table size.

5:01

That is an integer.

5:02

What does table size represent?

5:04

Well, that represents how many different rows of data are in your table.

5:08

and in the example we are using today with that table that we have showed on the previous page there were 27 rows of data such table size in this case of that example would be an integer value that has a value of 27.

5:22

Now you cannot type 27 as an input to that user defined function block you need to assign it as a variable and set that variable to a value of 27 again 27 being our size here but it can be any value up to 100.

5:37

This user defined function block has been defined to handle arrays up to 100 each.

5:42

That would be 100 rows of level data and up to 100 rows of volume data.

5:47

After table size you will have to fill height variable. What is your fill height variable?

5:52

That is the level in the tank that you would measure.

5:54

What that means is outside of this function block you would have some logic that took the data from the ultrasonic sensor for instance is measuring the level of liquid in the tank and you would need to convert that to centimeters of liquid in the tank that is what you would need to do there.

6:09

Fill height is another real value that correlates to the liquid in the tank in the same units that your table is expressed in so if your table is in inches your fill height would need to be in inches for instance and then there is one more input that is just a boolean on or off and that is a variable if it is on it means your table is in metric units, if it is off it means your table is in imperial units so metric being in centimeters and liters and imperial meaning not metric so that would be in inches or gallons.

6:40

Let’s take a look at the output side of things, now the first output is a boolean that is just an error bit, so if there is an error bit what kind of errors could you have?

6:49

Potential errors could be that you have entered a table or you have specified a table size is greater than 100 and we can only handle tables of 100 or less, so that would be an error.

7:00

Another error might be that your volume data was not in ascending order, remember when you are looking at the table as your inches are ascending and your volume should be ascending in terms of liquid level and number of volume of your liquid, if it is not that would be an error.

7:16

So there are a couple of possibilities where you can have an error with this function block but that would be flagged with the boolean output and then the other three outputs are the number of gallons in the tank and the number of liters in the tank and the fill percentage of the tank.

7:31

These are all real values so that is what the outputs look like on our user defined function block. Now what are the steps that are going to be involved to use this function block?

7:40

Here are the steps that are going to be involved.

7:42

So what you are going to do is you’re going to import a UDFB into your Cscape project and you are going to create variables in your program.

7:50

Variable window for each of the UDFB inputs and outputs.

7:54

Next you are going to add an instance of the UDFB into your logic program.

7:59

Now you are going to find those UDFBs that have been imported into your project toolbox.

8:04

Now each time you add one of those function blocks to your logic, let’s say you have 6 tanks and you want to add this function block 6 different times.

8:12

Each time you add it you have to assign a name to that, a unique name to that instance of the function block.

8:19

So if you had six tanks and they were labelled A through F for instance, you might name your function tanks tank A, tank B, tank C, tank D and so on, but each UDFB instance has a unique name.

8:32

And then once you have added that instance and named it, then you are going to fill in what the input variables that you need to be assigned to that UDFB and what are the output variables that need to be assigned to that UDFB.

8:44

So those are the basic steps.

8:46

When entering the data from the data table of the manufacturer’s data table that we are using, you are going to enter that as ladder logic by using constant move function block to enter in all the data in that column.

8:59

So if you were to read down the inches column right now from that chart that is on the screen, you will see it is in numeric order 1, 2, 3, 4, 5, 6, 7 and so on.

9:10

So that is the data from 1 to 27. You’re going to be listing the first constant move.

9:15

The second constant move that is the gallons data or the volume data and you can see the numbers there at the top would need to be entered in order 6 1 4 2 2 3 1 and so on.

9:27

And the third input that needs to be specified with our use and define function block is the number of data entries in the chart. In other words, the number of rows.

9:37

You count those up and then you enter that as another integer input.

9:41

For our demonstration we are going to start by being in Cscape.

9:44

This is our example program using the new user defined function block that we have been reviewing.

9:50

So let’s start with importing the user defined function block.

9:53

We can do that by going over here to the logic modules, right click and set import logic module.

9:59

And then we navigate it to the location where our logic module, where our UTFB file was located.

10:05

It is in the CPU file.

10:07

Once we enter star.cpu it showed up here.

10:12

We then hit click and open and it added it to our project.

10:16

Once it loads it shows up here under UDFB modules.

10:20

And then when you want to use it, it also shows up over here under your project toolbox.

10:25

At the very bottom under UDFBs.

10:28

You can see all the UDFBs will show up here.

10:31

And here is the tank, bottom table, UDFBs right there.

10:34

and then when you go to add in your project what you’re going to do is you’re going to click and drag it into your project and you’re going to assign it a name let’s call this gas tank 2 we will hit ok and then immediately after naming gas tank 2 it opens this dialog box so you can assign all the input variables and output variables to this user defined function block but we have already done this we are going to hit cancel here and you can see that the block went away and now we are going to show you an instance of this user-defined function block that we had previously placed here in our program and it has already been assigned with all the variables.

11:15

These are the input variables here and the output variables there.

11:19

Remember the first two variables are real-based arrays that contains the level data and the volume data.

11:25

We have got our integer variable that tells us how many tank charts and trees there are.

11:31

In our case they were 27. Your case will probably vary.

11:35

This is a variable that specifies what is the fill level coming in and if your charts are in inches then this gas level needs to be in inches as well. This is another real variable and then are the units metric or not.

11:49

Always on would indicate yes it is metric.

11:52

Always off would indicate no it is not and in our case it is not and these are our output variables, gallon liters and full percent are all real variables and then the error output is a boolean variable so that is the input and output variables that have been assigned to this instance of the user defined function block and then all that is left in terms of the application in getting data from our data table from the manufacturer of the tank into these arrays that were specified and we do this through the constant move function block right there so let’s double click on the first one which has our level data.

12:30

Remember the chart had 27 entries so these were just in even 1 inch increments in our example so you enter these all in order until you are done in one function block and it tells you that you have got 27 items in your list which matches what we have here and then this is our volume data and this is 27 entries here as well that we have entered in.

12:57

Now we have created a screen that you can use to exercise this demonstration. Let’s go ahead and go to the bench now.

13:04

Here is our X7. This is the micro OCS X7 that we are running this demo application in.

13:10

You can see we have imported a picture of the tank along with the data table that is just a picture of the data table.

13:17

And then for our demonstration we are going to have the ability to enter in manually what the tank level is, we are going to manually enter the value in inches and then it will calculate the tank level and display the volume in gallons and litres. So let’s go ahead and do this.

13:34

Now we are going to start with simulation a tank value of 5 inches of liquid that corresponds to 41 gallons.

13:41

As you can see if we look at our chart here you can see that at 5 inches that is 41 gallons.

13:48

Now let’s say that we at 25.5 inches as our level so we can go down here 25 is 260, 26 is 268 and we are halfway between those two at 264 so the linear interpolation that we are using at this function block is working just fine and throughout we are also getting how full the tank is as well as how many litres this represents as well.

14:13

Now you will notice this particular table starts at a non-zero value for the first entry.

14:19

So if we have half an inch of liquid in this tank, let’s type in half an inch.

14:24

So a half an inch we have got three gallons.

14:26

That looks right because a one inch we have got six gallons. So with the linear interpolation we will end up with three gallons.

14:33

So this appears to be working just the way we would expect.

14:37

And as you saw there was not much work needed in taking advantage of this user-defined function block.

14:43

That concludes our webinar for today.

14:45

Thank you so much for listening and the Q &A session will begin shortly.

14:55

Okay, so next week we carry on the team of UDFBs with a webinar on UDFBs within C-SCAPE 10.

15:03

Registration is up in the usual area, if you do have an interest in following up with that.

15:08

I don’t see any questions in on the topic here today, so I think we’re gonna leave it there.

15:13Thank you all