Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
baro_apogee.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2013 Gautier Hattenberger (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
28
30#include "peripherals/mpl3115.h"
31
32// to get MPU status
34
35#include "modules/core/abi.h"
36#include "mcu_periph/sys_time.h"
37
38// sd-log
39#if APOGEE_BARO_SDLOG
41#include "modules/gps/gps.h"
42bool log_apogee_baro_started;
43#endif
44
46#define BARO_STARTUP_COUNTER (4 * BARO_APOGEE_FREQ)
48
50
52{
55
56#if APOGEE_BARO_SDLOG
57 log_apogee_baro_started = false;
58#endif
59}
60
62{
63 // Baro is slave of the MPU, only start reading it after MPU is configured
64 if (imu_apogee.mpu.config.initialized) {
65 if (startup_cnt > 0 && apogee_baro.data_available) {
66 // Run some loops to get correct readings from the adc
68 apogee_baro.data_available = false;
69 }
70 // Read the sensor
72 }
73}
74
76{
78 if (apogee_baro.data_available && startup_cnt == 0) {
79 uint32_t now_ts = get_sys_time_usec();
80 float pressure = ((float)apogee_baro.pressure / (1 << 2));
81 AbiSendMsgBARO_ABS_RAW(BARO_MPL3115_SENDER_ID, now_ts, pressure);
82 float temp = apogee_baro.temperature / 16.0f;
83 AbiSendMsgTEMPERATURE_RAW(BARO_MPL3115_SENDER_ID, now_ts, temp, TEMPERATURE_TYPE_BARO);
84 apogee_baro.data_available = false;
85
86#if APOGEE_BARO_SDLOG
87 if (pprzLogFile != -1) {
88 if (!log_apogee_baro_started) {
89 sdLogWriteLog(pprzLogFile, "APOGEE_BARO: Pres(Pa) Temp(degC) GPS_fix TOW(ms) Week Lat(1e7deg) Lon(1e7deg) HMSL(mm) gpseed(cm/s) course(1e7deg) climb(cm/s)\n");
90 log_apogee_baro_started = true;
91 }
92 sdLogWriteLog(pprzLogFile, "apogee_baro: %9.4f %9.4f %d %d %d %d %d %d %d %d %d\n",
93 pressure,temp,
94 gps.fix, gps.tow, gps.week,
95 gps.lla_pos.lat, gps.lla_pos.lon, gps.hmsl,
96 gps.gspeed, gps.course, -gps.ned_vel.z);
97 }
98#endif
99
100
101 }
102}
103
Main include for ABI (AirBorneInterface).
#define TEMPERATURE_TYPE_BARO
barometer die
Definition abi_common.h:91
#define BARO_MPL3115_SENDER_ID
void baro_apogee_event(void)
Definition baro_apogee.c:75
void baro_apogee_periodic(void)
Definition baro_apogee.c:61
struct Mpl3115 apogee_baro
Definition baro_apogee.c:49
#define BARO_STARTUP_COUNTER
Number of readings skipped at startup, about 4 s.
Definition baro_apogee.c:46
uint16_t startup_cnt
Definition baro_apogee.c:47
void baro_apogee_init(void)
Definition baro_apogee.c:51
integrated barometer for Apogee boards (mpl3115)
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
struct GpsState gps
global GPS state
Definition gps.c:74
Device independent GPS code (interface).
struct ImuApogee imu_apogee
Definition imu_apogee.c:86
Driver for the IMU on the Apogee board.
static FILE * pprzLogFile
void mpl3115_periodic(struct Mpl3115 *mpl)
Definition mpl3115.c:153
void mpl3115_init(struct Mpl3115 *mpl, struct i2c_periph *i2c_p, uint8_t addr)
Definition mpl3115.c:31
void mpl3115_event(struct Mpl3115 *mpl)
Definition mpl3115.c:107
Driver for the baro MPL3115A2 from Freescale (i2c).
uint32_t pressure
pressure in 1/4 Pascal
Definition mpl3115.h:80
#define MPL3115_I2C_ADDR
Definition mpl3115.h:35
SdioError sdLogWriteLog(const FileDes fd, const char *fmt,...)
Architecture independent timing functions.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.