Skip to content

Commit

Permalink
[log] start support of flight recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
gautierhattenberger committed Mar 23, 2015
1 parent fe2db94 commit dd19ecd
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 13 deletions.
11 changes: 6 additions & 5 deletions conf/airframes/ENAC/fixed-wing/apogee.xml
Expand Up @@ -11,21 +11,22 @@
<!-- <load name="mcp355x.xml"> -->
<!-- <define name="USE_SPI1"/> -->
<!-- </load> -->
<load name="extra_dl.xml">
<!--load name="extra_dl.xml">
<configure name="EXTRA_DL_PORT" value="UART6"/>
<configure name="EXTRA_DL_BAUD" value="B57600"/>
</load>
<load name="meteo_france_DAQ.xml"/>
<load name="meteo_france_DAQ.xml"/-->
<load name="flight_recorder.xml"/>
</modules>

<firmware name="fixedwing">
<target name="sim" board="pc">
<subsystem name="radio_control" type="ppm"/>
</target>
<target name="ap" board="apogee_1.0_chibios">
<subsystem name="radio_control" type="sbus"/>
<configure name="PERIODIC_FREQUENCY" value="100"/>
</target>
<target name="sim" board="pc">
<subsystem name="radio_control" type="ppm"/>
</target>

<define name="USE_I2C1"/>
<!--define name="USE_I2C2"/-->
Expand Down
138 changes: 138 additions & 0 deletions conf/telemetry/fixedwing_flight_recorder.xml
@@ -0,0 +1,138 @@
<?xml version="1.0"?>
<!DOCTYPE telemetry SYSTEM "telemetry.dtd">
<telemetry>
<process name="Ap">
<mode name="default">
<message name="AUTOPILOT_VERSION" period="11.1"/>
<message name="AIRSPEED" period="1"/>
<message name="ALIVE" period="5.1"/>
<message name="GPS" period="0.25"/>
<message name="NAVIGATION" period="1."/>
<message name="ATTITUDE" period="0.1"/>
<message name="ESTIMATOR" period="0.5"/>
<message name="ENERGY" period="2.4"/>
<message name="WP_MOVED" period="0.5"/>
<message name="CIRCLE" period="1.05"/>
<message name="DESIRED" period="0.2"/>
<message name="BAT" period="1.1"/>
<message name="SEGMENT" period="1.2"/>
<message name="CALIBRATION" period="2.1"/>
<message name="NAVIGATION_REF" period="9."/>
<message name="PPRZ_MODE" period="4.9"/>
<message name="SETTINGS" period="5."/>
<message name="STATE_FILTER_STATUS" period="2.2"/>
<message name="DATALINK_REPORT" period="5.1"/>
<message name="DL_VALUE" period="1.5"/>
<message name="IR_SENSORS" period="1.2"/>
<message name="SURVEY" period="2.1"/>
<message name="GPS_SOL" period="2.0"/>
<message name="IMU_ACCEL" period=".8"/>
<message name="IMU_GYRO" period=".6"/>
<message name="IMU_MAG" period="1.3"/>
<message name="CAM" period="0.5"/>
<message name="CAM_POINT" period="1.0"/>
<message name="COMMANDS" period="5"/>
<message name="FBW_STATUS" period="2"/>
<message name="AIR_DATA" period="1.3"/>
</mode>
<mode name="minimal">
<message name="ALIVE" period="5"/>
<message name="ATTITUDE" period="4"/>
<message name="GPS" period="1.05"/>
<message name="ESTIMATOR" period="1.3"/>
<message name="WP_MOVED" period="1.4"/>
<message name="CIRCLE" period="3.05"/>
<message name="DESIRED" period="4.05"/>
<message name="BAT" period="1.1"/>
<message name="SEGMENT" period="3.2"/>
<message name="CALIBRATION" period="5.1"/>
<message name="NAVIGATION_REF" period="9."/>
<message name="NAVIGATION" period="3."/>
<message name="PPRZ_MODE" period="5."/>
<message name="STATE_FILTER_STATUS" period="5."/>
<message name="DATALINK_REPORT" period="5.1"/>
<message name="DL_VALUE" period="1.5"/>
<message name="IR_SENSORS" period="5.2"/>
<message name="SURVEY" period="2.1"/>
<message name="GPS_SOL" period="5.0"/>
</mode>
<mode name="extremal">
<message name="ALIVE" period="5"/>
<message name="GPS" period="5.1"/>
<message name="ESTIMATOR" period="5.3"/>
<message name="BAT" period="10.1"/>
<message name="DESIRED" period="10.2"/>
<message name="NAVIGATION" period="5.4"/>
<message name="PPRZ_MODE" period="7.5"/>
<message name="STATE_FILTER_STATUS" period="8."/>
<message name="DATALINK_REPORT" period="5.7"/>
</mode>
<mode name="raw_sensors">
<message name="DL_VALUE" period="0.5"/>
<message name="ALIVE" period="2.1"/>
<message name="IMU_ACCEL_RAW" period=".05"/>
<message name="IMU_GYRO_RAW" period=".05"/>
<message name="IMU_MAG_RAW" period=".05"/>
<message name="BARO_RAW" period="0.5"/>
</mode>
<mode name="scaled_sensors">
<message name="DL_VALUE" period="0.5"/>
<message name="ALIVE" period="2.1"/>
<message name="IMU_GYRO" period=".075"/>
<message name="IMU_ACCEL" period=".075"/>
<message name="IMU_MAG" period=".1"/>
</mode>
<mode name="debug_imu">
<message name="ATTITUDE" period="0.1"/>
<message name="ALIVE" period="5"/>
<message name="GPS" period="5.1"/>
<message name="ESTIMATOR" period="5.3"/>
<message name="BAT" period="10.1"/>
<message name="DESIRED" period="10.2"/>
<message name="NAVIGATION" period="5.4"/>
<message name="PPRZ_MODE" period="5.5"/>
<message name="STATE_FILTER_STATUS" period="5."/>
<message name="DATALINK_REPORT" period="5.7"/>
<message name="IMU_ACCEL" period=".5"/>
<message name="IMU_GYRO" period=".5"/>
<message name="IMU_MAG" period=".5"/>
<message name="IMU_ACCEL_RAW" period=".5"/>
<message name="IMU_GYRO_RAW" period=".5"/>
<message name="IMU_MAG_RAW" period=".5"/>
</mode>
</process>
<process name="Fbw">
<mode name="default">
<message name="COMMANDS" period="5"/>
<message name="FBW_STATUS" period="2"/>
<message name="ACTUATORS" period="5"/> <!-- For trimming -->
</mode>
<mode name="debug">
<message name="PPM" period="0.5"/>
<message name="RC" period="0.5"/>
<message name="COMMANDS" period="0.5"/>
<message name="FBW_STATUS" period="1"/>
<message name="ACTUATORS" period="5"/> <!-- For trimming -->
</mode>
</process>
<process name="FlightRecorder">
<mode name="default">
<message name="BAT" period="0.5"/>
<message name="ENERGY" period="0.5"/>
<message name="GPS" period="0.2"/>
<message name="ATTITUDE" period="0.05"/>
<message name="DESIRED" period="0.05"/>
<message name="IMU_ACCEL" period=".02"/>
<message name="IMU_GYRO" period=".02"/>
<message name="IMU_MAG" period=".02"/>
<message name="AIR_DATA" period="0.5"/>
<message name="RC" period="0.05"/>
<message name="COMMANDS" period="0.05"/>
<message name="ACTUATORS" period="0.05"/>
<message name="PPRZ_MODE" period="1.0"/>
<message name="FBW_MODE" period="1.0"/>
<message name="NAVIGATION" period="1.0"/>
<message name="DATALINK_REPORT" period="1.0"/>
</mode>
</process>
</telemetry>
84 changes: 84 additions & 0 deletions sw/airborne/modules/loggers/flight_recorder.c
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2015 Gautier Hattenberger <gautier.hattenberger@enac.fr>
*
* This file is part of paparazzi
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* @file "modules/loggers/flight_recorder.c"
* @author Gautier Hattenberger <gautier.hattenberger@enac.fr>
* Record flight data according to your telemetry file
*/

#define PERIODIC_C_FLIGHTRECORDER

#include "modules/loggers/flight_recorder.h"

#include "subsystems/datalink/telemetry.h"
#include "subsystems/datalink/pprzlog_transport.h"

#if FLIGHTRECORDER_SDLOG

#include "sdLog.h"
#include "subsystems/chibios-libopencm3/chibios_sdlog.h"
static struct chibios_sdlog flightrecorder_sdlog;
#ifndef FLIGHTRECORDER_DEVICE
#define FLIGHTRECORDER_DEVICE flightrecorder_sdlog
#else
#warning "SD log is activated, but FLIGHTRECORDER_DEVICE is alreay set (should not be defined)"
#endif

// Functions for the generic device API
static int sdlog_check_free_space(struct chibios_sdlog* p __attribute__((unused)), uint8_t len __attribute__((unused)))
{
return TRUE;
}

static void sdlog_transmit(struct chibios_sdlog* p __attribute__((unused)), uint8_t byte)
{
sdLogWriteByte(&flightRecorderLogFile, byte);
}

static void sdlog_send(struct chibios_sdlog* p __attribute__((unused))) { }

#else
// include downlink for other devices
#include "subsystems/datalink/downlink.h"
#endif

void flight_recorder_init()
{
#if FLIGHTRECORDER_SDLOG
flightrecorder_sdlog.device.periph = (void *)(&flightrecorder_sdlog);
flightrecorder_sdlog.device.check_free_space = (check_free_space_t) sdlog_check_free_space;
flightrecorder_sdlog.device.transmit = (transmit_t) sdlog_transmit;
flightrecorder_sdlog.device.send_message = (send_message_t) sdlog_send;
#endif
}

void flight_recorder_periodic()
{
#if FLIGHTRECORDER_SDLOG
// test if sd log is ready
if (flightRecorderLogFile.fs == NULL) return;
#endif

#if PERIODIC_TELEMETRY
periodic_telemetry_send_FlightRecorder(DefaultPeriodic, &pprzlog_tp.trans_tx, &(FLIGHTRECORDER_DEVICE).device);
#endif
}


40 changes: 40 additions & 0 deletions sw/airborne/modules/loggers/flight_recorder.h
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2015 Gautier Hattenberger <gautier.hattenberger@enac.fr>
*
* This file is part of paparazzi
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* @file "modules/loggers/flight_recorder.h"
* @author Gautier Hattenberger <gautier.hattenberger@enac.fr>
* Record flight data according to your telemetry file
*/

#ifndef FLIGHT_RECORDER_H
#define FLIGHT_RECORDER_H

/** Init function
*/
extern void flight_recorder_init(void);

/** Periodic function
*
* should be called at TELEMETRY_FREQUENCY
*/
extern void flight_recorder_periodic(void);

#endif

13 changes: 7 additions & 6 deletions sw/airborne/subsystems/chibios-libopencm3/chibios_sdlog.c
Expand Up @@ -46,13 +46,14 @@ EventListener powerOutageListener;

FIL pprzLogFile = {0};

#if LOG_FLIGHTRECORDER
struct chibios_sdlog chibios_sdlog;

#if FLIGHTRECORDER_SDLOG
static const char FLIGHTRECORDER_LOG_NAME[] = "fr_";
static const char FR_LOG_DIR[] = "FLIGHT_RECORDER";
FIL flightRecorderLogFile = {0};
#endif

struct chibios_sdlog chibios_sdlog;

static WORKING_AREA(waThdBatterySurvey, 4096);
static void launchBatterySurveyThread (void)
{
Expand Down Expand Up @@ -96,8 +97,8 @@ bool_t chibios_logInit(const bool_t binaryFile)
if (sdLogOpenLog (&pprzLogFile, PPRZ_LOG_DIR, PPRZ_LOG_NAME) != SDLOG_OK)
goto error;

#if LOG_FLIGHTRECORDER
if (sdLogOpenLog (&flightRecorderLogFile, FLIGHTRECORDER_LOG_NAME) != SDLOG_OK)
#if FLIGHTRECORDER_SDLOG
if (sdLogOpenLog (&flightRecorderLogFile, FR_LOG_DIR, FLIGHTRECORDER_LOG_NAME) != SDLOG_OK)
goto error;
#endif

Expand All @@ -120,7 +121,7 @@ void chibios_logFinish(void)
if (pprzLogFile.fs != NULL) {
sdLogStopThread ();
sdLogCloseLog (&pprzLogFile);
#if LOG_FLIGHTRECORDER
#if FLIGHTRECORDER_SDLOG
sdLogCloseLog (&flightRecorderLogFile);
#endif
sdLogFinish ();
Expand Down
2 changes: 1 addition & 1 deletion sw/airborne/subsystems/chibios-libopencm3/chibios_sdlog.h
Expand Up @@ -40,7 +40,7 @@

extern FIL pprzLogFile;

#if LOG_FLIGHTRECORDER
#if FLIGHTRECORDER_SDLOG
// if activated, will log all process states
extern FIL flightRecorderLogFile;
#endif
Expand Down
7 changes: 6 additions & 1 deletion sw/airborne/subsystems/chibios-libopencm3/ffconf.h
Expand Up @@ -185,7 +185,12 @@
/ function must be added to the project. */


#define _FS_SHARE 2 /* 0:Disable or >=1:Enable */
/* 0:Disable or >=1:Enable */
#if FLIGHTRECORDER_SDLOG
#define _FS_SHARE 2 // Open a second file if flight recorder is used
#else
#define _FS_SHARE 0
#endif
/* To enable file shareing feature, set _FS_SHARE to 1 or greater. The value
defines how many files can be opened simultaneously. */

Expand Down

0 comments on commit dd19ecd

Please sign in to comment.