Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
baro_ets.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Vassilis Varveropoulos
3  * Copyright (C) 2010 The Paparazzi Team
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 
42 #include "sensors/baro_ets.h"
43 #include "mcu_periph/i2c.h"
44 #include "state.h"
45 #include "subsystems/abi.h"
46 #include <math.h>
47 #include "mcu_periph/sys_time.h"
48 
50 
51 #ifdef BARO_ETS_SYNC_SEND
52 
53 #include "mcu_periph/uart.h"
54 #include "messages.h"
56 #endif //BARO_ETS_SYNC_SEND
57 
58 #define BARO_ETS_ADDR 0xE8
59 #define BARO_ETS_REG 0x07
60 #define BARO_ETS_OFFSET_MAX 30000
61 #define BARO_ETS_OFFSET_MIN 10
62 #define BARO_ETS_OFFSET_NBSAMPLES_INIT 20
63 #define BARO_ETS_OFFSET_NBSAMPLES_AVRG 40
64 #define BARO_ETS_R 0.5
65 #define BARO_ETS_SIGMA2 0.1
66 
74 #ifndef BARO_ETS_SCALE
75 #define BARO_ETS_SCALE 37.5
76 #endif
77 
79 #ifndef BARO_ETS_ALT_SCALE
80 #define BARO_ETS_ALT_SCALE 0.32
81 #endif
82 
84 #ifndef BARO_ETS_PRESSURE_OFFSET
85 #define BARO_ETS_PRESSURE_OFFSET 101325.0
86 #endif
87 
88 #ifndef BARO_ETS_I2C_DEV
89 #define BARO_ETS_I2C_DEV i2c0
90 #endif
92 
93 
95 
97 #ifndef BARO_ETS_START_DELAY
98 #define BARO_ETS_START_DELAY 0.2
99 #endif
101 
102 // Global variables
110 
112 
113 // Local variables
119 
120 void baro_ets_init( void ) {
121  baro_ets_adc = 0;
122  baro_ets_altitude = 0.0;
123  baro_ets_offset = 0;
124  baro_ets_offset_tmp = 0;
125  baro_ets_valid = FALSE;
126  baro_ets_offset_init = FALSE;
127  baro_ets_enabled = TRUE;
129  baro_ets_r = BARO_ETS_R;
130  baro_ets_sigma2 = BARO_ETS_SIGMA2;
131 
132  baro_ets_i2c_trans.status = I2CTransDone;
133 
134  baro_ets_delay_done = FALSE;
135  SysTimeTimerStart(baro_ets_delay_time);
136 }
137 
139  // Initiate next read
140  if (!baro_ets_delay_done) {
142  else baro_ets_delay_done = TRUE;
143  }
146  }
147 }
148 
149 void baro_ets_read_event( void ) {
150  // Get raw altimeter from buffer
152  // Check if this is valid altimeter
153  if (baro_ets_adc == 0)
155  else
157 
158  // Continue only if a new altimeter value was received
159  if (baro_ets_valid) {
160  // Calculate offset average if not done already
161  if (!baro_ets_offset_init) {
162  --baro_ets_cnt;
163  // Check if averaging completed
164  if (baro_ets_cnt == 0) {
165  // Calculate average
167  // Limit offset
173  }
174  // Check if averaging needs to continue
177  }
178  // Convert raw to m/s
179  if (baro_ets_offset_init) {
181  // New value available
183  AbiSendMsgBARO_ABS(BARO_ETS_SENDER_ID, &pressure);
184 #ifdef BARO_ETS_SYNC_SEND
186 #endif
187  } else {
188  baro_ets_altitude = 0.0;
189  }
190  } else {
191  baro_ets_altitude = 0.0;
192  }
193 
194  // Transaction has been read
196 }
#define BARO_ETS_START_DELAY
delay in seconds until sensor is read after startup
Definition: baro_ets.c:98
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
float ground_alt
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition: common_nav.c:40
I2C transaction structure.
Definition: i2c.h:93
struct i2c_transaction baro_ets_i2c_trans
Definition: baro_ets.c:111
#define BARO_ETS_SCALE
scale factor to convert raw ADC measurement to pressure in Pascal.
Definition: baro_ets.c:75
Main include for ABI (AirBorneInterface).
float baro_ets_r
Definition: baro_ets.c:108
int32_t pressure
pressure in Pascal
Definition: bmp085.h:73
#define FALSE
Definition: imu_chimu.h:141
#define BARO_ETS_PRESSURE_OFFSET
Pressure offset in Pascal when converting raw adc to real pressure (.
Definition: baro_ets.c:85
#define BARO_ETS_ADDR
Definition: baro_ets.c:58
uint32_t baro_ets_delay_time
Definition: baro_ets.c:117
#define BARO_ETS_SIGMA2
Definition: baro_ets.c:65
bool_t baro_ets_valid
Definition: baro_ets.c:105
transaction set to done by user level
Definition: i2c.h:59
Architecture independent timing functions.
#define BARO_ETS_R
Definition: baro_ets.c:64
Driver for the EagleTree Systems Altitude Sensor.
unsigned long uint32_t
Definition: types.h:18
float baro_ets_altitude
Definition: baro_ets.c:106
uint16_t baro_ets_cnt
Definition: baro_ets.c:116
void baro_ets_init(void)
Definition: baro_ets.c:120
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
#define USEC_OF_SEC(sec)
Definition: sys_time.h:190
#define BARO_ETS_ALT_SCALE
scale factor to convert raw ADC measurement to altitude change in meters
Definition: baro_ets.c:80
bool_t baro_ets_delay_done
Definition: baro_ets.c:118
#define SysTimeTimer(_t)
Definition: sys_time.h:199
#define BARO_ETS_OFFSET_MAX
Definition: baro_ets.c:60
#define TRUE
Definition: imu_chimu.h:144
bool_t baro_ets_enabled
Definition: baro_ets.c:107
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
bool_t baro_ets_offset_init
Definition: baro_ets.c:114
API to get/set the generic vehicle states.
float baro_ets_sigma2
Definition: baro_ets.c:109
#define BARO_ETS_OFFSET_MIN
Definition: baro_ets.c:61
void baro_ets_read_periodic(void)
Definition: baro_ets.c:138
uint16_t baro_ets_offset
Definition: baro_ets.c:104
#define BARO_ETS_OFFSET_NBSAMPLES_INIT
Definition: baro_ets.c:62
#define BARO_ETS_I2C_DEV
Definition: baro_ets.c:89
#define BARO_ETS_OFFSET_NBSAMPLES_AVRG
Definition: baro_ets.c:63
#define SysTimeTimerStart(_t)
Definition: sys_time.h:198
void baro_ets_read_event(void)
Definition: baro_ets.c:149
uint16_t baro_ets_adc
Definition: baro_ets.c:103
bool_t i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
Definition: i2c.c:248
uint32_t baro_ets_offset_tmp
Definition: baro_ets.c:115
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
#define BARO_ETS_SENDER_ID