pathfinder-for-autonomous-navigation / FlightSoftware

Flight software, test software, ground software, and mission control.
http://pan-software.readthedocs.io
MIT License
9 stars 6 forks source link

Magnetorquer Induced Magnetometer Offsets #701

Closed kylekrol closed 3 years ago

kylekrol commented 3 years ago

The MTRs induce offsets in our magnetometer measurements. We will characterize this offset and subtract it away from our magnetometer measurements we see.

kylekrol commented 3 years ago

To be completed after #281.

kylekrol commented 3 years ago

Logs for the follower testcase after fixing the MTR frames: Follower_MTRCase.zip

kylekrol commented 3 years ago

Logs for the leader testcase after fixing the MTR frames: Leader_MTRCase.zip

kylekrol commented 3 years ago

mtr_logs_leader.csv mtr_logs_follower.csv

kylekrol commented 3 years ago
%% extract data
clc; clear all; close all; format compact
for j = 1:2
    if j == 1
        filename = 'mtr_logs_leader';
    else
         filename = 'mtr_logs_follower';
    end
    D = readtable([filename '.csv']);
    D = table2cell(D);
    mtr_cmd = []; %mag command; Am^2
    mag1 = []; %x,y,z Teslas
    mag2 = []; %x,y,z Teslas
    c = 1; %counter
    for i = 1:length(D)-3
        if strcmp(D{i,2},'adcs_cmd.mtr_cmd') == 1 && ...
                strcmp(D{i+1,2},'adcs_monitor.mag1_vec') == 1 && ...
                strcmp(D{i+2,2},'adcs_monitor.mag2_vec') == 1

            mtr_cmd(c,1) = D{i,3};
            mtr_cmd(c,2) = D{i,4};
            mtr_cmd(c,3) = D{i,5};

            mag1(c,1) = D{i+1,3};
            mag1(c,2) = D{i+1,4};
            mag1(c,3) = D{i+1,5};

            mag2(c,1) = D{i+2,3};
            mag2(c,2) = D{i+2,4};
            mag2(c,3) = D{i+2,5};

            c = c + 1;
        end
    end
    save([filename '.mat'])
end

%% Load leader or follower

load('mtr_logs_leader.mat')
%load('mtr_logs_follower.mat')

%% Plot the data

figure

subplot(1,2,1)
plot(mag1(:,1)); hold on; grid on
plot(mag1(:,2))
plot(mag1(:,3))
legend({'x','y','z'},'Location','northwest')
title('Mag1')

subplot(1,2,2)
plot(mag2(:,1)); hold on; grid on
plot(mag2(:,2))
plot(mag2(:,3))
legend({'x','y','z'},'Location','northwest')
title('Mag2')

figure
plot(mtr_cmd(:,1)); hold on; grid on
plot(mtr_cmd(:,2))
plot(mtr_cmd(:,3))
legend({'x','y','z'},'Location','northwest')
title('MTR')

%% Calculations for offset matrices

format long

D1 = offsets(mag1, mtr_cmd)
D2 = offsets(mag2, mtr_cmd)

%% Results post magnetometer calibration

mag1_calib = mag1(2:end,:) - transpose(D1 * transpose(mtr_cmd(1:end-1,:)));
mag2_calib = mag2(2:end,:) - transpose(D2 * transpose(mtr_cmd(1:end-1,:)));

figure

subplot(1,2,1)
plot(mag1_calib(:,1)); hold on; grid on
plot(mag1_calib(:,2))
plot(mag1_calib(:,3))
legend({'x','y','z'},'Location','northwest')
title('Mag1 Calibrated')

subplot(1,2,2)
plot(mag2_calib(:,1)); hold on; grid on
plot(mag2_calib(:,2))
plot(mag2_calib(:,3))
legend({'x','y','z'},'Location','northwest')
title('Mag2 Calibrated')

function D = offsets(mag, mtr)
    D = [
        % mtr x,y,z offsets on the mag x
        (mean(squeeze(mag(1955:2005,1))) - mean(squeeze(mag(95:145,1)))) / mean(squeeze(mtr(1955:2005,1))),...
        (mean(squeeze(mag(2075:2125,1))) - mean(squeeze(mag(95:145,1)))) / mean(squeeze(mtr(2075:2125,2))),...
        (mean(squeeze(mag(2195:2245,1))) - mean(squeeze(mag(95:145,1)))) / mean(squeeze(mtr(2195:2245,3)));
        % mtr x,y,z offsets on the mag y
        (mean(squeeze(mag(1955:2005,2))) - mean(squeeze(mag(95:145,2)))) / mean(squeeze(mtr(1955:2005,1))),...
        (mean(squeeze(mag(2075:2125,2))) - mean(squeeze(mag(95:145,2)))) / mean(squeeze(mtr(2075:2125,2))),...
        (mean(squeeze(mag(2195:2245,2))) - mean(squeeze(mag(95:145,2)))) / mean(squeeze(mtr(2195:2245,3)));
        % mtr x,y,z offsets on the mag z
        (mean(squeeze(mag(1955:2005,3))) - mean(squeeze(mag(95:145,3)))) / mean(squeeze(mtr(1955:2005,1))),...
        (mean(squeeze(mag(2075:2125,3))) - mean(squeeze(mag(95:145,3)))) / mean(squeeze(mtr(2075:2125,2))),...
        (mean(squeeze(mag(2195:2245,3))) - mean(squeeze(mag(95:145,3)))) / mean(squeeze(mtr(2195:2245,3)));
    ];
end
kylekrol commented 3 years ago

Leader calibration results:

D1 =
   1.0e-03 *
   0.280962247255082  -0.491683932696393  -0.401720651555603
  -0.721090299605407   0.441166090209642   0.305529143258913
   0.721090299605407  -0.441166090209642  -0.305529143258913
D2 =
  -0.000141173148867  -0.000031487148399   0.001398583009120
  -0.000002076075719   0.000050863855107  -0.001078521335830
   0.000141173148867   0.000027681009582  -0.001398583009120

leader_mag leader_mag_calibrated

kylekrol commented 3 years ago

Follower calibration results:

D1 =
   1.0e-03 *
   0.279578196775993  -0.504832412247739  -0.411409004909227
  -0.732162703438119   0.437359951392147   0.294802752045973
   0.733546753917209  -0.434591850433969  -0.293072688947111
D2 =
  -0.000144633275065  -0.000035293287217   0.001440796548732
  -0.000002422088338   0.000050517842487  -0.001114852660906
   0.000144633275065   0.000035293287217  -0.001440796548732

follower_mag follower_mag_calibrated

kylekrol commented 3 years ago

The above closes out the analysis work for the magnetometer induced offsets. We have:

Brief observations: