nass-simscape/src/runSimulation.m

57 lines
1.9 KiB
Mathematica
Raw Normal View History

function [] = runSimulation(sys_name, sys_mass, ctrl_type, act_damp)
%% Load the controller and save it for the simulation
if strcmp(ctrl_type, 'cl') && strcmp(act_damp, 'none')
2019-12-06 12:03:34 +01:00
K_obj = load('./mat/K_fb.mat');
K = K_obj.(sprintf('K_%s_%s', sys_mass, sys_name)); %#ok
save('./mat/controllers.mat', 'K');
elseif strcmp(ctrl_type, 'cl') && strcmp(act_damp, 'iff')
2019-12-06 12:03:34 +01:00
K_obj = load('./mat/K_fb_iff.mat');
K = K_obj.(sprintf('K_%s_%s_iff', sys_mass, sys_name)); %#ok
save('./mat/controllers.mat', 'K');
elseif strcmp(ctrl_type, 'ol')
2019-12-06 12:03:34 +01:00
K = tf(zeros(6)); %#ok
save('./mat/controllers.mat', 'K');
else
2019-12-06 12:03:34 +01:00
error('ctrl_type should be cl or ol');
end
%% Active Damping
if strcmp(act_damp, 'iff')
2019-12-06 12:03:34 +01:00
K_iff_crit = load('./mat/K_iff_crit.mat');
K_iff = K_iff_crit.(sprintf('K_iff_%s_%s', sys_mass, sys_name)); %#ok
save('./mat/controllers.mat', 'K_iff', '-append');
elseif strcmp(act_damp, 'none')
2019-12-06 12:03:34 +01:00
K_iff = tf(zeros(6)); %#ok
save('./mat/controllers.mat', 'K_iff', '-append');
end
%%
if strcmp(sys_name, 'pz')
initializeNanoHexapod(struct('actuator', 'piezo'));
elseif strcmp(sys_name, 'vc')
2019-12-06 12:03:34 +01:00
initializeNanoHexapod(struct('actuator', 'lorentz'));
else
2019-12-06 12:03:34 +01:00
error('sys_name should be pz or vc');
end
if strcmp(sys_mass, 'light')
initializeSample(struct('mass', 1));
elseif strcmp(sys_mass, 'heavy')
2019-12-06 12:03:34 +01:00
initializeSample(struct('mass', 50));
else
2019-12-06 12:03:34 +01:00
error('sys_mass should be light or heavy');
end
%% Run the simulation
sim('sim_nano_station_ctrl.slx');
%% Split the Dsample matrix into vectors
[Dx, Dy, Dz, Rx, Ry, Rz] = matSplit(Es.Data, 1); %#ok
time = Dsample.Time; %#ok
%% Save the result
filename = sprintf('sim_%s_%s_%s_%s', sys_mass, sys_name, ctrl_type, act_damp);
save(sprintf('./mat/%s.mat', filename), ...
'time', 'Dx', 'Dy', 'Dz', 'Rx', 'Ry', 'Rz', 'K');
end