You might want to look at the
Legway code, since that incorporates the ability to do things such as line tracking (which implies riderless movement). He does it exactly the way you describe, by moving backwards slightly to offset the inverted pendulum.