1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

Improve log processing code

This commit is contained in:
James Cotton 2012-01-28 09:29:28 -06:00
parent a778c45d6f
commit 0b778667b3
3 changed files with 48 additions and 32 deletions

View File

@ -1,14 +0,0 @@
source = gyro;
clear data
data.freq = source(:,3)';
data.time = unwrap_time(source(:,end))'/1000;
data.rate = 1/mean(diff(data.time))
tau = 1/data.rate * round(logspace(0,7,200))
[retval, s, errorb, tau] = allan(data,tau,'gyro')
[~,~,gyro_residual] = regress(gyro(:,1)-mean(gyro(:,1)),[gyro(:,4)-mean(gyro(:,4)), (1:size(gyro,1))']);
data.freq = gyro_residual;
data.time = unwrap_time(source(:,end))'/1000;
data.rate = 1/mean(diff(data.time))
tau = 1/data.rate * round(logspace(0,7,200))
[retval, s, errorb, tau] = allan(data,tau,'gyro')

14
matlab/revo/allan_gyro.m Normal file
View File

@ -0,0 +1,14 @@
source = gyro;
clear data
data.freq = source(:,3)';
data.time = unwrap_time(source(:,end))'/1000;
data.rate = 1/mean(diff(data.time))
tau = 1/data.rate * round(logspace(0,7,200))
[retval, s, errorb, tau] = allan(data,tau,'gyro')
% [~,~,gyro_residual] = regress(gyro(:,1)-mean(gyro(:,1)),[gyro(:,4)-mean(gyro(:,4)), (1:size(gyro,1))']);
% data.freq = gyro_residual;
% data.time = unwrap_time(source(:,end))'/1000;
% data.rate = 1/mean(diff(data.time))
% tau = 1/data.rate * round(logspace(0,7,200))
% [retval, s, errorb, tau] = allan(data,tau,'gyro')

View File

@ -1,47 +1,61 @@
fn = '~/Desktop/kenn_stationary (2011-12-26 14:51:11 +0000)'; fn = '~/Documents/Programming/serial_logger/bma180_l3gd20_desk_20120228.dat';
fn = '~/Documents/Programming/serial_logger/mpu6000_desk_20120228.dat';
fn = '~/Documents/Programming/serial_logger/mpu6000_desk2_20110228.dat';
fn = '~/Documents/Programming/serial_logger/output.dat';
fid = fopen(fn); fid = fopen(fn);
dat = uint8(fread(fid,'uint8')); dat = uint8(fread(fid,'uint8'));
fclose(fid); fclose(fid);
accel = []; accel = zeros(4096,1);
accel_idx = 0; accel_idx = 0;
gyro = []; gyro = zeros(4096,1);
gyro_idx = 0; gyro_idx = 0;
mag = []; mag = zeros(4096,1);
mag_idx = 0; mag_idx = 0;
latitude = []; latitude = zeros(4096,1);
longitude = []; longitude = zeros(4096,1);
altitude = []; altitude = zeros(4096,1);
heading = []; heading = zeros(4096,1);
groundspeed = []; groundspeed = zeros(4096,1);
gps_satellites = []; gps_satellites = zeros(4096,1);
gps_time = []; gps_time = zeros(4096,1);
gps_idx = 0; gps_idx = 0;
baro = []; baro = zeros(4096,1);
baro_idx = 0; baro_idx = 0;
total = length(dat); total = length(dat);
count = 0; count = 0;
head = 0; head = 0;
last_time = 0; last_time = 0;
good_samples = 0;
bad_samples = 0;
while head < (length(dat) - 200) while head < (length(dat) - 200)
last_head = head;
count = count + 1; count = count + 1;
if count >= 100 if count >= 5000
disp(sprintf('%0.3g%%',(head/total) * 100)); disp(sprintf('Processed: %0.3g%% Bad: %0.3g%%',(head/total) * 100,bad_samples * 100 / (bad_samples + good_samples)));
count = 0; count = 0;
end end
head = head + find(dat(head+1:end)==255,1,'first'); idx = find(dat(head+1:head+100)==255,1,'first');
if isempty(idx)
head = head + 100;
continue;
end
head = head + idx;
% Get the time % Get the time
time = typecast(flipud(dat(head+(1:2))),'uint16'); time = double(dat(head+1))* 256 + double(dat(head+2));%typecast(flipud(dat(head+(1:2))),'uint16');
if (time - last_time) ~= 2 && (time-last_time) ~= (hex2dec('10000')-2) if min([(time - last_time) (last_time - time)]) > 2
disp(['Err' num2str(time-last_time)]);
last_time = time; last_time = time;
disp('Err'); bad_samples = bad_samples + (head - last_head);
continue continue
end end
last_time = time; last_time = time;
@ -124,6 +138,8 @@ while head < (length(dat) - 200)
baro(baro_idx,1) = typecast(dat(head+(1:4)),'single'); baro(baro_idx,1) = typecast(dat(head+(1:4)),'single');
baro(baro_idx,2) = time; baro(baro_idx,2) = time;
end end
good_samples = good_samples + (head - last_head);
end end
accel(accel_idx+1:end,:) = []; accel(accel_idx+1:end,:) = [];