I am trying to write the equation of motions for a simple pendulum but instead of writing them in generalized coordinates ($\theta$), I want to write them in cartesian coordinates (x, y), as I will need them later for further research.
I am writing this matrix in python and it's driving an openGL simulator, this is how I am testing it.
I think my constraint equations are wrong. This is the problem definition I have:
I have a simple pendulum, hinged at (0,0), with an arm of length L with no mass, and on the other end at position (x,y) there is a mass m. The two forces applied on m are g (pointing downards) (0, -g) and $F_{pend}$ (pointing to 0,0) ($F_{pend}^x, F_{pend}^y$)
The 4 unknowns are $\ddot x, \ddot y, F_{pend}^x, F_{pend}^y$.
Newton's Law gives us the first two equations:
$m \ddot x - F_{\text{pend}}^x = 0$
$m \ddot y - F_{\text{pend}}^y = -mg$
The constraint on the length of the arm gives us the third equation, after taking the second derivative:
$x^2 + y^2 - l^2 = 0$
$2 x \dot x + 2 y \dot y = 0$
$2 \dot x^2 + 2 x \ddot x + 2 \dot y^2 + 2 y \ddot y = 0$
$x \ddot x + y \ddot y = - \dot x^2 - \dot y^2$
At this point I need the 4th equation, which I have no idea what it could be. I currently think is:
$F_{pend} · \langle-y, x\rangle = 0$
$F_{pend}^x (- y) + F_{pend}^y (x) = 0$
This makes the matrix Ax=b for which we can run it to compute x:
$A = \begin{bmatrix} m & 0 & -1 & 0\\ 0 & m & 0 & -1\\ x & y & 0 & 0\\ 0 & 0 & -y & x \end{bmatrix}$
$ x^T = \begin{bmatrix} \ddot x & \ddot y & F_{pend}^x & F_{pend}^y \end{bmatrix}$
$ b^T = \begin{bmatrix} 0 & -mg & - \dot x^2 - \dot y^2 & 0 \end{bmatrix}$
The way I run the simulator is the following:
Initialize: $(x, y) = (-L, 0)$, $(\dot x, \dot y) = (0, 0)$, $dt = 0.001$
Loop forever:
- Run matrix to compute $(\ddot x, \ddot y)$
- Update position $(x, y) = (x, y) + (\dot x, \dot y) * dt$
- Update velocity $(\dot x, \dot y) = (\dot x, \dot y) + (\ddot x, \ddot y) * dt$
I know this is wrong because when I run this in the simulator I get a very weird motion that looks nothing like a pendulum and the mass drops forever.
Could anyone help me in finding the 4th equation, or even tell me if there are errors in my reasoning?