Update simscape page

This commit is contained in:
Thomas Dehaeze 2019-12-06 12:04:11 +01:00
parent f73becd5c9
commit 7835cdd4dc
2 changed files with 699 additions and 514 deletions

File diff suppressed because it is too large Load Diff

View File

@ -47,7 +47,6 @@ This file is used to explain how this Simscape Model works.
- In section [[sec:simscape_model]], an introduction to Simscape Multibody is done - In section [[sec:simscape_model]], an introduction to Simscape Multibody is done
- In section [[sec:simulink_files_signal_names]], each simscape files are presented with the associated signal names and joint architectures - In section [[sec:simulink_files_signal_names]], each simscape files are presented with the associated signal names and joint architectures
- In section [[sec:simulink_library]], the list of the Simulink library elements are described - In section [[sec:simulink_library]], the list of the Simulink library elements are described
- In section [[sec:scripts]], the scripts used for the simulations (initialization for instance) are described
- In section [[sec:functions]], a list of Matlab function that will be used are defined here - In section [[sec:functions]], a list of Matlab function that will be used are defined here
- In section [[sec:initialize_elements]], all the functions that are used to initialize the Simscape Multibody elements are defined here. This includes the mass of all solids for instance. - In section [[sec:initialize_elements]], all the functions that are used to initialize the Simscape Multibody elements are defined here. This includes the mass of all solids for instance.
@ -86,10 +85,6 @@ The project can be opened using the =simulinkproject= function:
When the project opens, a startup script is ran. When the project opens, a startup script is ran.
The startup script is defined below and is exported to the =project_startup.m= script. The startup script is defined below and is exported to the =project_startup.m= script.
#+begin_src matlab :eval no :tangle ../src/project_startup.m #+begin_src matlab :eval no :tangle ../src/project_startup.m
freqs = logspace(-1, 3, 1000);
save_fig = false;
save('./mat/config.mat', 'freqs', 'save_fig');
project = simulinkproject; project = simulinkproject;
projectRoot = project.RootFolder; projectRoot = project.RootFolder;
@ -322,33 +317,8 @@ A simulink library is developed in order to share elements between the different
** =RotationMatrixToAngle= ** =RotationMatrixToAngle=
[[../nass_library/RotationMatrixToAngle.slx][RotationMatrixToAngle.slx]] [[../nass_library/RotationMatrixToAngle.slx][RotationMatrixToAngle.slx]]
* Scripts
<<sec:scripts>>
** Simulation Initialization
:PROPERTIES:
:header-args:matlab+: :tangle ../src/init_simulation.m
:header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none
:END:
<<sec:init_simulation>>
This Matlab script is accessible [[file:../src/init_simulation.m][here]].
This script runs just before the simulation is started.
It is used to load the simulation configuration and the controllers used for the simulation.
#+begin_src matlab
%% Load all the data used for the simulation
load('sim_conf.mat');
%% Load Controller
load('controllers.mat');
#+end_src
* Functions * Functions
<<sec:functions>> <<sec:functions>>
** computePsdDispl ** computePsdDispl
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/computePsdDispl.m :header-args:matlab+: :tangle ../src/computePsdDispl.m
@ -787,71 +757,19 @@ This Matlab function is accessible [[file:../src/runSimulation.m][here]].
#+end_src #+end_src
* Initialize Elements * Initialize Elements
<<sec:initialize_elements>> <<sec:initialize_elements>>
** Simulation Configuration
:PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeSimConf.m
:header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none
:END:
<<sec:initializeSimConf>>
This Matlab function is accessible [[file:../src/initializeSimConf.m][here]].
#+begin_src matlab
function [] = initializeSimConf(opts_param)
%% Default values for opts
opts = struct('Ts', 1e-4, ... % Sampling time [s]
'Tsim', 10, ... % Simulation time [s]
'cl_time', 0, ... % Close Loop time [s]
'gravity', false ... % Gravity along the z axis
);
%% Populate opts with input parameters
if exist('opts_param','var')
for opt = fieldnames(opts_param)'
opts.(opt{1}) = opts_param.(opt{1});
end
end
%%
sim_conf = struct();
%%
sim_conf.Ts = opts.Ts;
sim_conf.Tsim = opts.Tsim;
sim_conf.cl_time = opts.cl_time;
%% Gravity
if opts.gravity
sim_conf.g = -9.8; %#ok
else
sim_conf.g = 0; %#ok
end
%% Save
save('./mat/sim_conf.mat', 'sim_conf');
end
#+end_src
** Experiment ** Experiment
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeExperiment.m :header-args:matlab+: :tangle ../src/initializeExperiment.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeExperiment>> <<sec:initializeExperiment>>
This Matlab function is accessible [[file:../src/initializeExperiment.m][here]]. This Matlab function is accessible [[file:../src/initializeExperiment.m][here]].
#+begin_src matlab #+begin_src matlab
function [] = initializeExperiment(exp_name, sys_mass) function [] = initializeExperiment(exp_name, sys_mass)
if strcmp(exp_name, 'tomography') if strcmp(exp_name, 'tomography')
opts_sim = struct(...
'Tsim', 5, ...
'cl_time', 5 ...
);
initializeSimConf(opts_sim);
if strcmp(sys_mass, 'light') if strcmp(sys_mass, 'light')
opts_inputs = struct(... opts_inputs = struct(...
'Dw', true, ... 'Dw', true, ...
@ -873,13 +791,145 @@ This Matlab function is accessible [[file:../src/initializeExperiment.m][here]].
end end
#+end_src #+end_src
** Inputs ** Generate Reference Signals
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeInputs.m :header-args:matlab+: :tangle ../src/initializeReferences.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeInputs>> <<sec:initializeReferences>>
This Matlab function is accessible [[file:../src/initializeInputs.m][here]].
#+begin_src matlab
function [ref] = initializeReferences(opts_param)
%% Default values for opts
opts = struct( ...
'Ts', 1e-3, ... % Sampling Frequency [s]
'Dy_type', 'constant', ... % Either "constant" / "triangular" / "sinusoidal"
'Dy_amplitude', 0, ... % Amplitude of the displacement [m]
'Dy_period', 1, ... % Period of the displacement [s]
'Ry_type', 'constant', ... % Either "constant" / "triangular" / "sinusoidal"
'Ry_amplitude', 0, ... % Amplitude [deg]
'Ry_period', 10, ... % Period of the displacement [s]
'Rz_type', 'constant', ... % Either "constant" / "rotating"
'Rz_amplitude', 0, ... % Initial angle [deg]
'Rz_period', 1, ... % Period of the rotating [s]
'Dh_type', 'constant', ... % For now, only constant is implemented
'Dh_pos', [0; 0; 0; 0; 0; 0], ... % Initial position [m,m,m,rad,rad,rad] of the top platform
'Rm_type', 'constant', ... % For now, only constant is implemented
'Rm_pos', [0; pi], ... % Initial position of the two masses
'Dn_type', 'constant', ... % For now, only constant is implemented
'Dn_pos', [0; 0; 0; 0; 0; 0] ... % Initial position [m,m,m,rad,rad,rad] of the top platform
);
%% Populate opts with input parameters
if exist('opts_param','var')
for opt = fieldnames(opts_param)'
opts.(opt{1}) = opts_param.(opt{1});
end
end
%% Set Sampling Time
Ts = opts.Ts;
%% Translation stage - Dy
t = 0:Ts:opts.Dy_period-Ts; % Time Vector [s]
Dy = zeros(length(t), 1);
switch opts.Dy_type
case 'constant'
Dy(:) = opts.Dy_amplitude;
case 'triangular'
Dy(:) = -4*opts.Dy_amplitude + 4*opts.Dy_amplitude/opts.Dy_period*t;
Dy(t<0.75*opts.Dy_period) = 2*opts.Dy_amplitude - 4*opts.Dy_amplitude/opts.Dy_period*t(t<0.75*opts.Dy_period);
Dy(t<0.25*opts.Dy_period) = 4*opts.Dy_amplitude/opts.Dy_period*t(t<0.25*opts.Dy_period);
case 'sinusoidal'
Dy(:) = opts.Dy_amplitude*sin(2*pi/opts.Dy_period*t);
otherwise
warning('Dy_type is not set correctly');
end
Dy = struct('time', t, 'signals', struct('values', Dy));
%% Tilt Stage - Ry
t = 0:Ts:opts.Ry_period-Ts;
Ry = zeros(length(t), 1);
switch opts.Ry_type
case 'constant'
Ry(:) = pi/180*opts.Ry_amplitude;
case 'triangular'
Ry(:) = -4*(pi/180*opts.Ry_amplitude) + 4*(pi/180*opts.Ry_amplitude)/opts.Ry_period*t;
Ry(t<0.75*opts.Ry_period) = 2*(pi/180*opts.Ry_amplitude) - 4*(pi/180*opts.Ry_amplitude)/opts.Ry_period*t(t<0.75*opts.Ry_period);
Ry(t<0.25*opts.Ry_period) = 4*(pi/180*opts.Ry_amplitude)/opts.Ry_period*t(t<0.25*opts.Ry_period);
case 'sinusoidal'
Ry(:) = opts.Ry_amplitude*sin(2*pi/opts.Ry_period*t);
otherwise
warning('Ry_type is not set correctly');
end
Ry = struct('time', t, 'signals', struct('values', Ry));
%% Spindle - Rz
t = 0:Ts:opts.Rz_period-Ts;
Rz = zeros(length(t), 1);
switch opts.Rz_type
case 'constant'
Rz(:) = pi/180*opts.Rz_amplitude;
case 'rotating'
Rz(:) = pi/180*opts.Rz_amplitude+2*pi/opts.Rz_period*t;
otherwise
warning('Rz_type is not set correctly');
end
Rz = struct('time', t, 'signals', struct('values', Rz));
%% Micro-Hexapod
t = [0, Ts];
Dh = zeros(length(t), 6);
opts.Dh_pos(4:6) = pi/180*opts.Dh_pos(4:6); % convert from [deg] to [rad]
switch opts.Dh_type
case 'constant'
Dh = [opts.Dh_pos, opts.Dh_pos];
otherwise
warning('Dh_type is not set correctly');
end
Dh = struct('time', t, 'signals', struct('values', Dh));
%% Axis Compensation - Rm
t = [0, Ts];
Rm = [opts.Rm_pos, opts.Rm_pos];
Rm = struct('time', t, 'signals', struct('values', Rm));
%% Nano-Hexapod
t = [0, Ts];
Dn = zeros(length(t), 6);
opts.Dn_pos(4:6) = pi/180*opts.Dn_pos(4:6); % convert from [deg] to [rad]
switch opts.Dn_type
case 'constant'
Dn = [opts.Dn_pos, opts.Dn_pos];
otherwise
warning('Dn_type is not set correctly');
end
Dn = struct('time', t, 'signals', struct('values', Dn));
%% Save
save('./mat/nass_references.mat', 'Dy', 'Ry', 'Rz', 'Dh', 'Rm', 'Dn', 'Ts');
end
#+end_src
** TODO Inputs
:PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeInputs.m
:header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none
:END:
<<sec:initializeInputs>>
- [ ] *This function should not be used anymore*. Now there are two functions to initialize disturbances and references.
This Matlab function is accessible [[file:../src/initializeInputs.m][here]]. This Matlab function is accessible [[file:../src/initializeInputs.m][here]].
@ -1062,12 +1112,12 @@ This Matlab function is accessible [[file:../src/initializeInputs.m][here]].
#+end_src #+end_src
** Ground ** Ground
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeGround.m :header-args:matlab+: :tangle ../src/initializeGround.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeGround>> <<sec:initializeGround>>
This Matlab function is accessible [[file:../src/initializeGround.m][here]]. This Matlab function is accessible [[file:../src/initializeGround.m][here]].
@ -1086,12 +1136,12 @@ end
#+end_src #+end_src
** Granite ** Granite
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeGranite.m :header-args:matlab+: :tangle ../src/initializeGranite.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeGranite>> <<sec:initializeGranite>>
This Matlab function is accessible [[file:../src/initializeGranite.m][here]]. This Matlab function is accessible [[file:../src/initializeGranite.m][here]].
@ -1152,12 +1202,12 @@ This Matlab function is accessible [[file:../src/initializeGranite.m][here]].
#+end_src #+end_src
** Translation Stage ** Translation Stage
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeTy.m :header-args:matlab+: :tangle ../src/initializeTy.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeTy>> <<sec:initializeTy>>
This Matlab function is accessible [[file:../src/initializeTy.m][here]]. This Matlab function is accessible [[file:../src/initializeTy.m][here]].
@ -1234,12 +1284,12 @@ This Matlab function is accessible [[file:../src/initializeTy.m][here]].
#+end_src #+end_src
** Tilt Stage ** Tilt Stage
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeRy.m :header-args:matlab+: :tangle ../src/initializeRy.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeRy>> <<sec:initializeRy>>
This Matlab function is accessible [[file:../src/initializeRy.m][here]]. This Matlab function is accessible [[file:../src/initializeRy.m][here]].
@ -1305,12 +1355,12 @@ This Matlab function is accessible [[file:../src/initializeRy.m][here]].
#+end_src #+end_src
** Spindle ** Spindle
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeRz.m :header-args:matlab+: :tangle ../src/initializeRz.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeRz>> <<sec:initializeRz>>
This Matlab function is accessible [[file:../src/initializeRz.m][here]]. This Matlab function is accessible [[file:../src/initializeRz.m][here]].
@ -1372,12 +1422,12 @@ This Matlab function is accessible [[file:../src/initializeRz.m][here]].
#+end_src #+end_src
** Micro Hexapod ** Micro Hexapod
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeMicroHexapod.m :header-args:matlab+: :tangle ../src/initializeMicroHexapod.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeMicroHexapod>> <<sec:initializeMicroHexapod>>
This Matlab function is accessible [[file:../src/initializeMicroHexapod.m][here]]. This Matlab function is accessible [[file:../src/initializeMicroHexapod.m][here]].
@ -1581,12 +1631,12 @@ This Matlab function is accessible [[file:../src/initializeMicroHexapod.m][here]
#+end_src #+end_src
** Center of gravity compensation ** Center of gravity compensation
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeAxisc.m :header-args:matlab+: :tangle ../src/initializeAxisc.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeAxisc>> <<sec:initializeAxisc>>
This Matlab function is accessible [[file:../src/initializeAxisc.m][here]]. This Matlab function is accessible [[file:../src/initializeAxisc.m][here]].
@ -1625,12 +1675,12 @@ This Matlab function is accessible [[file:../src/initializeAxisc.m][here]].
#+end_src #+end_src
** Mirror ** Mirror
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeMirror.m :header-args:matlab+: :tangle ../src/initializeMirror.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeMirror>> <<sec:initializeMirror>>
This Matlab function is accessible [[file:../src/initializeMirror.m][here]]. This Matlab function is accessible [[file:../src/initializeMirror.m][here]].
@ -1691,12 +1741,12 @@ This Matlab function is accessible [[file:../src/initializeMirror.m][here]].
#+end_src #+end_src
** Nano Hexapod ** Nano Hexapod
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeNanoHexapod.m :header-args:matlab+: :tangle ../src/initializeNanoHexapod.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeNanoHexapod>> <<sec:initializeNanoHexapod>>
This Matlab function is accessible [[file:../src/initializeNanoHexapod.m][here]]. This Matlab function is accessible [[file:../src/initializeNanoHexapod.m][here]].
@ -1908,12 +1958,12 @@ This Matlab function is accessible [[file:../src/initializeNanoHexapod.m][here]]
#+end_src #+end_src
** Cedrat Actuator ** Cedrat Actuator
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeCedratPiezo.m :header-args:matlab+: :tangle ../src/initializeCedratPiezo.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeCedratPiezo>> <<sec:initializeCedratPiezo>>
This Matlab function is accessible [[file:../src/initializeCedratPiezo.m][here]]. This Matlab function is accessible [[file:../src/initializeCedratPiezo.m][here]].
@ -1948,12 +1998,12 @@ This Matlab function is accessible [[file:../src/initializeCedratPiezo.m][here]]
#+end_src #+end_src
** Sample ** Sample
:PROPERTIES: :PROPERTIES:
:header-args:matlab+: :tangle ../src/initializeSample.m :header-args:matlab+: :tangle ../src/initializeSample.m
:header-args:matlab+: :comments org :mkdirp yes :header-args:matlab+: :comments org :mkdirp yes
:header-args:matlab+: :eval no :results none :header-args:matlab+: :eval no :results none
:END: :END:
<<sec:initializeSample>> <<sec:initializeSample>>
This Matlab function is accessible [[file:../src/initializeSample.m][here]]. This Matlab function is accessible [[file:../src/initializeSample.m][here]].