57 lines
1.9 KiB
Matlab
57 lines
1.9 KiB
Matlab
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')
|
|
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')
|
|
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')
|
|
K = tf(zeros(6)); %#ok
|
|
save('./mat/controllers.mat', 'K');
|
|
else
|
|
error('ctrl_type should be cl or ol');
|
|
end
|
|
|
|
%% Active Damping
|
|
if strcmp(act_damp, 'iff')
|
|
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')
|
|
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')
|
|
initializeNanoHexapod(struct('actuator', 'lorentz'));
|
|
else
|
|
error('sys_name should be pz or vc');
|
|
end
|
|
|
|
if strcmp(sys_mass, 'light')
|
|
initializeSample(struct('mass', 1));
|
|
elseif strcmp(sys_mass, 'heavy')
|
|
initializeSample(struct('mass', 50));
|
|
else
|
|
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
|