Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
meteo_france_DAQ.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Gautier Hattenberger
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 
35 
36 #include "state.h"
37 #include "autopilot.h"
42 
43 #include "subsystems/gps.h"
45 
46 struct MF_DAQ mf_daq;
48 
49 #ifndef MF_DAQ_POWER_INIT
50 #define MF_DAQ_POWER_INIT TRUE
51 #endif
52 
53 #if !(defined MF_DAQ_POWER_PORT) && !(defined MF_DAQ_POWER_PIN)
54 INFO("MF_DAQ power pin is not defined")
55 #endif
56 
57 void init_mf_daq(void)
58 {
59  mf_daq.nb = 0;
61 #if (defined MF_DAQ_POWER_PORT) && (defined MF_DAQ_POWER_PIN)
62  gpio_setup_output(MF_DAQ_POWER_PORT, MF_DAQ_POWER_PIN);
63 #endif
65  log_started = false;
66 }
67 
69 {
70  // Send aircraft state to DAQ board
71  DOWNLINK_SEND_MF_DAQ_STATE(extra_pprz_tp, EXTRA_DOWNLINK_DEVICE,
74  &stateGetBodyRates_f()->q,
75  &stateGetBodyRates_f()->r,
77  &stateGetNedToBodyEulers_f()->theta,
79  &stateGetAccelNed_f()->x,
80  &stateGetAccelNed_f()->y,
81  &stateGetAccelNed_f()->z,
82  &stateGetSpeedEnu_f()->x,
83  &stateGetSpeedEnu_f()->y,
84  &stateGetSpeedEnu_f()->z,
85  &stateGetPositionLla_f()->lat,
86  &stateGetPositionLla_f()->lon,
87  &stateGetPositionLla_f()->alt,
90 }
91 
93 {
94  // Send report over normal telemetry
95  if (mf_daq.nb > 0) {
96  DOWNLINK_SEND_PAYLOAD_FLOAT(DefaultChannel, DefaultDevice, 9, mf_daq.values);
97  }
98  // Test if log is started
99  if (pprzLogFile != -1) {
100  if (log_started == FALSE) {
101  // Log MD5SUM once
102  DOWNLINK_SEND_ALIVE(pprzlog_tp, chibios_sdlog, 16, MD5SUM);
103  log_started = true;
104  }
105  // Log GPS for time reference
106  uint8_t foo = 0;
107  int16_t climb = -gps.ned_vel.z;
108  int16_t course = (DegOfRad(gps.course) / ((int32_t)1e6));
109  struct UtmCoor_f utm = *stateGetPositionUtm_f();
110  int32_t east = utm.east * 100;
111  int32_t north = utm.north * 100;
112  DOWNLINK_SEND_GPS(pprzlog_tp, chibios_sdlog, &gps.fix,
113  &east, &north, &course, &gps.hmsl, &gps.gspeed, &climb,
114  &gps.week, &gps.tow, &utm.zone, &foo);
115  }
116 }
117 
119 {
120  mf_daq.nb = buf[2];
121  if (mf_daq.nb > 0) {
122  if (mf_daq.nb > MF_DAQ_SIZE) { mf_daq.nb = MF_DAQ_SIZE; }
123  // Store data struct directly from dl_buffer
124  float *bufloc = (float*)(buf+3);
125  memcpy(mf_daq.values, bufloc, mf_daq.nb * sizeof(float));
126  // Log on SD card
127  if (log_started) {
128  DOWNLINK_SEND_PAYLOAD_FLOAT(pprzlog_tp, chibios_sdlog, mf_daq.nb, mf_daq.values);
129  DOWNLINK_SEND_MF_DAQ_STATE(pprzlog_tp, chibios_sdlog,
132  &stateGetBodyRates_f()->q,
133  &stateGetBodyRates_f()->r,
135  &stateGetNedToBodyEulers_f()->theta,
137  &stateGetAccelNed_f()->x,
138  &stateGetAccelNed_f()->y,
139  &stateGetAccelNed_f()->z,
140  &stateGetSpeedEnu_f()->x,
141  &stateGetSpeedEnu_f()->y,
142  &stateGetSpeedEnu_f()->z,
143  &stateGetPositionLla_f()->lat,
144  &stateGetPositionLla_f()->lon,
148  }
149  }
150 }
151 
152 
pprzLogFile
FileDes pprzLogFile
Definition: sdlog_chibios.c:86
mf_daq_send_report
void mf_daq_send_report(void)
Definition: meteo_france_DAQ.c:92
MF_DAQ::nb
uint8_t nb
Definition: meteo_france_DAQ.h:45
UtmCoor_f::north
float north
in meters
Definition: pprz_geodetic_float.h:82
meteo_france_DAQ.h
GpsState::tow
uint32_t tow
GPS time of week in ms.
Definition: gps.h:109
stateGetAccelNed_f
static struct NedCoor_f * stateGetAccelNed_f(void)
Get acceleration in NED coordinates (float).
Definition: state.h:1038
pprz_autopilot::flight_time
uint16_t flight_time
flight time in seconds
Definition: autopilot.h:65
init_mf_daq
void init_mf_daq(void)
Definition: meteo_france_DAQ.c:57
stateGetNedToBodyEulers_f
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition: state.h:1143
stateGetBodyRates_f
static struct FloatRates * stateGetBodyRates_f(void)
Get vehicle body angular rate (float).
Definition: state.h:1200
gpio_setup_output
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
Definition: gpio_arch.c:33
UtmCoor_f::east
float east
in meters
Definition: pprz_geodetic_float.h:83
pprzlog_tp.h
Initialize pprzlog transport.
extra_pprz_dl.h
stateGetPositionUtm_f
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition: state.h:692
foo
uint16_t foo
Definition: main_demo5.c:59
GpsState::ned_vel
struct NedCoor_i ned_vel
speed NED in cm/s
Definition: gps.h:96
NedCoor_i::z
int32_t z
Down.
Definition: pprz_geodetic_int.h:71
sdlog_chibios.h
meteo_france_DAQ_SetPower
#define meteo_france_DAQ_SetPower(_x)
Definition: meteo_france_DAQ.h:63
gps.h
Device independent GPS code (interface)
GpsState::fix
uint8_t fix
status of fix
Definition: gps.h:107
autopilot
struct pprz_autopilot autopilot
Global autopilot structure.
Definition: autopilot.c:50
UtmCoor_f::alt
float alt
in meters (above WGS84 reference ellipsoid or above MSL)
Definition: pprz_geodetic_float.h:84
UtmCoor_f::zone
uint8_t zone
UTM zone number.
Definition: pprz_geodetic_float.h:85
log_started
bool log_started
Definition: meteo_france_DAQ.c:47
GpsState::week
uint16_t week
GPS week.
Definition: gps.h:108
chibios_sdlog
chibios_sdlog structure
Definition: sdlog_chibios.h:54
int16_t
signed short int16_t
Definition: types.h:17
uint8_t
unsigned char uint8_t
Definition: types.h:14
GpsState::gspeed
uint16_t gspeed
norm of 2d ground speed in cm/s
Definition: gps.h:97
MF_DAQ_SIZE
#define MF_DAQ_SIZE
Definition: meteo_france_DAQ.h:41
autopilot.h
extra_pprz_tp
struct pprz_transport extra_pprz_tp
Definition: extra_pprz_dl.c:57
stateGetHorizontalWindspeed_f
static struct FloatVect2 * stateGetHorizontalWindspeed_f(void)
Get horizontal windspeed (float).
Definition: state.h:1377
GpsState::course
int32_t course
GPS course over ground in rad*1e7, [0, 2*Pi]*1e7 (CW/north)
Definition: gps.h:99
MF_DAQ_POWER_INIT
#define MF_DAQ_POWER_INIT
Definition: meteo_france_DAQ.c:50
course
static int16_t course[3]
Definition: airspeed_uADC.c:58
int32_t
signed long int32_t
Definition: types.h:19
stateGetSpeedEnu_f
static struct EnuCoor_f * stateGetSpeedEnu_f(void)
Get ground speed in local ENU coordinates (float).
Definition: state.h:917
mf_daq
struct MF_DAQ mf_daq
Definition: meteo_france_DAQ.c:46
UtmCoor_f
position in UTM coordinates Units: meters
Definition: pprz_geodetic_float.h:81
mf_daq_send_state
void mf_daq_send_state(void)
Definition: meteo_france_DAQ.c:68
GpsState::hmsl
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:94
pprzlog_tp
struct pprzlog_transport pprzlog_tp
PPRZLOG transport structure.
Definition: pprzlog_tp.c:29
MF_DAQ::power
uint8_t power
Definition: meteo_france_DAQ.h:46
state.h
FALSE
#define FALSE
Definition: std.h:5
stateGetPositionLla_f
static struct LlaCoor_f * stateGetPositionLla_f(void)
Get position in LLA coordinates (float).
Definition: state.h:728
MF_DAQ
Definition: meteo_france_DAQ.h:43
MF_DAQ::values
float values[MF_DAQ_SIZE]
Definition: meteo_france_DAQ.h:44
gps
struct GpsState gps
global GPS state
Definition: gps.c:69
parse_mf_daq_msg
void parse_mf_daq_msg(uint8_t *buf)
Definition: meteo_france_DAQ.c:118
p
static float p[2][2]
Definition: ins_alt_float.c:268