Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
baro_bmp.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Martin Mueller
3  * Copyright (C) 2013 Felix Ruess <felix.ruess@gmail.com>
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  */
23 
32 #include "baro_bmp.h"
34 
35 #include "mcu_periph/sys_time.h"
36 #include "mcu_periph/i2c.h"
37 #include "led.h"
38 #include "mcu_periph/uart.h"
39 #include "subsystems/abi.h"
40 #include "pprzlink/messages.h"
42 
43 
44 #ifndef BMP_I2C_DEV
45 #define BMP_I2C_DEV i2c0
46 #endif
47 
48 #define BARO_BMP_R 0.5
49 #define BARO_BMP_SIGMA2 0.1
50 
51 
53 
55 float baro_bmp_r;
58 
59 void baro_bmp_init(void)
60 {
61 
63 
66  baro_bmp_enabled = true;
67 
68 }
69 
71 {
72 
73  if (baro_bmp.initialized) {
75  } else {
77  }
78 
79 }
80 
81 void baro_bmp_event(void)
82 {
83 
85 
87  uint32_t now_ts = get_sys_time_usec();
88  float tmp = baro_bmp.pressure / 101325.0; // pressure at sea level
89  tmp = pow(tmp, 0.190295);
90  baro_bmp_alt = 44330 * (1.0 - tmp);
91 
92  float pressure = (float)baro_bmp.pressure;
93  AbiSendMsgBARO_ABS(BARO_BMP_SENDER_ID, now_ts, pressure);
94  float temp = baro_bmp.temperature / 10.0f;
95  AbiSendMsgTEMPERATURE(BARO_BOARD_SENDER_ID, temp);
96  baro_bmp.data_available = false;
97 
98 #ifdef SENSOR_SYNC_SEND
99  DOWNLINK_SEND_BMP_STATUS(DefaultChannel, DefaultDevice, &baro_bmp.up,
102 #else
103  RunOnceEvery(10, DOWNLINK_SEND_BMP_STATUS(DefaultChannel, DefaultDevice,
104  &baro_bmp.up, &baro_bmp.ut,
107 #endif
108  }
109 }
baro_bmp_periodic
void baro_bmp_periodic(void)
Definition: baro_bmp.c:70
BARO_BOARD_SENDER_ID
#define BARO_BOARD_SENDER_ID
default onboard baro
Definition: abi_sender_ids.h:33
abi.h
bmp085_periodic
void bmp085_periodic(struct Bmp085 *bmp)
Start new measurement if idle or read temp/pressure.
Definition: bmp085.c:108
baro_bmp_init
void baro_bmp_init(void)
Definition: baro_bmp.c:59
Bmp085::temperature
int32_t temperature
temperature in 0.1 deg Celcius
Definition: bmp085.h:72
BARO_BMP_SIGMA2
#define BARO_BMP_SIGMA2
Definition: baro_bmp.c:49
baro_bmp_event
void baro_bmp_event(void)
Definition: baro_bmp.c:81
uint32_t
unsigned long uint32_t
Definition: types.h:18
BMP_I2C_DEV
#define BMP_I2C_DEV
Definition: baro_bmp.c:45
baro_bmp_r
float baro_bmp_r
Definition: baro_bmp.c:55
baro_bmp_sigma2
float baro_bmp_sigma2
Definition: baro_bmp.c:56
baro_bmp.h
bmp085_init
void bmp085_init(struct Bmp085 *bmp, struct i2c_periph *i2c_p, uint8_t addr)
Definition: bmp085.c:83
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
BARO_BMP_SENDER_ID
#define BARO_BMP_SENDER_ID
Definition: abi_sender_ids.h:48
Bmp085::ut
int32_t ut
uncompensated temperature
Definition: bmp085.h:70
BARO_BMP_R
#define BARO_BMP_R
Definition: baro_bmp.c:48
bmp085_regs.h
Bmp085::initialized
bool initialized
config done flag
Definition: bmp085.h:67
sys_time.h
Architecture independent timing functions.
led.h
arch independent LED (Light Emitting Diodes) API
bmp085_read_eeprom_calib
void bmp085_read_eeprom_calib(struct Bmp085 *bmp)
Definition: bmp085.c:73
Bmp085::up
int32_t up
uncompensated pressure
Definition: bmp085.h:71
Bmp085::pressure
int32_t pressure
pressure in Pascal
Definition: bmp085.h:73
Bmp085::data_available
volatile bool data_available
data ready flag
Definition: bmp085.h:68
int32_t
signed long int32_t
Definition: types.h:19
Bmp085
Definition: bmp085.h:62
baro_bmp_enabled
bool baro_bmp_enabled
Definition: baro_bmp.c:54
BMP085_SLAVE_ADDR
#define BMP085_SLAVE_ADDR
Definition: bmp085_regs.h:57
i2c.h
bmp085_event
void bmp085_event(struct Bmp085 *bmp)
Definition: bmp085.c:142
baro_bmp
struct Bmp085 baro_bmp
Definition: baro_bmp.c:52
baro_bmp_alt
int32_t baro_bmp_alt
Definition: baro_bmp.c:57