Another Two-Wheel Self-Balancing Robot

I had anticipated in my first blog post about my self balancing robot that a v2 was coming, so here, at long last, it is. Last time, motors were a big problem, they did not exhert nearly enough torque and they had a huge deadzone. They sucked pretty much all around.

I had also started thinking about replacing those wimpy motors with stepper motors, with the idea that controlling the motors in angular position/speed would be way waaay easier that controlling them in torque, especially considering my DC motors did not even have encoders to measure the angular speed, which would be needed to accurately control torque in a dc motor. Well, that’s a test for another day. A close day indeed, as I already bought motors and they’re curently en route.

I once again turned to academic papers, because surely had already tried to do this. I found [1] and [2]. I liked the approach done in [1]: start from the linearized model

\begin{equation} \begin{cases} (I_b+m_bl^2)\ddot{\theta} + m_bl\ddot{x} - m_bgl\theta = -(\tau_r + \tau_l) \\ (m_b + \frac{2I_w}{r^2} + 2m_w) \ddot{x} + m_bl\ddot{\theta} = \frac{\tau_r + \tau_l}{r} - 2b_w\frac{\dot{x}}{r^2} \end{cases} \end{equation}

Then again, ignore yaw and set $T = \tau_r + \tau_l$. Like last time pass into the Laplace domain. Solve one of the two equations for $T(s)$ and plug it into the other equation. Then solve for $\frac{\theta(s)}{sX(s)}$, as so to obtain a transfer function of the desidered output $\theta(s)$ using the input $sX(s)$, meaning the angular velocity of the motor. Stepper motors are not controlled in velocity however, they are controlled in position. Every pulse given to the driver, the motor takes one step. The step are fixed in displacement. Nema 17 motors usually are 1.8°/step, with the possibility, depending on the driver to microsteps of 1/4, 1/8, 1/16 or even smaller fractions of a step. While the steps are discrete, making them as small as possible with microstepping makes tem appear as if they were continuous.

Reference #