The dynamical equations governing the behavior of a single-link flexible joint robot are traditionally obtained from Lagrangian dynamics considerations. Let $q$ denote the angular position of the link (see attached image) of half length $L$ and mass $m$ and let $q_m$ be the angular position of the motor. The differential equations governing the controlled motions are given by
$$\begin{align*}
\tau &= D_m\ddot{q}_m + D_m\dot{q}_m + K_S(q_m-q) \\
0 &= D\ddot{q} + B\dot{q} + mgL\sin{q}+K_S(q-q_m),
\end{align*}$$
where $D$ denotes the inertia of the link, $D_m$ denotes the motor inertia; the flexible joint stiffness coefficient is $K_S$ and the motor viscous damping and the link viscous damping are $B_m$ and $B$, respectively. The gravitational acceleration is denoted by $g$.
Define $\rho^2 = 1 / K_S$, which is not to be taken as a small constant related to singular perturbation techniques. The state variables were defined as the motor's angular position $x_1 = q_m$, the corresponding angular velocity $x_2 = dq_m/dt$, the elastic force $x_3 = K_S(q - q_m)$ and $X_4 := (dq/dt- dq_m/dt)/\rho$. The state variable representation is then obtained as
$$\begin{align*}
\dot{x}_1 &= x_2 \\
\dot{x}_2 &=-a_5x_2 + a_1x_3 + a_1u \\
\dot{x}_3 &= x_4/\rho \\
\dot{x}_4 &= [-a_2a_3\sin{\rho^2x_3 + x_1}-a_4x_3 - a_7x_2 - a_6\rho x_4 - a_1u]/\rho
\end{align*}$$
with $a_1=1/D_m$, $a_2 = 1/D$, $a_3 = mgL$, $a_4=a_1+a_2$, $a_5 = B_m/D_m$, $a_6=B/D$, $a_7 = a_6-a_5$, $a=\tau.$