Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
file_logger.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freek van Tienen <freek.v.tienen@gmail.com>
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 
27 #include "file_logger.h"
28 
29 #include <stdio.h>
30 #include "subsystems/imu.h"
32 #include "state.h"
33 
35 #ifndef FILE_LOGGER_PATH
36 #define FILE_LOGGER_PATH "/data/video/usb/"
37 #endif
38 
40 static FILE* file_logger;
41 
43 void file_logger_start(void) {
44  uint32_t counter = 0;
45  char filename[512];
46 
47  // Check for available files
48  sprintf(filename, "%s%05d.csv", FILE_LOGGER_PATH, counter);
49  while ((file_logger = fopen(filename, "r"))) {
50  fclose(file_logger);
51 
52  counter++;
53  sprintf(filename, "%s%05d.csv", FILE_LOGGER_PATH, counter);
54  }
55 
56  file_logger = fopen(filename, "w");
57 
58  if (file_logger != NULL) {
59  fprintf(
61  "counter,gyro_unscaled_p,gyro_unscaled_q,gyro_unscaled_r,accel_unscaled_x,accel_unscaled_y,accel_unscaled_z,mag_unscaled_x,mag_unscaled_y,mag_unscaled_z,COMMAND_THRUST,COMMAND_ROLL,COMMAND_PITCH,COMMAND_YAW,qi,qx,qy,qz\n"
62  );
63  }
64 }
65 
67 void file_logger_stop(void) {
68  fclose(file_logger);
69  file_logger = NULL;
70 }
71 
74 {
75  if (file_logger == NULL) {
76  return;
77  }
78  static uint32_t counter;
79  struct Int32Quat* quat = stateGetNedToBodyQuat_i();
80 
81  fprintf(file_logger, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
82  counter,
92  stabilization_cmd[COMMAND_THRUST],
93  stabilization_cmd[COMMAND_ROLL],
94  stabilization_cmd[COMMAND_PITCH],
95  stabilization_cmd[COMMAND_YAW],
96  quat->qi,
97  quat->qx,
98  quat->qy,
99  quat->qz
100  );
101  counter++;
102 }
int32_t p
in rad/s with INT32_RATE_FRAC
Rotation quaternion.
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:49
static struct Int32Quat * stateGetNedToBodyQuat_i(void)
Get vehicle body attitude quaternion (int).
Definition: state.h:1002
void file_logger_periodic(void)
Log the values to a csv file.
Definition: file_logger.c:73
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:50
void file_logger_stop(void)
Stop the logger an nicely close the file.
Definition: file_logger.c:67
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:47
unsigned long uint32_t
Definition: types.h:18
Inertial Measurement Unit interface.
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:51
API to get/set the generic vehicle states.
File logger for Linux based autopilots.
General stabilization interface for rotorcrafts.
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
Definition: stabilization.c:28
#define FILE_LOGGER_PATH
Set the default File logger path to the USB drive.
Definition: file_logger.c:36
int32_t q
in rad/s with INT32_RATE_FRAC
int32_t r
in rad/s with INT32_RATE_FRAC
static FILE * file_logger
The file pointer.
Definition: file_logger.c:40
void file_logger_start(void)
Start the file logger and open a new file.
Definition: file_logger.c:43