Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 "std.h"
31 
32 #include "subsystems/imu.h"
34 #include "state.h"
35 
37 #ifndef FILE_LOGGER_PATH
38 #define FILE_LOGGER_PATH /data/video/usb
39 #endif
40 
42 static FILE *file_logger = NULL;
43 
46 {
47  uint32_t counter = 0;
48  char filename[512];
49 
50  // Check for available files
51  sprintf(filename, "%s/%05d.csv", STRINGIFY(FILE_LOGGER_PATH), counter);
52  while ((file_logger = fopen(filename, "r"))) {
53  fclose(file_logger);
54 
55  counter++;
56  sprintf(filename, "%s/%05d.csv", STRINGIFY(FILE_LOGGER_PATH), counter);
57  }
58 
59  file_logger = fopen(filename, "w");
60 
61  if (file_logger != NULL) {
62  fprintf(
64  "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"
65  );
66  }
67 }
68 
70 void file_logger_stop(void)
71 {
72  if (file_logger != NULL) {
73  fclose(file_logger);
74  file_logger = NULL;
75  }
76 }
77 
80 {
81  if (file_logger == NULL) {
82  return;
83  }
84  static uint32_t counter;
85  struct Int32Quat *quat = stateGetNedToBodyQuat_i();
86 
87  fprintf(file_logger, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
88  counter,
98  stabilization_cmd[COMMAND_THRUST],
99  stabilization_cmd[COMMAND_ROLL],
100  stabilization_cmd[COMMAND_PITCH],
101  stabilization_cmd[COMMAND_YAW],
102  quat->qi,
103  quat->qx,
104  quat->qy,
105  quat->qz
106  );
107  counter++;
108 }
static struct Int32Quat * stateGetNedToBodyQuat_i(void)
Get vehicle body attitude quaternion (int).
Definition: state.h:1084
void file_logger_periodic(void)
Log the values to a csv file.
Definition: file_logger.c:79
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:52
int32_t r
in rad/s with INT32_RATE_FRAC
struct Int32Rates gyro_unscaled
unscaled gyroscope measurements
Definition: imu.h:50
void file_logger_stop(void)
Stop the logger an nicely close the file.
Definition: file_logger.c:70
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:43
unsigned long uint32_t
Definition: types.h:18
int32_t counter
Inertial Measurement Unit interface.
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:38
int32_t p
in rad/s with INT32_RATE_FRAC
struct Int32Vect3 accel_unscaled
unscaled accelerometer measurements
Definition: imu.h:51
static FILE * file_logger
The file pointer.
Definition: file_logger.c:42
int32_t q
in rad/s with INT32_RATE_FRAC
Rotation quaternion.
void file_logger_start(void)
Start the file logger and open a new file.
Definition: file_logger.c:45