(video embedded, below) This is a classic control theory problem, where you need to measure the angle ... For some more inverted pendulum fun, do check out this simple linear sled.