PDA

View Full Version : Float32 Log not working as expected



Basil
09-17-2007, 04:23 AM
Hi All,

I have a problem again :)

I have the following code:





DAT
bADC word 0 'barometric adc data
bAlt long 0.0'ft
bPres long 0.0 'kpa
bGroundAlt long 0.0 'ft
bPrevAlt long 0.0 'ft
bVel long 0.0'ft/s
Period long 200
'Calibration
PRES_ALT_CONST long -6.8755856e-6

...
...
...

Pub do_pres_calcs(timechange) | bfADC,ftimechange

bfADC:=fl.fFloat(bADC)
ftimechange:=fl.fFloat(timechange)
'change time from ms to s for calcs
ftimechange:=fl.fDiv(ftimechange,1000.0)
bPrevAlt:=bAlt

'Pressure=((ADC/4096)+0.095)/0.009
bPres:=fl.fDiv(bfADC,4096.0)
bPres:=fl.fAdd(bPres,0.095)
bPres:=fl.fDiv(bPres,0.009)

'Altitude=(10^(LOG(Pressure/101.325)/5.2558797)-1)/(-6.8755856*(10^-6))
bAlt:=fl.fDiv(bPres,101.325)
bAlt:=fl.Log(bAlt)
bAlt:=fl.fDiv(bAlt,5.2558797)
bAlt:=fl.Pow(10.0,bAlt)
bAlt:=fl.fSub(bAlt,1.0)
bAlt:=fl.fDiv(bAlt,PRES_ALT_CONST) 'alt in feet
...
...
...




There is a bit more after here but nothing that touches bAlt (which is where my problem is)

The code seems to go wrong with bAlt:=fl.Log(bAlt).

Measuring ground pressure, bPres ends up ~102.48 which is correct for where I am.
I have calculated all the steps manually, and in excel

bAlt:=fl.fDiv(bPres,101.325) gives 1.0113989637305699481865284974093
bAlt:=fl.Log(bAlt) gives wild numbers between 0.14 and 0.49, where it should be 0.0049225043228992493572043410264757

Can anyone throw in some suggestions?
Thanks!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec

My our page
(http://our.rocketryplanet.com/profile/basil4j)

Tracy Allen
09-17-2007, 05:30 AM
Maybe it wants
fl.Log10(bAlt)
instead of
fl.Log(bAlt) -- base e
But that would not explain the wildness. ??

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)

Basil
09-17-2007, 05:43 AM
Hi Tracy,

Log10 gives similar results (still 0.xx rather than 0.00x).

The strange thing is, log (base e) works on my calc and also in excel :\

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec

My our page
(http://our.rocketryplanet.com/profile/basil4j)

Basil
09-18-2007, 07:01 AM
Hi Guys,

Righty, ive found a linear version of the same math which is ok but not ideal.
Id prefer not to use it as the log based result (when it works!) is more accurate.

Does anyone know who wrote Float32? or has anyone used fl.log sucessfully?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec

My our page
(http://our.rocketryplanet.com/profile/basil4j)