aboutsummaryrefslogtreecommitdiff
path: root/apps/systemlib
diff options
context:
space:
mode:
authorLorenz Meier <lm@inf.ethz.ch>2013-01-21 23:45:16 +0100
committerLorenz Meier <lm@inf.ethz.ch>2013-01-21 23:45:16 +0100
commit2ebb1812f1eea47f06e79650242416493ce279b9 (patch)
tree1957033e730cf778fa85f90036e9f963c8e2d6a6 /apps/systemlib
parent48e497e4069a2f8773d90f2d1887967a81e487d8 (diff)
downloadpx4-firmware-2ebb1812f1eea47f06e79650242416493ce279b9.tar.gz
px4-firmware-2ebb1812f1eea47f06e79650242416493ce279b9.tar.bz2
px4-firmware-2ebb1812f1eea47f06e79650242416493ce279b9.zip
Implemented airspeed measurement. Untested
Diffstat (limited to 'apps/systemlib')
-rw-r--r--apps/systemlib/Makefile3
-rw-r--r--apps/systemlib/airspeed.c8
-rw-r--r--apps/systemlib/airspeed.h11
-rw-r--r--apps/systemlib/conversions.c6
-rw-r--r--apps/systemlib/conversions.h5
5 files changed, 20 insertions, 13 deletions
diff --git a/apps/systemlib/Makefile b/apps/systemlib/Makefile
index 942116faa..8240dbe43 100644
--- a/apps/systemlib/Makefile
+++ b/apps/systemlib/Makefile
@@ -43,7 +43,8 @@ CSRCS = err.c \
conversions.c \
cpuload.c \
getopt_long.c \
- up_cxxinitialize.c
+ up_cxxinitialize.c \
+ airspeed.c
# ppm_decode.c \
diff --git a/apps/systemlib/airspeed.c b/apps/systemlib/airspeed.c
index e213b66c2..5c68f8ea5 100644
--- a/apps/systemlib/airspeed.c
+++ b/apps/systemlib/airspeed.c
@@ -41,11 +41,13 @@
*/
#include "math.h"
+#include "conversions.h"
+#include "airspeed.h"
float calc_indicated_airspeed(float pressure_front, float pressure_ambient, float temperature)
{
- return sqrtf((2.0f*(pressure_front - pressure_ambient)) / air_density_sea_level);
+ return sqrtf((2.0f*(pressure_front - pressure_ambient)) / CONSTANTS_AIR_DENSITY_SEA_LEVEL_15C);
}
/**
@@ -60,7 +62,7 @@ float calc_indicated_airspeed(float pressure_front, float pressure_ambient, floa
*/
float calc_true_airspeed_from_indicated(float speed, float pressure_ambient, float temperature)
{
- return speed * sqrtf(air_density_sea_level / get_air_density(pressure_ambient, temperature));
+ return speed * sqrtf(CONSTANTS_AIR_DENSITY_SEA_LEVEL_15C / get_air_density(pressure_ambient, temperature));
}
/**
@@ -76,4 +78,4 @@ float calc_true_airspeed_from_indicated(float speed, float pressure_ambient, flo
float calc_true_airspeed(float pressure_front, float pressure_ambient, float temperature)
{
return sqrtf((2.0f*(pressure_front - pressure_ambient)) / get_air_density(pressure_ambient, temperature));
-} \ No newline at end of file
+}
diff --git a/apps/systemlib/airspeed.h b/apps/systemlib/airspeed.h
index 62acfe2b0..b1beb79ae 100644
--- a/apps/systemlib/airspeed.h
+++ b/apps/systemlib/airspeed.h
@@ -33,13 +33,16 @@
****************************************************************************/
/**
- * @file airspeed.c
- * Airspeed estimation
+ * @file airspeed.h
+ * Airspeed estimation declarations
*
* @author Lorenz Meier <lm@inf.ethz.ch>
*
*/
+#ifndef AIRSPEED_H_
+#define AIRSPEED_H_
+
#include "math.h"
#include "conversions.h"
@@ -83,4 +86,6 @@ __EXPORT float calc_true_airspeed_from_indicated(float speed, float pressure_amb
*/
__EXPORT float calc_true_airspeed(float pressure_front, float pressure_ambient, float temperature);
-__END_DECLS \ No newline at end of file
+__END_DECLS
+
+#endif
diff --git a/apps/systemlib/conversions.c b/apps/systemlib/conversions.c
index fed97f101..2b8003e45 100644
--- a/apps/systemlib/conversions.c
+++ b/apps/systemlib/conversions.c
@@ -42,10 +42,6 @@
#include "conversions.h"
-#define air_gas_constant 8.31432f
-#define air_density_sea_level 1.225f
-#define absolute_null_kelvin 273.15f
-
int16_t
int16_t_from_bytes(uint8_t bytes[])
{
@@ -154,5 +150,5 @@ void quat2rot(const float Q[4], float R[9])
float get_air_density(float static_pressure, float temperature_celsius)
{
- return static_pressure / (air_gas_constant * (temperature_celsius + absolute_null_kelvin));
+ return static_pressure / (CONSTANTS_AIR_GAS_CONST * (temperature_celsius + CONSTANTS_ABSOLUTE_NULL_KELVIN));
}
diff --git a/apps/systemlib/conversions.h b/apps/systemlib/conversions.h
index 4db6de772..c2987709b 100644
--- a/apps/systemlib/conversions.h
+++ b/apps/systemlib/conversions.h
@@ -44,7 +44,10 @@
#include <float.h>
#include <stdint.h>
-#define CONSTANTS_ONE_G 9.80665f
+#define CONSTANTS_ONE_G 9.80665f
+#define CONSTANTS_AIR_DENSITY_SEA_LEVEL_15C 1.225f
+#define CONSTANTS_AIR_GAS_CONST 8.31432f
+#define CONSTANTS_ABSOLUTE_NULL_KELVIN 273.15f
__BEGIN_DECLS