Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pressure_board_navarro.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 ENAC
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 
23 /*
24  * Pressure Board Navarro
25  */
26 
27 
28 #include "pressure_board_navarro.h"
29 #include "estimator.h"
30 
31 /* Default I2C device on tiny is i2c0
32  */
33 #ifndef PBN_I2C_DEVICE
34 #define PBN_I2C_DEVICE i2c0
35 #endif
36 
37 /* Sensor I2C slave address */
38 #define PBN_I2C_ADDR 0x28
39 
40 /* Number of values to compute an offset at startup */
41 #define OFFSET_NBSAMPLES_AVRG 100
42 
43 /* Number of loops before starting to store data */
44 #define PBN_START_DELAY 30
45 
46 /* Weight for offset IIR filter */
47 #define PBN_OFFSET_FILTER 7
48 
49 /* Quadratic scale factor for airspeed */
50 #ifndef PBN_AIRSPEED_SCALE
51 #define PBN_AIRSPEED_SCALE (1./0.54)
52 #endif
53 
54 /* Linear scale factor for altitude */
55 #ifndef PBN_ALTITUDE_SCALE
56 #define PBN_ALTITUDE_SCALE 0.32
57 #endif
58 
59 // Global variables
62 bool_t data_valid;
64 
65 
75 
76 void pbn_init( void ) {
78  altitude_offset = 0;
79  airspeed_offset = 0;
80  airspeed_adc = 0;
81  altitude_adc = 0;
82  data_valid = TRUE;
84  pbn_airspeed = 0.;
85  pbn_altitude = 0.;
87 }
88 
89 
90 void pbn_periodic( void ) {
91 
92  if ( startup_delay > 0 ) {
93  --startup_delay;
94  return;
95  }
96 
97  // Initiate next read
98  pbn_trans.buf[0] = 0;
100 
101 }
102 
103 void pbn_read_event( void ) {
104 
106 
107  // Get raw values from buffer
108  airspeed_adc = ((uint16_t)(pbn_trans.buf[0]) << 8) | (uint16_t)(pbn_trans.buf[1]);
109  altitude_adc = ((uint16_t)(pbn_trans.buf[2]) << 8) | (uint16_t)(pbn_trans.buf[3]);
110 
111  // Consider 0 as a wrong value
112  if (airspeed_adc == 0 || altitude_adc == 0) {
113  data_valid = FALSE;
114  }
115  else {
116  data_valid = TRUE;
117 
118  if (offset_cnt > 0) {
119  // IIR filter to compute an initial offset
120 #ifndef PBN_AIRSPEED_OFFSET
122 #else
123  airspeed_offset = PBN_AIRSPEED_OFFSET;
124 #endif
125 #ifndef PBN_ALTITUDE_OFFSET
127 #else
128  altitude_offset = PBN_ALTITUDE_OFFSET;
129 #endif
130 
131  // decrease init counter
132  --offset_cnt;
133  }
134  else {
135  // Compute airspeed and altitude
136  //pbn_airspeed = (-4.45 + sqrtf(19.84-0.57*(float)(airspeed_offset-airspeed_adc)))/0.28;
138  float tmp_airspeed = sqrtf((float)diff * PBN_AIRSPEED_SCALE);
140 
141  pbn_airspeed = (airspeed_filter*pbn_airspeed + tmp_airspeed) / (airspeed_filter + 1.);
142 #if USE_AIRSPEED
144 #endif
145  //alt_kalman(pbn_altitude);
146 
147  }
148 
149  }
150 }
unsigned short uint16_t
Definition: types.h:16
uint16_t altitude_adc
uint16_t startup_delay
#define PBN_START_DELAY
#define OFFSET_NBSAMPLES_AVRG
#define PBN_OFFSET_FILTER
#define EstimatorSetAirspeed(airspeed)
Definition: estimator.h:132
#define FALSE
Definition: imu_chimu.h:141
float pbn_altitude
uint16_t airspeed_offset
uint32_t altitude_offset_tmp
#define PBN_ALTITUDE_SCALE
#define Max(x, y)
float airspeed_filter
uint16_t airspeed_adc
bool_t data_valid
void pbn_read_event(void)
unsigned long uint32_t
Definition: types.h:18
enum I2CTransactionStatus status
Definition: i2c.h:47
uint16_t offset_cnt
#define TRUE
Definition: imu_chimu.h:144
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
void pbn_init(void)
#define I2CTransceive(_p, _t, _s_addr, _len_w, _len_r)
Definition: i2c.h:156
struct i2c_transaction pbn_trans
State estimation, fusioning sensors.
#define PBN_I2C_DEVICE
void pbn_periodic(void)
#define PBN_AIRSPEED_SCALE
uint16_t altitude_offset
uint32_t airspeed_offset_tmp
float pbn_airspeed
#define PBN_I2C_ADDR