Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
baro_board.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 
29 #include "std.h"
31 #include "peripherals/mpl3115.h"
32 
33 // to get MPU status
35 
36 #include "subsystems/abi.h"
37 #include "led.h"
38 
39 // sd-log
40 #if APOGEE_BARO_SDLOG
42 #include "subsystems/gps.h"
43 bool log_apogee_baro_started;
44 #endif
45 
46 
51 #ifndef BARO_BOARD_APOGEE_FREQ
52 #define BARO_BOARD_APOGEE_FREQ 5
53 #endif
54 
59 #ifdef BARO_PERIODIC_FREQUENCY
60 #define MPL_PRESCALER ((BARO_PERIODIC_FREQUENCY)/BARO_BOARD_APOGEE_FREQ)
61 #else
62 #ifdef PERIODIC_FREQUENCY
63 #define MPL_PRESCALER ((PERIODIC_FREQUENCY)/BARO_BOARD_APOGEE_FREQ)
64 #else
65 // default: assuming 60Hz for a 5Hz baro update
66 #define MPL_PRESCALER 12
67 #endif
68 #endif
69 
71 #define BARO_STARTUP_COUNTER (200/(MPL_PRESCALER))
73 
75 
76 void baro_init(void)
77 {
79 #ifdef BARO_LED
80  LED_OFF(BARO_LED);
81 #endif
83 
84 #if APOGEE_BARO_SDLOG
85  log_apogee_baro_started = false;
86 #endif
87 
88 }
89 
90 void baro_periodic(void)
91 {
92 
93  // Baro is slave of the MPU, only start reading it after MPU is configured
95 
97  // Run some loops to get correct readings from the adc
98  --startup_cnt;
100 #ifdef BARO_LED
101  LED_TOGGLE(BARO_LED);
102  if (startup_cnt == 0) {
103  LED_ON(BARO_LED);
104  }
105 #endif
106  }
107  // Read the sensor
108  RunOnceEvery(MPL_PRESCALER, mpl3115_periodic(&apogee_baro));
109  }
110 }
111 
113 {
115  if (apogee_baro.data_available && startup_cnt == 0) {
116  float pressure = ((float)apogee_baro.pressure / (1 << 2));
117  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, pressure);
118  float temp = apogee_baro.temperature / 16.0f;
119  AbiSendMsgTEMPERATURE(BARO_BOARD_SENDER_ID, temp);
120  apogee_baro.data_available = false;
121 
122 #if APOGEE_BARO_SDLOG
123  if (pprzLogFile != -1) {
124  if (!log_apogee_baro_started) {
125  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");
126  log_apogee_baro_started = true;
127  }
128  sdLogWriteLog(pprzLogFile, "apogee_baro: %9.4f %9.4f %d %d %d %d %d %d %d %d %d\n",
129  pressure,temp,
130  gps.fix, gps.tow, gps.week,
133  }
134 #endif
135 
136 
137  }
138 }
139 
struct Mpu60x0_I2c mpu
Definition: imu_apogee.h:99
unsigned short uint16_t
Definition: types.h:16
volatile bool data_available
data ready flag
Definition: mpl3115.h:76
uint16_t startup_cnt
Definition: baro_board.c:72
Driver for the IMU on the Apogee board.
Common barometric sensor implementation.
struct Mpl3115 apogee_baro
Definition: baro_board.c:74
bool initialized
config done flag
Definition: mpu60x0.h:133
struct Mpu60x0Config config
Definition: mpu60x0_i2c.h:68
void mpl3115_init(struct Mpl3115 *mpl, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpl3115.c:31
#define LED_OFF(i)
Definition: led_hw.h:51
uint16_t week
GPS week.
Definition: gps.h:100
#define MPL_PRESCALER
Baro periodic prescaler.
Definition: baro_board.c:66
Main include for ABI (AirBorneInterface).
void mpl3115_event(struct Mpl3115 *mpl)
Definition: mpl3115.c:107
void baro_init(void)
Definition: baro_board.c:76
#define BARO_STARTUP_COUNTER
Counter to init ads1114 at startup.
Definition: baro_board.c:71
int32_t z
Down.
void baro_periodic(void)
Definition: baro_board.c:90
void mpl3115_periodic(struct Mpl3115 *mpl)
Definition: mpl3115.c:153
#define MPL3115_I2C_ADDR
Definition: mpl3115.h:35
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:88
uint32_t pressure
pressure in 1/4 Pascal
Definition: mpl3115.h:80
uint32_t tow
GPS time of week in ms.
Definition: gps.h:101
Device independent GPS code (interface)
int32_t lon
in degrees*1e7
FileDes pprzLogFile
Definition: sdlog_chibios.c:85
#define BARO_BOARD_SENDER_ID
default onboard baro
Driver for the baro MPL3115A2 from Freescale (i2c)
#define LED_TOGGLE(i)
Definition: led_hw.h:52
void apogee_baro_event(void)
Definition: baro_board.c:112
int16_t temperature
temperature in 1/16 degrees Celcius
Definition: mpl3115.h:79
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:93
arch independent LED (Light Emitting Diodes) API
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:91
#define LED_ON(i)
Definition: led_hw.h:50
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:86
int32_t lat
in degrees*1e7
uint8_t fix
status of fix
Definition: gps.h:99
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:90
struct GpsState gps
global GPS state
Definition: gps.c:75
struct ImuApogee imu_apogee
Definition: imu_apogee.c:85