Hello,
I have a tank in my boat wich is looking like you can see at the picture attached.
So the lower part of the tank is non propotional to the upper part of the tank.
This causes that I can not map the analog value of the sensor easily with byte tankValue map=(0,1023,0,100)
as well not with an custom mapping as far I know.
My though was now to map this using a while function:
Is the analog lower than 819 map=(0,205,0,80)
Is the analog read higher than 819 (80%) than map=(819,1023,80,100)
The reason why this is important to get this mapped propotional is the Multi function device (Marine GPS and Autopilot) I want to get connected to this tank. This device is getting the values through a NMEA2000 bus (CAN bus type) and will calculate distances based of gasoline left in the tank, use of gasoline and drops warning when tank level is lower than a defind volume.
Is there a better method of getting this done or will this conditional mapping work what I thought to do?
Thank for your help!
Regards..
Well it all depends on how many different profile shapes this tank has. My dad's boat tank is like parallel from 1/3 to the top, and like a pointed down triangle from the bottom to 2/3
If that's the case your solution is near to the real calculation, although a linear map wouldn't work in the triangle shape area
I would probably do a totally empirical test. Empty the tank, continously measure the sensor, while yo add gasoline in fractions. Draw the graph (x->liters; y->analog input) and see how it looks. Depending on that, try to approximate that with a function, I can try to help with finding out that equation if you manage to get the graphic
This is a task for multimap() ! non -linear mapping
Check the detailed explanation here - Arduino Playground - MultiMap
Of course you need to create the table first..
Looking at the picture it can be done simpler
Top part is linear,
Bottom part is a triangle ==> integral is quadratic
float readTankContent()
{
float liter = 0;
float cm = func(analogRead(PIN)); // based upon the resistance to be worked out
if (cm > 13.0)
{
liter = 60.0 + 240.0 * (cm - 13.0) / 33.0; // linear
}
else
{
liter = cm * cm * 60.0 / (13.0*13.0); // quadratic liter = cm * cm * 0.3550296;
}
return liter;
}
The function to get the cm from the resistance is probably in the datasheet
Hey,
Thank you for the answers!
@edugimeno
You are 100% right, to map the triangle liniar is not possible, I forgot that point!
To empty that tank could be a solution but it wouldn´t solve the isseu that the tank i going much more faster empty in the triangle area. Also it would be not that cheap to fill up 300 liters to burn them away or do that in the winter now. I could than cast the fuel I guess in the summer.
You can see the shape of the tank on the attached picture.
@robtillaart
Thank a lot!. I´ll check that out! Your code looks logic for me so I will defently try that out!
I may forgot to mention that I am still studing C++ / Arduino, now about a month long.
So this was very helpfull, thanks one more time guys!
Regards..
What you should add is that when you start with the oil in the "triangle", an warning led should light up
so if cm < 13 digitalWrite(warningLED, HIGH);
and if cm < 6.5 ==> digitalWrite(emergencyLed, HIGH)
something like that
and of course put them off when level is higher.
autopilotNOR:
Hello,
I have a tank in my boat which is looking like you can see at the picture attached.
So the lower part of the tank is non proportional to the upper part of the tank.
Thank for your help!
Regards..
I did the math to solve for tank shape. the triangular part of the tank cannot have the same X and Y dimension as the rectangular upper section and contain the volumes specified.
For the triangular section X * Y = 9230cm^2 for the rectangular Section X * Y = 7272cm^2
240,000 cm^3 = XY33cm => X * Y = 7272cm^2
60,000 cm^3 = (X * Y * 13cm)/2 => X * Y = 9230cm^2
They both cannot be true. At least one of your measurements are incorrect, either the volumes of the sections or the heights of the sections.
Each cm of the upper section contains 7.27 litres. The triangular section requires a function to calculate the volume for each cm.
// z is height from bottom of tank in cm
// v is current volume in cm^3 (milliliter)
long int v=(z>13)? 60000 + (z-13)*7272: (9230*(z/13)*z)/2;
// can be mathematically simplified to:
long int v=(z>13)? 60000 + (z-13)*7272: (4615*z*z)/13;
You need to remeasure the tank shape / volume. Given you sketch dimensions this equation will generate current volume in the composite tank. But, I do not believe it will match your tank volume until you can correct the measurement error.
Chuck.
Hey folks,
I did some new measurements to complete the missing values.
So the caaculateted total volume (Measured outside values) is 303.432 L.
The volume of the upper part of the tank is 202.288 L and the triangular prism have a volume of 101.144 L.
I guess the inside volume total is 300 L where the upper part will have thann 200 L and the triangular prism 100 L.
It is not possible to measure the insght dimensions of the tank.
I have attached a picture with the exact measurements and the shape of the tank.
So hopefully this help you and by that me to get a solution!
Thanks a lot !
autopilotNOR:
Hey folks,
I did some new measurements to complete the missing values.
So the caaculateted total volume (Measured outside values) is 303.432 L.
The volume of the upper part of the tank is 202.288 L and the triangular prism have a volume of 101.144 L.
I guess the inside volume total is 300 L where the upper part will have thann 200 L and the triangular prism 100 L.
It is not possible to measure the insght dimensions of the tank.
I have attached a picture with the exact measurements and the shape of the tank.
So hopefully this help you and by that me to get a solution!
Thanks a lot !
Same a prior, I'm assuming the measurements are in mm.
// z is height from bottom of tank in mm
// v is current volume in cm^3 (milliliter)
unsigned long int v=((z>167)? (1175*538*167)/2 + (z-167)*(1175*538): ((1175*z*z)/(167*2))*538)/1000;
// z valid from 0 to 488 mm
//z=488;
//v = 255704; // cm^3 or 255.704 L
Numbers still don't work. I think the Z depth of the prism is deeper. by your picture, the prism is 167mm tall it needs to be 334mm to get to 300L with the given sizes, it is ~250L
Chuck.