stevieb has asked for the wisdom of the Perl Monks concerning the following question:
Good afternoon fellow Monks,
I'm working on some prototype code that will eventually be translated to the Arduino platform that'll perform the task of monitoring a mixture tank of water and chlorine, and when it reaches a certain level (say only 1/4 full), will eventually perform a mixture of these two chemicals in the appropriate relative amounts to re-fill the tank.
I'm in the initial phase here, basically, I'm trying to get the math correct to ensure I'm seeing the tank at the proper level, both how many cubic inches are left in the tank, as well as how many litres are remaining (likewise, how many of each are missing).
Can I please, once again, have our mathematicians have a peek to see if I'm on the proper mathematical path? Calculations seem sane when using different variable values and comparing the percentages on my calculator (within a percent or two), but before I move on, I'm looking for some re-assurance.
Test sample code (if there are any questions or clarifications required, please advise):
use warnings; use strict; use constant { PII => 3.1416, DIVISOR => 61.02374409, # cubic inches to litres divisor RADIUS => 2.5, DEPTH => 6, }; my $cubic_inches = (RADIUS * RADIUS) * PII * DEPTH; # total cubes my $litres = $cubic_inches / DIVISOR; # total litres my $empty_depth_inches = 2.80; # inches from top of tank to current li +quid level printf("total cubic inches: %f\n", $cubic_inches); printf("total litres: %f\n", $litres); printf("current empty litres: %f\n", empty_litres($empty_depth_inches) +); printf("current litres: %f\n", current_litres($empty_depth_inches)); printf( "percent litres remaining: %f\n", current_litres($empty_depth_inches) / $litres * 100 ); printf( "percent litres missing: %f\n", empty_litres($empty_depth_inches) / $litres * 100 ); printf( "percent cubes remaining: %f\n", current_cubic_inches($empty_depth_inches) / $cubic_inches * 100 ); sub current_cubic_inches { my ($empty_inches) = @_; return (RADIUS * RADIUS) * PII * (DEPTH - $empty_inches); } sub empty_litres { my ($empty_inches) = @_; return $litres - (current_cubic_inches($empty_inches) / DIVISOR); } sub current_litres { my ($empty_inches) = @_; return $litres - empty_litres($empty_inches); }
Output:
total cubic inches: 117.810000 total litres: 1.930560 current empty litres: 0.900928 current litres: 1.029632 percent litres remaining: 53.333333 percent litres missing: 46.666667 percent cubes remaining: 53.333333
For those interested, I'll be using an ultra-sonic distance sensor, a laser level sensor as well as an analog water-level strip to calculate the depth level (to fully ensure as accurate a reading of the depth as possible, as well as for redundancy purposes in case one of the sensors fail). The project will also entail various pumps and solenoids based off of both 12v and 120v relays for the mixing of the chemicals into the mix tank.
All data will be sent over a 433Mhz RF feed from the water purification building back to a central Raspberry Pi, where I'll process the incoming data, and display it both in numerical and graph forms using Dancer2 and a myriad of other Perl distributions and technologies.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Cubic inch to litre calculations
by syphilis (Archbishop) on Feb 10, 2019 at 01:13 UTC | |
by stevieb (Canon) on Feb 10, 2019 at 01:29 UTC | |
Re: Cubic inch to litre calculations
by pryrt (Abbot) on Feb 10, 2019 at 01:40 UTC | |
by hippo (Bishop) on Feb 10, 2019 at 11:45 UTC | |
by bliako (Monsignor) on Feb 10, 2019 at 13:19 UTC | |
by Lotus1 (Vicar) on Feb 10, 2019 at 17:02 UTC | |
by stevieb (Canon) on Feb 10, 2019 at 02:23 UTC | |
Re: Cubic inch to litre calculations
by vr (Curate) on Feb 10, 2019 at 14:49 UTC |