#+TITLE: Flexible Joints - Test Bench
:DRAWER:
#+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="https://research.tdehaeze.xyz/css/style.css"/>
#+HTML_HEAD: <script type="text/javascript" src="https://research.tdehaeze.xyz/js/script.js"></script>

#+BIND: org-latex-image-default-option "scale=1"
#+BIND: org-latex-image-default-width ""

#+LaTeX_CLASS: scrreprt
#+LaTeX_CLASS_OPTIONS: [a4paper, 10pt, DIV=12, parskip=full, bibliography=totoc]
#+LaTeX_HEADER_EXTRA: \input{preamble.tex}
#+LATEX_HEADER_EXTRA: \bibliography{test-bench-flexible-joints.bib}

#+BIND: org-latex-bib-compiler "biber"

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

#+PROPERTY: header-args:latex  :headers '("\\usepackage{tikz}" "\\usepackage{import}" "\\import{$HOME/Cloud/tikz/org/}{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 file raw replace
#+PROPERTY: header-args:latex+ :buffer no
#+PROPERTY: header-args:latex+ :tangle no
#+PROPERTY: header-args:latex+ :eval no-export
#+PROPERTY: header-args:latex+ :exports results
#+PROPERTY: header-args:latex+ :mkdirp yes
#+PROPERTY: header-args:latex+ :output-dir figs
#+PROPERTY: header-args:latex+ :post pdf2svg(file=*this*, ext="png")
:END:

#+begin_export html
  <hr>
  <p>This report is also available as a <a href="./test-bench-flexible-joints.pdf">pdf</a>.</p>
  <hr>
#+end_export

#+latex: \clearpage

* Build                                                             :noexport:
#+NAME: startblock
#+BEGIN_SRC emacs-lisp :results none :tangle no
(add-to-list 'org-latex-classes
             '("scrreprt"
               "\\documentclass{scrreprt}"
               ("\\chapter{%s}" . "\\chapter*{%s}")
               ("\\section{%s}" . "\\section*{%s}")
               ("\\subsection{%s}" . "\\subsection*{%s}")
               ("\\paragraph{%s}" . "\\paragraph*{%s}")
               ))


;; Remove automatic org heading labels
(defun my-latex-filter-removeOrgAutoLabels (text backend info)
  "Org-mode automatically generates labels for headings despite explicit use of `#+LABEL`. This filter forcibly removes all automatically generated org-labels in headings."
  (when (org-export-derived-backend-p backend 'latex)
    (replace-regexp-in-string "\\\\label{sec:org[a-f0-9]+}\n" "" text)))
(add-to-list 'org-export-filter-headline-functions
             'my-latex-filter-removeOrgAutoLabels)

;; Remove all org comments in the output LaTeX file
(defun delete-org-comments (backend)
  (loop for comment in (reverse (org-element-map (org-element-parse-buffer)
                                    'comment 'identity))
        do
        (setf (buffer-substring (org-element-property :begin comment)
                                (org-element-property :end comment))
              "")))
(add-hook 'org-export-before-processing-hook 'delete-org-comments)

;; Use no package by default
(setq org-latex-packages-alist nil)
(setq org-latex-default-packages-alist nil)

;; Do not include the subtitle inside the title
(setq org-latex-subtitle-separate t)
(setq org-latex-subtitle-format "\\subtitle{%s}")

(setq org-export-before-parsing-hook '(org-ref-glossary-before-parsing
                                       org-ref-acronyms-before-parsing))
#+END_SRC

* Notes                                                             :noexport:

Prefix for figures/section/tables =test_joints=

Compilation of the following reports:
- [X] [[file:~/Cloud/work-projects/ID31-NASS/matlab/test-bench-flexible-joints-old/index.org][test-bench-flexible-joints-adv]]
  Ideas of measuring shear stiffness, axial stiffness and torsion
  Not done in the end
- [X] [[/home/thomas/Cloud/work-projects/ID31-NASS/matlab/test-bench-flexible-joints-old/bending.org][bending measurement]]
  Some possible errors when measuring bending stiffness
- [X] [[file:~/Cloud/documents/internships/2021-martin-reichert/Bachelor thesis.pdf][Report of Martin]]
  Analytical estimation of the stiffness
  Estimation of possible errors in the estimation of the stiffness
  May not be useful here.
- [X] [[file:~/Cloud/work-projects/ID31-NASS/matlab/test-bench-nass-flexible-joints/test-bench-flexible-joints.org][test-bench-nass-flexible-joints]]
  Here only the bending stiffness is measured
- [ ] Also check start of this report: [[file:~/Cloud/work-projects/ID31-NASS/matlab/nass-simscape/org/nano_hexapod.org][nano_hexapod]]
  Model of the flexible joints
  Maybe add a section for the model of the flexible joints (of maybe this was done in the "detailed design" section?)
- [X] Maybe say that some flexible joints where not machined properly (show picture with deformed machining and one with "chips" stuck inside)
- [X] Explain why the encoder is here: in line with the measurement, no "abbe errors"

Goal:
- Characterization of flexible joints:
  - Remind the specifications
  - Most important: bending stiffness
- Dimensional measurement
- Presentation of test bench to measure stiffness
  - Possible measurement errors and how to prevent them
  - Calibration of force sensor
- Section 6 is most important: measurement results
- Conclusion

** TODO [#A] Check if results from Martin are better matching the measured dimensions of the flexible joints

** TODO [#B] Add symbols for the different characteristics

- Axial Stiffness: $k_z$
- Shear Stiffness: $k_x$, $k_y$
- Bending Stiffness: $k_{R_x}$, $k_{R_y}$
- Torsion Stiffness: $k_{R_z}$
- Bending Stroke: $\theta_{R_x\text{max}}$, $\theta_{R_y\text{max}}$

* Introduction                                                        :ignore:

At both ends of the nano-hexapod struts, a flexible spherical joint is used.
Ideally, these flexible joints would behave as perfect spherical joints, that is to say no bending and torsional stiffnesses, infinite shear and axial stiffnesses, unlimited bending and torsional stroke, no friction and no backlash.

Deviations from this ideal properties will impact the dynamics of the Nano-Hexapod and could limit the attainable performances.
During the detailed design phase, specifications in term of stiffness and stroke have been determined and are summarized in Table ref:tab:test_joints_specs.

#+name: tab:test_joints_specs
#+caption: Specifications for the flexible joints and estimated characteristics from the Finite Element Model
#+attr_latex: :environment tabularx :width 0.5\linewidth :align Xcc
#+attr_latex: :center t :booktabs t :float t
|                   | *Specification*        | *FEM* |
|-------------------+------------------------+-------|
| Axial Stiffness   | $> 100\,N/\mu m$       |    94 |
| Shear Stiffness   | $> 1\,N/\mu m$         |    13 |
| Bending Stiffness | $< 100\,Nm/\text{rad}$ |     5 |
| Torsion Stiffness | $< 500\,Nm/\text{rad}$ |   260 |
| Bending Stroke    | $> 1\,\text{mrad}$     |  24.5 |

After optimization using a finite element model, the geometry shown in Figure ref:fig:test_joints_schematic has been obtained and the corresponding flexible joints characteristics are summarized in Table ref:tab:test_joints_specs.
This flexible joint is a monolithic piece of stainless steel[fn:1] manufactured using wire electrical discharge machining.
It serves several functions as shown in Figure ref:fig:test_joints_iso, such as:
- Rigid interfacing with the nano-hexapod plates (yellow surfaces)
- Rigid interfacing with the amplified piezoelectric actuator (blue surface)
- Allow two rotations between the "yellow" and the "blue" interfaces.
  The rotation axes are represented by the dashed lines which are intersecting

#+name: fig:test_joints_schematic
#+caption: Geometry of the optimized flexible joints
#+attr_latex: :options [htbp]
#+begin_figure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_iso}ISO view}
#+attr_latex: :options {0.39\textwidth}
#+begin_subfigure
#+attr_latex: :scale 1
[[file:figs/test_joints_iso.png]]
#+end_subfigure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_yz_plane}YZ plane}
#+attr_latex: :options {0.3\textwidth}
#+begin_subfigure
#+attr_latex: :scale 1
[[file:figs/test_joints_yz_plane.png]]
#+end_subfigure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_xz_plane}XZ plane}
#+attr_latex: :options {0.3\textwidth}
#+begin_subfigure
#+attr_latex: :scale 1
[[file:figs/test_joints_xz_plane.png]]
#+end_subfigure
#+end_figure

16 flexible joints have been ordered (shown in Figure ref:fig:test_joints_received) such some selection can be made for the 12 that will be used on the nano-hexapod.

#+name: fig:test_joints_picture
#+caption: Pictures of the received 16 flexible joints
#+attr_latex: :options [htbp]
#+begin_figure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_received}15 of the 16 received flexible joints}
#+attr_latex: :options {0.64\textwidth}
#+begin_subfigure
#+attr_latex: :height 5.5cm
[[file:figs/test_joints_received.jpg]]
#+end_subfigure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_received_zoom}Zoom on one flexible joint}
#+attr_latex: :options {0.35\textwidth}
#+begin_subfigure
#+attr_latex: :height 5.5cm
[[file:figs/test_joints_received_zoom.jpg]]
#+end_subfigure
#+end_figure

In this document, the received flexible joints are characterize to make sure they are fulfilling the requirements and such that they can well be modelled.

First, the flexible joints are visually inspected, and the minimum gaps (responsible for most of the joint compliance) are measured (Section ref:sec:test_joints_flex_dim_meas).
Then, a test bench is developed to measure the bending stiffness of the flexible joints.
The development of this test bench is presented in Section ref:sec:test_joints_test_bench_desc, including a noise budget and some requirements in terms of instrumentation.
Finally, the test bench is manufacturer and used to measure the bending stiffnesses of all the flexible joints.
Results are shown in Section ref:sec:test_joints_bending_stiffness_meas

#+name: tab:test_joints_section_matlab_code
#+caption: Report sections and corresponding Matlab files
#+attr_latex: :environment tabularx :width 0.6\linewidth :align lX
#+attr_latex: :center t :booktabs t
| *Sections*                                         | *Matlab File*                        |
|----------------------------------------------------+--------------------------------------|
| Section ref:sec:test_joints_flex_dim_meas          | =test_joints_1_dim_meas.m=           |
| Section ref:sec:test_joints_test_bench_desc        | =test_joints_2_bench_dimensioning.m= |
| Section ref:sec:test_joints_bending_stiffness_meas | =test_joints_3_bending_stiff_meas.m= |

* Flexible Joints Model                                             :noexport:
<<sec:test_joints_conf_flexible_joint>>

The model of the flexible joint is composed of 3 solid bodies as shown in Figure [[fig:simscape_model_flexible_joint]] which are connected by joints representing the flexibility of the joint.

We can represent:
- the bending flexibility $k_{R_x}$, $k_{R_y}$
- the torsional flexibility $k_{R_z}$
- the axial flexibility $k_z$

The configurations and the represented flexibilities are summarized in Table [[tab:flex_type_conf]].

#+name: tab:flex_type_conf
#+caption: Flexible joint's configuration and associated represented flexibility
#+attr_latex: :environment tabularx :width 0.6\linewidth :align lXXX
#+attr_latex: :center t :booktabs t :float t
| =flex_type= | Bending | Torsional | Axial |
|-------------+---------+-----------+-------|
| =2dof=      | x       |           |       |
| =3dof=      | x       | x         |       |
| =4dof=      | x       | x         | x     |

Of course, adding more DoF for the flexible joint will induce an addition of many states for the nano-hexapod simscape model.

#+name: fig:simscape_model_flexible_joint
#+caption: 3D view of the Sismcape model for the Flexible joint (4DoF configuration)
#+attr_latex: :width 0.8\linewidth
[[file:figs/simscape_model_flexible_joint.png]]

* Dimensional Measurements
:PROPERTIES:
:header-args:matlab+: :tangle matlab/test_joints_1_dim_meas.m
:END:
<<sec:test_joints_flex_dim_meas>>
** 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 :noweb yes
<<m-init-path>>
#+end_src

#+begin_src matlab :eval no :noweb yes
<<m-init-path-tangle>>
#+end_src

#+begin_src matlab :noweb yes
<<m-init-other>>
#+end_src

** Measurement Bench

The dimensions of the flexible part in the Y-Z plane will contribute to the X-bending stiffness.
Similarly, the dimensions of the flexible part in the X-Z plane will contribute to the Y-bending stiffness.

The setup to measure the dimension of the "X" flexible beam is shown in Figure ref:fig:test_joints_profilometer_setup.

What we typically observe is shown in Figure ref:fig:test_joints_profilometer_image.
It is then possible to estimate to dimension of the flexible beam with an accuracy of $\approx 5\,\mu m$,

#+name: fig:test_joints_profilometer
#+caption: Setup to measure the dimension of the flexible beam corresponding to the X-bending stiffness. The flexible joint is fixed to the profilometer (\subref{fig:test_joints_profilometer_image}) and a image is obtained with which the gap can be estimated (\subref{fig:test_joints_profilometer_setup})
#+attr_latex: :options [htbp]
#+begin_figure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_profilometer_image}Flexible joint fixed on the profilometer}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :width 0.95\linewidth
[[file:figs/test_joints_profilometer_image.jpg]]
#+end_subfigure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_profilometer_setup}Obtain image to estimate the gap}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :width 0.95\linewidth
[[file:figs/test_joints_profilometer_setup.png]]
#+end_subfigure
#+end_figure

** Measurement Results
The specified flexible beam thickness (gap) is $250\,\mu m$.
Four gaps are measured for each flexible joints (2 in the $x$ direction and 2 in the $y$ direction).
The "beam thickness" is then estimated to be the mean between the gaps measured on opposite sides.

An histogram of the measured beam thicknesses is shown in Figure ref:fig:test_joints_size_hist.
The measured thickness is less thant the specified value of $250\,\mu m$, but this optical method may not be very accurate as the estimated gap can depend on the lighting of the part and of its proper alignment.

However, what is more important than the true value of the thickness is the consistency between all the flexible joints.

#+begin_src matlab :exports none
%% Measured gap for the 16 flexible joints
meas_flex = [[223, 226, 224, 214];
             [229, 231, 237, 224];
             [234, 230, 239, 231];
             [233, 227, 229, 232];
             [225, 212, 228, 228];
             [220, 221, 224, 220];
             [206, 207, 228, 226];
             [230, 224, 224, 223];
             [223, 231, 228, 233];
             [228, 230, 235, 231];
             [197, 207, 211, 204];
             [227, 226, 225, 226];
             [215, 228, 231, 220];
             [216, 224, 224, 221];
             [209, 214, 220, 221];
             [213, 210, 230, 229]];
#+end_src


#+begin_src matlab :exports none
%% Histogram of the measured gap
figure;
hold on;
histogram([(meas_flex(:,1)+meas_flex(:,2))/2,(meas_flex(:,3)+meas_flex(:,4))/2], 7)
hold off;
xlabel("Measured beam thickness [$\mu m$]");
xticks([200, 205, 210, 215, 220, 225, 230, 235])
#+end_src

#+begin_src matlab :tangle no :exports results :results file replace
exportFig('figs/test_joints_size_hist.pdf', 'width', 'normal', 'height', 'normal');
#+end_src

#+name: fig:test_joints_size_hist
#+caption: Histogram for the (16x2) measured beams' thickness
#+RESULTS:
[[file:figs/test_joints_size_hist.png]]

#+begin_src matlab :exports none :tangle no
%% Save beam sizes
save('./matlab/mat/flex_meas_dim.mat', 'meas_flex');
#+end_src

#+begin_src matlab :exports none :eval no
%% Save beam sizes
save('./mat/flex_meas_dim.mat', 'meas_flex');
#+end_src

** Bad flexible joints

Using this profilometer allowed to detect flexible joints with manufacturing defects such as non-symmetrical shape (see Figure ref:fig:test_joints_bad_shape) or flexible joints with machining chips stuck in the gap (see Figure ref:fig:test_joints_bad_chips).

#+name: fig:test_joints_bad
#+caption: Example of two flexible joints that were considered unsatisfactory after visual inspection
#+attr_latex: :options [htbp]
#+begin_figure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_bad_shape}Non-Symmetrical shape}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :height 6cm
[[file:figs/test_joints_bad_shape.jpg]]
#+end_subfigure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_bad_chips}"Chips" stuck in the air gap}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :height 6cm
[[file:figs/test_joints_bad_chips.jpg]]
#+end_subfigure
#+end_figure

* Development of the Measurement Test Bench
:PROPERTIES:
:header-args:matlab+: :tangle matlab/test_joints_2_bench_dimensioning.m
:END:
<<sec:test_joints_test_bench_desc>>
** Introduction                                                      :ignore:
The most important characteristic of the flexible joint to be measured is its bending stiffness $k_{R_x} \approx k_{R_y}$.

To estimate the bending stiffness, the basic idea is to apply a torque $T_{x}$ to the flexible joints and to measure its angular deflection $\theta_{x}$.
Then, the bending stiffness can be computed from equation eqref:eq:test_joints_bending_stiffness.

\begin{equation}\label{eq:test_joints_bending_stiffness}
\boxed{k_{R_x} = \frac{T_x}{\theta_x}, \quad k_{R_y} = \frac{T_y}{\theta_y}}
\end{equation}

** 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 :noweb yes
<<m-init-path>>
#+end_src

#+begin_src matlab :eval no :noweb yes
<<m-init-path-tangle>>
#+end_src

#+begin_src matlab :noweb yes
<<m-init-other>>
#+end_src

** Measurement principle
<<ssec:test_joints_meas_principle>>
**** Torque and Rotation measurement

In order to apply torque $T_{y}$ between the two mobile parts of the flexible joint, a known "linear" force $F_{x}$ can be applied instead at the certain height $h$ with respect to the rotation point.
In that case the equivalent applied torque can be estimated from equation eqref:eq:test_joints_force_torque_distance.
Note that the application point of the force should be far enough from the rotation axis such that the resulting bending motion is much larger than the displacement due to shear.
Such effect is studied in Section ref:ssec:test_joints_error_budget.

\begin{equation}\label{eq:test_joints_force_torque_distance}
T_y = h F_x, \quad T_x = h F_y
\end{equation}

Similarly, instead of directly measuring the bending motion $\theta_y$ of the flexible joint, its linear motion $d_x$ at a certain height $h$ from the rotation points is measured.
The equivalent rotation is estimated from eqref:eq:test_joints_rot_displ.

\begin{equation}\label{eq:test_joints_rot_displ}
\theta_y = \tan^{-1}\left(\frac{d_x}{h}\right) \approx \frac{d_x}{h}, \quad \theta_x = \tan^{-1} \left( \frac{d_y}{h} \right) \approx \frac{d_y}{h}
\end{equation}

Then, the bending stiffness can be estimated from eqref:eq:test_joints_stiff_displ_force.

\begin{subequations}\label{eq:test_joints_stiff_displ_force}
\begin{align}
k_{R_x} &= \frac{T_x}{\theta_x} = \frac{h F_y}{\tan^{-1}\left( \frac{d_y}{h} \right)} \approx h^2 \frac{F_y}{d_y} \\
k_{R_y} &= \frac{T_y}{\theta_y} = \frac{h F_x}{\tan^{-1}\left( \frac{d_x}{h} \right)} \approx h^2 \frac{F_x}{d_x}
\end{align}
\end{subequations}

The working principle of the measurement bench is schematically shown in Figure ref:fig:test_joints_bench_working_principle.
One part of the flexible joint is fixed to a rigid frame while a (known) force $F_x$ is applied to the other side of the flexible joint.
The deflection of the joint $d_x$ is measured by a displacement sensor.

#+name: fig:test_joints_bench_working_principle
#+caption: Workind principle of the test bench used to estimate the bending stiffness $k_{R_y}$ of the flexible joints by measuring $F_x$, $d_x$ and $h$
[[file:figs/test_joints_bench_working_principle.png]]

**** Required external applied force

The bending stiffness is foreseen to be $k_{R_y} \approx k_{R_x} \approx 5\,\frac{Nm}{rad}$ and its stroke $\theta_{y,\text{max}}\approx \theta_{x,\text{max}}\approx 25\,mrad$.
The height between the flexible point (center of the joint) and the point where external forces are applied is $h = 22.5\,mm$ (see Figure ref:fig:test_joints_bench_working_principle).

#+begin_src matlab
%% Parameters for study
kRx = 5;       % Bending Stiffness [Nm/rad]
Rxmax = 25e-3; % Bending Stroke [rad]
h = 22.5e-3;     % Height [m]

%% Estimation of the force to test the full stroke
Fxmax = kRx*Rxmax/h; % Force to induce maximum stroke [N]
#+end_src

The bending $\theta_y$ of the flexible joint due to the force $F_x$ is given by equation eqref:eq:test_joints_deflection_force.

\begin{equation}\label{eq:test_joints_deflection_force}
  \theta_y = \frac{T_y}{k_{R_y}} = \frac{F_x h}{k_{R_y}}
\end{equation}

Therefore, the force that has to be applied to test the full range of the flexible joint is given by equation eqref:eq:test_joints_max_force.
The measurement range of the force sensor should then be higher than $5.5\,N$.

\begin{equation}\label{eq:test_joints_max_force}
  F_{x,\text{max}} = \frac{k_{R_y} \theta_{y,\text{max}}}{h} \approx 5.5\,N
\end{equation}

**** Required actuator stroke and sensors range

The flexible joint is designed to allow a bending motion of $\pm 25\,mrad$.
The corresponding stroke at the location of the force sensor is given by eqref:eq:test_joints_max_stroke.
In order to test the full range of the flexible joint, the means of applying a force (explained in the next section) should allow a motion of at least $0.5\,mm$.
Similarly, the measurement range of the displacement sensor should also be higher than $0.5\,mm$.

\begin{equation}\label{eq:test_joints_max_stroke}
d_{x,\text{max}} = h \tan(R_{x,\text{max}}) \approx 0.5\,mm
\end{equation}

#+begin_src matlab
%% Estimated maximum stroke [m]
dxmax = h*tan(Rxmax);
#+end_src

** Developed test bench
<<ssec:test_joints_test_bench>>

As explained in Section ref:ssec:test_joints_meas_principle, the flexible joint's bending stiffness is estimated by applying a known force to the flexible joint's tip and by measuring its deflection at the same point.

The force is applied using a load cell[fn:2] such that the applied force to the flexible joint's tip is directly measured.
In order to control the height and direction of the applied force, a cylinder cut in half is fixed at the tip of the force sensor (pink element in Figure ref:fig:test_joints_bench_side) that initially had a flat surface.
This way, the contact between the flexible joint cylindrical tip and the force sensor is a point (intersection of two cylinders) at a precise height, and the force is applied in a known direction.
To translate the load cell at a constant height, it is fixed to a translation stage[fn:3] which is moved by hand.

Instead of measuring the displacement directly at the tip of the flexible joint (with a probe or an interferometer for instance), the displacement of the load cell itself is measured.
To do so, an encoder[fn:4] is used that measures the motion of a ruler.
This ruler is fixed to the translation stage in line (i.e. at the same height) with the application point to reduce Abbe errors (see Figure ref:fig:test_joints_bench_overview).
Indirectly measuring the deflection of the flexible joint induces some errors due to the limited stiffness between the tip of the force sensor and the ruler.
Such error will be estimated in Section ref:ssec:test_joints_error_budget.

The flexible joint can be rotated by 90 degrees in order to measure the bending stiffness in the two directions.
The obtained CAD design of the measurement bench is shown in Figure ref:fig:test_joints_bench_overview while a zoom on the flexible joint with the associated important quantities is shown in Figure ref:fig:test_joints_bench_side.

#+name: fig:test_joints_bench
#+caption: CAD view of the test bench developped to measure the bending stiffness of the flexible joints. Different parts are shown in (\subref{fig:test_joints_bench_overview}) while a zoom on the flexible joint is shown in (\subref{fig:test_joints_bench_side})
#+attr_latex: :options [htbp]
#+begin_figure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_bench_overview} Schematic of the test bench to measure the bending stiffness of the flexible joints}
#+attr_latex: :options {0.78\textwidth}
#+begin_subfigure
#+attr_latex: :height 6cm
[[file:figs/test_joints_bench_overview.png]]
#+end_subfigure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_bench_side} Zoom}
#+attr_latex: :options {0.21\textwidth}
#+begin_subfigure
#+attr_latex: :height 6cm
[[file:figs/test_joints_bench_side.png]]
#+end_subfigure
#+end_figure

** Error budget
<<ssec:test_joints_error_budget>>
**** Introduction                                                  :ignore:
In order to estimate the accuracy of the measured bending stiffness that can be obtained using this measurement bench, an error budget is performed.

Based on equation eqref:eq:test_joints_stiff_displ_force, several errors can impact the accuracy of the measured bending stiffness:
- Errors in the measured torque $M_x, M_y$: this is mainly due to inaccuracies of the load cell and of the height estimation $h$
- Errors in the measured bending motion of the flexible joints $\theta_x, \theta_y$: errors from limited shear stiffness, from the deflection of the load cell itself, and from inaccuracy of the height estimation $h$

Let's first estimate the displacement induced only by the bending stiffness.

\begin{equation}\label{eq:test_joints_dbx}
  d_{x,b} = h \tan(\theta_y) = h \tan\left( \frac{F_x \cdot h}{k_{R_y}} \right)
\end{equation}

# From equation eqref:eq:test_joints_dbx, we can compute the bending stiffness:
# \begin{equation}
#   k_{R_y} = \frac{F_x \cdot h}{\tan^{-1}\left( \frac{D_b}{h} \right)}
# \end{equation}

# For small displacement, we have
# \begin{equation}
#   \boxed{k_{R_y} \approx h^2 \frac{F_x}{d_x}}
# \end{equation}

# And therefore, to precisely measure $k_{R_y}$, we need to:
# - precisely measure the motion $d_x$
# - precisely measure the applied force $F_x$
# - precisely now the height of the force application point $h$

#+begin_src matlab :exports none
%% Stiffness
ka = 94e6; % Axial Stiffness [N/m]
ks = 13e6; % Shear Stiffness [N/m]
kb = 5;    % Bending Stiffness [Nm/rad]
kt = 260;  % Torsional Stiffness [Nm/rad]

%% Maximum force
Fa = 469;    % Axial Force before yield [N]
Fs = 242;    % Shear Force before yield [N]
Fb = 0.118;  % Bending Force before yield [Nm]
Ft = 1.508; % Torsional Force before yield [Nm]

%% Compute the corresponding stroke
Xa = Fa/ka; % Axial Stroke before yield [m]
Xs = Fs/ks; % Shear Stroke before yield [m]
Xb = Fb/kb; % Bending Stroke before yield [rad]
Xt = Ft/kt; % Torsional Stroke before yield [rad]

%% Height between the joint's center and the force application point
h = 22.5e-3; % [m]
#+end_src

**** Effect of Shear
The applied force $F_x$ will induce some shear $d_{x,s}$ which is described by eqref:eq:test_joints_shear_displ with $k_s$ the shear stiffness of the flexible joint.

\begin{equation}\label{eq:test_joints_shear_displ}
  d_{x,s} = \frac{F_x}{k_s}
\end{equation}

The measured displacement $d_x$ is affected by the shear as shown in equation eqref:eq:test_joints_displ_shear.

\begin{equation}\label{eq:test_joints_displ_shear}
  d_x = d_{x,b} + d_{x,s} = h \tan\left( \frac{F_x \cdot h}{k_{R_y}} \right) + \frac{F_x}{k_s} \approx F_x \left( \frac{h^2}{k_{R_y}} + \frac{1}{k_s} \right)
\end{equation}

The estimated bending stiffness $k_{\text{est}}$ then depends on the shear stiffness eqref:eq:test_joints_error_shear.

\begin{equation}\label{eq:test_joints_error_shear}
  k_{R_y,\text{est}} = h^2 \frac{F_x}{d_x} \approx k_{R_y} \frac{1}{1 + \frac{k_{R_y}}{k_s h^2}} \approx k_{R_y} \Bigl( 1 - \underbrace{\frac{k_{R_y}}{k_s h^2}}_{\epsilon_{s}} \Bigl)
\end{equation}

With an estimated shear stiffness $k_s = 13\,N/\mu m$ from the finite element model and an height $h=25\,mm$, the estimation errors of the bending stiffness due to shear is $\epsilon_s < 0.1\,\%$

#+begin_src matlab
%% Estimated error due to shear
epsilon_s = 100*abs(1-1/(1 + kb/(ks*h^2))) % Error in %
#+end_src

**** Effect of load cell limited stiffness
As explained in the previous section, because the measurement of the flexible joint deflection is indirectly made with the encoder, errors will be made if the load cell experiences some compression.

Suppose the load cell has an internal stiffness $k_f$, the same reasoning that was made for the effect of shear can be applied here.
The estimation error of the bending stiffness due to the limited stiffness of the load cell is then described by eqref:eq:test_joints_error_load_cell_stiffness.

\begin{equation}\label{eq:test_joints_error_load_cell_stiffness}
  k_{R_y,\text{est}} = h^2 \frac{F_x}{d_x} \approx k_{R_y} \frac{1}{1 + \frac{k_{R_y}}{k_F h^2}} \approx k_{R_y} \Bigl( 1 - \underbrace{\frac{k_{R_y}}{k_F h^2}}_{\epsilon_f} \Bigl)
\end{equation}

With an estimated load cell stiffness of $k_f \approx 1\,N/\mu m$ (from the documentation), the errors due to the load cell limited stiffness is around $\epsilon_f = 1\,\%$.

#+begin_src matlab
%% Estimated error due to limited load cell stiffness
kF = 50/0.05e-3; % Estimated load cell stiffness [N/m]
epsilon_f = 100*abs(1-1/(1 + kb/(kF*h^2))); % Error in %
#+end_src

**** Estimation error due to height estimation error
Let's consider an error $\delta h$ in the estimation of the height $h$ as described by eqref:eq:test_joints_est_h_error.

\begin{equation}\label{eq:test_joints_est_h_error}
h_{\text{est}} = h + \delta h
\end{equation}

The computed bending stiffness will be eqref:eq:test_joints_stiffness_height_error.

\begin{equation}\label{eq:test_joints_stiffness_height_error}
  k_{R_y, \text{est}} \approx h_{\text{est}}^2 \frac{F_x}{d_x} \approx k_{R_y} \Bigl( 1 + \underbrace{2 \frac{\delta h}{h} + \frac{\delta h ^2}{h^2}}_{\epsilon_h} \Bigl)
\end{equation}

The height estimation is foreseen to be accurate to within $|\delta h| < 0.4\,mm$ which corresponds to a stiffness error $\epsilon_h < 3.5\,\%$.

**** Estimation error due to force and displacement sensors accuracy
The maximum error of the measured displacement due the encoder non-linearity is $40\,nm$.
As the measured displacement is foreseen to be $0.5\,mm$, the error $\epsilon_d$ due to the encoder non linearity is very small $\epsilon_d < 0.01\,\%$.

The accuracy of the load cell is specified at $1\,\%$ and therefore, estimation errors of the bending stiffness due to the limited load cell accuracy should be $\epsilon_F < 1\,\%$

**** Conclusion

The different sources of errors are summarized in Table ref:tab:test_joints_error_budget.
The most important source of error comes from estimation error of the distance between the flexible joint rotation axis and its contact with the force sensor.
An overall accuracy of $\approx 5\,\%$ can be expected with this measurement bench, which should be enough for a first estimation of the bending stiffness of the flexible joints.

#+name: tab:test_joints_error_budget
#+caption: Summary of the error budget for the estimation of the bending stiffness
#+attr_latex: :environment tabularx :width 0.4\linewidth :align lX
#+attr_latex: :center t :booktabs t
| *Effect*             | *Error*                 |
|----------------------+-------------------------|
| Shear effect         | $\epsilon_s < 0.1\,\%$  |
| Load cell compliance | $\epsilon_f = 1\,\%$    |
| Height error         | $\epsilon_h < 3.5\,\%$ |
| Displacement sensor  | $\epsilon_d < 0.01\,\%$ |
| Force sensor         | $\epsilon_F < 1\,\%$    |

* Bending Stiffness Measurement
:PROPERTIES:
:header-args:matlab+: :tangle ./matlab/test_joints_3_bending_stiff_meas.m
:END:
<<sec:test_joints_bending_stiffness_meas>>
** Introduction

A picture of the bench used to measure the X-bending stiffness of the flexible joints is shown in Figure ref:fig:test_joints_picture_bench_overview.
A closer view on the force sensor tip is shown in Figure ref:fig:test_joints_picture_bench_zoom.

#+name: fig:test_joints_picture_bench
#+caption: Caption with reference to sub figure (\subref{fig:fig_label_a})
#+attr_latex: :options [htbp]
#+begin_figure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_picture_bench_overview}Picture of the measurement bench}
#+attr_latex: :options {0.70\textwidth}
#+begin_subfigure
#+attr_latex: :height 5cm
[[file:figs/test_joints_picture_bench_overview.jpg]]
#+end_subfigure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_picture_bench_zoom}Zoom on the tip}
#+attr_latex: :options {0.29\textwidth}
#+begin_subfigure
#+attr_latex: :height 5cm
[[file:figs/test_joints_picture_bench_zoom.jpg]]
#+end_subfigure
#+end_figure

** 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 :noweb yes
<<m-init-path>>
#+end_src

#+begin_src matlab :eval no :noweb yes
<<m-init-path-tangle>>
#+end_src

#+begin_src matlab :noweb yes
<<m-init-other>>
#+end_src

** Load Cell Calibration
In order to estimate the measured errors of the load cell "FC2231", it is compared against another load cell[fn:5].
The two load cells are measured simultaneously while they are pushed against each other (see Figure ref:fig:test_joints_force_sensor_calib_picture).
The contact between the two load cells is well defined as one has a spherical interface while the other has a flat surface.

The measured forces are compared in Figure ref:fig:test_joints_force_sensor_calib_fit.
The gain mismatch between the two load cells is approximately $4\,\%$ which is higher than what was specified in the data-sheets.
However, the estimated non-linearity is bellow $1\,\%$ for forces between $0.5\,N$ and $5\,N$.

#+begin_src matlab
%% Force Sensor Calibration
% Load measurement data
load('calibration_force_sensor.mat', 't', 'F', 'Fc')

% Remove any offset such that they are both measuring no force when not in contact.
F  = F  - mean(F( t > 0.5 & t < 1.0)); % FC2231 [N]
Fc = Fc - mean(Fc(t > 0.5 & t < 1.0)); % XFL212R [N]

% Only get useful stroke
F  = F( t > 1.55 & t < 2.4);
Fc = Fc(t > 1.55 & t < 2.4);

% Make a line fit
fit_F = polyfit(Fc, F, 1);

% Estimate the gain mismatch
F_gain_mismatch = 100*(1 - fit_F(1)); % in %

% Estimate non-linearity of the sensors
F_non_linearity = 100*(F - (Fc*fit_F(1) + fit_F(2)))./F; % in %
#+end_src

#+begin_src matlab :exports none
%% Measured two forces and linear fit
figure;
hold on;
plot(Fc, F, 'k-', 'DisplayName', 'Raw Data');
plot(Fc([1,end]), Fc([1,end])*fit_F(1) + fit_F(2), '--', 'DisplayName', 'Line Fit');
hold off;
xlabel('XFL212R [N]'); ylabel('FC2231 [N]');
xlim([0.5,5.5]); ylim([0.5,5.5]);
legend('location', 'southeast', 'FontSize', 8);
#+end_src

#+begin_src matlab :tangle no :exports results :results file none
exportFig('figs/test_joints_force_sensor_calib_fit.pdf', 'width', 'half', 'height', 'normal');
#+end_src

#+name: fig:test_joints_force_sensor_calib
#+caption: Estimation of the load cell accuracy. A picture of the measurement bench is shown in (\subref{fig:test_joints_force_sensor_calib_picture}). Comparison of the two measured forces is made in (\subref{fig:test_joints_force_sensor_calib_fit})
#+attr_latex: :options [htbp]
#+begin_figure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_force_sensor_calib_picture}Zoom on the two force sensors in contact}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :height 5.5cm
[[file:figs/test_joints_force_sensor_calib_picture.jpg]]
#+end_subfigure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_force_sensor_calib_fit}Measured two force and linear fit}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :height 5.5cm
[[file:figs/test_joints_force_sensor_calib_fit.png]]
#+end_subfigure
#+end_figure

** Load Cell Stiffness
The objective of this measurement is to estimate the stiffness $k_F$ of the force sensor.
To do so, a stiff element (much stiffer than the estimated $k_F \approx 1\,N/\mu m$) is fixed in front of the force sensor as shown in Figure ref:fig:test_joints_meas_force_sensor_stiffness_picture.
Then, the force sensor is pushed again this stiff element while the force and the encoder displacement are measured.
Measured displacement as a function of the force is shown in Figure ref:fig:test_joints_force_sensor_stiffness_fit.
The load cell stiffness can then be estimated by computing a linear fit, and is found to be $k_F \approx 0.75\,N/\mu m$.

#+begin_src matlab
%% Estimaetd load cell stiffness
% Load measurement data
load('force_sensor_stiffness_meas.mat', 't', 'F', 'd')

% Remove offset
F  = F - mean(F(t > 0.5 & t < 1.0));

% Select important part of data
F  = F( t > 4.55 & t < 7.24);
d  = d( t > 4.55 & t < 7.24); d = d - d(1);
t  = t( t > 4.55 & t < 7.24);

% Linear fit
fit_k = polyfit(F, d, 1);
#+end_src

#+begin_src matlab :exports none
%% Displacement as a function of the measured force
figure;
hold on;
plot(F, 1e6*d, 'k-', 'DisplayName', 'Raw Data');
plot(F([1,end]), 1e6*(F([1,end])*fit_k(1) + fit_k(2)), '--', 'DisplayName', sprintf('Fit, $k_F \\approx %.2f N/\\mu m$', 1e-6/fit_k(1)));
hold off;
xlabel('Force [$N$]'); ylabel('Displacement [$\mu m$]');
xlim([0,45]); ylim([0,60]);
legend('location', 'southeast', 'FontSize', 8);
#+end_src

#+begin_src matlab :tangle no :exports results :results file none
exportFig('figs/test_joints_force_sensor_stiffness_fit.pdf', 'width', 'half', 'height', 'normal');
#+end_src

#+name: fig:test_joints_meas_force_sensor_stiffness
#+caption: Estimation of the load cell stiffness. Measurement setup is shown in (\subref{fig:test_joints_meas_force_sensor_stiffness_picture}). Measurement results is shown in (\subref{fig:test_joints_force_sensor_stiffness_fit}).
#+attr_latex: :options [htbp]
#+begin_figure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_meas_force_sensor_stiffness_picture}Picture of the measurement bench}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :height 5.5cm
[[file:figs/test_joints_meas_force_sensor_stiffness_picture.jpg]]
#+end_subfigure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_force_sensor_stiffness_fit}Measured displacement as a function of the force}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :height 5.5cm
[[file:figs/test_joints_force_sensor_stiffness_fit.png]]
#+end_subfigure
#+end_figure

** Bending Stiffness estimation
The actual stiffness measurement in now performed by manually moving the translation stage from a start position where the force sensor is not yet in contact with the flexible joint to a position where flexible joint is on its mechanical stop.

The measured force and displacement as a function of time are shown in Figure ref:fig:test_joints_meas_bend_time.
Three regions can be observed: first the force sensor tip is not in contact with the flexible joint and the measured force is zero, then the flexible joint deforms linearly, finally the flexible joint comes in contact with the mechanical stops.

The angular motion $\theta_{y}$ computed from the displacement $d_x$ is displacement as function of the measured torque $T_{y}$ in displayed in Figure ref:fig:test_joints_meas_F_d_lin_fit.
The bending stiffness of the flexible joint can be estimated by computing the slope of the curve in the linear regime (red dashed line) and is found to be $k_{R_y} = 4.4\,Nm/\text{rad}$.
The bending stroke can also be estimated as shown in Figure ref:fig:test_joints_meas_F_d_lin_fit and is found to be $\theta_{y,\text{max}} = 20.9\,\text{mrad}$.

#+begin_src matlab
%% Estimate the bending stiffness and stroke from the measurement - First Flexible joint
% Load Measured Data for first flexible joint
load('meas_stiff_flex_1_x.mat', 't', 'F', 'd');

% Start measurement at t = 0.2 s
d = d(t > 0.2);
F = F(t > 0.2);
t = t(t > 0.2); t = t - t(1);

% Zero the force
F = F - mean(F(t < 0.2));

% Find when the force sensor touches the flexible joint
i_l_start = find(F > 0.3, 1, 'first');

% Compute torque and angular displacement
h = 22.5e-3; % Height [m]
Tx = h * F; % Applied torque in [Nm]
thetax = atan2(d - d(i_l_start), h); % Measured angle in [rad]

% Find then the maximum torque is applied
[~, i_s_stop] = max(Tx);
% Linear region stops ~ when 90% of the stroke is reached
i_l_stop = find(thetax > 0.9*thetax(i_s_stop), 1, 'first');
% Mechanical "Stop" region start ~20Nmm before maximum torque is applied
i_s_start = find(Tx > max(Tx)-20e-3, 1, 'first');

% Linear fit in the "linear" region
fit_l = polyfit(Tx(i_l_start:i_l_stop), thetax(i_l_start:i_l_stop), 1);

% Linear fit in the "mechanical stop" region
fit_s = polyfit(Tx(i_s_start:i_s_stop), thetax(i_s_start:i_s_stop), 1);

% Reset displacement more precisely based on fit
thetax = thetax - fit_l(2);
fit_s(2) = fit_s(2) - fit_l(2);
fit_l(2) = 0;

%% Estimation of the bending stiffness
kRx_l = 1/fit_l(1); % Bending Stiffness [Nm/rad]
kRx_s = 1/fit_s(1); % Mechanical "Stop" Stiffness [Nm/rad]

%% Estimation of the bending stroke
% This is done by finding the intersection of the two linear fits
theta_max = fit_l(1)*fit_s(2)/(fit_l(1) - fit_s(1)); % Maximum angular stroke [rad]
Tx_at_theta_max = (fit_s(2) - fit_l(2))/(fit_l(1) - fit_s(1));
#+end_src

#+begin_src matlab :exports none :results none
%% Measured force and displacement as a function of time
figure;
yyaxis left
hold on;
plot(t, F);
plot(0.8*cos(0:0.01:2*pi)+0.8, ...
     2.8*sin(0:0.01:2*pi)-1, 'k--', 'HandleVisibility', 'off');
text(1.8, -1.2, sprintf('Not in\ncontact'), 'horizontalalignment', 'left');
plot(0.4*cos(0:0.01:2*pi)+3, ...
     1.1*sin(0:0.01:2*pi)+4.8, 'k--');
text(3.5, 4.8, sprintf('Mechanical\nStop'), 'horizontalalignment', 'left');
hold off;
ylabel('Force $F_y$ [N]');
ylim([-4, 6])
ylimr = get(gca,'Ylim');

yyaxis right
plot(t, 1e3*d);
xlabel('Time [s]');
ylabel('Displacement $d_y$ [mm]');
xlim([0,5]);
% Make the force and displacement superimpose
ylim([0.364 - 4*(0.8315-0.364)/4.095, 0.364 + 6*(0.8315-0.364)/4.095])
#+end_src

#+begin_src matlab :tangle no :exports results :results file none
exportFig('figs/test_joints_meas_bend_time.pdf', 'width', 'half', 'height', 'normal');
#+end_src

#+begin_src matlab :exports none
% Regions where to plot the fitted data
Tx_l_fit = [0, Tx_at_theta_max];
Tx_s_fit = [Tx_at_theta_max, Tx(i_s_stop)];

figure;
hold on;
plot(Tx(1:i_s_stop), 1e3*thetax(1:i_s_stop), '-k', 'DisplayName', 'Raw data')
plot(Tx_l_fit, 1e3*(Tx_l_fit*fit_l(1) + fit_l(2)), '--', 'DisplayName', sprintf('$k_{R_x} = %.1f$ Nm/rad', kRx_l))
plot(Tx_s_fit, 1e3*(Tx_s_fit*fit_s(1) + fit_s(2)), '--', 'DisplayName', sprintf('$k_{R_x,stop} = %.0f$ Nm/rad', kRx_s))
plot([0, Tx_at_theta_max], [1e3*theta_max, 1e3*theta_max], 'k--', 'HandleVisibility', 'off')
plot([0, Tx_at_theta_max], [0, 0], 'k--', 'HandleVisibility', 'off')
anArrow = annotation('doublearrow', 'LineWidth', 0.5);
anArrow.Parent = gca;
anArrow.Position = [0.05, 0, 0, 1e3*fit_l(1)*fit_s(2)/(fit_l(1) - fit_s(1))];
text(0.052, 0.4*1e3*fit_l(1)*fit_s(2)/(fit_l(1) - fit_s(1)), sprintf('$\\theta_{x,\\max} = %.1f$ mrad', 1e3*theta_max), 'horizontalalignment', 'left');
hold off;
xlabel('Torque $T_x$ [Nm]');
ylabel('Angle $\theta_x$ [mrad]');
xlim([0, 0.15]);
ylim([-5,25]);
leg = legend('location', 'southeast', 'FontSize', 8);
leg.ItemTokenSize(1) = 15;
#+end_src

#+begin_src matlab :tangle no :exports results :results file none
exportFig('figs/test_joints_meas_F_d_lin_fit.pdf', 'width', 'half', 'height', 'normal');
#+end_src

#+name: fig:test_joints_meas_example
#+caption: Results obtained on the first flexible joint. Measured force and displacement are shown in (\subref{fig:test_joints_meas_bend_time}). The estimated angular displacement $\theta_x$ as a function of the estimated applied torque $T_{x}$ is shown in (\subref{fig:test_joints_meas_F_d_lin_fit}). The bending stiffness $k_{R_x}$ of the flexible joint can be estimated by computing a best linear fit (red dashed line).
#+attr_latex: :options [htbp]
#+begin_figure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_meas_bend_time}Force and displacement measured as a function of time}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :height 5.3cm
[[file:figs/test_joints_meas_bend_time.png]]
#+end_subfigure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_meas_F_d_lin_fit}Angular displacement measured as a function of the applied torque}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :height 5.3cm
[[file:figs/test_joints_meas_F_d_lin_fit.png]]
#+end_subfigure
#+end_figure

** Measured flexible joint stiffnesses
The same measurement is performed for all the 16 flexible joints, both in the $x$ and $y$ directions.
The measured angular motion as a function of the applied torque are shown in Figure ref:fig:test_joints_meas_bending_all_raw_data for all the 16 flexible joints.
This gives a first idea of the dispersion of the measured bending stiffnesses (i.e. slope of the linear region) and of the angular stroke.

An histogram of the measured bending stiffnesses is show in Figure ref:fig:test_joints_bend_stiff_hist.
Most of the bending stiffnesses are between $4.6\,Nm/rad$ and $5.0\,Nm/rad$.

#+begin_src matlab :exports none
%% Measure the bending stiffness and Stroke for all the flexible joints
figure;
hold on;

%% Start with the X-bending
% Initialize variables
Rx = zeros(1,16); % Bending stiffnesses [Nm/rad]
kSx = zeros(1,16); % Bending stiffnesses at "stop" [Nm/rad]
Rmx = zeros(1,16); % Bending stroke [rad]

for i = 1:16
    % Load the data
    load(sprintf('meas_stiff_flex_%i_x.mat', i), 't', 'F', 'd');

    % Start measurement at t = 0.2 s
    d = d(t > 0.2);
    F = F(t > 0.2);
    t = t(t > 0.2); t = t - t(1);

    % Zero the force
    F = F - mean(F(t < 0.2));

    % Find when the force sensor touches the flexible joint
    i_l_start = find(F > 0.3, 1, 'first');

    % Zero the displacement when it comes in contact
    d = d - d(i_l_start);

    % Compute torque and angular displacement
    h = 22.5e-3; % Height [m]
    Tx = h * F; % Applied torque in [Nm]
    thetax = atan2(d, h); % Measured angle in [rad]

    % Find then the maximum torque is applied
    [~, i_s_stop] = max(Tx);
    % Linear region stops ~ when 90% of the stroke is reached
    i_l_stop = find(thetax > 0.9*thetax(i_s_stop), 1, 'first');
    % Mechanical "Stop" region start ~20Nmm before maximum torque is applied
    i_s_start = find(Tx > max(Tx)-20e-3, 1, 'first');

    % Linear fit in the "linear" region
    fit_l = polyfit(Tx(i_l_start:i_l_stop), thetax(i_l_start:i_l_stop), 1);

    % Linear fit in the "mechanical stop" region
    fit_s = polyfit(Tx(i_s_start:i_s_stop), thetax(i_s_start:i_s_stop), 1);

    % Reset displacement more precisely based on fit
    thetax = thetax - fit_l(2);
    fit_s(2) = fit_s(2) - fit_l(2);
    fit_l(2) = 0;

    % Estimation of the bending stiffness and bending stroke
    kRx(i) = 1/fit_l(1); % Bending Stiffness [Nm/rad]
    kSx(i) = 1/fit_s(1); % Mechanical "Stop" Stiffness [Nm/rad]
    Rmx(i) = fit_l(1)*fit_s(2)/(fit_l(1) - fit_s(1)); % Maximum angular stroke [rad]

    if i == 1
        plot(Tx(1:10:i_s_stop), 1e3*thetax(1:10:i_s_stop), '-', 'color', [colors(1,:), 0.4], ...
            'DisplayName', '$k_{R_x}$')
    else
        plot(Tx(1:10:i_s_stop), 1e3*thetax(1:10:i_s_stop), '-', 'color', [colors(1,:), 0.4], ...
            'HandleVisibility', 'off')
    end
end

%% Continue with the Y-bending
% Initialize variables
kRy = zeros(1,16); % Bending stiffnesses [Nm/rad]
kSy = zeros(1,16); % Bending stiffnesses at "stop" [Nm/rad]
Rmy = zeros(1,16); % Bending stroke [rad]

for i = 1:16
    % Load the data
    load(sprintf('meas_stiff_flex_%i_y.mat', i), 't', 'F', 'd');

    % Start measurement at t = 0.2 s
    d = d(t > 0.2);
    F = F(t > 0.2);
    t = t(t > 0.2); t = t - t(1);

    % Zero the force
    F = F - mean(F(t < 0.2));

    % Find when the force sensor touches the flexible joint
    i_l_start = find(F > 0.3, 1, 'first');

    % Zero the displacement when it comes in contact
    d = d - d(i_l_start);

    % Compute torque and angular displacement
    h = 22.5e-3; % Height [m]
    Ty = h * F; % Applied torque in [Nm]
    thetay = atan2(d, h); % Measured angle in [rad]

    % Find then the maximum torque is applied
    [~, i_s_stop] = max(Ty);
    % Linear region stops ~ when 90% of the stroke is reached
    i_l_stop = find(thetay > 0.9*thetay(i_s_stop), 1, 'first');
    % Mechanical "Stop" region start ~20Nmm before maximum torque is applied
    i_s_start = find(Ty > max(Ty)-20e-3, 1, 'first');

    % Linear fit in the "linear" region
    fit_l = polyfit(Ty(i_l_start:i_l_stop), thetay(i_l_start:i_l_stop), 1);

    % Linear fit in the "mechanical stop" region
    fit_s = polyfit(Ty(i_s_start:i_s_stop), thetay(i_s_start:i_s_stop), 1);

    % Reset displacement more precisely based on fit
    thetay = thetay - fit_l(2);
    fit_s(2) = fit_s(2) - fit_l(2);
    fit_l(2) = 0;

    % Estimation of the bending stiffness and bending stroke
    kRy(i) = 1/fit_l(1); % Bending Stiffness [Nm/rad]
    kSy(i) = 1/fit_s(1); % Mechanical "Stop" Stiffness [Nm/rad]
    Rmy(i) = fit_l(1)*fit_s(2)/(fit_l(1) - fit_s(1)); % Maximum angular stroke [rad]

    if i == 1
        plot(Ty(1:10:i_s_stop), 1e3*thetay(1:10:i_s_stop), '-', 'color', [colors(2,:), 0.4], ...
            'DisplayName', '$k_{R_y}$')
    else
        plot(Ty(1:10:i_s_stop), 1e3*thetay(1:10:i_s_stop), '-', 'color', [colors(2,:), 0.4], ...
            'HandleVisibility', 'off')
    end
end

xlabel('Torque $T$ [Nm]');
ylabel('Angle $\theta$ [mrad]');
xlim([0, 0.15]);
ylim([-5,25]);
legend('location', 'southeast', 'FontSize', 8);
#+end_src

#+begin_src matlab :tangle no :exports results :results file replace
exportFig('figs/test_joints_meas_bending_all_raw_data.pdf', 'width', 'half', 'height', 'normal');
#+end_src

#+begin_src matlab :exports none
figure;
histogram([kRx, kRy], [4:0.2:5])
xlabel('Bending stiffness [Nm/rad]')
xticks([4:0.2:5])
#+end_src

#+begin_src matlab :tangle no :exports results :results file replace
exportFig('figs/test_joints_bend_stiff_hist.pdf', 'width', 'half', 'height', 'normal');
#+end_src

#+name: fig:test_joints_meas_bending_results
#+caption: Result of measured $k_{R_x}$ and $k_{R_y}$ stiffnesses for all the 16 flexible joints. Raw data are shown in (\subref{fig:test_joints_meas_bending_all_raw_data}). An histogram of the measured stiffnesses is shown in (\subref{fig:test_joints_bend_stiff_hist})
#+attr_latex: :options [htbp]
#+begin_figure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_meas_bending_all_raw_data}Measured torque and angular motion for all the flexible joints}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :height 5.3cm
[[file:figs/test_joints_meas_bending_all_raw_data.png]]
#+end_subfigure
#+attr_latex: :caption \subcaption{\label{fig:test_joints_bend_stiff_hist}Histogram of the measured bending stiffness in the x and y directions}
#+attr_latex: :options {0.49\textwidth}
#+begin_subfigure
#+attr_latex: :height 5.3cm
[[file:figs/test_joints_bend_stiff_hist.png]]
#+end_subfigure
#+end_figure

** Conclusion
:PROPERTIES:
:UNNUMBERED: t
:END:

The measured bending stiffness and bending stroke of the flexible joints are very close to the estimated one using a Finite Element Model.

The characteristics of all the flexible joints are also quite close to each other.
This should allow us to model them with unique parameters.

* Conclusion
<<sec:test_joints_conclusion>>

* Bibliography                                                        :ignore:
#+latex: \printbibliography[heading=bibintoc,title={Bibliography}]

* Helping Functions                                                 :noexport:
** Initialize Path
#+NAME: m-init-path
#+BEGIN_SRC matlab
%% Path for functions, data and scripts
addpath('./matlab/mat/'); % Path for data
addpath('./matlab/');     % Path for scripts
#+END_SRC

#+NAME: m-init-path-tangle
#+BEGIN_SRC matlab
%% Path for functions, data and scripts
addpath('./mat/'); % Path for data
#+END_SRC

** Initialize other elements
#+NAME: m-init-other
#+BEGIN_SRC matlab
%% Colors for the figures
colors = colororder;
#+END_SRC

* Footnotes

[fn:5]XFL212R-50N from TE Connectivity. Measurement range is $50\,N$. Specified accuracy is $1\,\%$ of the full range
[fn:4]Resolute\texttrademark{} encoder with $1\,nm$ resolution and $\pm 40\,nm$ maximum non-linearity
[fn:3]V-408 PIMag\textsuperscript{\textregistered} linear stage is used. Crossed roller are used to guide the motion.
[fn:2]The load cell is FC22 from TE Connectivity. Measurement range is $50\,N$. Specified accuracy is $1\,\%$ of the full range
[fn:1]The alloy used is called /F16PH/, also refereed as "1.4542"
