aboutsummaryrefslogtreecommitdiff
path: root/apps/drivers/ms5611/ms5611.cpp
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2012-09-03 22:29:51 +0200
committerLorenz Meier <lm@inf.ethz.ch>2012-09-03 22:29:51 +0200
commiteb01cd6fd3ad8953db731d0880005cc28a104ace (patch)
tree680879302202788d30d919db75a6929f25c0a77d /apps/drivers/ms5611/ms5611.cpp
parentf92139f53b83fae1efd9f91f74e9cb20a612cb53 (diff)
downloadpx4-firmware-eb01cd6fd3ad8953db731d0880005cc28a104ace.tar.gz
px4-firmware-eb01cd6fd3ad8953db731d0880005cc28a104ace.tar.bz2
px4-firmware-eb01cd6fd3ad8953db731d0880005cc28a104ace.zip
Changed a critical section to double precision calculation. It may not be necessary, but lets not risk precision unless we have properly analyzed what numerical precision is required.
Diffstat (limited to 'apps/drivers/ms5611/ms5611.cpp')
-rw-r--r--apps/drivers/ms5611/ms5611.cpp49
1 files changed, 42 insertions, 7 deletions
diff --git a/apps/drivers/ms5611/ms5611.cpp b/apps/drivers/ms5611/ms5611.cpp
index 4639ae497..7a5c48716 100644
--- a/apps/drivers/ms5611/ms5611.cpp
+++ b/apps/drivers/ms5611/ms5611.cpp
@@ -702,17 +702,52 @@ MS5611::collect()
/* altitude calculations based on http://www.kansasflyer.org/index.asp?nav=Avi&sec=Alti&tab=Theory&pg=1 */
+ /*
+ * PERFORMANCE HINT:
+ *
+ * The single precision calculation is 50 microseconds faster than the double
+ * precision variant. It is however not obvious if double precision is required.
+ * Pending more inspection and tests, we'll leave the double precision variant active.
+ *
+ * Measurements:
+ * double precision: ms5611_read: 992 events, 258641us elapsed, min 202us max 305us
+ * single precision: ms5611_read: 963 events, 208066us elapsed, min 202us max 241us
+ */
+
+ // /* tropospheric properties (0-11km) for standard atmosphere */
+ // const float T1 = 15.0f + 273.15f; /* temperature at base height in Kelvin */
+ // const float a = -6.5f / 1000f; /* temperature gradient in degrees per metre */
+ // const float g = 9.80665f; /* gravity constant in m/s/s */
+ // const float R = 287.05f; /* ideal gas constant in J/kg/K */
+
+ // /* current pressure at MSL in kPa */
+ // float p1 = _msl_pressure / 1000.0f;
+
+ // /* measured pressure in kPa */
+ // float p = P / 1000.0f;
+
+ // /*
+ // * Solve:
+ // *
+ // * / -(aR / g) \
+ // * | (p / p1) . T1 | - T1
+ // * \ /
+ // * h = ------------------------------- + h1
+ // * a
+ // */
+ // _reports[_next_report].altitude = (((powf((p / p1), (-(a * R) / g))) * T1) - T1) / a;
+
/* tropospheric properties (0-11km) for standard atmosphere */
- const float T1 = 15.0 + 273.15; /* temperature at base height in Kelvin */
- const float a = -6.5 / 1000; /* temperature gradient in degrees per metre */
- const float g = 9.80665f; /* gravity constant in m/s/s */
- const float R = 287.05f; /* ideal gas constant in J/kg/K */
+ const double T1 = 15.0 + 273.15; /* temperature at base height in Kelvin */
+ const double a = -6.5 / 1000; /* temperature gradient in degrees per metre */
+ const double g = 9.80665; /* gravity constant in m/s/s */
+ const double R = 287.05; /* ideal gas constant in J/kg/K */
/* current pressure at MSL in kPa */
- float p1 = _msl_pressure / 1000.0f;
+ double p1 = _msl_pressure / 1000.0;
/* measured pressure in kPa */
- float p = P / 1000.0f;
+ double p = P / 1000.0;
/*
* Solve:
@@ -723,7 +758,7 @@ MS5611::collect()
* h = ------------------------------- + h1
* a
*/
- _reports[_next_report].altitude = (((powf((p / p1), (-(a * R) / g))) * T1) - T1) / a;
+ _reports[_next_report].altitude = (((pow((p / p1), (-(a * R) / g))) * T1) - T1) / a;
/* publish it */
orb_publish(ORB_ID(sensor_baro), _baro_topic, &_reports[_next_report]);