47 #include "pprzlink/messages.h"
51 #ifndef USE_AIRSPEED_ETS
53 #define USE_AIRSPEED_ETS TRUE
58 #if !USE_AIRSPEED_ETS && !AIRSPEED_ETS_SYNC_SEND
59 #warning either set USE_AIRSPEED_ETS or AIRSPEED_ETS_SYNC_SEND to use airspeed_ets
62 #define AIRSPEED_ETS_ADDR 0xEA
63 #ifndef AIRSPEED_ETS_SCALE
64 #define AIRSPEED_ETS_SCALE 1.8
66 #ifndef AIRSPEED_ETS_OFFSET
67 #define AIRSPEED_ETS_OFFSET 0
69 #define AIRSPEED_ETS_OFFSET_MAX 1750
70 #define AIRSPEED_ETS_OFFSET_MIN 1450
71 #define AIRSPEED_ETS_OFFSET_NBSAMPLES_INIT 40
72 #define AIRSPEED_ETS_OFFSET_NBSAMPLES_AVRG 60
73 #define AIRSPEED_ETS_NBSAMPLES_AVRG 10
75 #ifndef AIRSPEED_ETS_I2C_DEV
76 #define AIRSPEED_ETS_I2C_DEV i2c0
81 #ifndef AIRSPEED_ETS_START_DELAY
82 #define AIRSPEED_ETS_START_DELAY 0.2
87 #if AIRSPEED_ETS_SDLOG
90 bool log_airspeed_ets_started;
116 airspeed_ets_raw = 0;
118 airspeed_ets_offset = 0;
119 airspeed_ets_offset_tmp = 0;
120 airspeed_ets_i2c_done =
true;
121 airspeed_ets_valid =
false;
122 airspeed_ets_offset_init =
false;
125 airspeed_ets_buffer_idx = 0;
127 airspeed_ets_buffer[n] = 0.0;
132 airspeed_ets_delay_done =
false;
136 #if AIRSPEED_ETS_SDLOG
137 log_airspeed_ets_started =
false;
145 if (!airspeed_ets_delay_done) {
147 else { airspeed_ets_delay_done =
true; }
152 #elif !defined USE_NPS
161 float airspeed_tmp = 0.0;
166 if (airspeed_ets_raw == 0) {
167 airspeed_ets_valid =
false;
169 airspeed_ets_valid =
true;
173 if (airspeed_ets_valid) {
174 #if !AIRSPEED_ETS_3RD_PARTY_MODE
176 if (!airspeed_ets_offset_init) {
179 if (airspeed_ets_cnt == 0) {
189 airspeed_ets_offset_init =
true;
197 #ifdef AIRSPEED_ETS_REVERSE
198 if (airspeed_ets_offset_init && airspeed_ets_raw < airspeed_ets_offset) {
202 if (airspeed_ets_offset_init && airspeed_ets_raw > airspeed_ets_offset) {
212 #endif //AIRSPEED_ETS_3RD_PARTY_MODE
215 if (airspeed_tmp < 0.0) {
219 airspeed_ets_buffer[airspeed_ets_buffer_idx++] = airspeed_tmp;
221 airspeed_ets_buffer_idx = 0;
225 airspeed_ets += airspeed_ets_buffer[n];
227 airspeed_ets = airspeed_ets / (float)AIRSPEED_ETS_NBSAMPLES_AVRG;
231 #if AIRSPEED_ETS_SYNC_SEND
239 #if AIRSPEED_ETS_SDLOG
242 if (!log_airspeed_ets_started) {
243 sdLogWriteLog(
pprzLogFile,
"AIRSPEED_ETS: raw offset airspeed(m/s) GPS_fix TOW(ms) Week Lat(1e7deg) Lon(1e7deg) HMSL(mm) gpseed(cm/s) course(1e7rad) climb(cm/s)\n");
244 log_airspeed_ets_started =
true;
246 sdLogWriteLog(
pprzLogFile,
"airspeed_ets: %d %d %8.4f %d %d %d %d %d %d %d %d %d\n",
247 airspeed_ets_raw, airspeed_ets_offset, airspeed_ets,
#define AIRSPEED_ETS_OFFSET_NBSAMPLES_INIT
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
#define AIRSPEED_ETS_NBSAMPLES_AVRG
void airspeed_ets_init(void)
#define AIRSPEED_ETS_SCALE
#define AIRSPEED_ETS_OFFSET_MIN
uint16_t airspeed_ets_cnt
bool airspeed_ets_delay_done
bool airspeed_ets_offset_init
void airspeed_ets_read_periodic(void)
int32_t hmsl
height above mean sea level (MSL) in mm
#define AIRSPEED_ETS_OFFSET_NBSAMPLES_AVRG
transaction set to done by user level
Driver for the EagleTree Systems Airspeed Sensor.
Architecture independent timing functions.
#define AIRSPEED_ETS_I2C_DEV
uint32_t tow
GPS time of week in ms.
Device independent GPS code (interface)
#define AIRSPEED_ETS_ADDR
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
int32_t lon
in degrees*1e7
#define AIRSPEED_ETS_START_DELAY
delay in seconds until sensor is read after startup
#define AIRSPEED_ETS_OFFSET
int airspeed_ets_buffer_idx
I2C transaction structure.
enum I2CTransactionStatus status
Transaction status.
volatile bool airspeed_ets_i2c_done
API to get/set the generic vehicle states.
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
static void stateSetAirspeed_f(float airspeed)
Set airspeed (float).
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
struct i2c_transaction airspeed_ets_i2c_trans
Common code for AP and FBW telemetry.
uint16_t airspeed_ets_offset
void airspeed_ets_read_event(void)
float airspeed_ets_buffer[AIRSPEED_ETS_NBSAMPLES_AVRG]
uint16_t gspeed
norm of 2d ground speed in cm/s
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
#define SysTimeTimerStart(_t)
#define AIRSPEED_ETS_OFFSET_MAX
int32_t lat
in degrees*1e7
uint32_t airspeed_ets_delay_time
struct NedCoor_i ned_vel
speed NED in cm/s
struct GpsState gps
global GPS state
uint16_t airspeed_ets_raw
uint32_t airspeed_ets_offset_tmp
Architecture independent I2C (Inter-Integrated Circuit Bus) API.