To make an inverted pendulum behave like a regular pendulum you need to have a torque feedback proportional to tilt angle. A motor is a torque device as long as the back emf voltage generated by the motor speed doesn’t cancel the voltage command. So the torque will “washout” to zero as the motor speeds up and there will be nothing left to stabilize the robot unless you add some more command.
Its kind of a race between the dynamics of the pendulum and the dynamics of the motor/gearing. You want to get to the stable vertical position before the motor torque washes out. The pendulum can remain stable independent of speed so long as there is torque available.
So the motor is really a speed device in the long term and a torque device in the short term ( as long as there is current flowing). It would be nice to have the command increase automatically as the motor speeds up to counter the back emf voltage reduction in command.
Here are two approaches to helping the problem. One is to have a forward path integration on the angle error ( the I in PID) . This can stabilize the vertical but you still don’t know your wheel speed. I tried this but the nonlinearities of my Vex motors complicated the problem so I gave up.
The other way is to estimate motor speed and feed it back with the opposite sign of the back emf voltage so as the motor speeds up the command increases to counter the back emf and you can maintain a torque proportional to angle. We can estimate motor speed from wheel rate derived from differentiating encoder position. I prefer encoders since with wheel position and speed you can now add more PID loops to control velocity, position and turning.
Gear ratio which I define here as motor speed/wheel speed is important to the problem. There is an optimum gear ratio that keeps the motor torque from washing out too fast yet gives you the torque necessary to recover from a given tilt angle. If the gear ratio is too high, the motor sees a small inertia load and gets to speed very fast and you lose your torque. If the gear ratio is too low, the motor maintains its torque longer but the torque is very small on the pendulum body. Hence you can only recover from small tilt deviations from vertical. So there is a trade off. You will have to experiment with different gearing ratios..My robot can handle about 15 degrees off tilt.