test-bench-nano-hexapod/matlab/run_batch_identification.m

56 lines
1.6 KiB
Mathematica
Raw Permalink Normal View History

2021-08-05 16:48:14 +02:00
%% First make sure the model is open, and we are connected to the
% Speedgoat Machine.
%% Run Multiple Simulations
my_model = 'iff_measure';
tg = slrt;
%% For each strut
for i_leg = 1:6
%% Get excitation strut
p = Simulink.Mask.get([my_model, '/Subsystem7']);
p.Parameters.Value = sprintf('%i', i_leg);
2021-08-11 18:03:35 +02:00
pause(0.1);
2021-08-05 16:48:14 +02:00
%% Connect
2021-08-11 18:03:35 +02:00
set_param(my_model,'SimulationCommand','connect');
pause(0.1);
2021-08-05 16:48:14 +02:00
%% Run the simulation
sprintf('Start excitation for strut %i', i_leg)
set_param(my_model,'SimulationCommand','start')
%% Wait for the simulation to finish
pause(1)
while strcmp(get_param(my_model,'SimulationStatus'), 'external')
pause(1)
end
2021-08-11 18:03:35 +02:00
sprintf('Finished excitation for strut %i', i_leg);
2021-08-05 16:48:14 +02:00
%% Disconnect
2021-08-11 18:03:35 +02:00
set_param(my_model,'SimulationCommand','disconnect');
pause(0.1);
2021-08-05 16:48:14 +02:00
%% Save the data
f = SimulinkRealTime.openFTP(tg);
mget(f, 'data/data.dat');
close(f);
data = SimulinkRealTime.utils.getFileScopeData('data/data.dat').data;
de = data(:, 1:6); % Measurment displacement (encoder) [m]
Vs = data(:, 7:12); % Force Sensor [V]
u = data(:, 13:18); % Control Output [V]
Va = data(:, 19); % Excitation Signal [V]
% Rx = data(:, 20:25); % Reference Signal [m/rad]
t = data(:, end); % Time [s]
load('sim_data/data_sim.mat', 'Ts'); % To save Sampling Period
save('sim_data/Kiff.mat', 'Kiff'); % To save Controller
2021-08-11 18:03:35 +02:00
save(sprintf('mat/frf_data_exc_strut_%i_spindle_3m_iff_60rpm.mat', i_leg), ...
2021-08-05 16:48:14 +02:00
't', 'Ts', 'de', 'Vs', 'u', 'Va', 'Kiff');
sprintf('Saved Data for strut %i', i_leg)
2021-08-11 18:03:35 +02:00
pause(0.1);
2021-08-05 16:48:14 +02:00
end