Solution (source code)

= Solution

Away from the coordinate poles, use $\dot\phi=h/\sin^2\theta$ in the conserved <energy>:
$$
E=\frac{Ma^2}{6}\dot\theta^2+\frac{Ma^2h^2}{6\sin^2\theta}-\frac{Mga}{2}\cos\theta.
$$
Rearranging gives the first-order equation
$$
\boxed{\dot\theta^2=\frac{6E}{Ma^2}+\frac{3g}{a}\cos\theta-\frac{h^2}{\sin^2\theta}.}
$$
Where the right side is positive, either sign of its square root is possible, according to the direction of motion. Its zeros are turning points. For $h\ne0$, the centrifugal term excludes the poles; if $h=0$, the polar-coordinate formula is interpreted through the original rod equations.