Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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"
30 #include "modules/sensors/baro.h"
31 #include "peripherals/mpl3115.h"
32 
33 // to get MPU status
35 
36 #include "modules/core/abi.h"
37 #include "led.h"
38 
39 // sd-log
40 #if APOGEE_BARO_SDLOG
42 #include "modules/gps/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 
74 struct Mpl3115 apogee_baro;
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  uint32_t now_ts = get_sys_time_usec();
117  float pressure = ((float)apogee_baro.pressure / (1 << 2));
118  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, now_ts, pressure);
119  float temp = apogee_baro.temperature / 16.0f;
120  AbiSendMsgTEMPERATURE(BARO_BOARD_SENDER_ID, temp);
121  apogee_baro.data_available = false;
122 
123 #if APOGEE_BARO_SDLOG
124  if (pprzLogFile != -1) {
125  if (!log_apogee_baro_started) {
126  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");
127  log_apogee_baro_started = true;
128  }
129  sdLogWriteLog(pprzLogFile, "apogee_baro: %9.4f %9.4f %d %d %d %d %d %d %d %d %d\n",
130  pressure,temp,
131  gps.fix, gps.tow, gps.week,
134  }
135 #endif
136 
137 
138  }
139 }
140 
Main include for ABI (AirBorneInterface).
#define BARO_BOARD_SENDER_ID
default onboard baro
void baro_periodic(void)
Definition: baro_board.c:90
#define MPL_PRESCALER
Baro periodic prescaler.
Definition: baro_board.c:66
struct Mpl3115 apogee_baro
Definition: baro_board.c:74
#define BARO_STARTUP_COUNTER
Counter to init ads1114 at startup.
Definition: baro_board.c:71
void baro_init(void)
Definition: baro_board.c:76
void apogee_baro_event(void)
Definition: baro_board.c:112
uint16_t startup_cnt
Definition: baro_board.c:72
Common barometric sensor implementation.
#define LED_ON(i)
Definition: led_hw.h:51
#define LED_OFF(i)
Definition: led_hw.h:52
#define LED_TOGGLE(i)
Definition: led_hw.h:53
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
struct GpsState gps
global GPS state
Definition: gps.c:69
Device independent GPS code (interface)
uint32_t tow
GPS time of week in ms.
Definition: gps.h:108
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:93
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:91
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:98
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:95
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:96
uint16_t week
GPS week.
Definition: gps.h:107
uint8_t fix
status of fix
Definition: gps.h:106
int32_t lat
in degrees*1e7
int32_t z
Down.
int32_t lon
in degrees*1e7
struct ImuApogee imu_apogee
Definition: imu_apogee.c:86
Driver for the IMU on the Apogee board.
struct Mpu60x0_I2c mpu
Definition: imu_apogee.h:51
arch independent LED (Light Emitting Diodes) API
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
int16_t temperature
temperature in 1/16 degrees Celcius
Definition: mpl3115.h:79
#define MPL3115_I2C_ADDR
Definition: mpl3115.h:35
volatile bool data_available
data ready flag
Definition: mpl3115.h:76
bool initialized
config done flag
Definition: mpu60x0.h:149
struct Mpu60x0Config config
Definition: mpu60x0_i2c.h:68
FileDes pprzLogFile
Definition: sdlog_chibios.c:75
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78