Reminds me of an experiment that the Mechatronic's lads had to complete at Uni many years ago. They had a servo driven kart with a pendulum swung underneath. They had to get it to swing the pendulum up and make it remain balanced in an upright position. But they had constraints on the limits of travel and speed.
Here's a short video of something similar....