Calculate volume of cylindric tank

13 Ansichten (letzte 30 Tage)
Shaked Bar
Shaked Bar am 7 Aug. 2020
Kommentiert: Shaked Bar am 12 Aug. 2020
Hi all,
I'm trying to build a script/function that will help me calculate the volume of a cylindrical fuel tank, and translate about 10 (every 10%) points of the tank to 4-20mA output.
I'm using these tanks and as part of my work. The measurment is via a device that can read 4-20mA but it must be calibrated according to the calcultation above.
Basicaly what I'm looking for is to build a function that receives the diamater and length of the tank as an input and output 10 points of fuel level translated into 4-20 mA (where 4 mA means 0 liters of fuel and 20mA is the maximum the fuel tank can store)
Also plotting the fuel tank somehow and viewing it would be a great addition.
Any suggestions where and how to start building this??
I'm kind of new around matlab so any help would be more than appreciated.
Thanks ahead,

Akzeptierte Antwort

Sudheer Bhimireddy
Sudheer Bhimireddy am 7 Aug. 2020
Bearbeitet: Sudheer Bhimireddy am 7 Aug. 2020
Try this:
function [tank_volume mA_points fuel_level mA_reading] = get_tank_volume(tank_diameter, tank_length, sensor_read)
% Calculate the volume of the tank
tank_volume = pi * (tank_diameter/2)^2 * tank_length;
vol_temp = 0:0.1:1;
vol_temp = vol_temp .* tank_volume; % Now your volume is divided into 10% increments
mA_points = linspace(4,20,numel(vol_temp)); % your mA points divided in to same number of volume increments
% Now fit a straight line through the volume and mA points to get the line-equation
coeffs = polyfit(vol_temp, mA_points, 1);
mA_slope = coeffs (1);
mA_intercept = coeffs (2);
% Now if you have the mA reading from the sensors
% then you can get the current fuel level by:
fuel_level = (sensor_read - mA_intercept)/mA_slope;
mA_reading = sensor_read;
% Instead if you have the fuel level reading and would like to
% get the equivalent mA reading, uncomment the below 2 expression
% fuel_level = sensor_read;
% mA_reading = (mA_slope * sensor_read) + mA_intercept
end
Once you get the required variable, you can plot the level as a rectangle with curved edges to resemble the tank.
tank_diameter=10;tank_length = 100; fuel_level = 45;
h=figure(1);
clf;
hold on;
% The first rectangle will draw the tank
rectangle('Position',[1 0 tank_diameter tank_length],'Curvature',0.5);
% The second rectangle will fill the tank based on the reading
% make sure to keep the curvature value same between the two rectangles for it to look good
rectangle('Position',[1 0 tank_diameter fuel_level],'Curvature',0.5,'FaceColor','b');
ylabel('Fuel level (L)');
ax=gca;ax.XTick=[];ax.XColor='none';
daspect([1 1 1]);
Hope this helps.
  5 Kommentare
Sudheer Bhimireddy
Sudheer Bhimireddy am 8 Aug. 2020
Got it! :)
Shaked Bar
Shaked Bar am 12 Aug. 2020
Hi John,
This is not homework, this is actually for my work.
I'm trying to learn Matlab online from Youtube and from this respectful forum.
Thanks again Sudheer, I will definately try your suggestion.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu ThingSpeak finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by