\input{ccs_gyak_defs}
\author{Crane model}

\begin{document}
\maketitle

\begin{minipage}{0.64\textwidth}
    \section[Crane model (rakodó darumodell)]{Crane model \color{blue} (rakodó darumodell)}
    Consider the following mathematical model of a crane machine.
    For the sake of simplicity, we restrict the motion of the carried weight to the $(y,z)$ plane.
    In the model we identify the following time-dependent (state-) variables:
    \begin{itemize}[itemsep=0pt,topsep=3pt,leftmargin=0.7cm]
        \item $R = R(t)$ denotes the actual position of the car on the rail,
        \item $L = L(t)$ denotes the actual length of the wire,
        \item $\theta = \theta(t)$ denotes the actual angle of the wire with the vertical.
    \end{itemize}
    \vspace*{5pt}
\end{minipage}\hfill
\begin{minipage}{0.34\textwidth}
    \includegraphics[width=\textwidth]{fig/crane/crane_fig.pdf}
    Figure \refstepcounter{figure}\thefigure. {Kinetic model of the crane machine.}
    \label{fig:crane}
\end{minipage}

Know parameters (constants):
\begin{itemize}[itemsep=0pt,topsep=3pt,leftmargin=0.7cm]
    \item $\rho$ is the radius of the pulley\footnote{sheave or drum: tekercselő csiga vagy tekercselő dob}.
    In the geometrical expression the radius of the pulley is neglected, eg. if the angle is $\theta = 0$ and the position of the car is $R = 0$ than the position of the weight along the $y$ axis is considered to be $R$.
    \item $M$ is the mass of the car
    \item $m$ is the mass of the lifted weight
    \item $J$ is the moment of inertia\footnote{tehetetlenségi nyomaték} of the pulley.
\end{itemize}

Manipulate inputs are the following:
\begin{itemize}[itemsep=0pt,topsep=3pt,leftmargin=0.7cm]
    \item $F$ is the driving force applied to the car
    \item $T$ is the torque applied to the pulley
\end{itemize}
Measured quantities: $R(t)$ and $L(t)$.


{
    \color{blue}
    Tekintse az ábrán látható rakodó darut.
    Az egyszerűség kedvéért a teher mozgását az $(y,z)$ függőleges síkra korlátozzuk. Jelölje $R$ a sínen mozgó
    kocsi $y$ irányú pozícióját, $L$ a sodrony hosszát és $\theta$ a sodrony függőlegessel bezárt szögét.
    Ismert geometriai paraméter a sodronyt tekercselő dob sugara, melyet $\rho$-val jelöltünk.
    (A geometriai összefüggésekben a dob sugarát elhanyagoljuk, azaz $\theta = 0$ esetben $R = y$).
    Szintén ismertek az inercia paraméterek: $M$ a kocsi
    tömege; $m$ a mozgatott teher tömege és $J$ a sodronyt tekercselő hajtás és a dob tehetetlenségi nyomatéka.

    A beavatkozó jelek:
    \begin{itemize}
        \item $F$ a kocsira ható erő
        \item $T$ a sodronyt tekercselő dobra ható forgatónyomaték
    \end{itemize}
    A mért kimeneti változók: $R$ és $L$.
}

The system's kinetic energy is a composition of the followings:
\begin{enumerate}[itemsep=0pt,topsep=3pt,leftmargin=0.7cm]
    \item the kinetic energy of $M$ is $T_M = \displaystyle \frac{M \dot R^2}{2}$
    \item the kinetic energy of $m$ is $T_m = \displaystyle \frac{m v^2}{2}$
    \item the kinetic energy of the pulley is $T_J = \displaystyle \frac{J \dot \theta^2}{2} = \displaystyle \frac{J \dot L^2}{2 \rho^2}$
\end{enumerate}

The system's potential energy is the potential energy of $m$, that is $V_m = m g L (1 - \cos \theta)$.

The system's Lagrangian is
\begin{align}
    \begin{aligned}
        \mathcal L = T - V = \frac{M \dot R^2}{2} + \frac{m v^2}{2} + \frac{J \dot L^2}{2 \rho^2} - m g L (1 - \cos \theta)
    \end{aligned}
\end{align}

The velocity $\vec v$ of $m$ has the following components (see Figure \ref{fig:crane}):
\begin{align}
    \begin{aligned}
        \vec v = L \dot \theta \vec e_t + \dot R \vec e_x + \dot L \vec e_n
    \end{aligned}
\end{align}
Since $\vec e_t \perp \vec e_n$, the square of the norm of $\vec v$ can be computed in the following way
\begin{align}
    \begin{aligned}
        v &= \norm{\vec v}^2
        = \dotprod{\vec v, \vec v}
        = L^2 \dot \theta^2 + \dot R^2 + \dot L^2 + 2 L \dot \theta \dot R \dotprod{\vec e_t, \vec e_x}
        + 2 \dot R \dot L \dotprod{\vec e_n, \vec e_x} \\
        &= L^2 \dot \theta^2 + \dot R^2 + \dot L^2 + 2 L \dot \theta \dot R \cos{\theta}
        + 2 \dot R \dot L \cos\qty(\frac{\pi}{2} - \theta) \\
        &= L^2 \dot \theta^2 + \dot R^2 + \dot L^2 + 2 L \dot \theta \dot R \cos{\theta}
        + 2 \dot R \dot L \sin\theta
    \end{aligned}
\end{align}

Therefore, the Lagrangian can be written in the following form:
\begin{align}
    \begin{aligned}
        \mathcal L
        % &= \frac{M \dot R^2}{2}
        % + \frac{m L^2 \dot \theta^2}2 + \frac{m \dot R^2}2 + \frac{m  \dot L^2}2
        % + m L \dot \theta \dot R \cos{\theta}
        % + m \dot R \dot L \sin\theta
        % + \frac{J \dot L^2}{2 \rho^2} - m g L (1 - \cos \theta) \\
        &= \frac{(M + m) \dot R^2}{2}
        + \frac{m L^2 \dot \theta^2}2 + \frac{m  \dot L^2}2
        + m L \dot \theta \dot R \cos{\theta}
        + m \dot R \dot L \sin\theta
        + \frac{J \dot L^2}{2 \rho^2} - m g L (1 - \cos \theta) \\
    \end{aligned}
\end{align}

The Euler-Lagrange equations are the following:
\begin{align}
    &\begin{aligned}
        0 &= \dv{t}\pdv{\mathcal L}{\dot R} - \pdv{\mathcal L}{R}
        = \dv{t}\qty( (M + m) \dot R + m L \dot \theta \cos \theta + m \dot L \sin \theta ) \\
        &= (M + m) \ddot R + m \dot L \dot \theta \cos \theta
        + m L \ddot \theta \cos \theta - m L \dot \theta^2 \sin \theta
        + m \ddot L \sin \theta + m \dot L \dot \theta \cos \theta \\
        &= (M + m) \ddot R + 2 m \dot L \dot \theta \cos \theta
        + m L \ddot \theta \cos \theta - m L \dot \theta^2 \sin \theta
        + m \ddot L \sin \theta
    \end{aligned} \tag{A1}
    \shortintertext{Second equation:}
    &\begin{aligned}
        0 &= \dv{t}\pdv{\mathcal L}{\dot L} - \pdv{\mathcal L}{L}
        = \dv{t}\qty( m \dot L + m \dot R \sin \theta + \frac{J \dot L}{\rho^2}) - m L \dot \theta^2
        - m \dot \theta \dot R \cos \theta + m g (1 - \cos \vartheta) \\
        &= \qty(m + \frac{J}{\rho^2}) \ddot L + m \ddot R \sin \theta
        + \uwaver{m \dot R \dot \theta \cos \theta}
        - m L \dot \theta^2
        - \uwaver{m \dot \theta \dot R \cos \theta}
        + m g (1 - \cos \vartheta) \\
        &= \qty(m + \frac{J}{\rho^2}) \ddot L + m \ddot R \sin \theta
        - m L \dot \theta^2
        + m g (1 - \cos \vartheta) \\
    \end{aligned} \tag{A2}
    \shortintertext{Third equation:}
    &\begin{aligned}
        0 &= \dv{t}\pdv{\mathcal L}{\dot \theta} - \pdv{\mathcal L}{\theta}
        = \dv{t}\qty( m L^2 \dot \theta + m L \dot R \cos \theta )
        + m L \dot \theta \dot R \sin \theta - m \dot R \dot L \cos \theta + m g L \sin \theta \\
        &= 2 m L \dot L \dot \theta + m L^2 \ddot \theta
        + \uwaveb{m \dot L \dot R \cos \theta}
        + m L \ddot R \cos \theta
        - \uwaver{m L \dot R \dot \theta \sin \theta}
        + \uwaver{m L \dot \theta \dot R \sin \theta}
        - \uwaveb{m \dot R \dot L \cos \theta}
        + m g L \sin \theta \\
        &= 2 m L \dot L \dot \theta + m L^2 \ddot \theta
        + m L \ddot R \cos \theta
        + m g L \sin \theta
    \end{aligned} \nonumber
    \shortintertext{Dividing by $L$ we get: }
    &\begin{aligned}
        0 &= 2 m \dot L \dot \theta + m L \ddot \theta
        + m \ddot R \cos \theta
        + m g \sin \theta
    \end{aligned} \tag{A3}
\end{align}

In equilibrium point the torque is $T_0 = m g \rho$. Let $T = T_0 + \tau$ be the net torque.
Furthermore, we consider an $F$ external force applying to $M$.
Therefore, the equations of motion could be written as follows:
\begin{align} \label{eq:basic_eqns}
    \begin{aligned}
        F &= (M + m) \ddot R + 2 m \dot L \dot \theta \cos \theta
        + m L \ddot \theta \cos \theta - m L \dot \theta^2 \sin \theta
        + m \ddot L \sin \theta
        \\
        -\frac{T}{\rho} = -\frac{m g + \tau}{\rho}
        &= \qty(m + \frac{J}{\rho^2}) \ddot L + m \ddot R \sin \theta
        - m L \dot \theta^2
        - m g \cos \vartheta
        \\
        0 &= 2 m \dot L \dot \theta + m L \ddot \theta
        + m \ddot R \cos \theta
        + m g \sin \theta
    \end{aligned}
\end{align}

% \begin{align} \label{eq:basic_eqns}
%     \begin{aligned}
%         m (\ddot R + \ddot L \sin \theta + 2 \dot L \dot \theta \cos \theta + L \ddot \theta \cos \theta - L \dot \theta^2 \sin \theta) + M \ddot R = F
%         \\
%         m (\ddot R \sin \theta + \ddot L) + \frac{J}{\rho^2} \ddot L - m L \dot \theta^2 - m g \cos \theta = -\frac{T}{\rho}
%         \\
%         m (\ddot R \cos \theta + 2 \dot L \dot \theta + L \ddot \theta) + m g \sin \theta = 0
%     \end{aligned}
% \end{align}


We considering the following operating point parameter values ({\color{blue} munkaponti paraméter értékek}):
\begin{align}
    \begin{aligned}
        R_0,~~~  L_0,~~~  \Theta_0 = 0,~~~  F_0 = 0,~~~  T_0 = m g \rho
    \end{aligned}
\end{align}
Than we center the input and state variables:
\begin{align}
    \begin{aligned}
        R = R_0 + r,~~~
        % \Theta = \Theta_0 + \theta,~~~
        L = L_0 + l,~~~
        F = F_0 + f,~~~
        T = T_0 + \tau
    \end{aligned}
\end{align}
Substituting these expressions into \eqref{eq:basic_eqns}, we get:
\begin{align}
    \underbrace{f - 2 m \dot l \dot \theta \cos \theta + m \dot \theta^2 (L_0 + l) \sin \theta}_{\color{blue} b_1}
    &= {\color{red} \ddot l}\, \underbrace{m \sin \theta}_{\color{blue} a_{11}}
    + {\color{red} \ddot r}\, \underbrace{(M+m)}_{\color{blue} a_{12}}
    + {\color{red} \ddot \theta}\, \underbrace{m (L_0 + l) \cos \theta}_{\color{blue} a_{13}}
    \\
    \underbrace{M (L_0 + l) \dot \theta^2 - m g (1 - \cos \theta) - \frac{\tau}{\rho}}_{\color{blue} b_2}
    &= {\color{red} \ddot l}\, \underbrace{\qty(m + \frac{J}{\rho^2})}_{\color{blue} a_{21}}
    + {\color{red} \ddot r}\, \underbrace{m \sin \theta}_{\color{blue} a_{22}}
    \\
    \underbrace{-2 m \dot l \dot \theta - m g \sin \theta}_{\color{blue} b_3}
    &= {\color{red} \ddot r}\, \underbrace{m \cos \theta}_{\color{blue} a_{32}}
    + {\color{red} \ddot \theta}\, \underbrace{m (L_0 + l)}_{\color{blue} a_{33}}
\end{align}
% \begin{align}
%     \underbrace{f - 2 m \dot l \dot \theta \cos \theta - m \dot \theta^2 (L_0 + l) \sin \theta}_{\color{blue} b_1}
%     &= {\color{red} \ddot r}\, \underbrace{(M+m)}_{\color{blue} a_{11}}
%     + {\color{red} \ddot \theta}\, \underbrace{m (L_0 + l) \cos \theta}_{\color{blue} a_{12}}
%     + {\color{red} \ddot l}\, \underbrace{m \sin \theta}_{\color{blue} a_{13}}
%     \\
%     \underbrace{M (L_0 + l) \dot \theta^2 - m g (1 - \cos \theta) - \frac{\tau}{\rho}}_{\color{blue} b_2}
%     &= {\color{red} \ddot r}\, \underbrace{m \sin \theta}_{\color{blue} a_{21}}
%     + {\color{red} \ddot l}\, \underbrace{\qty(m + \frac{J}{\rho^2})}_{\color{blue} a_{23}}
%     \\
%     \underbrace{-2 m \dot l \dot \theta - m g \sin \theta}_{\color{blue} b_3}
%     &= {\color{red} \ddot r}\, \underbrace{m \cos \theta}_{\color{blue} a_{31}}
%     + {\color{red} \ddot \theta}\, \underbrace{m (L_0 + l)}_{\color{blue} a_{32}}
% \end{align}

Let us introduce the following state and input variables:
\begin{align}
    \begin{aligned}
        x_1 = l \\
        x_2 = \dot l
    \end{aligned} ~~~~~~~~
    \begin{aligned}
        x_3 = r \\
        x_4 = \dot r \\
    \end{aligned} ~~~~~~~~
    \begin{aligned}
        x_5 = \theta \\
        x_6 = \dot \theta \\
    \end{aligned}
    \quad \rightarrow \quad
    x = \pmqty{x_1 \\ ... \\ x_6}
    ~~~~~~~~~~~~~~~
    \begin{aligned}
        u_1 = f \\
        u_2 = \tau \\
    \end{aligned}
    \quad \rightarrow \quad
    u = \pmqty{u_1 \\ u_2}
\end{align}
Then, the resulting nonlinear state equation is the following
\begin{align}
    \begin{aligned}
        \pmqty{\dot x_1 \\ \dot x_3 \\ \dot x_5} = \pmqty{x_2 \\ x_4 \\ x_6} = \pmqty{f_1(x,u) \\ f_3(x,u) \\ f_5(x,u)},\quad
        \pmqty{\dot x_2 \\ \dot x_4 \\ \dot x_6} = \pmqty{\ddot l \\ \ddot r \\ \ddot \theta} =
        \left(\begin{array}{ccc} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & 0 \\ 0 & a_{32} & a_{33} \end{array}\right)^{-1}
        \left(\begin{array}{c} b_{1} \\ b_{2} \\ b_{3} \end{array}\right)
        = \pmqty{f_2(x,u) \\ f_4(x,u) \\ f_6(x,u)}
    \end{aligned}
\end{align}
Computing the matrix inverse, we get
\begin{align}
    \begin{aligned}
        \pmqty{f_2(x,u) \\ f_4(x,u) \\ f_6(x,u)} = \frac{1}{a_{11}a_{22}a_{33}-a_{12}a_{21}a_{33}+a_{13}a_{21}a_{32}}
        \left(\begin{array}{c} a_{13}a_{32}b_{2}-a_{12}a_{33}b_{2}-a_{13}a_{22}b_{3}+a_{22}a_{33}b_{1} \\ a_{13}a_{21}b_{3}+a_{11}a_{33}b_{2}-a_{21}a_{33}b_{1} \\ a_{11}a_{22}b_{3}-a_{12}a_{21}b_{3}-a_{11}a_{32}b_{2}+a_{21}a_{32}b_{1} \end{array}\right)
    \end{aligned}
\end{align}
Therefore, the nonlinear state-space model can be written as follows:
\begin{align}
    \begin{aligned}
        \dot x = F(x,u), ~~~ \text{ where } ~~~ F(x,u) =
        \pmqty{f_1(x,u) \\ f_2(x,u) \\ f_3(x,u) \\ f_4(x,u) \\ f_5(x,u) \\ f_6(x,u)}
    \end{aligned}
\end{align}
In order to get a linearized model (in the operating point $(x_0 = 0,u_0 = 0)$, we considering the second order Taylor polynomial of $F(x,u)$:
\begin{align}
    \begin{aligned}
        F(x,u) \simeq F(x_0,u_0)
        + \qty[\pdv{F(x,u)}{x}]_{\substack{x = 0 \\ u = 0}}(x - x_0)
        + \qty[\pdv{F(x,u)}{u}]_{\substack{x = 0 \\ u = 0}}(u - u_0)
    \end{aligned}
\end{align}
Since $F(x_0,u_0) = 0$, the linearized model is $\dot x = A x + B u$, where:
\begin{align}
    \begin{aligned}
        &A = \qty[\pdv{F(x,u)}{x}]_{\substack{x = 0 \\ u = 0}} = \left(\begin{array}{cc|cccc} 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 \\\hline 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & \frac{gm}{M} & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & -\frac{g(M+m)}{L_{0}M} & 0 \end{array}\right)
        &B = \qty[\pdv{F(x,u)}{u}]_{\substack{x = 0 \\ u = 0}} = \left(\begin{array}{c|c} 0 & 0 \\ 0 & -\frac{\rho }{m\rho ^2+J} \\\hline 0 & 0 \\ \frac{1}{M} & 0 \\ 0 & 0 \\ -\frac{1}{L_{0}M} & 0 \end{array}\right)
    \end{aligned}
\end{align}
As one can immediately observe, we obtained two decoupled subsystems in the linearized model:
\begin{align}
    \begin{aligned}
        &\dot \xi_1 = A_1 \xi_1 + B_1 \tau, && \text{ where } && A_1 = \pmqty{0 & 1 \\ 0 & 0}, && B_1 = \pmqty{ 0 \\ -\frac{\rho }{m\rho ^2+J}} \\
        &\dot \xi_1 = A_2 \xi_2 + B_2 f, && \text{ where } && A_2 = \pmqty{ 0 & 1 & 0 & 0 \\ 0 & 0 & \frac{gm}{M} & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & -\frac{g(M+m)}{L_{0}M} & 0 }, && B_2 = \pmqty{ 0 \\ \frac{1}{M} \\ 0 \\ -\frac{1}{L_{0}M} }
    \end{aligned}
\end{align}
The new state vectors $\xi_1$ and $\xi_2$ are the following:
\begin{align}
    \begin{aligned}
        \xi_1 = \pmqty{l \\ \dot l} = \pmqty{x_1 \\ x_2}, && \xi_2 = \pmqty{r \\ \dot r \\ \theta \\ \dot \theta} = \pmqty{x_3 \\ x_4 \\ x_5 \\ x_6}
    \end{aligned}
\end{align}

\end{document}