#+TITLE: Simscape Uniaxial Model
: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:

* Introduction                                                       :ignore:
The idea is to use the same model as the full Simscape Model but to restrict the motion only in the vertical direction.

This is done in order to more easily study the system and evaluate control techniques.

* Simscape Model
<<sec:simscape_model>>

A schematic of the uniaxial model used for simulations is represented in figure [[fig:uniaxial-model-nass-flexible]].

The perturbations $w$ are:
- $F_s$: direct forces applied to the sample such as inertia forces and cable forces
- $F_{rz}$: parasitic forces due to the rotation of the spindle
- $F_{ty}$: parasitic forces due to scans with the translation stage
- $D_w$: ground motion

The quantity to $z$ to control is:
- $D$: the position of the sample with respect to the granite

The measured quantities $v$ are:
- $D$: the position of the sample with respect to the granite

We study the use of an additional sensor:
- $F_n$: a force sensor located in the nano-hexapod
- $v_n$: an absolute velocity sensor located on the top platform of the nano-hexapod
- $d_r$: a relative motion sensor located in the nano-hexapod

The control signal $u$ is:
- $F$ the force applied by the nano-hexapod actuator

#+begin_src latex :file uniaxial-model-nass-flexible.pdf :post pdf2svg(file=*this*, ext="png") :exports results
  \begin{tikzpicture}
    % ====================
    % Parameters
    % ====================
    \def\massw{2.2}  % Width of the masses
    \def\massh{0.8}  % Height of the masses
    \def\spaceh{1.2} % Height of the springs/dampers
    \def\dispw{0.4}  % Width of the dashed line for the displacement
    \def\disph{0.3}  % Height of the arrow for the displacements
    \def\bracs{0.05} % Brace spacing vertically
    \def\brach{-12pt} % Brace shift horizontaly
    \def\fsensh{0.2} % Height of the force sensor
    \def\velsize{0.2} % Size of the velocity sensor
    % ====================


    % ====================
    % Ground
    % ====================
    \draw (-0.5*\massw, 0) -- (0.5*\massw, 0);
    \draw[dashed] (0.5*\massw, 0) -- ++(1, 0);
    \draw[->, dasehd] (0.5*\massw+0.8, 0) -- ++(0, 0.5) node[right]{$D_{w}$};
    % ====================


    % ====================
    % Marble
    \begin{scope}[shift={(0, 0)}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{m}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{m}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{m}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Marble};

      % Displacements
      \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(2*\dispw, 0) coordinate(xm) -- ++(2.2*\dispw, 0) coordinate(dbot);
    \end{scope}
    % ====================


    % ====================
    % Ty
    \begin{scope}[shift={(0, \spaceh+\massh)}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{t}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{t}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{t}$};
      \draw[actuator={0.45}{0.2}] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](ft){$F_{ty}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Ty};
    \end{scope}
    % ====================


    % ====================
    % Rz
    \begin{scope}[shift={(0, 2*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{z}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{z}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{z}$};
      \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F_{rz}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Rz};
    \end{scope}
    % ====================


    % ====================
    % Hexapod
    \begin{scope}[shift={(0, 3*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{h}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{h}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{h}$};

      % Displacements
      % \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(3*\dispw, 0) coordinate(drbot);

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Hexapod};
    \end{scope}
    % ====================


    % ====================
    % NASS
    \begin{scope}[shift={(0, 4*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{n}$};

      % % Force Sensor
      % \node[forcesensor={\massw}{\fsensh}] (fsensn) at (0, \spaceh-\fsensh){};
      % \node[right] at (fsensn.east) {$F_n$};

      % % Velocity Sensor
      % \node[inertialsensor={\velsize}] (veln) at (0.5*\massw, \spaceh+\massh) {};
      % \node[right] at (veln.north east) {$v_n$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{n}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{n}$};
      \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F$};

      % % Displacements
      % \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(2*\dispw, 0) coordinate(xn) -- ++(\dispw, 0) coordinate(drtop);

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{NASS};
    \end{scope}
    % ====================

    % ====================
    % sample
    \begin{scope}[shift={(0, 5*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{s}$};

      % External Force
      \draw[->] (0, \spaceh+\massh) node[]{$\bullet$} -- ++(0, 0.5*\massh) node[right]{$F_s$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{s}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{s}$};

      % Displacements
      \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(2*\dispw, 0) coordinate(xs) -- ++(2.2*\dispw, 0) coordinate(dtop);

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Sample};
    \end{scope}
    % ====================


    \draw[<->] ($(dbot)+(-0.3,0)$) --node[midway, right]{$D$} ($(dtop)+(-0.3,0)$);
  \end{tikzpicture}
#+end_src

#+name: fig:uniaxial-model-nass-flexible
#+caption: Schematic of the uniaxial model used
#+RESULTS:
[[file:figs/uniaxial-model-nass-flexible.png]]


Few active damping techniques will be compared in order to decide which sensor is to be included in the system.
Schematics of the active damping techniques are displayed in figure [[fig:uniaxial-model-nass-flexible-active-damping]].

#+begin_src latex :file uniaxial-model-nass-flexible-active-damping.pdf :post pdf2svg(file=*this*, ext="png") :exports results
  \begin{tikzpicture}
    % ====================
    % Parameters
    % ====================
    \def\massw{2.2}  % Width of the masses
    \def\massh{0.8}  % Height of the masses
    \def\spaceh{1.2} % Height of the springs/dampers
    \def\dispw{0.4}  % Width of the dashed line for the displacement
    \def\disph{0.3}  % Height of the arrow for the displacements
    \def\bracs{0.05} % Brace spacing vertically
    \def\brach{-12pt} % Brace shift horizontaly
    \def\fsensh{0.2} % Height of the force sensor
    \def\velsize{0.2} % Size of the velocity sensor
    % ====================


      \begin{scope}
      % ====================
      % Ground
      % ====================
      \draw (-0.5*\massw, 0) -- (0.5*\massw, 0);
      \draw[dashed] (0.5*\massw, 0) -- ++(1, 0);
      \draw[->, dasehd] (0.5*\massw+0.8, 0) -- ++(0, 0.5) node[right]{$D_{w}$};
      % ====================


      % ====================
      % Marble
      \begin{scope}[shift={(0, 0)}]
        % Mass
        \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{m}$};

        % Spring, Damper, and Actuator
        \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{m}$};
        \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{m}$};

        % Legend
        \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
        (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Marble};
      \end{scope}
      % ====================


      % ====================
      % Ty
      \begin{scope}[shift={(0, \spaceh+\massh)}]
        % Mass
        \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{t}$};

        % Spring, Damper, and Actuator
        \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{t}$};
        \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{t}$};
        \draw[actuator={0.45}{0.2}] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](ft){$F_{ty}$};

        % Legend
        \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
        (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Ty};
      \end{scope}
      % ====================


      % ====================
      % Rz
      \begin{scope}[shift={(0, 2*(\spaceh+\massh))}]
        % Mass
        \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{z}$};

        % Spring, Damper, and Actuator
        \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{z}$};
        \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{z}$};
        \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F_{rz}$};

        % Legend
        \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
        (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Rz};
      \end{scope}
      % ====================


      % ====================
      % Hexapod
      \begin{scope}[shift={(0, 3*(\spaceh+\massh))}]
        % Mass
        \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{h}$};

        % Spring, Damper, and Actuator
        \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{h}$};
        \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{h}$};

        % Displacements
        % \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(3*\dispw, 0) coordinate(drbot);

        % Legend
        \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
        (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Hexapod};
      \end{scope}
      % ====================


      % ====================
      % NASS
      \begin{scope}[shift={(0, 4*(\spaceh+\massh))}]
        % Mass
        \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{n}$};

        % Force Sensor
        \node[forcesensor={\massw}{\fsensh}] (fsensn) at (0, \spaceh-\fsensh){};
        \node[right] (fn) at (fsensn.east) {$F_n$};

        % % Velocity Sensor
        % \node[inertialsensor={\velsize}] (veln) at (0.5*\massw, \spaceh+\massh) {};
        % \node[right] at (veln.north east) {$v_n$};

        % Spring, Damper, and Actuator
        \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh-\fsensh) node[midway, left=0.1]{$k_{n}$};
        \draw[damper] (0, 0)           -- ( 0, \spaceh-\fsensh)          node[midway, left=0.2]{$c_{n}$};
        \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh-\fsensh) node[midway, right=0.1](F){$F$};

        % % Displacements
        % \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(2*\dispw, 0) coordinate(xn) -- ++(\dispw, 0) coordinate(drtop);

        % Legend
        \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
        (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{NASS};
      \end{scope}
      % ====================

      % ====================
      % sample
      \begin{scope}[shift={(0, 5*(\spaceh+\massh))}]
        % Mass
        \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{s}$};

        % External Force
        \draw[->] (0, \spaceh+\massh) node[]{$\bullet$} -- ++(0, 0.5*\massh) node[right]{$F_s$};

        % Spring, Damper, and Actuator
        \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{s}$};
        \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{s}$};

        % Legend
        \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
        (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Sample};
      \end{scope}
      % ====================

      % ====================
      % IFF Control
      \node[block={2em}{2em}, right=0.3 of fn] (iff) {$K_{\text{IFF}}$};
      \draw[->] (fn.east) -- (iff.west);
      \draw[->] (iff.south) |- (F.east);
      % ====================
      \end{scope}



      \begin{scope}[shift={(5,0)}]
        % ====================
        % Ground
        % ====================
        \draw (-0.5*\massw, 0) -- (0.5*\massw, 0);
        \draw[dashed] (0.5*\massw, 0) -- ++(1, 0);
        \draw[->, dasehd] (0.5*\massw+0.8, 0) -- ++(0, 0.5) node[right]{$D_{w}$};
        % ====================


        % ====================
        % Marble
        \begin{scope}[shift={(0, 0)}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{m}$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{m}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{m}$};
        \end{scope}
        % ====================


        % ====================
        % Ty
        \begin{scope}[shift={(0, \spaceh+\massh)}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{t}$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{t}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{t}$};
          \draw[actuator={0.45}{0.2}] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](ft){$F_{ty}$};
        \end{scope}
        % ====================


        % ====================
        % Rz
        \begin{scope}[shift={(0, 2*(\spaceh+\massh))}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{z}$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{z}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{z}$};
          \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F_{rz}$};
        \end{scope}
        % ====================


        % ====================
        % Hexapod
        \begin{scope}[shift={(0, 3*(\spaceh+\massh))}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{h}$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{h}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{h}$};

          % Displacements
          % \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(3*\dispw, 0) coordinate(drbot);
        \end{scope}
        % ====================


        % ====================
        % NASS
        \begin{scope}[shift={(0, 4*(\spaceh+\massh))}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{n}$};

          % % Force Sensor
          % \node[forcesensor={\massw}{\fsensh}] (fsensn) at (0, \spaceh-\fsensh){};
          % \node[right] (fn) at (fsensn.east) {$F_n$};

          % Velocity Sensor
          \node[inertialsensor={\velsize}] (veln) at (0.5*\massw, \spaceh+\massh) {};
          \node[above right] at (veln.east) {$v_n$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{n}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{n}$};
          \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F$};

          % % Displacements
          % \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(2*\dispw, 0) coordinate(xn) -- ++(\dispw, 0) coordinate(drtop);
        \end{scope}
        % ====================

        % ====================
        % sample
        \begin{scope}[shift={(0, 5*(\spaceh+\massh))}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{s}$};

          % External Force
          \draw[->] (0, \spaceh+\massh) node[]{$\bullet$} -- ++(0, 0.5*\massh) node[right]{$F_s$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{s}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{s}$};
        \end{scope}
        % ====================

        % ====================
        % DVF Control
        \node[block={2em}{2em}, below right=0.4 and 0.4 of veln] (ppf) {$K_{\text{DVF}}$};
        \draw[->] (veln.east) -| (ppf.north);
        \draw[->] (ppf.south) |- (F.east);
        % ====================
      \end{scope}



      \begin{scope}[shift={(10,0)}]
        % ====================
        % Ground
        % ====================
        \draw (-0.5*\massw, 0) -- (0.5*\massw, 0);
        \draw[dashed] (0.5*\massw, 0) -- ++(1, 0);
        \draw[->, dasehd] (0.5*\massw+0.8, 0) -- ++(0, 0.5) node[right]{$D_{w}$};
        % ====================


        % ====================
        % Marble
        \begin{scope}[shift={(0, 0)}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{m}$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{m}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{m}$};
        \end{scope}
        % ====================


        % ====================
        % Ty
        \begin{scope}[shift={(0, \spaceh+\massh)}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{t}$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{t}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{t}$};
          \draw[actuator={0.45}{0.2}] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](ft){$F_{ty}$};
        \end{scope}
        % ====================


        % ====================
        % Rz
        \begin{scope}[shift={(0, 2*(\spaceh+\massh))}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{z}$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{z}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{z}$};
          \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F_{rz}$};
        \end{scope}
        % ====================


        % ====================
        % Hexapod
        \begin{scope}[shift={(0, 3*(\spaceh+\massh))}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{h}$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{h}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{h}$};

          % Displacements
          \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(3*\dispw, 0) coordinate(drbot);
        \end{scope}
        % ====================


        % ====================
        % NASS
        \begin{scope}[shift={(0, 4*(\spaceh+\massh))}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{n}$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{n}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{n}$};
          \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F$};

          % Displacements
          \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(2*\dispw, 0) coordinate(xn) -- ++(\dispw, 0) coordinate(drtop);
        \end{scope}
        % ====================

        % ====================
        % sample
        \begin{scope}[shift={(0, 5*(\spaceh+\massh))}]
          % Mass
          \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{s}$};

          % External Force
          \draw[->] (0, \spaceh+\massh) node[]{$\bullet$} -- ++(0, 0.5*\massh) node[right]{$F_s$};

          % Spring, Damper, and Actuator
          \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{s}$};
          \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{s}$};
        \end{scope}
        % ====================

        % ====================
        % RMC Control
        \draw[<->, dashed] ($(drbot)+(-0.1, 0)$) -- ($(drtop)+(-0.1, 0)$) node[right](dr){$d_r$};
        \node[block={2em}{2em}, below right=0.2 and 0.2 of dr] (rmc) {$K_{\text{RMC}}$};
        \draw[->] (dr.east) -| (rmc.north);
        \draw[->] (rmc.south) |- (F.east);
        % ====================
      \end{scope}
  \end{tikzpicture}
#+end_src

#+name: fig:uniaxial-model-nass-flexible-active-damping
#+caption: Comparison of used active damping techniques
#+RESULTS:
[[file:figs/uniaxial-model-nass-flexible-active-damping.png]]

* Undamped System
<<sec:undamped>>
** Introduction                                                     :ignore:
Let's start by study the undamped system.

** 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/sim_nano_station_uniaxial.slx'
#+end_src

** Init
We initialize all the stages with the default parameters.
The nano-hexapod is a piezoelectric hexapod and the sample has a mass of 50kg.

#+begin_src matlab :exports none
  initializeGround();
  initializeGranite();
  initializeTy();
  initializeRy();
  initializeRz();
  initializeMicroHexapod();
  initializeAxisc();
  initializeMirror();
  initializeNanoHexapod(struct('actuator', 'piezo'));
  initializeSample(struct('mass', 50));
#+end_src

All the controllers are set to 0 (Open Loop).
#+begin_src matlab :exports none
  K = tf(0);
  save('./mat/controllers.mat', 'K', '-append');
  K_iff = tf(0);
  save('./mat/controllers.mat', 'K_iff', '-append');
  K_rmc = tf(0);
  save('./mat/controllers.mat', 'K_rmc', '-append');
  K_dvf = tf(0);
  save('./mat/controllers.mat', 'K_dvf', '-append');
#+end_src

** Identification
We identify the dynamics of the system.
#+begin_src matlab
  %% Options for Linearized
  options = linearizeOptions;
  options.SampleTime = 0;

  %% Name of the Simulink File
  mdl = 'sim_nano_station_uniaxial';
#+end_src

The inputs and outputs are defined below and corresponds to the name of simulink blocks.
#+begin_src matlab
  %% Input/Output definition
  io(1)  = linio([mdl, '/Dw'],   1, 'input'); % Ground Motion
  io(2)  = linio([mdl, '/Fs'],   1, 'input'); % Force applied on the sample
  io(3)  = linio([mdl, '/Fnl'],  1, 'input'); % Force applied by the NASS
  io(4)  = linio([mdl, '/Fdty'], 1, 'input'); % Parasitic force Ty
  io(5)  = linio([mdl, '/Fdrz'], 1, 'input'); % Parasitic force Rz

  io(6)  = linio([mdl, '/Dsm'],  1, 'output'); % Displacement of the sample
  io(7)  = linio([mdl, '/Fnlm'], 1, 'output'); % Force sensor in NASS's legs
  io(8)  = linio([mdl, '/Dnlm'], 1, 'output'); % Displacement of NASS's legs
  io(9)  = linio([mdl, '/Dgm'],  1, 'output'); % Absolute displacement of the granite
  io(10) = linio([mdl, '/Vlm'],  1, 'output'); % Measured absolute velocity of the top NASS platform
#+end_src

Finally, we use the =linearize= Matlab function to extract a state space model from the simscape model.
#+begin_src matlab
  %% Run the linearization
  G = linearize(mdl, io, options);
  G.InputName  = {'Dw',   ... % Ground Motion [m]
                  'Fs',   ... % Force Applied on Sample [N]
                  'Fn',   ... % Force applied by NASS [N]
                  'Fty',  ... % Parasitic Force Ty [N]
                  'Frz'};     % Parasitic Force Rz [N]
  G.OutputName = {'D',    ... % Measured sample displacement x.r.t. granite [m]
                  'Fnm',  ... % Force Sensor in NASS [N]
                  'Dnm',  ... % Displacement Sensor in NASS [m]
                  'Dgm',  ... % Asbolute displacement of Granite [m]
                  'Vlm'}; ... % Absolute Velocity of NASS [m/s]
#+end_src

Finally, we save the identified system dynamics for further analysis.
#+begin_src matlab
  save('./uniaxial/mat/plants.mat', 'G');
#+end_src

** Sensitivity to Disturbances
We show several plots representing the sensitivity to disturbances:
- in figure [[fig:uniaxial-sensitivity-disturbances]] the transfer functions from ground motion $D_w$ to the sample position $D$ and the transfer function from direct force on the sample $F_s$ to the sample position $D$ are shown
- in figure [[fig:uniaxial-sensitivity-force-dist]], it is the effect of parasitic forces of the positioning stages ($F_{ty}$ and $F_{rz}$) on the position $D$ of the sample that are shown

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

  figure;

  subplot(2, 1, 1);
  title('$D_w$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D',   'Dw'), freqs, 'Hz'))), 'k-');
  % plot(freqs, abs(squeeze(freqresp(G('Dgm', 'Dw'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/m]'); xlabel('Frequency [Hz]');

  subplot(2, 1, 2);
  title('$F_s$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fs'), freqs, 'Hz'))), 'k-');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial-sensitivity-disturbances
#+CAPTION: Sensitivity to disturbances ([[./figs/uniaxial-sensitivity-disturbances.png][png]], [[./figs/uniaxial-sensitivity-disturbances.pdf][pdf]])
[[file:figs/uniaxial-sensitivity-disturbances.png]]


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

  figure;

  subplot(2, 1, 1);
  title('$F_{ty}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fty'), freqs, 'Hz'))), 'k-');
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');

  subplot(2, 1, 2);
  title('$F_{rz}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Frz'), freqs, 'Hz'))), 'k-');
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial-sensitivity-force-dist
#+CAPTION: Sensitivity to disturbances ([[./figs/uniaxial-sensitivity-force-dist.png][png]], [[./figs/uniaxial-sensitivity-force-dist.pdf][pdf]])
[[file:figs/uniaxial-sensitivity-force-dist.png]]

** Noise Budget
We first load the measured PSD of the disturbance.
#+begin_src matlab
  load('./disturbances/mat/dist_psd.mat', 'dist_f');
#+end_src

The effect of these disturbances on the distance $D$ is computed below.
#+begin_src matlab :exports none
  % Power Spectral Density of the relative Displacement [m^2/Hz]
  psd_gm_d = dist_f.psd_gm.*abs(squeeze(freqresp(G('D', 'Dw'),  dist_f.f, 'Hz'))).^2;
  psd_ty_d = dist_f.psd_ty.*abs(squeeze(freqresp(G('D', 'Fty'), dist_f.f, 'Hz'))).^2;
  psd_rz_d = dist_f.psd_rz.*abs(squeeze(freqresp(G('D', 'Frz'), dist_f.f, 'Hz'))).^2;
#+end_src

The PSD of the obtain distance $D$ due to each of the perturbation is shown in figure [[fig:uniaxial-psd-dist]] and the Cumulative Amplitude Spectrum is shown in figure [[fig:uniaxial-cas-dist]].


The Root Mean Square value of the obtained displacement $D$ is computed below and can be determined from the figure [[fig:uniaxial-cas-dist]].
#+begin_src matlab :results value replace :exports results
  cas_tot_d = sqrt(cumtrapz(dist_f.f, psd_rz_d+psd_ty_d+psd_gm_d)); cas_tot_d(end)
#+end_src

#+RESULTS:
: 3.3793e-06

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

  figure;
  hold on;
  plot(dist_f.f, psd_gm_d, 'DisplayName', '$D_w$');
  plot(dist_f.f, psd_ty_d, 'DisplayName', '$T_y$');
  plot(dist_f.f, psd_rz_d, 'DisplayName', '$R_z$');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('PSD of the effect of disturbances on $D$ $\left[\frac{m^2}{Hz}\right]$');  xlabel('Frequency [Hz]');
  legend('location', 'northeast')
  xlim([0.5, 500]);
#+end_src

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

#+NAME: fig:uniaxial-psd-dist
#+CAPTION: PSD of the effect of disturbances on $D$ ([[./figs/uniaxial-psd-dist.png][png]], [[./figs/uniaxial-psd-dist.pdf][pdf]])
[[file:figs/uniaxial-psd-dist.png]]


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

  figure;
  hold on;
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_gm_d)))), 'DisplayName', '$D_w$');
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_ty_d)))), 'DisplayName', '$T_y$');
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_rz_d)))), 'DisplayName', '$R_z$');
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_gm_d+psd_ty_d+psd_rz_d)))), 'k-', 'DisplayName', 'tot');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('CAS of the effect of disturbances on $D$ [m]');  xlabel('Frequency [Hz]');
  legend('location', 'northeast')
  xlim([0.5, 500]); ylim([1e-12, 1e-6]);
#+end_src

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

#+NAME: fig:uniaxial-cas-dist
#+CAPTION: CAS of the effect of disturbances on $D$ ([[./figs/uniaxial-cas-dist.png][png]], [[./figs/uniaxial-cas-dist.pdf][pdf]])
[[file:figs/uniaxial-cas-dist.png]]

** Plant
The transfer function from the force $F$ applied by the nano-hexapod to the position of the sample $D$ is shown in figure [[fig:uniaxial-plant]].
It corresponds to the plant to control.

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

  figure;

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

  ax2 = subplot(2, 1, 2);
  plot(freqs, 180/pi*angle(squeeze(freqresp(G('D', 'Fn'), 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/uniaxial-plant.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial-plant
#+CAPTION: Bode plot of the Plant ([[./figs/uniaxial-plant.png][png]], [[./figs/uniaxial-plant.pdf][pdf]])
[[file:figs/uniaxial-plant.png]]

* Integral Force Feedback
<<sec:iff>>
** Introduction                                                     :ignore:
#+begin_src latex :file uniaxial-model-nass-flexible-iff.pdf :post pdf2svg(file=*this*, ext="png") :exports results
  \begin{tikzpicture}
    % ====================
    % Parameters
    % ====================
    \def\massw{2.2}  % Width of the masses
    \def\massh{0.8}  % Height of the masses
    \def\spaceh{1.2} % Height of the springs/dampers
    \def\dispw{0.4}  % Width of the dashed line for the displacement
    \def\disph{0.3}  % Height of the arrow for the displacements
    \def\bracs{0.05} % Brace spacing vertically
    \def\brach{-12pt} % Brace shift horizontaly
    \def\fsensh{0.2} % Height of the force sensor
    \def\velsize{0.2} % Size of the velocity sensor
    % ====================


    % ====================
    % Ground
    % ====================
    \draw (-0.5*\massw, 0) -- (0.5*\massw, 0);
    \draw[dashed] (0.5*\massw, 0) -- ++(1, 0);
    \draw[->, dasehd] (0.5*\massw+0.8, 0) -- ++(0, 0.5) node[right]{$D_{w}$};
    % ====================


    % ====================
    % Marble
    \begin{scope}[shift={(0, 0)}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{m}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{m}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{m}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Marble};
    \end{scope}
    % ====================


    % ====================
    % Ty
    \begin{scope}[shift={(0, \spaceh+\massh)}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{t}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{t}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{t}$};
      \draw[actuator={0.45}{0.2}] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](ft){$F_{ty}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Ty};
    \end{scope}
    % ====================


    % ====================
    % Rz
    \begin{scope}[shift={(0, 2*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{z}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{z}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{z}$};
      \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F_{rz}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Rz};
    \end{scope}
    % ====================


    % ====================
    % Hexapod
    \begin{scope}[shift={(0, 3*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{h}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{h}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{h}$};

      % Displacements
      % \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(3*\dispw, 0) coordinate(drbot);

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Hexapod};
    \end{scope}
    % ====================


    % ====================
    % NASS
    \begin{scope}[shift={(0, 4*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{n}$};

      % Force Sensor
      \node[forcesensor={\massw}{\fsensh}] (fsensn) at (0, \spaceh-\fsensh){};
      \node[right] (fn) at (fsensn.east) {$F_n$};

      % % Velocity Sensor
      % \node[inertialsensor={\velsize}] (veln) at (0.5*\massw, \spaceh+\massh) {};
      % \node[right] at (veln.north east) {$v_n$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh-\fsensh) node[midway, left=0.1]{$k_{n}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh-\fsensh)          node[midway, left=0.2]{$c_{n}$};
      \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh-\fsensh) node[midway, right=0.1](F){$F$};

      % % Displacements
      % \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(2*\dispw, 0) coordinate(xn) -- ++(\dispw, 0) coordinate(drtop);

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{NASS};
    \end{scope}
    % ====================

    % ====================
    % sample
    \begin{scope}[shift={(0, 5*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{s}$};

      % External Force
      \draw[->] (0, \spaceh+\massh) node[]{$\bullet$} -- ++(0, 0.5*\massh) node[right]{$F_s$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{s}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{s}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Sample};
    \end{scope}
    % ====================

      % ====================
      % IFF Control
      \node[block={2em}{2em}, right=0.3 of fn] (iff) {$K_{\text{IFF}}$};
      \draw[->] (fn.east) -- (iff.west);
      \draw[->] (iff.south) |- (F.east);
      % ====================
  \end{tikzpicture}
#+end_src

#+name: fig:iff_schematic
#+caption: Uniaxial IFF Control Schematic
#+RESULTS:
[[file:figs/uniaxial-model-nass-flexible-iff.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/sim_nano_station_uniaxial.slx'
#+end_src

** Control Design
#+begin_src matlab
  load('./uniaxial/mat/plants.mat', 'G');
#+end_src

Let's look at the transfer function from actuator forces in the nano-hexapod to the force sensor in the nano-hexapod legs for all 6 pairs of actuator/sensor.

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

  figure;

  ax1 = subplot(2, 1, 1);
  plot(freqs, abs(squeeze(freqresp(G('Fnm', 'Fn'), 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('Fnm', 'Fn'), 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/uniaxial_iff_plant.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_iff_plant
#+CAPTION: Transfer function from forces applied in the legs to force sensor ([[./figs/uniaxial_iff_plant.png][png]], [[./figs/uniaxial_iff_plant.pdf][pdf]])
[[file:figs/uniaxial_iff_plant.png]]

The controller for each pair of actuator/sensor is:
#+begin_src matlab
  K_iff = -1000/s;
#+end_src

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

  figure;

  ax1 = subplot(2, 1, 1);
  plot(freqs, abs(squeeze(freqresp(K_iff*G('Fnm', 'Fn'), 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('Fnm', 'Fn'), 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/uniaxial_iff_open_loop.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_iff_open_loop
#+CAPTION: Loop Gain for the Integral Force Feedback ([[./figs/uniaxial_iff_open_loop.png][png]], [[./figs/uniaxial_iff_open_loop.pdf][pdf]])
[[file:figs/uniaxial_iff_open_loop.png]]

** Identification
Let's initialize the system prior to identification.
#+begin_src matlab
  initializeGround();
  initializeGranite();
  initializeTy();
  initializeRy();
  initializeRz();
  initializeMicroHexapod();
  initializeAxisc();
  initializeMirror();
  initializeNanoHexapod(struct('actuator', 'piezo'));
  initializeSample(struct('mass', 50));
#+end_src

All the controllers are set to 0.
#+begin_src matlab
  K = tf(0);
  save('./mat/controllers.mat', 'K', '-append');
  K_iff = -K_iff;
  save('./mat/controllers.mat', 'K_iff', '-append');
  K_rmc = tf(0);
  save('./mat/controllers.mat', 'K_rmc', '-append');
  K_dvf = tf(0);
  save('./mat/controllers.mat', 'K_dvf', '-append');
#+end_src

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

  %% Name of the Simulink File
  mdl = 'sim_nano_station_uniaxial';
#+end_src

#+begin_src matlab
  %% Input/Output definition
  io(1)  = linio([mdl, '/Dw'],    1, 'input');  % Ground Motion
  io(2)  = linio([mdl, '/Fs'],    1, 'input');  % Force applied on the sample
  io(3)  = linio([mdl, '/Fnl'],   1, 'input');  % Force applied by the NASS
  io(4)  = linio([mdl, '/Fdty'],  1, 'input');  % Parasitic force Ty
  io(5)  = linio([mdl, '/Fdrz'],  1, 'input');  % Parasitic force Rz

  io(6)  = linio([mdl, '/Dsm'],  1, 'output'); % Displacement of the sample
  io(7)  = linio([mdl, '/Fnlm'], 1, 'output'); % Force sensor in NASS's legs
  io(8)  = linio([mdl, '/Dnlm'], 1, 'output'); % Displacement of NASS's legs
  io(9)  = linio([mdl, '/Dgm'],  1, 'output'); % Absolute displacement of the granite
  io(10) = linio([mdl, '/Vlm'],  1, 'output'); % Measured absolute velocity of the top NASS platform
#+end_src

#+begin_src matlab
  %% Run the linearization
  G_iff = linearize(mdl, io, options);
  G_iff.InputName  = {'Dw',   ... % Ground Motion [m]
                      'Fs',   ... % Force Applied on Sample [N]
                      'Fn',   ... % Force applied by NASS [N]
                      'Fty',  ... % Parasitic Force Ty [N]
                      'Frz'};     % Parasitic Force Rz [N]
  G_iff.OutputName = {'D',    ... % Measured sample displacement x.r.t. granite [m]
                      'Fnm',  ... % Force Sensor in NASS [N]
                      'Dnm',  ... % Displacement Sensor in NASS [m]
                      'Dgm',  ... % Asbolute displacement of Granite [m]
                      'Vlm'}; ... % Absolute Velocity of NASS [m/s]
#+end_src

#+begin_src matlab
  save('./uniaxial/mat/plants.mat', 'G_iff', '-append');
#+end_src

** Sensitivity to Disturbance
#+begin_src matlab :exports none
  freqs = logspace(0, 3, 1000);

  figure;

  subplot(2, 1, 1);
  title('$D_w$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D',   'Dw'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_iff('D',   'Dw'), freqs, 'Hz'))), 'k--', 'DisplayName', 'IFF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/m]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');

  subplot(2, 1, 2);
  title('$F_s$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fs'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_iff('D', 'Fs'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_dist_iff
#+CAPTION: Sensitivity to disturbance once the IFF controller is applied to the system ([[./figs/uniaxial_sensitivity_dist_iff.png][png]], [[./figs/uniaxial_sensitivity_dist_iff.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_dist_iff.png]]

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

  figure;

  subplot(2, 1, 1);
  title('$F_{ty}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fty'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_iff('D', 'Fty'), freqs, 'Hz'))), 'k--', 'DisplayName', 'IFF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');

  subplot(2, 1, 2);
  title('$F_{rz}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Frz'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_iff('D', 'Frz'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_dist_stages_iff
#+CAPTION: Sensitivity to force disturbances in various stages when IFF is applied ([[./figs/uniaxial_sensitivity_dist_stages_iff.png][png]], [[./figs/uniaxial_sensitivity_dist_stages_iff.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_dist_stages_iff.png]]

** Damped Plant
#+begin_src matlab :exports none
  freqs = logspace(0, 3, 1000);

  figure;

  ax1 = subplot(2, 1, 1);
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fn'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_iff('D', 'Fn'), freqs, 'Hz'))), 'k--', 'DisplayName', 'IFF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); set(gca, 'XTickLabel',[]);
  legend('location', 'northeast');

  ax2 = subplot(2, 1, 2);
  hold on;
  plot(freqs, 180/pi*angle(squeeze(freqresp(G('D', 'Fn'), freqs, 'Hz'))), 'k-');
  plot(freqs, 180/pi*angle(squeeze(freqresp(G_iff('D', 'Fn'), freqs, 'Hz'))), 'k--');
  hold off;
  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/uniaxial_plant_iff_damped.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_plant_iff_damped
#+CAPTION: Damped Plant after IFF is applied ([[./figs/uniaxial_plant_iff_damped.png][png]], [[./figs/uniaxial_plant_iff_damped.pdf][pdf]])
[[file:figs/uniaxial_plant_iff_damped.png]]

** Conclusion
#+begin_important
Integral Force Feedback:
#+end_important

* Relative Motion Control
<<sec:rmc>>
** Introduction                                                     :ignore:
In the Relative Motion Control (RMC), a derivative feedback is applied between the measured actuator displacement to the actuator force input.

#+begin_src latex :file uniaxial-model-nass-flexible-rmc.pdf :post pdf2svg(file=*this*, ext="png") :exports results
  \begin{tikzpicture}
    % ====================
    % Parameters
    % ====================
    \def\massw{2.2}  % Width of the masses
    \def\massh{0.8}  % Height of the masses
    \def\spaceh{1.2} % Height of the springs/dampers
    \def\dispw{0.4}  % Width of the dashed line for the displacement
    \def\disph{0.3}  % Height of the arrow for the displacements
    \def\bracs{0.05} % Brace spacing vertically
    \def\brach{-12pt} % Brace shift horizontaly
    \def\fsensh{0.2} % Height of the force sensor
    \def\velsize{0.2} % Size of the velocity sensor
    % ====================


    % ====================
    % Ground
    % ====================
    \draw (-0.5*\massw, 0) -- (0.5*\massw, 0);
    \draw[dashed] (0.5*\massw, 0) -- ++(1, 0);
    \draw[->, dasehd] (0.5*\massw+0.8, 0) -- ++(0, 0.5) node[right]{$D_{w}$};
    % ====================


    % ====================
    % Marble
    \begin{scope}[shift={(0, 0)}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{m}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{m}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{m}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Marble};
    \end{scope}
    % ====================


    % ====================
    % Ty
    \begin{scope}[shift={(0, \spaceh+\massh)}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{t}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{t}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{t}$};
      \draw[actuator={0.45}{0.2}] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](ft){$F_{ty}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Ty};
    \end{scope}
    % ====================


    % ====================
    % Rz
    \begin{scope}[shift={(0, 2*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{z}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{z}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{z}$};
      \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F_{rz}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Rz};
    \end{scope}
    % ====================


    % ====================
    % Hexapod
    \begin{scope}[shift={(0, 3*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{h}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{h}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{h}$};

      % Displacements
      \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(3*\dispw, 0) coordinate(drbot);

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Hexapod};
    \end{scope}
    % ====================


    % ====================
    % NASS
    \begin{scope}[shift={(0, 4*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{n}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{n}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{n}$};
      \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F$};

      % Displacements
      \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(2*\dispw, 0) coordinate(xn) -- ++(\dispw, 0) coordinate(drtop);

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{NASS};
    \end{scope}
    % ====================

    % ====================
    % sample
    \begin{scope}[shift={(0, 5*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{s}$};

      % External Force
      \draw[->] (0, \spaceh+\massh) node[]{$\bullet$} -- ++(0, 0.5*\massh) node[right]{$F_s$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{s}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{s}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Sample};
    \end{scope}
    % ====================

    % ====================
    % RMC Control
    \draw[<->, dashed] ($(drbot)+(-0.1, 0)$) -- ($(drtop)+(-0.1, 0)$) node[right](dr){$d_r$};
    \node[block={2em}{2em}, below right=0.2 and 0.2 of dr] (rmc) {$K_{\text{RMC}}$};
    \draw[->] (dr.east) -| (rmc.north);
    \draw[->] (rmc.south) |- (F.east);
    % ====================
  \end{tikzpicture}
#+end_src

#+name: fig:rmc_schematic
#+caption: Uniaxial RMC Control Schematic
#+RESULTS:
[[file:figs/uniaxial-model-nass-flexible-rmc.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/sim_nano_station_uniaxial.slx'
#+end_src

** Control Design
#+begin_src matlab
  load('./uniaxial/mat/plants.mat', 'G');
#+end_src

Let's look at the transfer function from actuator forces in the nano-hexapod to the measured displacement of the actuator for all 6 pairs of actuator/sensor.

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

  figure;

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

  ax2 = subplot(2, 1, 2);
  plot(freqs, 180/pi*angle(squeeze(freqresp(G('Dnm', 'Fn'), 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/uniaxial_rmc_plant.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_rmc_plant
#+CAPTION: Transfer function from forces applied in the legs to leg displacement sensor ([[./figs/uniaxial_rmc_plant.png][png]], [[./figs/uniaxial_rmc_plant.pdf][pdf]])
[[file:figs/uniaxial_rmc_plant.png]]

The Relative Motion Controller is defined below.
A Low pass Filter is added to make the controller transfer function proper.
#+begin_src matlab
  K_rmc = s*50000/(1 + s/2/pi/10000);
#+end_src

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

  figure;

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

  ax2 = subplot(2, 1, 2);
  plot(freqs, 180/pi*angle(squeeze(freqresp(K_rmc*G('Dnm', 'Fn'), 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/uniaxial_rmc_open_loop.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_rmc_open_loop
#+CAPTION: Loop Gain for the Integral Force Feedback ([[./figs/uniaxial_rmc_open_loop.png][png]], [[./figs/uniaxial_rmc_open_loop.pdf][pdf]])
[[file:figs/uniaxial_rmc_open_loop.png]]

** Identification
Let's initialize the system prior to identification.
#+begin_src matlab
  initializeGround();
  initializeGranite();
  initializeTy();
  initializeRy();
  initializeRz();
  initializeMicroHexapod();
  initializeAxisc();
  initializeMirror();
  initializeNanoHexapod(struct('actuator', 'piezo'));
  initializeSample(struct('mass', 50));
#+end_src

And initialize the controllers.
#+begin_src matlab
  K = tf(0);
  save('./mat/controllers.mat', 'K', '-append');
  K_iff = tf(0);
  save('./mat/controllers.mat', 'K_iff', '-append');
  K_rmc = -K_rmc;
  save('./mat/controllers.mat', 'K_rmc', '-append');
  K_dvf = tf(0);
  save('./mat/controllers.mat', 'K_dvf', '-append');
#+end_src

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

  %% Name of the Simulink File
  mdl = 'sim_nano_station_uniaxial';
#+end_src

#+begin_src matlab
  %% Input/Output definition
  io(1)  = linio([mdl, '/Dw'],    1, 'input');  % Ground Motion
  io(2)  = linio([mdl, '/Fs'],    1, 'input');  % Force applied on the sample
  io(3)  = linio([mdl, '/Fnl'],   1, 'input');  % Force applied by the NASS
  io(4)  = linio([mdl, '/Fdty'],  1, 'input');  % Parasitic force Ty
  io(5)  = linio([mdl, '/Fdrz'],  1, 'input');  % Parasitic force Rz

  io(6)  = linio([mdl, '/Dsm'],  1, 'output'); % Displacement of the sample
  io(7)  = linio([mdl, '/Fnlm'], 1, 'output'); % Force sensor in NASS's legs
  io(8)  = linio([mdl, '/Dnlm'], 1, 'output'); % Displacement of NASS's legs
  io(9)  = linio([mdl, '/Dgm'],  1, 'output'); % Absolute displacement of the granite
  io(10) = linio([mdl, '/Vlm'],  1, 'output'); % Measured absolute velocity of the top NASS platform
#+end_src

#+begin_src matlab
  %% Run the linearization
  G_rmc = linearize(mdl, io, options);
  G_rmc.InputName  = {'Dw',   ... % Ground Motion [m]
                      'Fs',   ... % Force Applied on Sample [N]
                      'Fn',   ... % Force applied by NASS [N]
                      'Fty',  ... % Parasitic Force Ty [N]
                      'Frz'};     % Parasitic Force Rz [N]
  G_rmc.OutputName = {'D',    ... % Measured sample displacement x.r.t. granite [m]
                      'Fnm',  ... % Force Sensor in NASS [N]
                      'Dnm',  ... % Displacement Sensor in NASS [m]
                      'Dgm',  ... % Asbolute displacement of Granite [m]
                      'Vlm'}; ... % Absolute Velocity of NASS [m/s]
#+end_src

#+begin_src matlab
  save('./uniaxial/mat/plants.mat', 'G_rmc', '-append');
#+end_src


** Sensitivity to Disturbance
#+begin_src matlab :exports none
  freqs = logspace(0, 3, 1000);

  figure;

  subplot(2, 1, 1);
  title('$D_w$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D',   'Dw'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_rmc('D',   'Dw'), freqs, 'Hz'))), 'k--', 'DisplayName', 'RMC');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/m]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');

  subplot(2, 1, 2);
  title('$F_s$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fs'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_rmc('D', 'Fs'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_dist_rmc
#+CAPTION: Sensitivity to disturbance once the RMC controller is applied to the system ([[./figs/uniaxial_sensitivity_dist_rmc.png][png]], [[./figs/uniaxial_sensitivity_dist_rmc.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_dist_rmc.png]]

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

  figure;

  subplot(2, 1, 1);
  title('$F_{ty}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fty'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_rmc('D', 'Fty'), freqs, 'Hz'))), 'k--', 'DisplayName', 'RMC');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');

  subplot(2, 1, 2);
  title('$F_{rz}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Frz'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_rmc('D', 'Frz'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_dist_stages_rmc
#+CAPTION: Sensitivity to force disturbances in various stages when RMC is applied ([[./figs/uniaxial_sensitivity_dist_stages_rmc.png][png]], [[./figs/uniaxial_sensitivity_dist_stages_rmc.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_dist_stages_rmc.png]]

** Damped Plant
#+begin_src matlab :exports none
  freqs = logspace(0, 3, 1000);

  figure;

  ax1 = subplot(2, 1, 1);
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fn'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_rmc('D', 'Fn'), freqs, 'Hz'))), 'k--', 'DisplayName', 'RMC');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); set(gca, 'XTickLabel',[]);
  legend('location', 'northeast');

  ax2 = subplot(2, 1, 2);
  hold on;
  plot(freqs, 180/pi*angle(squeeze(freqresp(G('D', 'Fn'), freqs, 'Hz'))), 'k-');
  plot(freqs, 180/pi*angle(squeeze(freqresp(G_rmc('D', 'Fn'), freqs, 'Hz'))), 'k--');
  hold off;
  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/uniaxial_plant_rmc_damped.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_plant_rmc_damped
#+CAPTION: Damped Plant after RMC is applied ([[./figs/uniaxial_plant_rmc_damped.png][png]], [[./figs/uniaxial_plant_rmc_damped.pdf][pdf]])
[[file:figs/uniaxial_plant_rmc_damped.png]]

** Conclusion
#+begin_important
Relative Motion Control:
#+end_important

* Direct Velocity Feedback
<<sec:dvf>>
** Introduction                                                     :ignore:
In the Relative Motion Control (RMC), a feedback is applied between the measured velocity of the platform to the actuator force input.

#+begin_src latex :file uniaxial-model-nass-flexible-dvf.pdf :post pdf2svg(file=*this*, ext="png") :exports results
  \begin{tikzpicture}
    % ====================
    % Parameters
    % ====================
    \def\massw{2.2}  % Width of the masses
    \def\massh{0.8}  % Height of the masses
    \def\spaceh{1.2} % Height of the springs/dampers
    \def\dispw{0.4}  % Width of the dashed line for the displacement
    \def\disph{0.3}  % Height of the arrow for the displacements
    \def\bracs{0.05} % Brace spacing vertically
    \def\brach{-12pt} % Brace shift horizontaly
    \def\fsensh{0.2} % Height of the force sensor
    \def\velsize{0.2} % Size of the velocity sensor
    % ====================


    % ====================
    % Ground
    % ====================
    \draw (-0.5*\massw, 0) -- (0.5*\massw, 0);
    \draw[dashed] (0.5*\massw, 0) -- ++(1, 0);
    \draw[->, dasehd] (0.5*\massw+0.8, 0) -- ++(0, 0.5) node[right]{$D_{w}$};
    % ====================


    % ====================
    % Marble
    \begin{scope}[shift={(0, 0)}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{m}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{m}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{m}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Marble};
    \end{scope}
    % ====================


    % ====================
    % Ty
    \begin{scope}[shift={(0, \spaceh+\massh)}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{t}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{t}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{t}$};
      \draw[actuator={0.45}{0.2}] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](ft){$F_{ty}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Ty};
    \end{scope}
    % ====================


    % ====================
    % Rz
    \begin{scope}[shift={(0, 2*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{z}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{z}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{z}$};
      \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F_{rz}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Rz};
    \end{scope}
    % ====================


    % ====================
    % Hexapod
    \begin{scope}[shift={(0, 3*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{h}$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{h}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{h}$};

      % Displacements
      % \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(3*\dispw, 0) coordinate(drbot);

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Hexapod};
    \end{scope}
    % ====================


    % ====================
    % NASS
    \begin{scope}[shift={(0, 4*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{n}$};

      % % Force Sensor
      % \node[forcesensor={\massw}{\fsensh}] (fsensn) at (0, \spaceh-\fsensh){};
      % \node[right] (fn) at (fsensn.east) {$F_n$};

      % Velocity Sensor
      \node[inertialsensor={\velsize}] (veln) at (0.5*\massw, \spaceh+\massh) {};
      \node[above right] at (veln.east) {$v_n$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{n}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{n}$};
      \draw[actuator] ( 0.4*\massw, 0) -- (	0.4*\massw, \spaceh) node[midway, right=0.1](F){$F$};

      % % Displacements
      % \draw[dashed] (0.5*\massw, \spaceh+\massh) -- ++(2*\dispw, 0) coordinate(xn) -- ++(\dispw, 0) coordinate(drtop);

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{NASS};
    \end{scope}
    % ====================

    % ====================
    % sample
    \begin{scope}[shift={(0, 5*(\spaceh+\massh))}]
      % Mass
      \draw[fill=white] (-0.5*\massw, \spaceh) rectangle (0.5*\massw, \spaceh+\massh) node[pos=0.5]{$m_{s}$};

      % External Force
      \draw[->] (0, \spaceh+\massh) node[]{$\bullet$} -- ++(0, 0.5*\massh) node[right]{$F_s$};

      % Spring, Damper, and Actuator
      \draw[spring] (-0.4*\massw, 0) -- (-0.4*\massw, \spaceh) node[midway, left=0.1]{$k_{s}$};
      \draw[damper] (0, 0)           -- ( 0, \spaceh)          node[midway, left=0.2]{$c_{s}$};

      % Legend
      \draw[decorate, decoration={brace, amplitude=8pt}, xshift=\brach] %
      (-0.5*\massw, \bracs) -- (-0.5*\massw, \spaceh+\massh-\bracs) node[midway,rotate=90,anchor=south,yshift=10pt]{Sample};
    \end{scope}
    % ====================

      % ====================
      % DVF Control
      \node[block={2em}{2em}, below right=0.4 and 0.4 of veln] (ppf) {$K_{\text{DVF}}$};
      \draw[->] (veln.east) -| (ppf.north);
      \draw[->] (ppf.south) |- (F.east);
      % ====================
  \end{tikzpicture}
#+end_src

#+name: fig:dvf_schematic
#+caption: Uniaxial DVF Control Schematic
#+RESULTS:
[[file:figs/uniaxial-model-nass-flexible-dvf.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/sim_nano_station_uniaxial.slx'
#+end_src

** Control Design
#+begin_src matlab
  load('./uniaxial/mat/plants.mat', 'G');
#+end_src

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

  figure;

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

  ax2 = subplot(2, 1, 2);
  plot(freqs, 180/pi*angle(squeeze(freqresp(G('Vlm', 'Fn'), 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/uniaxial_dvf_plant.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_dvf_plant
#+CAPTION: Transfer function from forces applied in the legs to leg velocity sensor ([[./figs/uniaxial_dvf_plant.png][png]], [[./figs/uniaxial_dvf_plant.pdf][pdf]])
[[file:figs/uniaxial_dvf_plant.png]]

#+begin_src matlab
  K_dvf = tf(5e4);
#+end_src

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

  figure;

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

  ax2 = subplot(2, 1, 2);
  plot(freqs, 180/pi*angle(squeeze(freqresp(K_dvf*G('Vlm', 'Fn'), 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/uniaxial_dvf_loop_gain.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_dvf_loop_gain
#+CAPTION: Transfer function from forces applied in the legs to leg velocity sensor ([[./figs/uniaxial_dvf_loop_gain.png][png]], [[./figs/uniaxial_dvf_loop_gain.pdf][pdf]])
[[file:figs/uniaxial_dvf_loop_gain.png]]

** Identification
Let's initialize the system prior to identification.
#+begin_src matlab
  initializeGround();
  initializeGranite();
  initializeTy();
  initializeRy();
  initializeRz();
  initializeMicroHexapod();
  initializeAxisc();
  initializeMirror();
  initializeNanoHexapod(struct('actuator', 'piezo'));
  initializeSample(struct('mass', 50));
#+end_src

And initialize the controllers.
#+begin_src matlab
  K = tf(0);
  save('./mat/controllers.mat', 'K', '-append');
  K_iff = tf(0);
  save('./mat/controllers.mat', 'K_iff', '-append');
  K_rmc = tf(0);
  save('./mat/controllers.mat', 'K_rmc', '-append');
  K_dvf = -K_dvf;
  save('./mat/controllers.mat', 'K_dvf', '-append');
#+end_src

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

  %% Name of the Simulink File
  mdl = 'sim_nano_station_uniaxial';
#+end_src

#+begin_src matlab
  %% Input/Output definition
  io(1)  = linio([mdl, '/Dw'],    1, 'input');  % Ground Motion
  io(2)  = linio([mdl, '/Fs'],    1, 'input');  % Force applied on the sample
  io(3)  = linio([mdl, '/Fnl'],   1, 'input');  % Force applied by the NASS
  io(4)  = linio([mdl, '/Fdty'],  1, 'input');  % Parasitic force Ty
  io(5)  = linio([mdl, '/Fdrz'],  1, 'input');  % Parasitic force Rz

  io(6)  = linio([mdl, '/Dsm'],  1, 'output'); % Displacement of the sample
  io(7)  = linio([mdl, '/Fnlm'], 1, 'output'); % Force sensor in NASS's legs
  io(8)  = linio([mdl, '/Dnlm'], 1, 'output'); % Displacement of NASS's legs
  io(9)  = linio([mdl, '/Dgm'],  1, 'output'); % Absolute displacement of the granite
  io(10) = linio([mdl, '/Vlm'],  1, 'output'); % Measured absolute velocity of the top NASS platform
#+end_src

#+begin_src matlab
  %% Run the linearization
  G_dvf = linearize(mdl, io, options);
  G_dvf.InputName  = {'Dw',   ... % Ground Motion [m]
                      'Fs',   ... % Force Applied on Sample [N]
                      'Fn',   ... % Force applied by NASS [N]
                      'Fty',  ... % Parasitic Force Ty [N]
                      'Frz'};     % Parasitic Force Rz [N]
  G_dvf.OutputName = {'D',    ... % Measured sample displacement x.r.t. granite [m]
                      'Fnm',  ... % Force Sensor in NASS [N]
                      'Dnm',  ... % Displacement Sensor in NASS [m]
                      'Dgm',  ... % Asbolute displacement of Granite [m]
                      'Vlm'}; ... % Absolute Velocity of NASS [m/s]
#+end_src

#+begin_src matlab
  save('./uniaxial/mat/plants.mat', 'G_dvf', '-append');
#+end_src

** Sensitivity to Disturbance
#+begin_src matlab :exports none
  freqs = logspace(0, 3, 1000);

  figure;

  subplot(2, 1, 1);
  title('$D_w$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D',   'Dw'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_dvf('D',   'Dw'), freqs, 'Hz'))), 'k--', 'DisplayName', 'DVF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/m]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');

  subplot(2, 1, 2);
  title('$F_s$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fs'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_dvf('D', 'Fs'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_dist_dvf
#+CAPTION: Sensitivity to disturbance once the DVF controller is applied to the system ([[./figs/uniaxial_sensitivity_dist_dvf.png][png]], [[./figs/uniaxial_sensitivity_dist_dvf.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_dist_dvf.png]]

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

  figure;

  subplot(2, 1, 1);
  title('$F_{ty}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fty'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_dvf('D', 'Fty'), freqs, 'Hz'))), 'k--', 'DisplayName', 'DVF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');

  subplot(2, 1, 2);
  title('$F_{rz}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Frz'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_dvf('D', 'Frz'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_dist_stages_dvf
#+CAPTION: Sensitivity to force disturbances in various stages when DVF is applied ([[./figs/uniaxial_sensitivity_dist_stages_dvf.png][png]], [[./figs/uniaxial_sensitivity_dist_stages_dvf.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_dist_stages_dvf.png]]

** Damped Plant
#+begin_src matlab :exports none
  freqs = logspace(0, 3, 1000);

  figure;

  ax1 = subplot(2, 1, 1);
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fn'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_dvf('D', 'Fn'), freqs, 'Hz'))), 'k--', 'DisplayName', 'DVF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); set(gca, 'XTickLabel',[]);
  legend('location', 'northeast');

  ax2 = subplot(2, 1, 2);
  hold on;
  plot(freqs, 180/pi*angle(squeeze(freqresp(G('D', 'Fn'), freqs, 'Hz'))), 'k-');
  plot(freqs, 180/pi*angle(squeeze(freqresp(G_dvf('D', 'Fn'), freqs, 'Hz'))), 'k--');
  hold off;
  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/uniaxial_plant_dvf_damped.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_plant_dvf_damped
#+CAPTION: Damped Plant after DVF is applied ([[./figs/uniaxial_plant_dvf_damped.png][png]], [[./figs/uniaxial_plant_dvf_damped.pdf][pdf]])
[[file:figs/uniaxial_plant_dvf_damped.png]]

** Conclusion
#+begin_important
Direct Velocity Feedback:
#+end_important
* With Cedrat Piezo-electric Actuators
<<sec:cedrat_actuator>>
** Introduction                                                     :ignore:
The model used for the Cedrat actuator is shown in figure [[fig:cedrat_schematic]].

#+begin_src latex :file cedrat-uniaxial-actuator.pdf :post pdf2svg(file=*this*, ext="png") :exports results
  \begin{tikzpicture}
    % Spring, Damper, and Actuator
    \draw[] (0, -0.2) -- (0, 0);
    \draw[] (-1, 0) -- (1, 0);

    \draw[spring] (-1, 0) -- (-1, 2)   node[midway, left=0.1]{$k_{a}$};
    \draw[damper] (0, 0)  -- ( 0, 2)   node[midway, left=0.2]{$c_{a}$};
    \draw[actuator] (1, 0)  -- ( 1, 2) node[midway, left=0.2]{$F$};

    \draw[] (-1, 2) -- (1, 2);
    \draw[] (0, 2) -- (0, 2.2);
    \node[forcesensor={0.4}{0.4}] (fsensn) at (0, 2.2){};
    \draw[] (0, 2.6) -- (0, 2.8);


    \draw[spring] (2, -0.2)  -- (2, 2.8) node[midway, left=0.2]{$k$};

    \draw[] (0, -0.2) -- (2, -0.2);
    \draw[] (0,  2.8) -- (2, 2.8);

    \draw[] (1, 2.8) -- (1, 3);
    \draw[] (1, -0.2) -- (1, -0.4);
  \end{tikzpicture}
#+end_src

#+name: fig:cedrat_schematic
#+caption: Schematic of the model used for the Cedrat Actuator
#+RESULTS:
[[file:figs/cedrat-uniaxial-actuator.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/sim_nano_station_uniaxial_cedrat.slx'
#+end_src

** Identification
Let's initialize the system prior to identification.
#+begin_src matlab
  initializeGround();
  initializeGranite();
  initializeTy();
  initializeRy();
  initializeRz();
  initializeMicroHexapod();
  initializeAxisc();
  initializeMirror();
  initializeNanoHexapod(struct('actuator', 'piezo'));
  initializeCedratPiezo();
  initializeSample(struct('mass', 50));
#+end_src

And initialize the controllers.
#+begin_src matlab
  K = tf(0);
  save('./mat/controllers.mat', 'K', '-append');
  K_iff = tf(0);
  save('./mat/controllers.mat', 'K_iff', '-append');
  K_rmc = tf(0);
  save('./mat/controllers.mat', 'K_rmc', '-append');
  K_dvf = tf(0);
  save('./mat/controllers.mat', 'K_dvf', '-append');
#+end_src

We identify the dynamics of the system.
#+begin_src matlab
  %% Options for Linearized
  options = linearizeOptions;
  options.SampleTime = 0;

  %% Name of the Simulink File
  mdl = 'sim_nano_station_uniaxial_cedrat_bis';
#+end_src

The inputs and outputs are defined below and corresponds to the name of simulink blocks.
#+begin_src matlab
  %% Input/Output definition
  io(1)  = linio([mdl, '/Dw'],   1, 'input'); % Ground Motion
  io(2)  = linio([mdl, '/Fs'],   1, 'input'); % Force applied on the sample
  io(3)  = linio([mdl, '/Fnl'],  1, 'input'); % Force applied by the NASS
  io(4)  = linio([mdl, '/Fdty'], 1, 'input'); % Parasitic force Ty
  io(5)  = linio([mdl, '/Fdrz'], 1, 'input'); % Parasitic force Rz

  io(6)  = linio([mdl, '/Dsm'],  1, 'output'); % Displacement of the sample
  io(7)  = linio([mdl, '/Fnlm'], 1, 'output'); % Force sensor in NASS's legs
  io(8)  = linio([mdl, '/Dnlm'], 1, 'output'); % Displacement of NASS's legs
  io(9)  = linio([mdl, '/Dgm'],  1, 'output'); % Absolute displacement of the granite
  io(10) = linio([mdl, '/Vlm'],  1, 'output'); % Measured absolute velocity of the top NASS platform
#+end_src

Finally, we use the =linearize= Matlab function to extract a state space model from the simscape model.
#+begin_src matlab
  %% Run the linearization
  G = linearize(mdl, io, options);
  G.InputName  = {'Dw',   ... % Ground Motion [m]
                  'Fs',   ... % Force Applied on Sample [N]
                  'Fn',   ... % Force applied by NASS [N]
                  'Fty',  ... % Parasitic Force Ty [N]
                  'Frz'};     % Parasitic Force Rz [N]
  G.OutputName = {'D',    ... % Measured sample displacement x.r.t. granite [m]
                  'Fnm',  ... % Force Sensor in NASS [N]
                  'Dnm',  ... % Displacement Sensor in NASS [m]
                  'Dgm',  ... % Asbolute displacement of Granite [m]
                  'Vlm'}; ... % Absolute Velocity of NASS [m/s]
#+end_src

** Control Design
Let's look at the transfer function from actuator forces in the nano-hexapod to the force sensor in the nano-hexapod legs for all 6 pairs of actuator/sensor.

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

  figure;

  ax1 = subplot(2, 1, 1);
  plot(freqs, abs(squeeze(freqresp(G('Fnm', 'Fn'), 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('Fnm', 'Fn'), 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/uniaxial_cedrat_plant.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_cedrat_plant
#+CAPTION: Transfer function from forces applied in the legs to force sensor ([[./figs/uniaxial_cedrat_plant.png][png]], [[./figs/uniaxial_cedrat_plant.pdf][pdf]])
[[file:figs/uniaxial_cedrat_plant.png]]

The controller for each pair of actuator/sensor is:
#+begin_src matlab
  K_cedrat = -5000/s;
#+end_src

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

  figure;

  ax1 = subplot(2, 1, 1);
  plot(freqs, abs(squeeze(freqresp(K_cedrat*G('Fnm', 'Fn'), 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_cedrat*G('Fnm', 'Fn'), 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/uniaxial_cedrat_open_loop.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_cedrat_open_loop
#+CAPTION: Loop Gain for the Integral Force Feedback ([[./figs/uniaxial_cedrat_open_loop.png][png]], [[./figs/uniaxial_cedrat_open_loop.pdf][pdf]])
[[file:figs/uniaxial_cedrat_open_loop.png]]

** Identification
Let's initialize the system prior to identification.
#+begin_src matlab
  initializeGround();
  initializeGranite();
  initializeTy();
  initializeRy();
  initializeRz();
  initializeMicroHexapod();
  initializeAxisc();
  initializeMirror();
  initializeNanoHexapod(struct('actuator', 'piezo'));
  initializeCedratPiezo();
  initializeSample(struct('mass', 50));
#+end_src

All the controllers are set to 0.
#+begin_src matlab
  K = tf(0);
  save('./mat/controllers.mat', 'K', '-append');
  K_iff = -K_cedrat;
  save('./mat/controllers.mat', 'K_iff', '-append');
  K_rmc = tf(0);
  save('./mat/controllers.mat', 'K_rmc', '-append');
  K_dvf = tf(0);
  save('./mat/controllers.mat', 'K_dvf', '-append');
#+end_src

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

  %% Name of the Simulink File
  mdl = 'sim_nano_station_uniaxial_cedrat_bis';
#+end_src

#+begin_src matlab
  %% Input/Output definition
  io(1)  = linio([mdl, '/Dw'],    1, 'input');  % Ground Motion
  io(2)  = linio([mdl, '/Fs'],    1, 'input');  % Force applied on the sample
  io(3)  = linio([mdl, '/Fnl'],   1, 'input');  % Force applied by the NASS
  io(4)  = linio([mdl, '/Fdty'],  1, 'input');  % Parasitic force Ty
  io(5)  = linio([mdl, '/Fdrz'],  1, 'input');  % Parasitic force Rz

  io(6)  = linio([mdl, '/Dsm'],  1, 'output'); % Displacement of the sample
  io(7)  = linio([mdl, '/Fnlm'], 1, 'output'); % Force sensor in NASS's legs
  io(8)  = linio([mdl, '/Dnlm'], 1, 'output'); % Displacement of NASS's legs
  io(9)  = linio([mdl, '/Dgm'],  1, 'output'); % Absolute displacement of the granite
  io(10) = linio([mdl, '/Vlm'],  1, 'output'); % Measured absolute velocity of the top NASS platform
#+end_src

#+begin_src matlab
  %% Run the linearization
  G_cedrat = linearize(mdl, io, options);
  G_cedrat.InputName  = {'Dw',   ... % Ground Motion [m]
                      'Fs',   ... % Force Applied on Sample [N]
                      'Fn',   ... % Force applied by NASS [N]
                      'Fty',  ... % Parasitic Force Ty [N]
                      'Frz'};     % Parasitic Force Rz [N]
  G_cedrat.OutputName = {'D',    ... % Measured sample displacement x.r.t. granite [m]
                      'Fnm',  ... % Force Sensor in NASS [N]
                      'Dnm',  ... % Displacement Sensor in NASS [m]
                      'Dgm',  ... % Asbolute displacement of Granite [m]
                      'Vlm'}; ... % Absolute Velocity of NASS [m/s]
#+end_src

#+begin_src matlab
  % save('./uniaxial/mat/plants.mat', 'G_cedrat', '-append');
#+end_src

** Sensitivity to Disturbance
#+begin_src matlab :exports none
  freqs = logspace(0, 3, 1000);

  figure;

  subplot(2, 1, 1);
  title('$D_w$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D',   'Dw'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_cedrat('D',   'Dw'), freqs, 'Hz'))), 'k--', 'DisplayName', 'CEDRAT');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/m]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');

  subplot(2, 1, 2);
  title('$F_s$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fs'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_cedrat('D', 'Fs'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_dist_cedrat
#+CAPTION: Sensitivity to disturbance once the CEDRAT controller is applied to the system ([[./figs/uniaxial_sensitivity_dist_cedrat.png][png]], [[./figs/uniaxial_sensitivity_dist_cedrat.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_dist_cedrat.png]]

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

  figure;

  subplot(2, 1, 1);
  title('$F_{ty}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fty'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_cedrat('D', 'Fty'), freqs, 'Hz'))), 'k--', 'DisplayName', 'CEDRAT');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');

  subplot(2, 1, 2);
  title('$F_{rz}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Frz'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G_cedrat('D', 'Frz'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_dist_stages_cedrat
#+CAPTION: Sensitivity to force disturbances in various stages when CEDRAT is applied ([[./figs/uniaxial_sensitivity_dist_stages_cedrat.png][png]], [[./figs/uniaxial_sensitivity_dist_stages_cedrat.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_dist_stages_cedrat.png]]

** Damped Plant
#+begin_src matlab :exports none
  freqs = logspace(0, 3, 1000);

  figure;

  ax1 = subplot(2, 1, 1);
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fn'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_cedrat('D', 'Fn'), freqs, 'Hz'))), 'k--', 'DisplayName', 'CEDRAT');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); set(gca, 'XTickLabel',[]);
  legend('location', 'northeast');

  ax2 = subplot(2, 1, 2);
  hold on;
  plot(freqs, 180/pi*angle(squeeze(freqresp(G('D', 'Fn'), freqs, 'Hz'))), 'k-');
  plot(freqs, 180/pi*angle(squeeze(freqresp(G_cedrat('D', 'Fn'), freqs, 'Hz'))), 'k--');
  hold off;
  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/uniaxial_plant_cedrat_damped.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_plant_cedrat_damped
#+CAPTION: Damped Plant after CEDRAT is applied ([[./figs/uniaxial_plant_cedrat_damped.png][png]], [[./figs/uniaxial_plant_cedrat_damped.pdf][pdf]])
[[file:figs/uniaxial_plant_cedrat_damped.png]]

** Conclusion
#+begin_important
  This gives similar results than with a classical force sensor.
#+end_important

* Comparison of Active Damping Techniques
<<sec:comparison>>
** 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/sim_nano_station_uniaxial.slx'
#+end_src

** Load the plants
#+begin_src matlab
  load('./uniaxial/mat/plants.mat', 'G', 'G_iff', 'G_rmc', 'G_dvf');
#+end_src

** Sensitivity to Disturbance
#+begin_src matlab :exports none
  freqs = logspace(0, 3, 1000);

  figure;

  title('$D_w$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G    ('D',   'Dw'), freqs, 'Hz'))), 'k-',  'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_iff('D',   'Dw'), freqs, 'Hz'))), 'k:',  'DisplayName', 'IFF');
  plot(freqs, abs(squeeze(freqresp(G_rmc('D',   'Dw'), freqs, 'Hz'))), 'k--', 'DisplayName', 'RMC');
  plot(freqs, abs(squeeze(freqresp(G_dvf('D',   'Dw'), freqs, 'Hz'))), 'k-.', 'DisplayName', 'DVF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/m]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_ground_motion
#+CAPTION: Sensitivity to Ground Motion - Comparison ([[./figs/uniaxial_sensitivity_ground_motion.png][png]], [[./figs/uniaxial_sensitivity_ground_motion.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_ground_motion.png]]


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

  figure;
  title('$F_s$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G    ('D', 'Fs'), freqs, 'Hz'))), 'k-' , 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_iff('D', 'Fs'), freqs, 'Hz'))), 'k:' , 'DisplayName', 'IFF');
  plot(freqs, abs(squeeze(freqresp(G_rmc('D', 'Fs'), freqs, 'Hz'))), 'k--', 'DisplayName', 'RMC');
  plot(freqs, abs(squeeze(freqresp(G_dvf('D', 'Fs'), freqs, 'Hz'))), 'k-.', 'DisplayName', 'DVF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_direct_force
#+CAPTION: Sensitivity to disturbance - Comparison ([[./figs/uniaxial_sensitivity_direct_force.png][png]], [[./figs/uniaxial_sensitivity_direct_force.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_direct_force.png]]

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

  figure;

  title('$F_{ty}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G    ('D', 'Fty'), freqs, 'Hz'))), 'k-',  'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_iff('D', 'Fty'), freqs, 'Hz'))), 'k:',  'DisplayName', 'IFF');
  plot(freqs, abs(squeeze(freqresp(G_rmc('D', 'Fty'), freqs, 'Hz'))), 'k--', 'DisplayName', 'RMC');
  plot(freqs, abs(squeeze(freqresp(G_dvf('D', 'Fty'), freqs, 'Hz'))), 'k-.', 'DisplayName', 'DVF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_fty
#+CAPTION: Sensitivity to force disturbances - Comparison ([[./figs/uniaxial_sensitivity_fty.png][png]], [[./figs/uniaxial_sensitivity_fty.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_fty.png]]

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

  figure;

  title('$F_{rz}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G    ('D', 'Frz'), freqs, 'Hz'))), 'k-' , 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_iff('D', 'Frz'), freqs, 'Hz'))), 'k:'  , 'DisplayName', 'IFF');
  plot(freqs, abs(squeeze(freqresp(G_rmc('D', 'Frz'), freqs, 'Hz'))), 'k--', 'DisplayName', 'RMC');
  plot(freqs, abs(squeeze(freqresp(G_dvf('D', 'Frz'), freqs, 'Hz'))), 'k-.', 'DisplayName', 'DVF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
  legend('location', 'northeast');
#+end_src

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

#+NAME: fig:uniaxial_sensitivity_frz
#+CAPTION: Sensitivity to force disturbances - Comparison ([[./figs/uniaxial_sensitivity_frz.png][png]], [[./figs/uniaxial_sensitivity_frz.pdf][pdf]])
[[file:figs/uniaxial_sensitivity_frz.png]]

** Noise Budget
We first load the measured PSD of the disturbance.
#+begin_src matlab
  load('./disturbances/mat/dist_psd.mat', 'dist_f');
#+end_src

The effect of these disturbances on the distance $D$ is computed for all active damping techniques.
#+begin_src matlab :exports none
  % Power Spectral Density of the relative Displacement [m^2/Hz]
  psd_ol_gm_d = dist_f.psd_gm.*abs(squeeze(freqresp(G('D', 'Dw'),  dist_f.f, 'Hz'))).^2;
  psd_ol_ty_d = dist_f.psd_ty.*abs(squeeze(freqresp(G('D', 'Fty'), dist_f.f, 'Hz'))).^2;
  psd_ol_rz_d = dist_f.psd_rz.*abs(squeeze(freqresp(G('D', 'Frz'), dist_f.f, 'Hz'))).^2;

  psd_iff_gm_d = dist_f.psd_gm.*abs(squeeze(freqresp(G_iff('D', 'Dw'),  dist_f.f, 'Hz'))).^2;
  psd_iff_ty_d = dist_f.psd_ty.*abs(squeeze(freqresp(G_iff('D', 'Fty'), dist_f.f, 'Hz'))).^2;
  psd_iff_rz_d = dist_f.psd_rz.*abs(squeeze(freqresp(G_iff('D', 'Frz'), dist_f.f, 'Hz'))).^2;

  psd_rmc_gm_d = dist_f.psd_gm.*abs(squeeze(freqresp(G_rmc('D', 'Dw'),  dist_f.f, 'Hz'))).^2;
  psd_rmc_ty_d = dist_f.psd_ty.*abs(squeeze(freqresp(G_rmc('D', 'Fty'), dist_f.f, 'Hz'))).^2;
  psd_rmc_rz_d = dist_f.psd_rz.*abs(squeeze(freqresp(G_rmc('D', 'Frz'), dist_f.f, 'Hz'))).^2;

  psd_dvf_gm_d = dist_f.psd_gm.*abs(squeeze(freqresp(G_dvf('D', 'Dw'),  dist_f.f, 'Hz'))).^2;
  psd_dvf_ty_d = dist_f.psd_ty.*abs(squeeze(freqresp(G_dvf('D', 'Fty'), dist_f.f, 'Hz'))).^2;
  psd_dvf_rz_d = dist_f.psd_rz.*abs(squeeze(freqresp(G_dvf('D', 'Frz'), dist_f.f, 'Hz'))).^2;
#+end_src

We then compute the Cumulative Amplitude Spectrum (figure [[fig:uniaxial-comp-cas-dist]]).
#+begin_src matlab :exports none
  cas_ol_tot_d  = flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_ol_rz_d+psd_ol_ty_d+psd_ol_gm_d))));
  cas_iff_tot_d = flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_iff_rz_d+psd_iff_ty_d+psd_iff_gm_d))));
  cas_rmc_tot_d = flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_rmc_rz_d+psd_rmc_ty_d+psd_rmc_gm_d))));
  cas_dvf_tot_d = flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_dvf_rz_d+psd_dvf_ty_d+psd_dvf_gm_d))));
#+end_src

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

  figure;
  hold on;
  plot(dist_f.f, cas_ol_tot_d, 'DisplayName', 'OL');
  plot(dist_f.f, cas_iff_tot_d, 'DisplayName', 'IFF');
  plot(dist_f.f, cas_rmc_tot_d, 'DisplayName', 'RMC');
  plot(dist_f.f, cas_dvf_tot_d, 'DisplayName', 'DVF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('CAS of the effect of disturbances on $D$ [m]');  xlabel('Frequency [Hz]');
  legend('location', 'northeast')
  xlim([0.5, 500]); ylim([1e-11, 1e-6]);
#+end_src

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

#+NAME: fig:uniaxial-comp-cas-dist
#+CAPTION: Comparison of the Cumulative Amplitude Spectrum of $D$ for different active damping techniques ([[./figs/uniaxial-comp-cas-dist.png][png]], [[./figs/uniaxial-comp-cas-dist.pdf][pdf]])
[[file:figs/uniaxial-comp-cas-dist.png]]

The obtained Root Mean Square Value for each active damping technique is shown below.
#+begin_src matlab :exports results :results value table replace :tangle no :post addhdr(*this*)
  data2orgtable([cas_ol_tot_d(1); cas_iff_tot_d(1); cas_rmc_tot_d(1); cas_dvf_tot_d(1)], {'OL', 'IFF', 'RMC', 'DVF'}, {'D [m rms]'}, ' %.2e ');
#+end_src

#+name: tab:rms_d_comp
#+caption: Obtain Root Mean Square value of $D$ for each Active Damping Technique applied
#+RESULTS:
|     | D [m rms] |
|-----+-----------|
| OL  |  3.38e-06 |
| IFF |  3.40e-06 |
| RMC |  3.37e-06 |
| DVF |  3.38e-06 |

It is important to note that the effect of direct forces applied to the sample are not taken into account here.

** Damped Plant
#+begin_src matlab :exports none
  freqs = logspace(0, 3, 1000);

  figure;

  ax1 = subplot(2, 1, 1);
  hold on;
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fn'), freqs, 'Hz'))), 'k-', 'DisplayName', 'OL');
  plot(freqs, abs(squeeze(freqresp(G_iff('D', 'Fn'), freqs, 'Hz'))), 'k:', 'DisplayName', 'IFF');
  plot(freqs, abs(squeeze(freqresp(G_rmc('D', 'Fn'), freqs, 'Hz'))), 'k--', 'DisplayName', 'RMC');
  plot(freqs, abs(squeeze(freqresp(G_dvf('D', 'Fn'), freqs, 'Hz'))), 'k-.', 'DisplayName', 'DVF');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); set(gca, 'XTickLabel',[]);
  legend('location', 'northeast');

  ax2 = subplot(2, 1, 2);
  hold on;
  plot(freqs, 180/pi*angle(squeeze(freqresp(G('D', 'Fn'), freqs, 'Hz'))), 'k-');
  plot(freqs, 180/pi*angle(squeeze(freqresp(G_iff('D', 'Fn'), freqs, 'Hz'))), 'k:');
  plot(freqs, 180/pi*angle(squeeze(freqresp(G_rmc('D', 'Fn'), freqs, 'Hz'))), 'k--');
  plot(freqs, 180/pi*angle(squeeze(freqresp(G_dvf('D', 'Fn'), freqs, 'Hz'))), 'k-.');
  hold off;
  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/uniaxial_plant_damped_comp.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_plant_damped_comp
#+CAPTION: Damped Plant - Comparison ([[./figs/uniaxial_plant_damped_comp.png][png]], [[./figs/uniaxial_plant_damped_comp.pdf][pdf]])
[[file:figs/uniaxial_plant_damped_comp.png]]

** Conclusion

#+name: tab:active_damping_comparison
#+caption: Comparison of proposed active damping techniques
|                           | IFF             | RMC             | DVF      |
|---------------------------+-----------------+-----------------+----------|
| Sensor Type               | Force sensor    | Relative Motion | Inertial |
| Guaranteed Stability      | +               | +               | -        |
| Sensitivity ($D_w$)       | -               | +               | -        |
| Sensitivity ($F_s$)       | - (at low freq) | +               | +        |
| Sensitivity ($F_{ty,rz}$) | +               | -               | +        |
| Overall RMS of $D$        | =               | =               | =        |
* Voice Coil
<<sec:voice_coil>>
** 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/sim_nano_station_uniaxial.slx'
#+end_src

** Init
We initialize all the stages with the default parameters.
The nano-hexapod is an hexapod with voice coils and the sample has a mass of 50kg.

#+begin_src matlab :exports none
  initializeGround();
  initializeGranite();
  initializeTy();
  initializeRy();
  initializeRz();
  initializeMicroHexapod();
  initializeAxisc();
  initializeMirror();
  initializeNanoHexapod(struct('actuator', 'lorentz'));
  initializeSample(struct('mass', 50));
#+end_src

All the controllers are set to 0 (Open Loop).
#+begin_src matlab :exports none
  K = tf(0);
  save('./mat/controllers.mat', 'K', '-append');
  K_iff = tf(0);
  save('./mat/controllers.mat', 'K_iff', '-append');
  K_rmc = tf(0);
  save('./mat/controllers.mat', 'K_rmc', '-append');
  K_dvf = tf(0);
  save('./mat/controllers.mat', 'K_dvf', '-append');
#+end_src

** Identification
We identify the dynamics of the system.
#+begin_src matlab
  %% Options for Linearized
  options = linearizeOptions;
  options.SampleTime = 0;

  %% Name of the Simulink File
  mdl = 'sim_nano_station_uniaxial';
#+end_src

The inputs and outputs are defined below and corresponds to the name of simulink blocks.
#+begin_src matlab
  %% Input/Output definition
  io(1)  = linio([mdl, '/Dw'],   1, 'input'); % Ground Motion
  io(2)  = linio([mdl, '/Fs'],   1, 'input'); % Force applied on the sample
  io(3)  = linio([mdl, '/Fnl'],  1, 'input'); % Force applied by the NASS
  io(4)  = linio([mdl, '/Fdty'], 1, 'input'); % Parasitic force Ty
  io(5)  = linio([mdl, '/Fdrz'], 1, 'input'); % Parasitic force Rz

  io(6)  = linio([mdl, '/Dsm'],  1, 'output'); % Displacement of the sample
  io(7)  = linio([mdl, '/Fnlm'], 1, 'output'); % Force sensor in NASS's legs
  io(8)  = linio([mdl, '/Dnlm'], 1, 'output'); % Displacement of NASS's legs
  io(9)  = linio([mdl, '/Dgm'],  1, 'output'); % Absolute displacement of the granite
  io(10) = linio([mdl, '/Vlm'],  1, 'output'); % Measured absolute velocity of the top NASS platform
#+end_src

Finally, we use the =linearize= Matlab function to extract a state space model from the simscape model.
#+begin_src matlab
  %% Run the linearization
  G_vc = linearize(mdl, io, options);
  G_vc.InputName  = {'Dw',   ... % Ground Motion [m]
                     'Fs',   ... % Force Applied on Sample [N]
                     'Fn',   ... % Force applied by NASS [N]
                     'Fty',  ... % Parasitic Force Ty [N]
                     'Frz'};     % Parasitic Force Rz [N]
  G_vc.OutputName = {'D',    ... % Measured sample displacement x.r.t. granite [m]
                     'Fnm',  ... % Force Sensor in NASS [N]
                     'Dnm',  ... % Displacement Sensor in NASS [m]
                     'Dgm',  ... % Asbolute displacement of Granite [m]
                     'Vlm'}; ... % Absolute Velocity of NASS [m/s]
#+end_src

Finally, we save the identified system dynamics for further analysis.
#+begin_src matlab
  save('./uniaxial/mat/plants.mat', 'G_vc', '-append');
#+end_src

** Sensitivity to Disturbances
We load the dynamics when using a piezo-electric nano hexapod to compare the results.
#+begin_src matlab
  load('./uniaxial/mat/plants.mat', 'G');
#+end_src

We show several plots representing the sensitivity to disturbances:
- in figure [[fig:uniaxial-sensitivity-vc-disturbances]] the transfer functions from ground motion $D_w$ to the sample position $D$ and the transfer function from direct force on the sample $F_s$ to the sample position $D$ are shown
- in figure [[fig:uniaxial-sensitivity-vc-force-dist]], it is the effect of parasitic forces of the positioning stages ($F_{ty}$ and $F_{rz}$) on the position $D$ of the sample that are shown

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

  figure;

  subplot(2, 1, 1);
  title('$D_w$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G_vc('D',   'Dw'), freqs, 'Hz'))), 'k-', 'DisplayName', 'G - VC');
  plot(freqs, abs(squeeze(freqresp(G('D',   'Dw'), freqs, 'Hz'))), 'k--', 'DisplayName', 'G - PZ');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  legend('location', 'northeast');
  ylabel('Amplitude [m/m]'); xlabel('Frequency [Hz]');

  subplot(2, 1, 2);
  title('$F_s$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G_vc('D', 'Fs'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fs'), freqs, 'Hz'))), 'k--');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial-sensitivity-vc-disturbances
#+CAPTION: Sensitivity to disturbances ([[./figs/uniaxial-sensitivity-vc-disturbances.png][png]], [[./figs/uniaxial-sensitivity-vc-disturbances.pdf][pdf]])
[[file:figs/uniaxial-sensitivity-vc-disturbances.png]]

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

  figure;

  subplot(2, 1, 1);
  title('$F_{ty}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G_vc('D', 'Fty'), freqs, 'Hz'))), 'k-', 'DisplayName', 'G - VC');
  plot(freqs, abs(squeeze(freqresp(G('D', 'Fty'), freqs, 'Hz'))), 'k--', 'DisplayName', 'G - PZ');
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  legend('location', 'northeast');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');

  subplot(2, 1, 2);
  title('$F_{rz}$ to $D$');
  hold on;
  plot(freqs, abs(squeeze(freqresp(G_vc('D', 'Frz'), freqs, 'Hz'))), 'k-');
  plot(freqs, abs(squeeze(freqresp(G('D', 'Frz'), freqs, 'Hz'))), 'k--');
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('Amplitude [m/N]'); xlabel('Frequency [Hz]');
#+end_src

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

#+NAME: fig:uniaxial-sensitivity-vc-force-dist
#+CAPTION: Sensitivity to disturbances ([[./figs/uniaxial-sensitivity-vc-force-dist.png][png]], [[./figs/uniaxial-sensitivity-vc-force-dist.pdf][pdf]])
[[file:figs/uniaxial-sensitivity-vc-force-dist.png]]

** Noise Budget
We first load the measured PSD of the disturbance.
#+begin_src matlab
  load('./disturbances/mat/dist_psd.mat', 'dist_f');
#+end_src

The effect of these disturbances on the distance $D$ is computed below.
#+begin_src matlab :exports none
  % Power Spectral Density of the relative Displacement [m^2/Hz]
  psd_vc_gm_d = dist_f.psd_gm.*abs(squeeze(freqresp(G_vc('D', 'Dw'),  dist_f.f, 'Hz'))).^2;
  psd_vc_ty_d = dist_f.psd_ty.*abs(squeeze(freqresp(G_vc('D', 'Fty'), dist_f.f, 'Hz'))).^2;
  psd_vc_rz_d = dist_f.psd_rz.*abs(squeeze(freqresp(G_vc('D', 'Frz'), dist_f.f, 'Hz'))).^2;
#+end_src

#+begin_src matlab :exports none
  % Power Spectral Density of the relative Displacement [m^2/Hz]
  psd_gm_d = dist_f.psd_gm.*abs(squeeze(freqresp(G('D', 'Dw'),  dist_f.f, 'Hz'))).^2;
  psd_ty_d = dist_f.psd_ty.*abs(squeeze(freqresp(G('D', 'Fty'), dist_f.f, 'Hz'))).^2;
  psd_rz_d = dist_f.psd_rz.*abs(squeeze(freqresp(G('D', 'Frz'), dist_f.f, 'Hz'))).^2;
#+end_src

The PSD of the obtain distance $D$ due to each of the perturbation is shown in figure [[fig:uniaxial-vc-psd-dist]] and the Cumulative Amplitude Spectrum is shown in figure [[fig:uniaxial-vc-cas-dist]].

The Root Mean Square value of the obtained displacement $D$ is computed below and can be determined from the figure [[fig:uniaxial-vc-cas-dist]].
#+begin_src matlab :results value replace :exports results
  cas_tot_d = sqrt(cumtrapz(dist_f.f, psd_vc_rz_d+psd_vc_ty_d+psd_vc_gm_d)); cas_tot_d(end)
#+end_src

#+RESULTS:
: 4.8793e-06

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

  figure;
  hold on;
  plot(dist_f.f, psd_vc_gm_d, 'DisplayName', '$D_w$');
  plot(dist_f.f, psd_vc_ty_d, 'DisplayName', '$T_y$');
  plot(dist_f.f, psd_vc_rz_d, 'DisplayName', '$R_z$');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('CAS of the effect of disturbances on $D$ $\left[\frac{m^2}{Hz}\right]$');  xlabel('Frequency [Hz]');
  legend('location', 'northeast')
  xlim([0.5, 500]);
#+end_src

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

#+NAME: fig:uniaxial-vc-psd-dist
#+CAPTION: PSD of the displacement $D$ due to disturbances ([[./figs/uniaxial-vc-psd-dist.png][png]], [[./figs/uniaxial-vc-psd-dist.pdf][pdf]])
[[file:figs/uniaxial-vc-psd-dist.png]]

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

  figure;
  hold on;
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_vc_gm_d)))), 'DisplayName', '$D_w$ - VC');
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_vc_ty_d)))), 'DisplayName', '$T_y$ - VC');
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_vc_rz_d)))), 'DisplayName', '$R_z$ - VC');
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_vc_gm_d+psd_vc_ty_d+psd_vc_rz_d)))), 'k-', 'DisplayName', 'tot - VC');
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_gm_d+psd_ty_d+psd_rz_d)))), 'k--', 'DisplayName', 'tot - PZ');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('CAS of the effect of disturbances on $D$ [m]');  xlabel('Frequency [Hz]');
  legend('location', 'northeast')
  xlim([0.5, 500]); ylim([1e-12, 5e-6]);
#+end_src

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

#+NAME: fig:uniaxial-vc-cas-dist
#+CAPTION: CAS of the displacement $D$ due the disturbances ([[./figs/uniaxial-vc-cas-dist.png][png]], [[./figs/uniaxial-vc-cas-dist.pdf][pdf]])
[[file:figs/uniaxial-vc-cas-dist.png]]

#+begin_important
  Even though the RMS value of the displacement $D$ is lower when using a piezo-electric actuator, the motion is mainly due to high frequency disturbances which are more difficult to control (an higher control bandwidth is required).

  Thus, it may be desirable to use voice coil actuators.
#+end_important
** Integral Force Feedback
#+begin_src matlab
  K_iff = -20/s;
#+end_src

#+begin_src matlab :exports none
  freqs = logspace(-1, 2, 1000);

  figure;

  ax1 = subplot(2, 1, 1);
  plot(freqs, abs(squeeze(freqresp(K_iff*G_vc('Fnm', 'Fn'), 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_vc('Fnm', 'Fn'), 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/uniaxial_iff_vc_open_loop.pdf" :var figsize="full-tall" :post pdf2svg(file=*this*, ext="png")
  <<plt-matlab>>
#+end_src

#+NAME: fig:uniaxial_iff_vc_open_loop
#+CAPTION: Open Loop Transfer Function for IFF control when using a voice coil actuator ([[./figs/uniaxial_iff_vc_open_loop.png][png]], [[./figs/uniaxial_iff_vc_open_loop.pdf][pdf]])
[[file:figs/uniaxial_iff_vc_open_loop.png]]

** Identification of the Damped Plant
Let's initialize the system prior to identification.
#+begin_src matlab
  initializeGround();
  initializeGranite();
  initializeTy();
  initializeRy();
  initializeRz();
  initializeMicroHexapod();
  initializeAxisc();
  initializeMirror();
  initializeNanoHexapod(struct('actuator', 'lorentz'));
  initializeSample(struct('mass', 50));
#+end_src

All the controllers are set to 0.
#+begin_src matlab
  K = tf(0);
  save('./mat/controllers.mat', 'K', '-append');
  K_iff = -K_iff;
  save('./mat/controllers.mat', 'K_iff', '-append');
  K_rmc = tf(0);
  save('./mat/controllers.mat', 'K_rmc', '-append');
  K_dvf = tf(0);
  save('./mat/controllers.mat', 'K_dvf', '-append');
#+end_src

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

  %% Name of the Simulink File
  mdl = 'sim_nano_station_uniaxial';
#+end_src

#+begin_src matlab
  %% Input/Output definition
  io(1)  = linio([mdl, '/Dw'],    1, 'input');  % Ground Motion
  io(2)  = linio([mdl, '/Fs'],    1, 'input');  % Force applied on the sample
  io(3)  = linio([mdl, '/Fnl'],   1, 'input');  % Force applied by the NASS
  io(4)  = linio([mdl, '/Fdty'],  1, 'input');  % Parasitic force Ty
  io(5)  = linio([mdl, '/Fdrz'],  1, 'input');  % Parasitic force Rz

  io(6)  = linio([mdl, '/Dsm'],  1, 'output'); % Displacement of the sample
  io(7)  = linio([mdl, '/Fnlm'], 1, 'output'); % Force sensor in NASS's legs
  io(8)  = linio([mdl, '/Dnlm'], 1, 'output'); % Displacement of NASS's legs
  io(9)  = linio([mdl, '/Dgm'],  1, 'output'); % Absolute displacement of the granite
  io(10) = linio([mdl, '/Vlm'],  1, 'output'); % Measured absolute velocity of the top NASS platform
#+end_src

#+begin_src matlab
  %% Run the linearization
  G_vc_iff = linearize(mdl, io, options);
  G_vc_iff.InputName  = {'Dw',   ... % Ground Motion [m]
                         'Fs',   ... % Force Applied on Sample [N]
                         'Fn',   ... % Force applied by NASS [N]
                         'Fty',  ... % Parasitic Force Ty [N]
                         'Frz'};     % Parasitic Force Rz [N]
  G_vc_iff.OutputName = {'D',    ... % Measured sample displacement x.r.t. granite [m]
                         'Fnm',  ... % Force Sensor in NASS [N]
                         'Dnm',  ... % Displacement Sensor in NASS [m]
                         'Dgm',  ... % Asbolute displacement of Granite [m]
                         'Vlm'}; ... % Absolute Velocity of NASS [m/s]
#+end_src

** Noise Budget
We compute the obtain PSD of the displacement $D$ when using IFF.
#+begin_src matlab :exports none
  % Power Spectral Density of the relative Displacement [m^2/Hz]
  psd_vc_iff_gm_d = dist_f.psd_gm.*abs(squeeze(freqresp(G_vc_iff('D', 'Dw'),  dist_f.f, 'Hz'))).^2;
  psd_vc_iff_ty_d = dist_f.psd_ty.*abs(squeeze(freqresp(G_vc_iff('D', 'Fty'), dist_f.f, 'Hz'))).^2;
  psd_vc_iff_rz_d = dist_f.psd_rz.*abs(squeeze(freqresp(G_vc_iff('D', 'Frz'), dist_f.f, 'Hz'))).^2;
#+end_src

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

  figure;
  hold on;
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_gm_d+psd_ty_d+psd_rz_d)))), '-', 'DisplayName', 'OL - PZ');
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_vc_gm_d+psd_vc_ty_d+psd_vc_rz_d)))), 'k-', 'DisplayName', 'OL - VC');
  plot(dist_f.f, flip(sqrt(-cumtrapz(flip(dist_f.f), flip(psd_vc_iff_gm_d+psd_vc_iff_ty_d+psd_vc_iff_rz_d)))), 'k--', 'DisplayName', 'IFF - VC');
  hold off;
  set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log');
  ylabel('CAS of the effect of disturbances on $D$ [m]');  xlabel('Frequency [Hz]');
  legend('location', 'northeast')
  xlim([0.5, 500]); ylim([1e-12, 5e-6]);
#+end_src

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

#+NAME: fig:uniaxial-cas-iff-vc
#+CAPTION: CAS of the displacement $D$ ([[./figs/uniaxial-cas-iff-vc.png][png]], [[./figs/uniaxial-cas-iff-vc.pdf][pdf]])
[[file:figs/uniaxial-cas-iff-vc.png]]

** Conclusion
#+begin_important
  The use of voice coil actuators would allow a better disturbance rejection for a fixed bandwidth compared with a piezo-electric hexapod.

  Similarly, it would require much lower bandwidth to attain the same level of disturbance rejection for $D$.
#+end_important
