tg = slrt;

%%
% if tg.Connected == "Yes"
%     if tg.Status == "stopped"
%         %% Load the application
%         tg.load('test_cercalo');
% 
%         %% Run the application
%         tg.start;
%         pause(10);
%         tg.stop;
%     end
% end

%%
f = SimulinkRealTime.openFTP(tg);
mget(f, 'data/data_001.dat');
close(f);

%% Convert the Data
data = SimulinkRealTime.utils.getFileScopeData('data/data_001.dat').data;

t  = data(:, end);
ux = data(:, 1);
uy = data(:, 2);
yx = data(:, 3);
yy = data(:, 4);

save('mat/data_001.mat', 't', 'ux', 'uy', 'yx', 'yy');

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

figure;
hold on;
plot(t, yx);
plot(t, yy);
hold off
xlabel('Time [s]');
ylabel('Voltage [V]');
