Paparazzi UAS  v5.15_devel-81-gd13dafb
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
baro_board_ms5611_i2c.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2013 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
31 #include "peripherals/ms5611_i2c.h"
32 
33 #include BOARD_CONFIG // include board specific settings
34 
35 #include "mcu_periph/sys_time.h"
36 #include "led.h"
37 #include "std.h"
38 #include "subsystems/abi.h"
39 
40 #include "mcu_periph/uart.h"
41 #include "pprzlink/messages.h"
43 
44 #include "filters/median_filter.h"
45 
46 #if BARO_PERIODIC_FREQUENCY > 100
47 #error "For MS5611 BARO_PERIODIC_FREQUENCY has to be <= 100"
48 #endif
49 
50 
57 #ifndef BB_MS5611_SLAVE_ADDR
58 #define BB_MS5611_SLAVE_ADDR 0xEE
59 #endif
60 
62 #ifndef BB_MS5611_TYPE_MS5607
63 #define BB_MS5611_TYPE_MS5607 FALSE
64 #endif
65 PRINT_CONFIG_VAR(BB_MS5611_TYPE_MS5607)
66 
69 
70 void baro_init(void)
71 {
72  ms5611_i2c_init(&bb_ms5611, &BB_MS5611_I2C_DEV, BB_MS5611_SLAVE_ADDR, BB_MS5611_TYPE_MS5607);
73 
74 #ifdef BARO_LED
75  LED_OFF(BARO_LED);
76 #endif
77 
78  init_median_filter_f(&bb_ms5611_filt, 5);
79 }
80 
81 void baro_periodic(void)
82 {
83  if (sys_time.nb_sec > 1) {
84 
85  /* call the convenience periodic that initializes the sensor and starts reading*/
87 
88 #if DEBUG
90  RunOnceEvery((50 * 30), DOWNLINK_SEND_MS5611_COEFF(DefaultChannel, DefaultDevice,
91  &bb_ms5611.data.c[0],
92  &bb_ms5611.data.c[1],
93  &bb_ms5611.data.c[2],
94  &bb_ms5611.data.c[3],
95  &bb_ms5611.data.c[4],
96  &bb_ms5611.data.c[5],
97  &bb_ms5611.data.c[6],
98  &bb_ms5611.data.c[7]));
99 #endif
100  }
101 }
102 
103 void baro_event(void)
104 {
105  if (sys_time.nb_sec > 1) {
107 
109  uint32_t now_ts = get_sys_time_usec();
110  float pressure = update_median_filter_f(&bb_ms5611_filt, (float)bb_ms5611.data.pressure);
111  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, now_ts, pressure);
112  float temp = bb_ms5611.data.temperature / 100.0f;
113  AbiSendMsgTEMPERATURE(BARO_BOARD_SENDER_ID, temp);
114  bb_ms5611.data_available = false;
115 
116 #ifdef BARO_LED
117  RunOnceEvery(10, LED_TOGGLE(BARO_LED));
118 #endif
119 
120 #if DEBUG
121  float fbaroms = bb_ms5611.data.pressure / 100.;
122  DOWNLINK_SEND_BARO_MS5611(DefaultChannel, DefaultDevice,
124  &fbaroms, &temp);
125 #endif
126  }
127  }
128 }
uint32_t d1
Definition: ms5611.h:55
struct Ms5611_I2c bb_ms5611
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void ms5611_i2c_init(struct Ms5611_I2c *ms, struct i2c_periph *i2c_p, uint8_t addr, bool is_ms5607)
Definition: ms5611_i2c.c:33
uint16_t c[PROM_NB]
Definition: ms5611.h:54
Common barometric sensor implementation.
struct Ms5611Data data
Definition: ms5611_i2c.h:43
#define LED_OFF(i)
Definition: led_hw.h:52
uint32_t pressure
pressure in Pascal (0.01mbar)
Definition: ms5611.h:52
void baro_init(void)
Main include for ABI (AirBorneInterface).
float fbaroms
uint32_t d2
Definition: ms5611.h:56
void baro_event(void)
#define BB_MS5611_SLAVE_ADDR
default i2c address when CSB is set to GND addr is 0xEE when CSB is set to VCC addr is 0xEC ...
volatile bool data_available
data ready flag
Definition: ms5611_i2c.h:42
Architecture independent timing functions.
Measurement Specialties (Intersema) MS5611-01BA and MS5607-02BA03 pressure/temperature sensor interfa...
unsigned long uint32_t
Definition: types.h:18
static void ms5611_i2c_periodic(struct Ms5611_I2c *ms)
convenience function
Definition: ms5611_i2c.h:69
static void init_median_filter_f(struct MedianFilterFloat *filter, uint8_t size)
void baro_periodic(void)
#define BARO_BOARD_SENDER_ID
default onboard baro
void ms5611_i2c_event(struct Ms5611_I2c *ms)
Definition: ms5611_i2c.c:119
static float update_median_filter_f(struct MedianFilterFloat *filter, float new_data)
#define LED_TOGGLE(i)
Definition: led_hw.h:53
struct MedianFilterFloat bb_ms5611_filt
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
bool initialized
config done flag
Definition: ms5611_i2c.h:41
arch independent LED (Light Emitting Diodes) API
#define BB_MS5611_TYPE_MS5607
set to TRUE if baro is actually a MS5607
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
int32_t temperature
temperature with 0.01 degrees Celsius resolution
Definition: ms5611.h:53