#+TITLE: Cedrat Actuator
:DRAWER:
#+STARTUP: overview

#+LANGUAGE: en
#+EMAIL: dehaeze.thomas@gmail.com
#+AUTHOR: Dehaeze Thomas

#+HTML_LINK_HOME: ../index.html
#+HTML_LINK_UP: ../index.html

#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../css/htmlize.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../css/readtheorg.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../css/zenburn.css"/>
#+HTML_HEAD: <script type="text/javascript" src="../js/jquery.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="../js/bootstrap.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="../js/jquery.stickytableheaders.min.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="../js/readtheorg.js"></script>

#+HTML_MATHJAX: align: center tagside: right font: TeX

#+PROPERTY: header-args:matlab  :session *MATLAB*
#+PROPERTY: header-args:matlab+ :comments org
#+PROPERTY: header-args:matlab+ :results none
#+PROPERTY: header-args:matlab+ :exports both
#+PROPERTY: header-args:matlab+ :eval no-export
#+PROPERTY: header-args:matlab+ :output-dir figs
#+PROPERTY: header-args:matlab+ :tangle matlab/modal_frf_coh.m
#+PROPERTY: header-args:matlab+ :mkdirp yes

#+PROPERTY: header-args:shell  :eval no-export

#+PROPERTY: header-args:latex  :headers '("\\usepackage{tikz}" "\\usepackage{import}" "\\import{$HOME/Cloud/thesis/latex/}{config.tex}")
#+PROPERTY: header-args:latex+ :imagemagick t :fit yes
#+PROPERTY: header-args:latex+ :iminoptions -scale 100% -density 150
#+PROPERTY: header-args:latex+ :imoutoptions -quality 100
#+PROPERTY: header-args:latex+ :results raw replace :buffer no
#+PROPERTY: header-args:latex+ :eval no-export
#+PROPERTY: header-args:latex+ :exports both
#+PROPERTY: header-args:latex+ :mkdirp yes
#+PROPERTY: header-args:latex+ :output-dir figs
:END:

* Documentation
- Blocked force: $1400\ N$
- Stiffness: $10.8\ N/\mu m$
- Resonance (free-free): $6450\ Hz$
- Resonance (blocked-free): $1750\ Hz$
- Height: $H = 45\ mm$
- Length: $L = 80\ mm$
- Width: $22\ mm$
- Mass: $160\ g$

#+begin_src latex :file cedrat_geometry.pdf :post pdf2svg(file=*this*, ext="png") :exports results
  \begin{tikzpicture}
    \node[branch] (O) at ( 0, 0){};
    \node[branch] (A) at (-3, 1.5){};
    \node[branch] (C) at ( 0, 1.5){};
    \node[branch] (B) at ( 3, 1.5){};
    \node[branch] (T) at ( 0, 3){};

    \draw[] (O) -- (A);
    \draw[] (O) -- node[midway, below]{$L_2$} (B);
    \draw[] (A) -- (C);
    \draw[] (C) -- (B);
    \draw[] (A) -- (T);
    \draw[] (B) -- (T);

    \draw[dashed] (O) -- (T);
    \draw[dashed] (0, 0.5) arc (90:26:0.5) node[midway, above]{$\alpha$};

    \draw[dashed, <->] ($(O) + (3.5,  0)$) -- node[right]{$H$} ($(T) + (3.5, 0)$);
    \draw[dashed, <->] ($(A) + (0, -2)$) -- node[below]{$L$} ($(B) + (0, -2)$);
  \end{tikzpicture}
#+end_src

#+RESULTS:
[[file:figs/cedrat_geometry.png]]


* Matlab Init                                               :noexport:ignore:
#+begin_src matlab :tangle no :exports none :results silent :noweb yes :var current_dir=(file-name-directory buffer-file-name)
  <<matlab-dir>>
#+end_src

#+begin_src matlab :exports none :results silent :noweb yes
  <<matlab-init>>
#+end_src

#+begin_src matlab :tangle no
  simulinkproject('../');
#+end_src

#+begin_src matlab
  open 'simscape/cedrat_piezo.slx'
#+end_src

* Parameters
#+begin_src matlab
  cedrat.L = 80; % Total Width of the Actuator[mm]
  cedrat.H = 45; % Total Height of the Actuator [mm]
  cedrat.L2 = sqrt((cedrat.L/2)^2 + (cedrat.H/2)^2); % Length of the elipsoidal sections [mm]
  cedrat.alpha = 180/pi*atan2(cedrat.L/2, cedrat.H/2); % [deg]
  cedrat.mtot = 0.160; % Total mass of the Actuator [kg]
  cedrat.m = cedrat.mtot/6; % Mass of each single element [kg]
#+end_src

#+begin_src matlab
  cedrat.k = 1e9; % Linear Stiffness of each "blade" [N/m]
  cedrat.c = 0.1*sqrt(cedrat.mtot*cedrat.k); % [N/(m/s)]

  cedrat.ka = 5e7; % Linear Stiffness of the stack [N/m]
  cedrat.ca = 0.1*sqrt(cedrat.mtot*cedrat.ka); % [N/(m/s)]

  cedrat.kr = 10; % Rotation Stiffness [N*m/(deg)]
  cedrat.cr = 0.0001; % Rotation Damping [N*m/(deg/s)]
#+end_src

#+begin_src matlab
  K_iff = tf(0);
#+end_src

#+begin_src matlab
  % dummy_mass = 140; % [kg]
  dummy_mass = 1; % [kg]
#+end_src

* Identification
#+begin_src matlab
  %% Options for Linearized
  options = linearizeOptions;
  options.SampleTime = 0;

  %% Name of the Simulink File
  mdl = 'cedrat_piezo';

  %% Input/Output definition
  io(1)  = linio([mdl, '/F'],  1, 'input');
  io(2)  = linio([mdl, '/Fz'], 1, 'input');
  io(3)  = linio([mdl, '/Dw'], 1, 'input');
  io(4)  = linio([mdl, '/Dz'], 1, 'output');
  io(5)  = linio([mdl, '/Fm'], 1, 'output');

  %% Run the linearization
  G = linearize(mdl, io, options);
  G.InputName  = {'F', 'Fz', 'Dw'};
  G.OutputName = {'Dz', 'Fm'};
#+end_src

#+begin_src matlab :exports none
  freqs = logspace(0, 5, 1000);

  figure;
  subplot(2, 2, 1);
  title('From $F_z$ to $D_z$ - Compliance');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('Dz', 'Fz'), freqs, 'Hz'))), 'k-');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');

  subplot(2, 2, 2);
  title('From $D_w$ to $D_z$ - Transmissibility');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('Dz', 'Dw'), freqs, 'Hz'))), 'k-');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [V/N]'); xlabel('Frequency [Hz]');

  subplot(2, 2, 3);
  title('From $F$ to $D_z$ - Plant');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('Dz', 'F'), freqs, 'Hz'))), 'k-');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');

  subplot(2, 2, 4);
  title('From $F$ to $F_m$ - IFF Plant');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('Fm', 'F'), freqs, 'Hz'))), 'k-');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [V/N]'); xlabel('Frequency [Hz]');
#+end_src

#+HEADER: :tangle no :exports results :results none :noweb yes
#+begin_src matlab :var filepath="figs/cedrat_piezo_identified_tf.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:cedrat_piezo_identified_tf
#+CAPTION: Identified Transfer function ([[./figs/cedrat_piezo_identified_tf.png][png]], [[./figs/cedrat_piezo_identified_tf.pdf][pdf]])
[[file:figs/cedrat_piezo_identified_tf.png]]

* Integral Force Feedback
#+begin_src matlab :exports none
  freqs = logspace(1, 5, 1000);

  figure;

  ax1 = subplot(2, 1, 1);
  plot(freqs, abs(squeeze(freqresp(-G('Fm', 'F'), freqs, 'Hz'))), 'k-');
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [N/N]'); set(gca, 'XTickLabel',[]);

  ax2 = subplot(2, 1, 2);
  plot(freqs, 180/pi*angle(squeeze(freqresp(-G('Fm', 'F'), freqs, 'Hz'))), 'k-');
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'lin');
  ylabel('Phase [deg]'); xlabel('Frequency [Hz]');
  ylim([-180, 180]);
  yticks([-180, -90, 0, 90, 180]);

  linkaxes([ax1,ax2],'x');
#+end_src

#+HEADER: :tangle no :exports results :results none :noweb yes
#+begin_src matlab :var filepath="figs/iff_plant_cedrat.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:iff_plant_cedrat
#+CAPTION: Transfer function from $F$ to $F_m$ ([[./figs/iff_plant_cedrat.png][png]], [[./figs/iff_plant_cedrat.pdf][pdf]])
[[file:figs/iff_plant_cedrat.png]]


#+begin_src matlab
  K_iff = -100000/s*(s/2/pi/100)/(1 + s/2/pi/100)*(s/2/pi/100)/(1 + s/2/pi/100);
#+end_src

#+begin_src matlab :exports none
  freqs = logspace(0, 5, 1000);

  figure;

  ax1 = subplot(2, 1, 1);
  plot(freqs, abs(squeeze(freqresp(K_iff*G('Fm', 'F'), freqs, 'Hz'))), 'k-');
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [N/N]'); set(gca, 'XTickLabel',[]);

  ax2 = subplot(2, 1, 2);
  plot(freqs, 180/pi*angle(squeeze(freqresp(K_iff*G('Fm', 'F'), freqs, 'Hz'))), 'k-');
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'lin');
  ylabel('Phase [deg]'); xlabel('Frequency [Hz]');
  ylim([-180, 180]);
  yticks([-180, -90, 0, 90, 180]);

  linkaxes([ax1,ax2],'x');
#+end_src

#+HEADER: :tangle no :exports results :results none :noweb yes
#+begin_src matlab :var filepath="figs/iff_open_loop_cedrat.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:iff_open_loop_cedrat
#+CAPTION: Open Loop Gain Transfer Function - Cedrat ([[./figs/iff_open_loop_cedrat.png][png]], [[./figs/iff_open_loop_cedrat.pdf][pdf]])
[[file:figs/iff_open_loop_cedrat.png]]

* Damped System
#+begin_src matlab
  %% Options for Linearized
  options = linearizeOptions;
  options.SampleTime = 0;

  %% Name of the Simulink File
  mdl = 'cedrat_piezo';

  %% Input/Output definition
  io(1)  = linio([mdl, '/F'],  1, 'input');
  io(2)  = linio([mdl, '/Fz'],  1, 'input');
  io(3)  = linio([mdl, '/Dw'], 1, 'input');
  io(4)  = linio([mdl, '/Dz'], 1, 'output');
  io(5)  = linio([mdl, '/Fm'], 1, 'output');

  %% Run the linearization
  G_iff = linearize(mdl, io, options);
  G_iff.InputName  = {'F', 'Fz', 'Dw'};
  G_iff.OutputName = {'Dz', 'Fm'};
#+end_src

#+begin_src matlab :exports none
  freqs = logspace(0, 5, 1000);

  figure;
  subplot(2, 2, 1);
  title('From $F_z$ to $D_z$ - Compliance');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('Dz', 'Fz'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_iff('Dz', 'Fz'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');

  subplot(2, 2, 2);
  title('From $D_w$ to $D_z$ - Transmissibility');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('Dz', 'Dw'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_iff('Dz', 'Dw'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [V/N]'); xlabel('Frequency [Hz]');

  subplot(2, 2, 3);
  title('From $F$ to $D_z$ - Plant');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('Dz', 'F'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_iff('Dz', 'F'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');

  subplot(2, 2, 4);
  title('From $F$ to $F_m$ - IFF Plant');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('Fm', 'F'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_iff('Fm', 'F'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [V/N]'); xlabel('Frequency [Hz]');
#+end_src

#+HEADER: :tangle no :exports results :results none :noweb yes
#+begin_src matlab :var filepath="figs/cedrat_iff_piezo_identified_tf.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:cedrat_iff_piezo_identified_tf
#+CAPTION: Identified Transfer function ([[./figs/cedrat_iff_piezo_identified_tf.png][png]], [[./figs/cedrat_iff_piezo_identified_tf.pdf][pdf]])
[[file:figs/cedrat_iff_piezo_identified_tf.png]]
