This page is part of a serie of articles on how to write the model of an inverted pendulum. We strongly recommand to read the previous pages for a better understanding.
As the trolley and the pendulum are linked by a pivot, the following equations can be written. This equations expresses the coordinate and orientation of each body of our system. For the trolley (body 1):
$$ \begin{array}{r c l} x_1 &=& x_1 \\ y_1 &=& 0 \\ \Theta_1 &=& 0 \\ \end{array} $$
For the pendulum (body 2):
$$ \begin{array}{r c l} x_2 &=& x_1 - L.sin(\Theta) \\ y_2 &=& y_1 + L.cos(\Theta) &=& L.cos(\Theta) \\ \Theta_2 &=& \Theta \end{array} $$
Let's define the vector \( \vec{q} \) representing position of our system :
$$ \vec{q}=\begin{pmatrix} x_1 \ \Theta_2 \end{pmatrix} $$
Let's define the constraints on position:
$$ \phi = \begin{pmatrix} y_1 \\ \Theta_1 \\ x_2 \\ y_2 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ x_1 - L.sin(\Theta) \\ L.cos(\Theta) \end{pmatrix} $$
Let's calculate the constraints on velocity:
$$ \dot{\phi} = \begin{pmatrix} \dot{y_1} \\ \dot{\Theta_1} \\ \dot{x_2} \\ \dot{y_2} \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ \dot{x_1} - L.\dot{\Theta_2}.cos(\Theta_2) \\ -L.\dot{\Theta_2}.sin(\Theta_2) \end{pmatrix} $$
Let's calculate the constraints on acceleration:
$$ \ddot{\phi} = \begin{pmatrix} \dot{y_1} \\ \ddot{\Theta_1} \\ \ddot{x_2} \\ \ddot{y_2} \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ \ddot{x_1} - L.\ddot{\Theta_2}.cos(\Theta_2) + L.\dot{\Theta_2}^2.sin(\Theta_2) \\ -L.\ddot{\Theta_2}.sin(\Theta_2) - L.\dot{\Theta_2}^2.cos(\Theta_2) \end{pmatrix} $$