\documentclass[10pt,a4paper]{article}
\usepackage[margin=1.5cm]{geometry} %other geomentry
\setlength{\parindent}{0cm} %other indent of paragraphs
\usepackage[utf8]{inputenc}%needed for äöüàéè etc.
\usepackage[T1]{fontenc} %needed for äöüàéè etc. read http://de.wikipedia.org/wiki/LaTeX
\usepackage[bookmarks]{hyperref} %adds commands as \url for external links
\usepackage{fancyvrb} %Verbatim
\usepackage[abspath]{currfile} %%works only with PDFLaTeX-argument -recorder 
\usepackage{fancyhdr} %define new headers and footers
\pagestyle{fancy}
\fancyhead{} % sets header to nothing (instead of chapter)
\renewcommand{\headrulewidth}{0pt}%remove header line
\fancyfoot[R]{\currfilename}
\input{|"/home/zamofing_t/Documents/doc-git/git2texInfo.sh"}%works only with PDFLaTeX-argument -shell-escape
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{amsmath}
\renewcommand{\deg}{$^\circ$}

\title{Tuning/modeling fast stages of ESB-MX}
\author{Thierry Zamofing}
\usepackage{datetime}
\date{\today, \currenttime\\
\texttt{git:\gitAbrHash, ver:\gitVerNo{ }\gitStatus}} 


\begin{document}
\maketitle 
\tableofcontents
\section{Introduction}
This document describes the tuning and modeling process of the ESB-MX fast stages.

\section{Measurements}
The tool used to record data of the fast stages is the bode plots is MXTuning.py, a script specially developed to record system responses. The main cal to collect all data was:\\
\verb|./MXTuning.py --dir MXTuning/19_01_29 --mode 64|\\
The used frequencies are:  20 kHz Phase, 5 kHz Servo, 6.25MHz AdcAmp.\\
This results in 50us PhaseTime and 0.2ms ServoTime.
According to the amplifier specs (Power Brick LV User Manual.pdf p.19). a DAC Value of  $32737=2^{15}$ corresponds to 33.85A current. So 1 \verb|curr_bit| is $33.85/32737A =1.034mA$.


The Parker stages are configured to contCur=800mA ,peakCur=2400mA. Ste Specs of the D11 stage are 0.8Amp RMS (producing 4N force)  and 2.4Amp peak.

\subsection{Measure Current Step}
\verb|MXTuning.py –mode 1| $\rightarrow$ \verb|identifyFxFyStage.m|\\

\includegraphics[scale=.5]{../../matlab/figures/currstep_1.eps} 
\includegraphics[scale=.5]{/home/zamofing_t/Documents/doc-ext/DeltaTau/UsrMan257.png} 
The current step looks similar for both motors.
The transfer function is: $k \cdot {w_0}^2/({w_0}^2+2 \cdot damp \cdot w_0 \cdot s+s^2)$\\
rise time $(0\rightarrow 100\%)$ ca. 0.4ms\\
rise time: \url{https://nptel.ac.in/courses/101108056/module7/lecture20.pdf}\\
$\rightarrow$ \verb|1/(w0*np.sqrt(1-0.75**2))*(np.pi/2+np.arcsin(0.75))|\\
The loop parameters are:\\
IiGain=5, IpfGain=8, IpbGain=8


\subsection{Measure Open Loop}

The frequency response has been measured with chirps at different amplitudes  and frequency regions. The yellow line is averaged measurement data. The black line is the approximated model. The diagram shows \verb|curr_bits| (ca.1mA) to \verb|ActPos| (in um) transfer function.\\
The images have been generated with 
\verb|./MXTuning.py --dir MXTuning/19_01_29 --mode 32|.\\

\begin{figure}[h]
\includegraphics[scale=.45]{../MXTuning/19_01_29/img/bode_model_plot0.eps} 
\includegraphics[scale=.45]{../MXTuning/19_01_29/img/bode_model_plot2.eps} 
\caption{open loop of motor 1 and 2}
\end{figure}


\emph{Motor 1 (fy) has a better response, as expected because it has less mass to move.}\\

\hbox{
\parbox[t]{5cm}{
Motor 1:\\
0dB at 20.28Hz\\	
10 Hz: 9.63 dB -134\deg	\\
100Hz: -28.5dB -191.7\deg\\
resonances 198 Hz	\\
}

\parbox[t]{6cm}{
Motor 2\\
0dB at 12.39Hz\\
10 Hz: 4.68 dB -162\deg\\
100 Hz: -38.15 dB -187.5\deg\\
resonances 60Hz,142Hz,414Hz,231Hz\\
}
}

\subsection{Closed Loop}
\subsubsection{Deltatau schematics}

\includegraphics[scale=.7]{../../../../../../doc-ext/DeltaTau/UsrMan290.png}

\includegraphics[scale=.2]{../../../../../../doc-ext/DeltaTau/ServoBlockDiag.png}
\\

Closed loops have been measured with the following control loop settings.
\begin{verbatim}
motor_servo(mot=1,Kp=25,Kvfb=400,Ki=0.02,Kvff=350,Kaff=5000,MaxInt=1000)
motor_servo(mot=2,Kp=22,Kvfb=350,Ki=0.02,Kvff=240,Kaff=1500,MaxInt=1000)
\end{verbatim}



\subsubsection{chirp sine closed loop}


Bode plot and chirp input(blue) and output(green)
The parameters for that sweep is:\\
\verb| amp: 5, minFrq: 10, maxFrq: 220, ts: 0.0002, tSec: 20|
 


\begin{figure}[h!]
\includegraphics[scale=.45]{../MXTuning/19_01_29/img/chirp_all_1b0.eps} 
\includegraphics[scale=.45]{../MXTuning/19_01_29/img/chirp_all_1b1.eps} 
\caption{DesPos->ActPos of motor 1}
\end{figure}

\begin{figure}[h!]
\includegraphics[scale=.45]{../MXTuning/19_01_29/img/chirp_all_2b0.eps} 
\includegraphics[scale=.45]{../MXTuning/19_01_29/img/chirp_all_2b1.eps} 
\caption{DesPos->ActPos of motor 2}
\end{figure}


\begin{figure}[h!]
\includegraphics[scale=.45]{../MXTuning/19_01_29/img/chirp_all_1b2.eps} 
\includegraphics[scale=.45]{../MXTuning/19_01_29/img/chirp_all_1b3.eps} 
\caption{DesPos->IqCmd of motor 1}
\end{figure}

\begin{figure}[h!]
\includegraphics[scale=.45]{../MXTuning/19_01_29/img/chirp_all_2b2.eps} 
\includegraphics[scale=.45]{../MXTuning/19_01_29/img/chirp_all_2b3.eps} 
\caption{DesPos->IqCmd  of motor 2}
\end{figure}


Moving 5um with frequencies from 10 to 220Hz\\
$\rightarrow$ at frequencies above 200 Hz, the current increses up to 2 amps, and the the following error kicks in\\
$\rightarrow$ The response becomes bad above 15Hz (about 3dB)\\
$\rightarrow$ Moving 1um at 1kHz seems to consume a current of about 2 amps.\\


%→n times higher mass → n times lower frequency for same amplitude response
%→n times higher frequency → n times higher velocity → n² times more acceleration==current
%1um at 12Hz with 1 mA →with 2000mA → sqrt(2000)*12Hz=540Hz
%
%A very simplified transfer function of the system is G(s)=k/s²
\newpage 
\section{Modeling the system}
\subsection{Electrical model}
\begin{figure}[h!]
\centering
\includegraphics[scale=.45]{model1.eps} 
\includegraphics[scale=.6]{model2.eps} 
\caption{electrical model}
\end{figure}

Basic formulas: $U=R \cdot I$ \hspace{.5cm}
$U=L \cdot \frac{di}{dt}$\\

Solving in Laplace space:\\
$iqVolts=(R+Ls)\cdot iqMeas$\\
$s \cdot iqMeas =\frac{1}{L}iqVolts - \frac{R}{L}iqMeas$\\


\subsection{Mechanical model}

\begin{figure}[h!]
\centering
\includegraphics[scale=.45]{model3.eps} 
\caption{mechanical model}
\end{figure}

Input: Force $u(t)=F$\\
Output: Position $y(t)=x_1(t)$\\
total mass $m=m_1+m_2+\ldots+m_n$\\
damping: $d_1 \ldots d_n$\\
springs: $k_1 \ldots k_n$\\

\eqref{mech1} shows the mechanical differential equations:

\begin{equation}
\begin{aligned}
 m_1\ddot{x}_1 = & u(t) -k_1x_1-d_1\dot{x}_1\\
                     & + k_2x_2+d_2\dot{x}_2
                       + k_3x_3+d_3\dot{x}_3
                       + k_4x_4+d_4\dot{x}_4\\
 m_2\ddot{x}_2= & -k_2x_2-d_2\dot{x}_2\\
 m_3\ddot{x}_3= & -k_3x_3-d_3\dot{x}_3\\
 m_4\ddot{x}_4= & -k_4x_4-d_4\dot{x}_4\\
\end{aligned}\label{mech1}
\end{equation}

\begin{equation}
\begin{aligned}
\dot{x} = Ax + Bu\\
y = Cx + Du
\end{aligned}\label{mech2}
\end{equation}

\eqref{mech2} are the general input output equations in matrix form with x and A defines as \eqref{mech3}:

\begin{equation}
x=
\begin{bmatrix}
x_1\\
\dot{x}_1\\
x_2\\
\dot{x}_2\\
x_3\\
\dot{x}_3\\
x_4\\
\dot{x}_4\\
\end{bmatrix},\quad
\dot{x}=
\begin{bmatrix}
\dot{x}_1\\
\ddot{x}_1\\
\dot{x}_2\\
\ddot{x}_2\\
\dot{x}_3\\
\ddot{x}_3\\
\dot{x}_4\\
\ddot{x}_4\\
\end{bmatrix},\quad
A=
\begin{bmatrix}
0 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\
-\frac{k_1}{m_1} & -\frac{d_1}{m_1} & -\frac{k_2}{m_1} & -\frac{d_2}{m_1} & -\frac{k_3}{m_1} & -\frac{d_3}{m_1} & -\frac{k_4}{m_1} & -\frac{d_4}{m_1}\\

0 & 0 & 0 & 1 & 0 & 0 & 0 & 0\\
0 & 0 & -\frac{k_2}{m_1} & -\frac{d_2}{m_2} & 0 & 0 & 0 & 0 \\

0 & 0 & 0 & 0 & 0 & 1 & 0 & 0\\
0 & 0 & 0 & 0 & -\frac{k_3}{m_1} & -\frac{d_3}{m_3} & 0 & 0 \\

0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\
0 & 0 & 0 & 0 & 0 & 0 & -\frac{k_4}{m_1} & -\frac{d_4}{m_4} \\
\end{bmatrix},\quad
B=\begin{bmatrix}
\frac{1}{m} \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0\\
\end{bmatrix}
%,\quad
%C=\begin{bmatrix}
%\1 \\ 1 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0\\
%\end{bmatrix},\quad
%D=0
\label{mech2}
\end{equation}



\section{Simulink/MATLAB simulations}

Simulink simulation \verb|stage_closed_loop.slx| with \verb|ServoDeltaTau_z G(z)| showed similar response
Therefore the model seems good enough



%proces compiled as job \texttt{\jobname} from the file \texttt{\currfileabspath}\\
%\eject
%
%hyperref package sample
%\url{http://stackoverflow.com/questions/9845292/converting-matlab-to-python}\\
%
%fancyvrb package sample
%\begin{Verbatim}[frame=single]
%Verbatim Verbatim Verbatim
%Verbatim
%         Verbatim
%\end{Verbatim}
\end{document}