project-hermes / hermes-sensor

:no_entry:Depreciated:no_entry:
MIT License
0 stars 2 forks source link

Depth sensor does not really read depth #35

Closed sonyccd closed 6 years ago

sonyccd commented 6 years ago

Need to fix the pressure to depth conversion http://docs.bluerobotics.com/calc/pressure-depth/ https://www.grc.nasa.gov/www/k-12/WindTunnel/Activities/fluid_pressure.html

sonyccd commented 6 years ago

for this to work the sensor needs to first read the atmo pressure to be subtracted from the pressure under water

d = (Pt-Pa)/(r*g) where d: depth Pt: pressure at depth Pa: pressure of atmosphere r: density of the water (salt:1023.6kg/m^3 fresh:1000.0kg/m^3) g: acceleration do to gravity

sonyccd commented 6 years ago

There also appears to be an error with the pressures sensors temperature readings. It is giving back ~20c and the TS temperature sensors is reading ~23.6 and the apartment is set to ~23

sonyccd commented 6 years ago

Reading the air pressure might just be noise. Need to figure out how to clean up the signal.

sonyccd commented 6 years ago

Dumped every value during the pressure and temperature calculation

0000002661 [app] INFO: Calibration Value0:40961
0000002662 [app] INFO: Calibration Value1:35012
0000002663 [app] INFO: Calibration Value2:34753
0000002664 [app] INFO: Calibration Value3:20707
0000002665 [app] INFO: Calibration Value4:21268
0000002665 [app] INFO: Calibration Value5:26549
0000002666 [app] INFO: Calibration Value6:26017
0000203071 [app] INFO: rawTemp:6922093 rawPressure:4311112
0000203072 [app] INFO: deltaTemp:1477485 msTemp:2068
0000203113 [app] INFO: rawTemp:6926281 rawPressure:4311089
0000203114 [app] INFO: deltaTemp:1481673 msTemp:2081
0000203114 [app] INFO: offest:2299360768.000000 sensitivity:-150926.468750 msPresure:-280721
0000203115 [app] INFO: Temp:20.680000 Pressure:-280.721008
sonyccd commented 6 years ago

changed everything to double as the sensitivity was not fitting in a float

0000085939 [app] INFO: rawTemp:6939825 rawPressure:4312235
0000085939 [app] INFO: deltaTemp:1495217 msTemp:2124
0000085981 [app] INFO: rawTemp:6944020 rawPressure:4312297
0000085982 [app] INFO: deltaTemp:1499412 msTemp:2137
0000085982 [app] INFO: offest:2302230441.468750 sensitivity:2257212.078125 msPresure:-280467
0000085983 [app] INFO: Temp:21.240000 Pressure:-280.467010
sonyccd commented 6 years ago
0000002661 [app] INFO: Calibration Value0:40961
0000002662 [app] INFO: Calibration Value1:35012
0000002663 [app] INFO: Calibration Value2:34753
0000002664 [app] INFO: Calibration Value3:20707
0000002665 [app] INFO: Calibration Value4:21268
0000002665 [app] INFO: Calibration Value5:26549
0000002666 [app] INFO: Calibration Value6:26017
0000237044 [app] INFO: rawTemp:6943855 rawPressure:4314960

Working out the math by hand with raw values

cval = [40961,35012,34753,20707,21268,26549,26017]
print 'calibration values:',cval

rawTemp = 6943855
rawPressure = 4314960
print 'rawTemp:',rawTemp
print 'rawPressure:',rawPressure

dT = rawTemp - cval[4] * pow(2,8)
print 'dT:',dT

temp = 2000 + dT * cval[5] / pow(2,23)
print 'temp:', temp

offset = cval[1] * pow(2,16) + (cval[3] * dT) / pow(2,7)
print 'offset:', offset

sensitivity = cval[0] * pow(2,15) + (cval[2] * dT) / pow(2,8)
print 'sensitivity:', sensitivity

pressure = (rawPressure * sensitivity / pow(2,21) - offset) / pow(2,13)
print 'pressure:', pressure

print 'pressure in bar:', pressure/1000.0

we get

calibration values: [40961, 35012, 34753, 20707, 21268, 26549, 26017]
rawTemp: 6943855
rawPressure: 4314960
dT: 1499247
temp: 6744
offset: 2537084772
sensitivity: 1545738684
pressure: 78530
pressure in bar: 78.53
sonyccd commented 6 years ago

so it looks like the first calibration value is just for the crc

sonyccd commented 6 years ago

Got it! 🎉

calibration values: [40961, 35012, 34753, 20707, 21268, 26549, 26017]
rawTemp: 6943855
rawPressure: 4314960
dT: 147311
temp: 2456
offset: 2302049251
sensitivity: 1159188719
pressure: 10134
temp in c: 24.56
pressure in bar: 1.0134
cval = [40961,35012,34753,20707,21268,26549,26017]
print 'calibration values:',cval

rawTemp = 6943855
rawPressure = 4314960
print 'rawTemp:',rawTemp
print 'rawPressure:',rawPressure

dT = rawTemp - cval[5] * pow(2,8)
print 'dT:',dT

temp = 2000 + dT * cval[6] / pow(2,23)
print 'temp:', temp

offset = cval[2] * pow(2,16) + (cval[4] * dT) / pow(2,7)
print 'offset:', offset

sensitivity = cval[1] * pow(2,15) + (cval[3] * dT) / pow(2,8)
print 'sensitivity:', sensitivity

pressure = (rawPressure * sensitivity / pow(2,21) - offset) / pow(2,13)
print 'pressure:', pressure

print 'temp in c:', temp / 100.0
print 'pressure in bar:', pressure/10000.0