2018-06-16 22:57:54 +02:00
|
|
|
function [inputs] = initializeInputs(opts_param)
|
|
|
|
%% Default values for opts
|
2018-10-25 13:12:07 +02:00
|
|
|
opts = struct( ...
|
|
|
|
'Dw', false, ...
|
|
|
|
'Dy', false, ...
|
|
|
|
'Ry', false, ...
|
|
|
|
'Rz', false, ...
|
|
|
|
'Dh', false, ...
|
|
|
|
'Rm', false, ...
|
|
|
|
'Dn', false ...
|
2018-06-16 22:57:54 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
%% Populate opts with input parameters
|
|
|
|
if exist('opts_param','var')
|
|
|
|
for opt = fieldnames(opts_param)'
|
|
|
|
opts.(opt{1}) = opts_param.(opt{1});
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%% Load Sampling Time and Simulation Time
|
2018-06-21 11:42:46 +02:00
|
|
|
load('./mat/sim_conf.mat', 'sim_conf');
|
2018-06-16 22:57:54 +02:00
|
|
|
|
|
|
|
%% Define the time vector
|
2018-10-25 13:12:07 +02:00
|
|
|
t = 0:sim_conf.Ts:sim_conf.Tsim;
|
2018-06-21 11:42:46 +02:00
|
|
|
|
2018-10-25 13:12:07 +02:00
|
|
|
%% Ground motion - Dw
|
2018-10-12 18:17:03 +02:00
|
|
|
if islogical(opts.Dw) && opts.Dw == true
|
2018-10-24 15:08:23 +02:00
|
|
|
load('./mat/perturbations.mat', 'Wxg');
|
2018-10-25 13:12:07 +02:00
|
|
|
Dw = 1/sqrt(2)*100*random('norm', 0, 1, length(t), 3);
|
|
|
|
Dw(:, 1) = lsim(Wxg, Dw(:, 1), t);
|
|
|
|
Dw(:, 2) = lsim(Wxg, Dw(:, 2), t);
|
|
|
|
Dw(:, 3) = lsim(Wxg, Dw(:, 3), t);
|
2018-10-12 18:17:03 +02:00
|
|
|
elseif islogical(opts.Dw) && opts.Dw == false
|
2018-10-25 13:12:07 +02:00
|
|
|
Dw = zeros(length(t), 3);
|
2018-06-21 14:16:08 +02:00
|
|
|
else
|
2018-10-12 18:17:03 +02:00
|
|
|
Dw = opts.Dw;
|
2018-06-16 22:57:54 +02:00
|
|
|
end
|
|
|
|
|
2018-10-25 13:12:07 +02:00
|
|
|
%% Translation stage - Dy
|
|
|
|
if islogical(opts.Dy) && opts.Dy == true
|
|
|
|
Dy = zeros(length(t), 1);
|
|
|
|
elseif islogical(opts.Dy) && opts.Dy == false
|
|
|
|
Dy = zeros(length(t), 1);
|
2018-06-21 14:16:08 +02:00
|
|
|
else
|
2018-10-25 13:12:07 +02:00
|
|
|
Dy = opts.Dy;
|
2018-06-16 22:57:54 +02:00
|
|
|
end
|
|
|
|
|
2018-10-25 13:12:07 +02:00
|
|
|
%% Tilt Stage - Ry
|
|
|
|
if islogical(opts.Ry) && opts.Ry == true
|
|
|
|
Ry = 3*(2*pi/360)*sin(2*pi*0.2*t);
|
|
|
|
elseif islogical(opts.Ry) && opts.Ry == false
|
|
|
|
Ry = zeros(length(t), 1);
|
2018-10-29 13:37:36 +01:00
|
|
|
elseif isnumeric(opts.Ry) && length(opts.Ry) == 1
|
|
|
|
Ry = opts.Ry*(2*pi/360)*ones(length(t), 1);
|
2018-06-21 14:16:08 +02:00
|
|
|
else
|
2018-10-25 13:12:07 +02:00
|
|
|
Ry = opts.Ry;
|
2018-06-16 22:57:54 +02:00
|
|
|
end
|
|
|
|
|
2018-10-25 13:12:07 +02:00
|
|
|
%% Spindle - Rz
|
|
|
|
if islogical(opts.Rz) && opts.Rz == true
|
|
|
|
Rz = 2*pi*0.5*t;
|
|
|
|
elseif islogical(opts.Rz) && opts.Rz == false
|
|
|
|
Rz = zeros(length(t), 1);
|
|
|
|
elseif isnumeric(opts.Rz) && length(opts.Rz) == 1
|
2018-10-30 14:37:19 +01:00
|
|
|
Rz = opts.Rz*(2*pi/60)*t;
|
2018-06-21 14:16:08 +02:00
|
|
|
else
|
2018-10-25 13:12:07 +02:00
|
|
|
Rz = opts.Rz;
|
2018-06-16 22:57:54 +02:00
|
|
|
end
|
|
|
|
|
2018-10-25 13:12:07 +02:00
|
|
|
%% Micro Hexapod - Dh
|
|
|
|
if islogical(opts.Dh) && opts.Dh == true
|
|
|
|
Dh = zeros(length(t), 6);
|
|
|
|
elseif islogical(opts.Dh) && opts.Dh == false
|
|
|
|
Dh = zeros(length(t), 6);
|
2018-06-21 14:16:08 +02:00
|
|
|
else
|
2018-10-25 13:12:07 +02:00
|
|
|
Dh = opts.Dh;
|
2018-06-21 14:16:08 +02:00
|
|
|
end
|
2018-06-16 22:57:54 +02:00
|
|
|
|
2018-10-25 13:12:07 +02:00
|
|
|
%% Axis Compensation - Rm
|
|
|
|
if islogical(opts.Rm)
|
|
|
|
Rm = zeros(length(t), 2);
|
|
|
|
Rm(:, 2) = pi*ones(length(t), 1);
|
2018-06-21 14:16:08 +02:00
|
|
|
else
|
2018-10-25 13:12:07 +02:00
|
|
|
Rm = opts.Rm;
|
2018-06-21 14:16:08 +02:00
|
|
|
end
|
2018-06-16 22:57:54 +02:00
|
|
|
|
2018-10-25 13:12:07 +02:00
|
|
|
%% Nano Hexapod - Dn
|
|
|
|
if islogical(opts.Dn) && opts.Dn == true
|
|
|
|
Dn = zeros(length(t), 6);
|
|
|
|
elseif islogical(opts.Dn) && opts.Dn == false
|
|
|
|
Dn = zeros(length(t), 6);
|
2018-06-21 14:16:08 +02:00
|
|
|
else
|
2018-10-25 13:12:07 +02:00
|
|
|
Dn = opts.Dn;
|
2018-06-21 14:16:08 +02:00
|
|
|
end
|
2018-06-16 22:57:54 +02:00
|
|
|
|
2018-10-25 13:12:07 +02:00
|
|
|
%% Setpoint - Ds
|
|
|
|
Ds = zeros(length(t), 6);
|
|
|
|
for i = 1:length(t)
|
|
|
|
Ds(i, :) = computeSetpoint(Dy(i), Ry(i), Rz(i));
|
2018-06-21 11:42:46 +02:00
|
|
|
end
|
|
|
|
|
2018-10-25 13:12:07 +02:00
|
|
|
%% External Forces applied on the Granite
|
|
|
|
Fg = zeros(length(t), 3);
|
|
|
|
|
|
|
|
%% External Forces applied on the Sample
|
2018-10-29 12:57:13 +01:00
|
|
|
Fs = zeros(length(t), 6);
|
2018-10-25 13:12:07 +02:00
|
|
|
|
|
|
|
%% Create the input Structure that will contain all the inputs
|
|
|
|
inputs = struct( ...
|
2018-10-29 12:57:13 +01:00
|
|
|
'Ts', sim_conf.Ts, ...
|
2018-10-25 14:06:37 +02:00
|
|
|
'Dw', timeseries(Dw, t), ...
|
|
|
|
'Dy', timeseries(Dy, t), ...
|
|
|
|
'Ry', timeseries(Ry, t), ...
|
|
|
|
'Rz', timeseries(Rz, t), ...
|
|
|
|
'Dh', timeseries(Dh, t), ...
|
|
|
|
'Rm', timeseries(Rm, t), ...
|
|
|
|
'Dn', timeseries(Dn, t), ...
|
|
|
|
'Ds', timeseries(Ds, t), ...
|
|
|
|
'Fg', timeseries(Fg, t), ...
|
|
|
|
'Fs', timeseries(Fs, t) ...
|
2018-10-25 13:12:07 +02:00
|
|
|
);
|
2018-06-21 11:42:46 +02:00
|
|
|
|
2018-10-07 22:07:21 +02:00
|
|
|
%% Save
|
|
|
|
save('./mat/inputs.mat', 'inputs');
|
2018-10-25 13:12:07 +02:00
|
|
|
|
|
|
|
%% Custom Functions
|
|
|
|
function setpoint = computeSetpoint(ty, ry, rz)
|
|
|
|
%%
|
|
|
|
setpoint = zeros(6, 1);
|
|
|
|
|
|
|
|
%% Ty
|
|
|
|
TMTy = [1 0 0 0 ;
|
|
|
|
0 1 0 ty ;
|
|
|
|
0 0 1 0 ;
|
|
|
|
0 0 0 1 ];
|
|
|
|
|
|
|
|
%% Ry
|
|
|
|
TMRy = [ cos(ry) 0 sin(ry) 0 ;
|
|
|
|
0 1 0 0 ;
|
|
|
|
-sin(ry) 0 cos(ry) 0 ;
|
|
|
|
0 0 0 1 ];
|
|
|
|
|
|
|
|
%% Rz
|
|
|
|
TMRz = [cos(rz) -sin(rz) 0 0 ;
|
|
|
|
sin(rz) cos(rz) 0 0 ;
|
|
|
|
0 0 1 0 ;
|
|
|
|
0 0 0 1 ];
|
|
|
|
|
|
|
|
%% All stages
|
|
|
|
TM = TMTy*TMRy*TMRz;
|
|
|
|
|
|
|
|
[thetax, thetay, thetaz] = RM2angle(TM(1:3, 1:3));
|
|
|
|
|
|
|
|
setpoint(1:3) = TM(1:3, 4);
|
|
|
|
setpoint(4:6) = [thetax, thetay, thetaz];
|
|
|
|
|
|
|
|
%% Custom Functions
|
|
|
|
function [thetax, thetay, thetaz] = RM2angle(R)
|
|
|
|
if abs(abs(R(3, 1)) - 1) > 1e-6 % R31 != 1 and R31 != -1
|
|
|
|
thetay = -asin(R(3, 1));
|
|
|
|
thetax = atan2(R(3, 2)/cos(thetay), R(3, 3)/cos(thetay));
|
|
|
|
thetaz = atan2(R(2, 1)/cos(thetay), R(1, 1)/cos(thetay));
|
|
|
|
else
|
|
|
|
thetaz = 0;
|
|
|
|
if abs(R(3, 1)+1) < 1e-6 % R31 = -1
|
|
|
|
thetay = pi/2;
|
|
|
|
thetax = thetaz + atan2(R(1, 2), R(1, 3));
|
|
|
|
else
|
|
|
|
thetay = -pi/2;
|
|
|
|
thetax = -thetaz + atan2(-R(1, 2), -R(1, 3));
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-06-16 22:57:54 +02:00
|
|
|
end
|