From 5f016884901f92f2c14d23ee0b15b513e9154c9a Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Thu, 25 Oct 2012 18:53:03 +0200 Subject: Fixed automatic log conversion / plotting script --- ROMFS/logging/logconv.m | 16 ++++++++++++++-- apps/sdlog/sdlog.c | 10 +++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ROMFS/logging/logconv.m b/ROMFS/logging/logconv.m index 81fcc1d7e..579a582d3 100644 --- a/ROMFS/logging/logconv.m +++ b/ROMFS/logging/logconv.m @@ -1,5 +1,5 @@ clear all -clc +close all %%%%%%%%%%%%%%%%%%%%%%% % SYSTEM VECTOR @@ -51,9 +51,21 @@ if exist('sysvector.bin', 'file') gps = sysvector(:,33:35); gps(~any(gps,2), :) = []; - plot3(gps(:,1), gps(:,2), gps(:,3)); + all_data = figure('Name', 'GPS RAW'); + gps_position = plot3(gps(:,1), gps(:,2), gps(:,3)); + + all_data = figure('Name', 'Complete Log Data (exc. GPS)'); plot(sysvector(:,1), sysvector(:,2:32)); + + actuator_inputs = figure('Name', 'Attitude controller outputs'); + plot(sysvector(:,1), sysvector(:,14:17)); + legend('roll motor setpoint', 'pitch motor setpoint', 'yaw motor setpoint', 'throttle motor setpoint'); + + actuator_outputs = figure('Name', 'Actuator outputs'); + plot(sysvector(:,1), sysvector(:,18:25)); + legend('actuator 0', 'actuator 1', 'actuator 2', 'actuator 3', 'actuator 4', 'actuator 5', 'actuator 6', 'actuator 7'); + end if exist('actuator_outputs0.bin', 'file') diff --git a/apps/sdlog/sdlog.c b/apps/sdlog/sdlog.c index a934d0d33..7d2f6afba 100644 --- a/apps/sdlog/sdlog.c +++ b/apps/sdlog/sdlog.c @@ -567,6 +567,7 @@ int file_copy(const char* file_old, const char* file_new) { FILE *source, *target; source = fopen(file_old, "r"); + int ret = 0; if( source == NULL ) { @@ -580,21 +581,24 @@ int file_copy(const char* file_old, const char* file_new) { fclose(source); warnx("failed to open output file to copy"); + return 1; } char buf[128]; int nread; - while ((nread = fread(buf, sizeof(buf), 1, source)) > 0) { - int ret = fwrite(buf, sizeof(buf), 1, target); + while ((nread = fread(buf, 1, sizeof(buf), source)) > 0) { + int ret = fwrite(buf, 1, nread, target); if (ret <= 0) { warnx("error writing file"); + ret = 1; break; } } + fsync(fileno(target)); fclose(source); fclose(target); - return 0; + return ret; } -- cgit v1.2.3