Paparazzi UAS  v6.2_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 
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 
LlaCoor_i::lon
int32_t lon
in degrees*1e7
Definition: pprz_geodetic_int.h:61
uint32_t
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
pprzLogFile
FileDes pprzLogFile
Definition: sdlog_chibios.c:86
BARO_BOARD_SENDER_ID
#define BARO_BOARD_SENDER_ID
default onboard baro
Definition: abi_sender_ids.h:33
mpl3115_event
void mpl3115_event(struct Mpl3115 *mpl)
Definition: mpl3115.c:107
LED_OFF
#define LED_OFF(i)
Definition: led_hw.h:52
abi.h
MPL_PRESCALER
#define MPL_PRESCALER
Baro periodic prescaler.
Definition: baro_board.c:66
GpsState::tow
uint32_t tow
GPS time of week in ms.
Definition: gps.h:112
ImuApogee::mpu
struct Mpu60x0_I2c mpu
Definition: imu_apogee.h:51
apogee_baro
struct Mpl3115 apogee_baro
Definition: baro_board.c:74
mpl3115.h
imu_apogee.h
LED_ON
#define LED_ON(i)
Definition: led_hw.h:51
Mpl3115::pressure
uint32_t pressure
pressure in 1/4 Pascal
Definition: mpl3115.h:80
LED_TOGGLE
#define LED_TOGGLE(i)
Definition: led_hw.h:53
baro_init
void baro_init(void)
Definition: baro_board.c:76
baro_periodic
void baro_periodic(void)
Definition: baro_board.c:90
GpsState::ned_vel
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:99
BARO_STARTUP_COUNTER
#define BARO_STARTUP_COUNTER
Counter to init ads1114 at startup.
Definition: baro_board.c:71
Mpl3115
Definition: mpl3115.h:70
NedCoor_i::z
int32_t z
Down.
Definition: pprz_geodetic_int.h:71
sdlog_chibios.h
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:75
LlaCoor_i::lat
int32_t lat
in degrees*1e7
Definition: pprz_geodetic_int.h:60
std.h
gps.h
Device independent GPS code (interface)
GpsState::fix
uint8_t fix
status of fix
Definition: gps.h:110
MPL3115_I2C_ADDR
#define MPL3115_I2C_ADDR
Definition: mpl3115.h:35
GpsState::week
uint16_t week
GPS week.
Definition: gps.h:111
mpl3115_periodic
void mpl3115_periodic(struct Mpl3115 *mpl)
Definition: mpl3115.c:153
GpsState::gspeed
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:100
imu_apogee
struct ImuApogee imu_apogee
Definition: imu_apogee.c:85
led.h
arch independent LED (Light Emitting Diodes) API
Mpu60x0_I2c::config
struct Mpu60x0Config config
Definition: mpu60x0_i2c.h:68
baro.h
GpsState::course
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:102
apogee_baro_event
void apogee_baro_event(void)
Definition: baro_board.c:112
GpsState::lla_pos
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:95
GpsState::hmsl
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:97
Mpl3115::temperature
int16_t temperature
temperature in 1/16 degrees Celcius
Definition: mpl3115.h:79
Mpl3115::data_available
volatile bool data_available
data ready flag
Definition: mpl3115.h:76
uint16_t
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
gps
struct GpsState gps
global GPS state
Definition: gps.c:69
Mpu60x0Config::initialized
bool initialized
config done flag
Definition: mpu60x0.h:149
startup_cnt
uint16_t startup_cnt
Definition: baro_board.c:72
mpl3115_init
void mpl3115_init(struct Mpl3115 *mpl, struct i2c_periph *i2c_p, uint8_t addr)
Definition: mpl3115.c:31