I have a 76 cm, aluminum rod, attached to the shaft of a 12v DC banebot motor. The rod is hanging vertically initially, and rotates in the vertical plane. The task is to control the rod to make it stop at a particular angle. I am using a quadrature encoder alongside the motors to measure the angle. Apart from this, I am also using a cytron 10A motor driver along with an Arduino UNO.
What makes this problem tricky IMO, is the fact that we have to offset the effect of gravity. Had the rod been just rotating in the horizontal plane, we simply could've controlled the angular speed to be = $kp(\theta-\theta_{ref})$, so that as $\theta$ approaches $\theta_{ref}$, the motor keeps slowing down. (Ofcourse, we could've added I and D terms too for better performance.)
But the same code will not work in the vertical plane, as we have a continuous torque due to gravity as well. The equation of the system looks something like
$$\ddot{\theta}= \dfrac{6g}{l}\sin \theta + \dfrac{\tau_m}{I}$$ $$\dot{\theta}= \int \dfrac{6g}{l}\sin \theta dt + \Omega$$
Where I think $\Omega$ is the motor's contribution of the motor output to the angular speed, which is something we can control.So if we set $\Omega$ to be something like $kp(\theta-\theta_{ref})-\int \dfrac{6g}{l}\sin \theta dt$, Then I think as $\theta$ approaches $\theta_{ref}$, $\dot{\theta}$ approaches zero. But I am not sure if that will drive $\ddot{\theta}$ to zero too...
Also, How exactly will we implement the integration step? Something simply like I+=6*g*sin(\theta)*dt/l
in a loop?