I have to come up with a PD-controller for an inverted Spherical Cart Pendulum, therefore I tried to compute the Dynamics of such a Pendulum. Spherical Pendulum

The Spherical Cart Pendulum is a hybrid between the Cart Pole and the Spherical Pendulum. The underlying Cart can move in the X-Y Plane.

Cart Pole


$l$ is the length of the Pendulum, $m_p$ is the mass of the pendulum, $m_c$ is the mass of the cart, $\theta$ denotes the azimuthal and $\phi$ the polar

As generalized Coordinates I use the conversion between spherical Coordinates and cartesian Coordinates:

$$x=l\sin(\theta)\cos(\phi)$$ $$y=l\sin(\theta)\sin(\phi)$$ $$z=l\cos(\theta)$$

The generalized Coordinates for the Pendulum look like this:

$$x_p=l\sin(\theta)\cos(\phi)+x$$ $$y_p=l\sin(\theta)\sin(\phi)+y$$ $$z_p=l\cos(\theta)$$ and $$\dot x_p = -l\sin(\phi)\sin(\theta)\dot\phi+l\cos(\phi)\cos(\theta)\dot\theta+\dot x$$ $$\dot y_p = l\sin(\phi)\cos(\theta)\dot\theta+l\sin(\theta)\cos(\phi)\dot\phi+\dot y$$ $$\dot z_p = -l\sin(\theta)\dot \theta$$ The Lagrangian Equation is defined by: $$L=T-V$$ with $$T=T_c+T_p$$ $$T_c=\frac{1}{2}m_c(\dot x^2+\dot y^2)$$ $$T_c=\frac{1}{2}m_p(\dot x_p^2+\dot y_p^2 + \dot z_p^2)$$ and $$V=m_p\cdot g \cdot z_p$$ results in: $$L=- g l m_{p} \cos{\left(\theta \right)} + 0.5 l^{2} m_{p} \sin^{2}{\left(\theta \right)} \dot{\theta}^{2} + 0.5 m_{c} \dot{x}^{2} + 0.5 m_{c} \dot{y}^{2} + 0.5 m_{p} \left(- l \sin{\left(\phi \right)} \sin{\left(\theta \right)} \dot{\phi} + l \cos{\left(\phi \right)} \cos{\left(\theta \right)} \dot{\theta} + \dot{x}\right)^{2} + 0.5 m_{p} \left(l \sin{\left(\phi \right)} \cos{\left(\theta \right)} \dot{\theta} + l \sin{\left(\theta \right)} \cos{\left(\phi \right)} \dot{\phi} + \dot{y}\right)^{2}$$

and after $$\frac{\partial L}{\partial q_j}-\frac{d}{dt}\frac{\partial L}{\partial \dot q_j}=0$$

I get a set of differential equations$A=(\ddot \phi, \ddot \theta, \ddot x, \ddot y)^T$. They are all looking good, except one:

Now my Problem:

The equilibrium point of the inverted Pendulum I want to control is at $\theta=0$. Therefore the differential equation for $$ \ddot{\phi} =\frac{- 2 l \cos{\left(\theta \right)} \dot{\phi} \dot{\theta} + \sin{\left(\phi \right)} \ddot{x} - \cos{\left(\phi \right)} \ddot{y}}{l \sin{\left(\theta \right)}} $$

$$ \lim_{\theta \to 0}\ddot{\phi}=\infty $$ means that I cannot compute $\theta$ for very small angles. I know that for $\ddot x=0$ and $\ddot y=0$, $\ddot \phi$ is a cyclic Coordinate and displays the angular momentum.

How can I interpret $\ddot \phi$ in a way that my differential equation makes sense and does not explode into the infinity?


2 Answers 2


Imagine the pendulum swinging along $y=0$, with $x$ changing. As the pendulum swings directly below the cart, $\phi$ instantly changes from 0 to $\pi$, so you would expect $\ddot{\phi}$ to be infinite - when $\theta=0$, $\phi$ can take any value without the mass moving. It's similar to gimbal lock (https://en.wikipedia.org/wiki/Gimbal_lock).

You probably need to rephrase in a different coordinate system or reference frame - for example, set $\theta$ to be the angle from the z-axis in the yz-plane, and $\phi$ to be the angle from the z-axis in the xz-plane, and redo the analysis, that shouldn't lead to either blowing up with the pendulum vertical with $\theta=\phi=0$ (but will have discontinuities with it horizontal if aligned to the axes, so at $\theta=\pi/2$, $phi$ will be similarly undefined).

  • $\begingroup$ I agree. You don't want to work around the point that is the axis about which $\phi$ is measured. +1 $\endgroup$
    – Dale
    May 18 at 16:47
  • $\begingroup$ Thank you for your answer. So you think that general coordinates like $x=l\cdot \sin(\theta) \cdot \sin(\phi) + x$ $y=l\cdot\cos(\theta) + y$ and $z=l\cdot\sin(\theta)\sin(\phi)$ should work? Because I think that the equations I obtain are looking funky and I cannot solve the equations for the state variable. $\endgroup$ May 23 at 14:12
  • $\begingroup$ Maybe try defining $\theta$ from the z-axis, and $\phi$ from the line that's at $x=0$ and is $\theta$ from the axis - so that $x=l\sin\theta \cos \phi$, $y=l\sin\phi$, $z=l\cos\theta \cos\phi$ - I think I've seen that set work in the past (So $\theta$ is from the axis and increasing $\theta$ increases $x$, and $\phi$ is from a line from to (0,0,0) to ($\sin\theta$,0,$\cos\theta$), increasing $\phi$ increases $y$, rather than both angles defined relative to the axis - I think this makes the maths easier than my original suggestion) $\endgroup$
    – sqek
    May 23 at 15:51

You are modelling this using a simple pendulum. $\phi$ describes the angular displacement of the point about the $z$-axis. This only makes sense if $\theta\neq0$.

As $\theta\to0$, using conservation laws it makes sense that $\ddot\phi$ increases.

Your problem is that you are trying to interpret the $\theta\to0$ case by considering a real-life physical pendulum bob that can spin about an axis passing through it (i.e. it's not point-like). Since you used a point in your analysis, spinning about an axis passing through the point does not make mathematical sense. Therefore, for the $\theta=0$ case, one cannot even talk about $\phi$ because a point-like particle does not have angular displacement about an axis passing through that same point (whereas an object that occupies space would). As such, your equation breaks down for $\theta=0$.

For small angles $\theta$ angles, the physical size of the pendulum bob does matter, and, if accounted for mathematically, will give you the correct expression for $\ddot \phi$ (which, as you correctly stated, will be related to the angular momentum of the physical pendulum).

The takeaway is that your equations are approximations, and in particular the $\ddot\phi$ expression becomes considerably less accurate for small angles of $\theta$.

@sqek 's answer is true -- by redefining your coordinate system, you get to 'displace,' if you will, the problem of $\phi$ 'losing its meaning' in your coordinate system.

  • $\begingroup$ Thank you for your reply. But it seems that even with a different representation, I get weird equations. And sympy cannot solve the system in respect of the state variables. $\endgroup$ May 23 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.