Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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
41
42#include "sensors/baro_ets.h"
43#include "mcu_periph/i2c.h"
44#include "state.h"
45#include "modules/core/abi.h"
46#include <math.h>
47#include "mcu_periph/sys_time.h"
48
50
51#define BARO_ETS_ADDR 0xE8
52#define BARO_ETS_REG 0x07
53#define BARO_ETS_OFFSET_MAX 30000
54#define BARO_ETS_OFFSET_MIN 10
55#define BARO_ETS_OFFSET_NBSAMPLES_INIT 20
56#define BARO_ETS_OFFSET_NBSAMPLES_AVRG 40
57#define BARO_ETS_R 0.5
58#define BARO_ETS_SIGMA2 0.1
59
67#ifndef BARO_ETS_SCALE
68#define BARO_ETS_SCALE 37.5
69#endif
70
72#ifndef BARO_ETS_ALT_SCALE
73#define BARO_ETS_ALT_SCALE 0.32
74#endif
75
77#ifndef BARO_ETS_PRESSURE_OFFSET
78#define BARO_ETS_PRESSURE_OFFSET 101325.0
79#endif
80
81#ifndef BARO_ETS_I2C_DEV
82#define BARO_ETS_I2C_DEV i2c0
83#endif
85
86
88
89
90#ifndef BARO_ETS_START_DELAY
91#define BARO_ETS_START_DELAY 0.2
92#endif
94
95// Global variables
103
105
106// Local variables
112
131
133{
134 // Initiate next read
135 if (!baro_ets_delay_done) {
137 else { baro_ets_delay_done = true; }
138 }
139 if (baro_ets_i2c_trans.status == I2CTransDone) {
141 }
142}
143
145{
146 // Get raw altimeter from buffer
148 // Check if this is valid altimeter
149 if (baro_ets_adc == 0) {
150 baro_ets_valid = false;
151 } else {
152 baro_ets_valid = true;
153 }
154
155 // Continue only if a new altimeter value was received
156 if (baro_ets_valid) {
157 // Calculate offset average if not done already
159 --baro_ets_cnt;
160 // Check if averaging completed
161 if (baro_ets_cnt == 0) {
162 // Calculate average
164 // Limit offset
167 }
170 }
172 }
173 // Check if averaging needs to continue
176 }
177 }
178 // Convert raw to m/s
181 // New value available
182 uint32_t now_ts = get_sys_time_usec();
183 float pressure = BARO_ETS_SCALE * (float) baro_ets_adc + BARO_ETS_PRESSURE_OFFSET;
184 AbiSendMsgBARO_ABS_RAW(BARO_ETS_SENDER_ID, now_ts, pressure);
185 } else {
186 baro_ets_altitude = 0.0;
187 }
188 } else {
189 baro_ets_altitude = 0.0;
190 }
191
192 // Transaction has been read
194}
Main include for ABI (AirBorneInterface).
#define BARO_ETS_SENDER_ID
void baro_ets_read_periodic(void)
Definition baro_ets.c:132
float baro_ets_r
Definition baro_ets.c:101
uint32_t baro_ets_delay_time
Definition baro_ets.c:110
bool baro_ets_valid
Definition baro_ets.c:98
#define BARO_ETS_ALT_SCALE
scale factor to convert raw ADC measurement to altitude change in meters
Definition baro_ets.c:73
#define BARO_ETS_ADDR
Definition baro_ets.c:51
#define BARO_ETS_SCALE
scale factor to convert raw ADC measurement to pressure in Pascal.
Definition baro_ets.c:68
#define BARO_ETS_I2C_DEV
Definition baro_ets.c:82
struct i2c_transaction baro_ets_i2c_trans
Definition baro_ets.c:104
#define BARO_ETS_START_DELAY
delay in seconds until sensor is read after startup
Definition baro_ets.c:91
void baro_ets_init(void)
Definition baro_ets.c:113
bool baro_ets_offset_init
Definition baro_ets.c:107
bool baro_ets_enabled
Definition baro_ets.c:100
#define BARO_ETS_OFFSET_MIN
Definition baro_ets.c:54
uint16_t baro_ets_adc
Definition baro_ets.c:96
#define BARO_ETS_SIGMA2
Definition baro_ets.c:58
void baro_ets_read_event(void)
Definition baro_ets.c:144
uint16_t baro_ets_cnt
Definition baro_ets.c:109
#define BARO_ETS_PRESSURE_OFFSET
Pressure offset in Pascal when converting raw adc to real pressure (.
Definition baro_ets.c:78
uint32_t baro_ets_offset_tmp
Definition baro_ets.c:108
uint16_t baro_ets_offset
Definition baro_ets.c:97
float baro_ets_sigma2
Definition baro_ets.c:102
float baro_ets_altitude
Definition baro_ets.c:99
#define BARO_ETS_R
Definition baro_ets.c:57
#define BARO_ETS_OFFSET_MAX
Definition baro_ets.c:53
#define BARO_ETS_OFFSET_NBSAMPLES_AVRG
Definition baro_ets.c:56
#define BARO_ETS_OFFSET_NBSAMPLES_INIT
Definition baro_ets.c:55
bool baro_ets_delay_done
Definition baro_ets.c:111
Driver for the EagleTree Systems Altitude Sensor.
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
float ground_alt
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition common_nav.c:46
bool 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:212
@ I2CTransDone
transaction set to done by user level
Definition i2c.h:60
I2C transaction structure.
Definition i2c.h:94
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
Fixedwing Navigation library.
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
API to get/set the generic vehicle states.
Architecture independent timing functions.
#define SysTimeTimerStart(_t)
Definition sys_time.h:329
#define USEC_OF_SEC(sec)
Definition sys_time.h:322
#define SysTimeTimer(_t)
Definition sys_time.h:330
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.