Let us consider the simple pendulum depicted on the right. The world reference frame is placed on top of the pin joing, with the \(x\)-axis pointing right, and \(y\)-axis pointing up. The tip of the bob is restricted to lie on a circle \(S^1\) of radius \(l\). As a result, the position of the tip of the bob can be written as \begin{equation*} r = l\left(\sin{\theta}, \; \cos{\theta}\right) \end{equation*} Differentiating this expression, we acquire the velocity and acceleration of the tip of the bob in terms of the pendulum angle \(\theta\). \begin{align*} \dot{r} &= l\dot{\theta}\left(\cos{\theta}, \; -\sin{\theta}\right) \\ \ddot{r} &= l\ddot{\theta}\left(\cos{\theta}, \; -\sin{\theta}\right) - l\dot{\theta}^2 \left( \sin{\theta} \; \cos{\theta} \right) \end{align*}
Drawing the free-body diagram of the pendulum suggests that there are two forces acting on the bob, the tension, \(T\), acting along the cable towards the revolute joing, the gravity, \(g(0 \;\; -1)\) acting along the negative \(y\)-direction, and the force \(\overrightarrow{f}\) due to the input torque around the revolute joint. As a result, Newton's law gives \begin{equation*} { m\ddot{r} = F = T \frac{-r}{\left|r\right|} + m g \left(0 \;\; -1\right) + \overrightarrow{f} } \end{equation*} Inserting the expressions for \(r\), \(\dot{r}\), and \(\ddot{r}\) derived above, we get the following two equations \begin{align} \label{eq:implicit_eq1} ml\left( \ddot{\theta}\cos{\theta} - \dot{\theta}^2 \sin{\theta} \right) &= -T\sin{\theta} - f\cos{\theta} \\ -ml \left( \ddot{\theta}\sin{\theta} + \dot{\theta}^2 \cos{\theta} \right) &= -T \cos{\theta} - mg + f\sin{\theta} \label{eq:implicit_eq2} \end{align} Multiple equation \eqref{eq:implicit_eq1} by \(\cos{\theta}\) and equation \eqref{eq:implicit_eq2} by \(-\sin{\theta}\) and add them together to get \begin{equation} \ddot{\theta} = \zeta \sin{\theta} + \tau \label{eq:EoM_Newton} \end{equation} where \(\zeta = \frac{g}{l}\) and \(\tau = m l f\) is the input torque. We regard \eqref{eq:EoM_Newton} as the equations of motion of the simple pendulum. Note that we can also find an expression for the tension \(T\) on the cable by multiplying equation \eqref{eq:implicit_eq1} by \(\sin{\theta}\) and equation \eqref{eq:implicit_eq2} by \(\cos{\theta}\) and adding them together \begin{equation*} T = m\left(l\dot{\theta}^2 - g \cos{\theta}\right) \end{equation*} Finally, let us briefly discuss how we could derive the equations of motion \eqref{eq:EoM_Newton} more succinctly using Lagrange's equations. To this end, we define the lagrangian \(L: S^1 \times \mathbb{R} \rightarrow \mathbb{R}\) by \(L = T-U \), where \(T: S^1 \times \mathbb{R} \rightarrow \mathbb{R} \) is the kinetic energy and \(U: S^1 \rightarrow \mathbb{R}\) is the potential energy \begin{equation} L = \frac{1}{2}ml^2\dot{\theta}^2 - mgl\cos{\theta} \label{eq:lagrangian} \end{equation} We then use Lagrange's equations to come up with the equations of motion of our mechanical system. The Lagrange's equations are given by \begin{equation} \frac{d}{dt}\frac{\partial L}{\partial \dot{\theta}} - \frac{\partial L}{\partial \theta} = u \label{eq:lagranges_eqns} \end{equation} where \(u\) is the external input to the system. As a result we get the equations of motion as \begin{equation} ml^2 \ddot{\theta} - mgl \sin{\theta} = ml^2\tau \label{eq:EoM_Lagrange} \end{equation} which is the same as the equations of motion \eqref{eq:EoM_Newton} we derived using Newton's law. Expressing the equaions of motion as a set of first order differential equation, we get \begin{equation} {\dot{x} = \begin{bmatrix} x_2 \\ \zeta \sin{x_1} \end{bmatrix} + \begin{bmatrix} 0 \\ 1 \end{bmatrix}u =: f(x) + g(x)u } \label{eq:system_dynamics} \end{equation} where \( x:= \left( \theta \;\; \dot{\theta} \right) \).
Since the equilibirium point we wish to stabilize $x_d = (\theta_d, \dot{\theta}_d) = (0,0)$ satisfies $V(x_d) = 0$, if $\dot{\theta} \not\equiv 0$, $x$ comes arbitrarily close to $x_d$ infinitely many times. The control strategy is then to switch to a linear controller of the form $\tau = -Kx$ once the trajectory is ``close'' to the desired equilibrium point.
As written, the optimization above is an optimization over continuous trajectories. In order to formulate this as a numerical optimization, we must parametrize it with a finite set of numbers. Perhaps not surprisingly, there are many different ways to write down this parametrization, with a variety of different properties in terms of speed, robustness, and accuracy of the results. For a great exposure to these methods, see the following reference
Before we tackle the complete mechanism, we are going to derive the kinematics equations for just the sliding contact linkage. Afterwards, grappling the full mechanism is going to be much more easier.
We have the following position vectors: $\overrightarrow{O_1P_1} = l_1 \hat{a}_1$, $\overrightarrow{O_2P_1} = s \hat{b}_1$, and $\overrightarrow{O_1O_2} = l_0 \hat{e}_2$. Note that $l_0, l_1$ are constants, but $s$ is a time-varying variable that depends on the position of the slider.Let $p_1$ be the position vector from $O_1$ to $P_1$, $p_2$ the position vector from $O_2$ to $P_1$ and $p_0$ be the position vector from $O_2$ to $O_1$. The position level kinematics can simply be derived using the loop equation: \begin{align} \begin{split} p_0 + p_1 - p_2 &= 0 \\ l_1 \hat{a}_1 - s \hat{b}_1 + l_0 \hat{e}_2 &= 0 \end{split} \label{eq:sliding_contact_position_level} \end{align} Differentiation of this equation in the earth frame with respect to time yields the velocity level equations. \begin{align*} \frac{{}^Ed p_1}{dt} - \frac{{}^Ed p_2}{dt} &= 0 \\ {}^E \omega^A \times \hat{a}_1 - {}^E v^{P_1} &= 0 \end{align*} Now, the point $P_1$ is moving with respect to the body $B$; as a result, we compute ${}^E v^{P_1}$ as follows \begin{align*} {}^E v^{P_1} &= {}^E v^{\bar{P}_1} + {}^B v^{P_1} \\ &= s {}^E \omega ^B \times \hat{b}_1 + {}^B v^{P_1} \\ &= s {}^E \omega ^B \times \hat{b}_1 + \dot{s}\hat{b}_1 \end{align*} where ${}^E v^{\bar{P}_1}$ denotes the velocity in $E$ of the point $\bar{P}_1$ of $B$ that coincides with $P_1$ at the instant under consideration. As a result, this point is fixed with respect to the reference frame $B$. This is the reason the second equation above follows from the first equation. Finally, the point $P_1$ is moving along the $\hat{b}_1$ axis. Since $\hat{b}_1$ is constant in the frame $B$, this velocity is given by $\dot{s} \hat{b}_1$, which yields the final equation. Consequently, the velocity level kinematics is given by the equation \begin{equation} l_1 \left( {}^E \omega^A \times \hat{a}_1 \right) - \dot{s} \hat{b}_1 - s {}^E \omega^B \times \hat{b}_1 = 0 \label{eq:sliding_contact_velocity_level} \end{equation}
Again, since the point $P_1$ is moving with respect to the body $B$, to compute ${}^E a^{P_1}$ we use the following formula \begin{align*} {}^E a^{P_1} &= {}^E a^{\bar{P}_1} + {}^B v^{P_1} + 2 {}^E \omega^B \times {}^B v^{P_1} \\ &= s \left( {}^E \alpha^{P_1} \times \hat{b}_1 + {}^E \omega^{B} \times \left( {}^E \omega^{B} \times \hat{b}_1 \right) \right) + \ddot{s} \hat{b}_1 + 2 \dot{s} \left( {}^E \omega^{B} \times \hat{b}_1 \right) \end{align*} Note that the second equation follows from the fact that \begin{align*} {}^E a^{\bar{P}_1} &= \frac{{}^E d}{dt} {}^E v^{\bar{P}_1} \\ &= \frac{{}^E d}{dt} \left( {}^E \omega ^B \times p\hat{b}_1 \right) \\ &= s{}^E \alpha^B \times \hat{b}_1 + s{}^E \omega^B \times \left( {}^E \omega^B \times \hat{b}_1 \right) \end{align*} where $p\hat{b}_1$ is the vector from $O_2$ to $\bar{P}_1$, which is momentarily equal to $s \hat{b}_1$. Consequently, the acceleration level kinematics is given by the equation \begin{equation} { l_1 \left( {}^E \alpha^A \times \hat{a}_1 + {}^E \omega^A \times \left( {}^E \omega^A \times \hat{a}_1 \right) \right) - \ddot{s} \hat{b}_1 - 2\dot{s} \left({}^E \omega^B \times \hat{b}_1 \right) } \\ { - s \left( {}^E \alpha^B \times \hat{b}_1 + \left( {}^E \omega^B \times \left( {}^E \omega^B \times \hat{b}_1 \right) \right) \right) = 0 } \label{eq:sliding_contact_acceleration_level} \end{equation} It is now pretty easy to derive the kinematics of the full quick-return mechanism. For this, we only need to add another set of equations. For the position level, let $p_2^\prime = \overrightarrow{O_2P_2}$, $p_3 = \overrightarrow{P_2P_3}$ and $\xi$ be the position of the tool. Then, \begin{align} \begin{split} p_2^\prime + p_3 &= \xi \\ l_2 \hat{b}_1 + l_3 \hat{c}_1 &= x \hat{e}_1 + y \hat{e}_2 \end{split} \label{eq:quick_return_position_level} \end{align} Here, $l_3$ is the length of link $C$ and $y$ is the constant height of the tool. For velocity level kinematics, we differentiate this expression in the earth frame to get \begin{align} \begin{split} l_2 {}^E \omega^B \times \hat{b}_1 + l_3 {}^E \omega^C \times \hat{c}_1 &= \dot{\xi} \\ l_2 {}^E \omega^B \times \hat{b}_1 + l_3 \left({}^E \omega^B + {}^B \omega^C \right) \times \hat{c}_1 &= \dot{\xi} \\ \end{split} \label{eq:quick_return_velocity_level} \end{align} Lastly, the acceleration level kinematics is obtained by differentiating this expression with respect to time in the earth frame. \begin{equation} { l_2 \left( {}^E \alpha^B \times \hat{b}_1 + {}^E \omega^B \times \left( {}^E \omega^B \times \hat{b}_1 \right) \right) } \\ {+ l_3 \left( {}^E \alpha^C \times \hat{c}_1 + {}^E \omega^C \times \left( {}^E \omega^C \times \hat{c}_1 \right) \right) = \ddot{\xi} } \label{eq:quick_return_acceleration_level} \end{equation} where ${}^E \omega^C = {}^E \omega^B + {}^B \omega^C$ and ${}^E \alpha^C = {}^E \alpha^B + {}^B \alpha^C$.