Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
airspeed_amsys.c
Go to the documentation of this file.
1/*
2 * Driver for a Amsys Differential Presure Sensor I2C
3 * AMS 5812-0003-D
4 * AMS 5812-0001-D
5 *
6 * Copyright (C) 2010 The Paparazzi Team
7 *
8 * This file is part of paparazzi.
9 *
10 * paparazzi is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * paparazzi is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with paparazzi; see the file COPYING. If not, write to
22 * the Free Software Foundation, 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
24 */
25
27#include "modules/core/abi.h"
28#include "mcu_periph/sys_time.h"
29#include "state.h"
30#include "mcu_periph/i2c.h"
31#include "mcu_periph/uart.h"
32#include "pprzlink/messages.h"
34#include <math.h>
35//#include <stdlib.h>
36
37
38#define AIRSPEED_AMSYS_ADDR 0xE8 // original F0
39#ifndef AIRSPEED_AMSYS_SCALE
40#define AIRSPEED_AMSYS_SCALE 1
41#endif
42#define AIRSPEED_AMSYS_OFFSET_MAX 29491
43#define AIRSPEED_AMSYS_OFFSET_MIN 3277
44#define AIRSPEED_AMSYS_OFFSET_NBSAMPLES_INIT 40
45#define AIRSPEED_AMSYS_OFFSET_NBSAMPLES_AVRG 60
46#define AIRSPEED_AMSYS_NBSAMPLES_AVRG 10
47#ifndef AIRSPEED_AMSYS_MAXPRESURE
48#define AIRSPEED_AMSYS_MAXPRESURE 2068 //003-2068, 001-1034 //Pascal
49#endif
50#ifndef AIRSPEED_AMSYS_I2C_DEV
51#define AIRSPEED_AMSYS_I2C_DEV i2c0
52#endif
53#ifdef MEASURE_AMSYS_TEMPERATURE
54#define TEMPERATURE_AMSYS_OFFSET_MAX 29491
55#define TEMPERATURE_AMSYS_OFFSET_MIN 3277
56#define TEMPERATURE_AMSYS_MAX 85
57#define TEMPERATURE_AMSYS_MIN -25
58#endif
59
60
61
62
63// Global variables
69float airspeed_amsys_p; //Pascal
70float airspeed_amsys; //mps
73
74// Local variables
80
82
98
100{
101#ifndef SITL
103#ifndef MEASURE_AMSYS_TEMPERATURE
105#else
107#endif
108 }
109#elif !defined USE_NPS
110 extern float sim_air_speed;
111 AbiSendMsgAIRSPEED_RAW(AIRSPEED_AMSYS_ID, get_sys_time_usec(), sim_air_speed);
112#endif //SITL
113}
114
116{
117
118 // Get raw airspeed from buffer
121#ifdef MEASURE_AMSYS_TEMPERATURE
123 const float temp_off_scale = (float)(TEMPERATURE_AMSYS_MAX - TEMPERATURE_AMSYS_MIN) /
124 (TEMPERATURE_AMSYS_OFFSET_MAX - TEMPERATURE_AMSYS_OFFSET_MIN);
125 // Tmin=-25, Tmax=85
126 airspeed_temperature = temp_off_scale * (tempAS_amsys_raw - TEMPERATURE_AMSYS_OFFSET_MIN) +
127 TEMPERATURE_AMSYS_MIN;
128#endif
129
130 // Check if this is valid airspeed
131 if (airspeed_amsys_raw == 0) {
132 airspeed_amsys_valid = false;
133 } else {
135 }
136
137 // Continue only if a new airspeed value was received
139
140 // raw not under offest min
143 }
144 // raw not over offest max
147 }
148
149 // calculate raw to pressure
150 const float p_off_scale = (float)(AIRSPEED_AMSYS_MAXPRESURE) /
153
156 // Check if averaging completed
157 if (airspeed_amsys_cnt == 0) {
158 // Calculate average
161 }
162 // Check if averaging needs to continue
165 }
166
167 airspeed_amsys = 0.;
168
169 } else {
171 if (airspeed_amsys_p <= 0) {
172 airspeed_amsys_p = 0.000000001;
173 }
174 // convert pressure to airspeed
175 airspeed_amsys_tmp = sqrtf(2 * airspeed_amsys_p * airspeed_scale / 1.2041);
177
178 //New value available, air_data filters and calibrates it and sets the airspeed
179 AbiSendMsgAIRSPEED_RAW(AIRSPEED_AMSYS_ID, get_sys_time_usec(), airspeed_amsys);
180 }
181
182 }
183 /*else {
184 airspeed_amsys = 0.0;
185 }*/
186
187
188 // Transaction has been read
190}
191
Main include for ABI (AirBorneInterface).
#define AIRSPEED_AMSYS_ID
void airspeed_amsys_init(void)
double airspeed_amsys_offset_tmp
#define AIRSPEED_AMSYS_OFFSET_MAX
struct i2c_transaction airspeed_amsys_i2c_trans
uint16_t tempAS_amsys_raw
#define AIRSPEED_AMSYS_SCALE
float airspeed_scale
float airspeed_amsys_offset
#define AIRSPEED_AMSYS_OFFSET_MIN
void airspeed_amsys_read_event(void)
float airspeed_temperature
float airspeed_amsys_tmp
volatile bool airspeed_amsys_i2c_done
#define AIRSPEED_AMSYS_OFFSET_NBSAMPLES_AVRG
float airspeed_amsys
uint16_t airspeed_amsys_raw
void airspeed_amsys_downlink(void)
bool airspeed_amsys_offset_init
void airspeed_amsys_read_periodic(void)
float airspeed_amsys_p
uint16_t airspeed_amsys_cnt
bool airspeed_amsys_valid
#define AIRSPEED_AMSYS_I2C_DEV
#define AIRSPEED_AMSYS_ADDR
#define AIRSPEED_AMSYS_OFFSET_NBSAMPLES_INIT
#define AIRSPEED_AMSYS_MAXPRESURE
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
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.
API to get/set the generic vehicle states.
Architecture independent timing functions.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.