[baro] convert baro modules to ABI

This commit is contained in:
Gautier Hattenberger
2013-09-01 23:25:08 +02:00
parent e867282eb0
commit d1d1a7e57d
21 changed files with 106 additions and 162 deletions
+8 -4
View File
@@ -33,9 +33,14 @@
#ifndef BARO_NO_DOWNLINK
#include "ap_downlink.h"
#endif
#include "subsystems/abi.h"
#include "subsystems/nav.h"
#include "state.h"
#ifndef BARO_MS5534A_SENDER_ID
#define BARO_MS5534A_SENDER_ID 15
#endif
bool_t baro_MS5534A_do_reset;
uint32_t baro_MS5534A_pressure;
uint16_t baro_MS5534A_temp;
@@ -257,11 +262,10 @@ void baro_MS5534A_event( void ) {
spi_message_received = FALSE;
baro_MS5534A_event_task();
if (baro_MS5534A_available) {
// baro_MS5534A_available = FALSE; // Checked by INS
baro_MS5534A_available = FALSE;
baro_MS5534A_z = ground_alt +((float)baro_MS5534A_ground_pressure - baro_MS5534A_pressure)*0.084;
// if (alt_baro_enabled) {
// EstimatorSetAlt(baro_MS5534A_z); // Updated by INS
// }
float pressure = (float)baro_MS5534A_pressure;
AbiSendMsgBARO_ABS(BARO_MS5534A_SENDER_ID, &pressure);
}
}
}
@@ -54,8 +54,6 @@ void baro_MS5534A_event_task( void );
void baro_MS5534A_event( void );
#define BaroMS5534AUpdate(_b, _h) { if (baro_MS5534A_available) { _b = baro_MS5534A_pressure; _h(); baro_MS5534A_available = FALSE; } }
#endif // USE_BARO_MS5534A
#endif // BARO_MS5534A_H
+8 -4
View File
@@ -25,6 +25,7 @@
#include "sensors/baro_amsys.h"
#include "mcu_periph/i2c.h"
#include "subsystems/abi.h"
#include "state.h"
#include <math.h>
#include "generated/flight_plan.h" // for ground alt
@@ -43,10 +44,6 @@
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif
#ifdef SITL
#include "subsystems/gps.h"
#endif
#define BARO_AMSYS_ADDR 0xE4
#define BARO_AMSYS_REG 0x07
#ifndef BARO_AMSYS_SCALE
@@ -77,6 +74,10 @@
#define BARO_AMSYS_I2C_DEV i2c0
#endif
#ifndef BARO_AMSYS_SENDER_ID
#define BARO_AMSYS_SENDER_ID 16
#endif
// Global variables
uint16_t pBaroRaw;
uint16_t tBaroRaw;
@@ -180,6 +181,9 @@ void baro_amsys_read_event( void ) {
//Convert to pressure
baro_amsys_p = (float)(pBaroRaw-BARO_AMSYS_OFFSET_MIN)*BARO_AMSYS_MAX_PRESSURE/(float)(BARO_AMSYS_OFFSET_MAX-BARO_AMSYS_OFFSET_MIN);
// Send pressure over ABI
AbiSendMsgBARO_ABS(BARO_AMSYS_SENDER_ID, &baro_amsys_p);
// compute altitude localy
if (!baro_amsys_offset_init) {
--baro_amsys_cnt;
// Check if averaging completed
-2
View File
@@ -48,6 +48,4 @@ extern void baro_amsys_read_event( void );
#define BaroAmsysEvent() { if (baro_amsys_i2c_trans.status == I2CTransSuccess) baro_amsys_read_event(); }
#define BaroAmsysUpdate(_b, _h) { if (baro_amsys_valid) { _b = baro_amsys_adc; _h(); baro_amsys_valid = FALSE; } }
#endif // BARO_AMSYS_H
+7
View File
@@ -36,6 +36,7 @@
#include "mcu_periph/i2c.h"
#include "led.h"
#include "mcu_periph/uart.h"
#include "subsystems/abi.h"
#include "messages.h"
#include "subsystems/datalink/downlink.h"
@@ -51,6 +52,9 @@
#define BMP_I2C_DEV i2c0
#endif
#ifndef BARO_BMP_SENDER_ID
#define BARO_BMP_SENDER_ID 17
#endif
#define BARO_BMP_R 0.5
#define BARO_BMP_SIGMA2 0.1
@@ -92,6 +96,9 @@ void baro_bmp_event(void) {
tmp = pow(tmp, 0.190295);
baro_bmp_alt = 44330 * (1.0 - tmp);
float pressure = (float)baro_bmp.pressure;
AbiSendMsgBARO_ABS(BARO_BMP_SENDER_ID, &pressure);
#ifdef SENSOR_SYNC_SEND
DOWNLINK_SEND_BMP_STATUS(DefaultChannel, DefaultDevice, &baro_bmp.up,
&baro_bmp.ut, &baro_bmp.pressure,
-2
View File
@@ -51,6 +51,4 @@ void baro_bmp_init(void);
void baro_bmp_periodic(void);
void baro_bmp_event(void);
#define BaroBmpUpdate(_b, _h) { if (baro_bmp.data_available) { _b = baro_bmp.pressure; _h(); baro_bmp.data_available = FALSE; } }
#endif
@@ -1,59 +0,0 @@
/*
* Copyright (C) 2012 Gautier Hattenberger
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
/*
* Wrapper for the board specific barometer
* Allows to use external baro sensor to feed the general baro interface
*/
#include "modules/sensors/baro_board_module.h"
/* Common Baro struct */
struct Baro baro;
/* Counter to init custom baro at startup */
#define BARO_STARTUP_COUNTER 200
uint16_t startup_cnt;
/** Implementation of the generic baro interface initialization.
* No need to call this functions from the modules, already done by main.
*/
void baro_init( void ) {
baro.status = BS_UNINITIALIZED;
baro.absolute = 0;
baro.differential = 0;
startup_cnt = BARO_STARTUP_COUNTER;
}
/** Implementation of the generic baro interface periodic task.
* No need to call this functions from the modules, already done by main.
*/
void baro_periodic( void ) {
if (baro.status == BS_UNINITIALIZED) {
// Run some loops to get correct readings from the adc
--startup_cnt;
if (startup_cnt == 0) {
baro.status = BS_RUNNING;
}
}
}
@@ -1,70 +0,0 @@
/*
* Copyright (C) 2011 Gautier Hattenberger
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/**
* @file modules/sensors/baro_board_module.h
*
* Wrapper for the board specific barometer.
*/
#ifndef BARO_BOARD_MODULE_H
#define BARO_BOARD_MODULE_H
#include "subsystems/sensors/baro.h"
/** Absolute baro macro mapping.
* Select the baro module you want to use to feed the common baro interface
* in your airframe file when configuring baro_board module
* ex:
* for module baro_ets
* @verbatim
* <define name="BARO_ABS_EVENT" value="BaroEtsUpdate"/>
* @endverbatim
*/
#ifndef BARO_ABS_EVENT
#define BARO_ABS_EVENT NoBaro
#endif
/** Differential baro macro mapping.
* TODO
*/
#ifndef BARO_DIFF_EVENT
#define BARO_DIFF_EVENT NoBaro
#endif
#define NoBaro(_b, _h) {}
/** BaroEvent macro.
* Need to be maped to one the external baro running has a module
*
* Undef if necessary (already defined in a baro_board.h file)
*/
#ifdef BaroEvent
#undef BaroEvent
#endif
#define BaroEvent(_b_abs_handler, _b_diff_handler) { \
BARO_ABS_EVENT(baro.absolute, _b_abs_handler); \
BARO_DIFF_EVENT(baro.differential, _b_diff_handler); \
}
#endif
+13
View File
@@ -42,6 +42,7 @@
#include "sensors/baro_ets.h"
#include "mcu_periph/i2c.h"
#include "state.h"
#include "subsystems/abi.h"
#include <math.h>
#include "mcu_periph/sys_time.h"
@@ -73,11 +74,21 @@
#define BARO_ETS_R 0.5
#define BARO_ETS_SIGMA2 0.1
// Pressure offset to convert raw adc to real pressure (FIXME find real value)
#ifndef BARO_ETS_PRESSURE_OFFSET
#define BARO_ETS_PRESSURE_OFFSET 101325.0
#endif
#ifndef BARO_ETS_I2C_DEV
#define BARO_ETS_I2C_DEV i2c0
#endif
PRINT_CONFIG_VAR(BARO_ETS_I2C_DEV)
#ifndef BARO_ETS_SENDER_ID
#define BARO_ETS_SENDER_ID 18
#endif
PRINT_CONFIG_VAR(BARO_ETS_SENDER_ID)
/** delay in seconds until sensor is read after startup */
#ifndef BARO_ETS_START_DELAY
#define BARO_ETS_START_DELAY 0.2
@@ -178,6 +189,8 @@ void baro_ets_read_event( void ) {
if (baro_ets_offset_init) {
baro_ets_altitude = ground_alt + BARO_ETS_SCALE * (float)(baro_ets_offset-baro_ets_adc);
// New value available
float pressure = BARO_ETS_SCALE * (float) baro_ets_adc + BARO_ETS_PRESSURE_OFFSET;
AbiSendMsgBARO_ABS(BARO_ETS_SENDER_ID, &pressure);
#ifdef BARO_ETS_SYNC_SEND
DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &baro_ets_adc, &baro_ets_offset, &baro_ets_altitude);
#endif
-2
View File
@@ -64,6 +64,4 @@ extern void baro_ets_read_event( void );
#define BaroEtsEvent() { if (baro_ets_i2c_trans.status == I2CTransSuccess) baro_ets_read_event(); }
#define BaroEtsUpdate(_b, _h) { if (baro_ets_valid) { _b = baro_ets_adc; _h(); baro_ets_valid = FALSE; } }
#endif // BARO_ETS_H
+17
View File
@@ -22,6 +22,7 @@
#include "sensors/baro_hca.h"
#include "mcu_periph/i2c.h"
#include "subsystems/abi.h"
#include <math.h>
//Messages
@@ -39,10 +40,24 @@
#define BARO_HCA_MAX_OUT 27852 //dec
#define BARO_HCA_MIN_OUT 1638 //dec
// FIXME
#ifndef BARO_HCA_SCALE
#define BARO_HCA_SCALE 1.0
#endif
// FIXME
#ifndef BARO_HCA_PRESSURE_OFFSET
#define BARO_HCA_PRESSURE_OFFSET 101325.0
#endif
#ifndef BARO_HCA_I2C_DEV
#define BARO_HCA_I2C_DEV i2c0
#endif
#ifndef BARO_HCA_SENDER_ID
#define BARO_HCA_SENDER_ID 19
#endif
// Global variables
uint16_t pBaroRaw;
bool_t baro_hca_valid;
@@ -83,6 +98,8 @@ void baro_hca_read_event( void ) {
if (pBaroRaw > BARO_HCA_MAX_OUT)
pBaroRaw = BARO_HCA_MAX_OUT;
float pressure = BARO_HCA_SCALE*(float)pBaroRaw + BARO_HCA_PRESSURE_OFFSET;
AbiSendMsgBARO_ABS(BARO_HCA_SENDER_ID, &pressure);
}
baro_hca_i2c_trans.status = I2CTransDone;
+13 -5
View File
@@ -21,6 +21,7 @@
*/
#include "modules/sensors/baro_mpl3115.h"
#include "subsystems/abi.h"
//Messages
#include "mcu_periph/uart.h"
@@ -31,23 +32,30 @@
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif
#ifndef BARO_MPL3115_SENDER_ID
#define BARO_MPL3115_SENDER_ID 20
#endif
void baro_mpl3115_init( void ) {
mpl3115_init();
}
void baro_mpl3115_read_periodic( void ) {
#ifdef SENSOR_SYNC_SEND
if (mpl3115_data_available) {
DOWNLINK_SEND_MPL3115_BARO(DefaultChannel, DefaultDevice, &mpl3115_pressure, &mpl3115_temperature, &mpl3115_alt);
}
#endif
Mpl3115Periodic();
}
void baro_mpl3115_read_event( void ) {
mpl3115_event();
if (mpl3115_data_available) {
float pressure = (float)mpl3115_pressure;
AbiSendMsgBARO_ABS(BARO_MPL3115_SENDER_ID, &pressure);
#ifdef SENSOR_SYNC_SEND
DOWNLINK_SEND_MPL3115_BARO(DefaultChannel, DefaultDevice, &mpl3115_pressure, &mpl3115_temperature, &mpl3115_alt);
#endif
mpl3115_data_available = FALSE;
}
}
@@ -30,6 +30,7 @@
#include "modules/sensors/baro_ms5611_i2c.h"
#include "mcu_periph/sys_time.h"
#include "subsystems/abi.h"
#include "mcu_periph/uart.h"
#include "messages.h"
#include "subsystems/datalink/downlink.h"
@@ -38,6 +39,10 @@
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif
#ifndef BARO_MS5611_SENDER_ID
#define BARO_MS5611_SENDER_ID 20
#endif
#ifndef MS5611_I2C_DEV
#define MS5611_I2C_DEV i2c0
#endif
@@ -97,6 +102,8 @@ void baro_ms5611_event( void ) {
ms5611_i2c_event(&baro_ms5611);
if (baro_ms5611.data_available) {
float pressure = (float)baro_ms5611.data.pressure;
AbiSendMsgBARO_ABS(BARO_MS5611_SENDER_ID, &pressure);
float tmp_float = baro_ms5611.data.pressure / 101325.0; //pressure at sea level
tmp_float = pow(tmp_float, 0.190295);
baro_ms5611_alt = 44330 * (1.0 - tmp_float); //altitude above MSL
@@ -22,8 +22,4 @@ extern void baro_ms5611_read(void);
extern void baro_ms5611_periodic_check(void);
extern void baro_ms5611_event(void);
#define BaroMs5611UpdatePressure(_b, _h) { if (baro_ms5611.data_available) { _b = baro_ms5611.data.pressure; _h(); baro_ms5611.data_available = FALSE; } }
#define BaroMs5611UpdateAlt(_b, _h) { if (baro_ms5611.data_available) { _b = baro_ms5611_alt; _h(); baro_ms5611.data_available = FALSE; } }
#endif
@@ -30,6 +30,7 @@
#include "modules/sensors/baro_ms5611_spi.h"
#include "mcu_periph/sys_time.h"
#include "subsystems/abi.h"
#include "mcu_periph/uart.h"
#include "messages.h"
#include "subsystems/datalink/downlink.h"
@@ -38,6 +39,10 @@
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif
#ifndef BARO_MS5611_SENDER_ID
#define BARO_MS5611_SENDER_ID 20
#endif
#ifndef MS5611_SPI_DEV
#define MS5611_SPI_DEV spi1
#endif
@@ -97,6 +102,8 @@ void baro_ms5611_event( void ) {
ms5611_spi_event(&baro_ms5611);
if (baro_ms5611.data_available) {
float pressure = (float)baro_ms5611.data.pressure;
AbiSendMsgBARO_ABS(BARO_MS5611_SENDER_ID, &pressure);
float tmp_float = baro_ms5611.data.pressure / 101325.0; //pressure at sea level
tmp_float = pow(tmp_float, 0.190295);
baro_ms5611_alt = 44330 * (1.0 - tmp_float); //altitude above MSL
@@ -50,8 +50,4 @@ extern void baro_ms5611_read(void);
extern void baro_ms5611_periodic_check(void);
extern void baro_ms5611_event(void);
#define BaroMs5611UpdatePressure(_b) { if (baro_ms5611.data_available) { _b = baro_ms5611.data.pressure; baro_ms5611.data_available = FALSE; } }
#define BaroMs5611UpdateAlt(_b) { if (baro_ms5611.data_available) { _b = baro_ms5611_alt; baro_ms5611.data_available = FALSE; } }
#endif
+7
View File
@@ -2,6 +2,7 @@
#include "mcu_periph/sys_time.h"
#include "led.h"
#include "mcu.h"
#include "subsystems/abi.h"
#include "mcu_periph/uart.h"
#include "messages.h"
@@ -15,6 +16,10 @@
#warning set SENSOR_SYNC_SEND to use baro_scp
#endif
#ifndef BARO_SCP_SENDER_ID
#define BARO_SCP_SENDER_ID 21
#endif
#ifndef DOWNLINK_DEVICE
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif
@@ -184,6 +189,8 @@ static void baro_scp_read(void) {
void baro_scp_event( void ) {
if (baro_scp_available == TRUE) {
float pressure = (float)baro_scp_pressure;
AbiSendMsgBARO_ABS(BARO_SCP_SENDER_ID, &pressure);
#ifdef SENSOR_SYNC_SEND
DOWNLINK_SEND_SCP_STATUS(DefaultChannel, DefaultDevice, &baro_scp_pressure, &baro_scp_temperature);
#endif
-2
View File
@@ -20,6 +20,4 @@ void baro_scp_init(void);
void baro_scp_periodic(void);
void baro_scp_event(void);
#define BaroScpUpdate(_b, _h) { if (baro_scp_available) { _b = baro_scp_pressure; _h(); baro_scp_available = FALSE; } }
#endif
@@ -9,6 +9,7 @@
#include "mcu_periph/sys_time.h"
#include "mcu_periph/i2c.h"
#include "subsystems/abi.h"
#include "led.h"
#include "mcu_periph/uart.h"
@@ -19,6 +20,10 @@
#warning set SENSOR_SYNC_SEND to use baro_scp_i2c
#endif
#ifndef BARO_SCP_SENDER_ID
#define BARO_SCP_SENDER_ID 21
#endif
#ifndef DOWNLINK_DEVICE
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif
@@ -99,6 +104,8 @@ void baro_scp_event( void ) {
baro_scp_pressure |= scp_trans.buf[1];
baro_scp_pressure *= 25;
float pressure = (float) baro_scp_pressure;
AbiSendMsgBARO_ABS(BARO_SCP_SENDER_ID, &pressure);
#ifdef SENSOR_SYNC_SEND
DOWNLINK_SEND_SCP_STATUS(DefaultChannel, DefaultDevice, &baro_scp_pressure, &baro_scp_temperature);
#endif
@@ -27,6 +27,7 @@
#include "pressure_board_navarro.h"
#include "state.h"
#include "subsystems/abi.h"
/* Default I2C device on tiny is i2c0
*/
@@ -56,6 +57,14 @@
#define PBN_ALTITUDE_SCALE 0.32
#endif
#ifndef PBN_PRESSURE_OFFSET
#define PBN_PRESSURE_OFFSET 101325.0
#endif
#ifndef BARO_PBN_SENDER_ID
#define BARO_PBN_SENDER_ID 22
#endif
// Global variables
uint16_t altitude_adc;
uint16_t airspeed_adc;
@@ -132,6 +141,9 @@ void pbn_read_event( void ) {
--offset_cnt;
}
else {
// Compute pressure
float pressure = PBN_ALTITUDE_SCALE * (float) altitude_adc + PBN_PRESSURE_OFFSET;
AbiSendMsgBARO_ABS(BARO_PBN_SENDER_ID, &pressure);
// Compute airspeed and altitude
//pbn_airspeed = (-4.45 + sqrtf(19.84-0.57*(float)(airspeed_offset-airspeed_adc)))/0.28;
uint16_t diff = Max(airspeed_adc-airspeed_offset, 0);
@@ -54,8 +54,6 @@ extern void pbn_read_event( void );
#define PbnEvent() { if (pbn_trans.status == I2CTransSuccess) pbn_read_event(); }
#define BaroPbnUpdate(_b) { if (data_valid) { _b = altitude_adc; data_valid = FALSE; } }
#define PERIODIC_SEND_PBN(_chan) DOWNLINK_SEND_PBN(DefaultChannel, DefaultDevice,&airspeed_adc,&altitude_adc,&pbn_airspeed,&pbn_altitude,&airspeed_offset,&altitude_offset);
#endif // PRESSURE_BOARD_NAVARRO_H