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
video_usb_logger.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 The Paparazzi Community
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 
26 #include "video_usb_logger.h"
27 
28 #include <stdio.h>
29 #include "state.h"
30 #include "viewvideo.h"
31 
33 #ifndef VIDEO_USB_LOGGER_PATH
34 #define VIDEO_USB_LOGGER_PATH /data/video/usb
35 #endif
36 
38 static FILE *video_usb_logger = NULL;
39 
42 {
43  uint32_t counter = 0;
44  char filename[512];
45 
46  // Check for available files
47  sprintf(filename, "%s/%05d.csv", STRINGIFY(VIDEO_USB_LOGGER_PATH), counter);
48  while ((video_usb_logger = fopen(filename, "r"))) {
49  fclose(video_usb_logger);
50 
51  counter++;
52  sprintf(filename, "%s/%05d.csv", STRINGIFY(VIDEO_USB_LOGGER_PATH), counter);
53  }
54 
55  video_usb_logger = fopen(filename, "w");
56 
57  if (video_usb_logger != NULL) {
58  fprintf(video_usb_logger, "counter,image,roll,pitch,yaw,x,y,z,sonar\n");
59  }
60 }
61 
64 {
65  if (video_usb_logger != NULL) {
66  fclose(video_usb_logger);
67  video_usb_logger = NULL;
68  }
69 }
70 
73 {
74  if (video_usb_logger == NULL) {
75  return;
76  }
77  static uint32_t counter = 0;
78  struct NedCoor_i *ned = stateGetPositionNed_i();
79  struct Int32Eulers *euler = stateGetNedToBodyEulers_i();
80  static uint32_t sonar = 0;
81 
82  // Take a new shot
84 
85  // Save to the file
86  fprintf(video_usb_logger, "%d,%d,%d,%d,%d,%d,%d,%d,%d\n", counter,
87  viewvideo.shot_number, euler->phi, euler->theta, euler->psi, ned->x,
88  ned->y, ned->z, sonar);
89  counter++;
90 }
int32_t psi
in rad with INT32_ANGLE_FRAC
struct viewvideo_t viewvideo
Definition: viewvideo.c:100
int32_t theta
in rad with INT32_ANGLE_FRAC
void video_usb_logger_periodic(void)
Log the values to a csv file.
int32_t z
Down.
int32_t y
East.
#define TRUE
Definition: std.h:4
Camera image logger for Linux based autopilots.
euler angles
#define VIDEO_USB_LOGGER_PATH
Set the default File logger path to the USB drive.
int32_t x
North.
unsigned long uint32_t
Definition: types.h:18
int32_t counter
void video_usb_logger_stop(void)
Stop the logger an nicely close the file.
void viewvideo_take_shot(bool_t take)
Definition: viewvideo_nps.c:42
Get live images from a RTP/UDP stream and save pictures on internal memory.
int32_t phi
in rad with INT32_ANGLE_FRAC
API to get/set the generic vehicle states.
vector in North East Down coordinates
void video_usb_logger_start(void)
Start the file logger and open a new file.
static FILE * video_usb_logger
The file pointer.
static struct NedCoor_i * stateGetPositionNed_i(void)
Get position in local NED coordinates (int).
Definition: state.h:648
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1096