tg = slrt;

%% TODO - Build this application if updated

%%
if tg.Connected == "Yes"
    if tg.Status == "stopped"
        %% Load the application
        tg.load('slip_ring_test');

        %% Run the application
        tg.start;
        pause(10);
        tg.stop;

        %% Load the data
        f = SimulinkRealTime.openFTP(tg);
        cd(f, 'data/slip_ring_test/');
        mget(f, 'data_001.dat', 'data');
        close(f);
    end
end

data = SimulinkRealTime.utils.getFileScopeData('data/data_001.dat').data;

size(data)

t  = data(:, end);
x1 = data(:, 1);
x2 = data(:, 2);

save('mat/data_002.mat', 't', 'x1', 'x2');

%% Plot the data
figure;
hold on;
plot(t, x1);
plot(t, x2);
hold off
xlabel('Time [s]');
ylabel('Voltage [V]');

%%
figure;
hold on;
plot(t, x1-x2);
hold off
xlabel('Time [s]');
ylabel('Voltage [V]');