pid or other will fail. you have to use state controller --> look for keywords like Ackermann controller or something else. In the case of the inverted pendulum you have divide the controll algo into two parts:
first you have to swing over
then a state controller takes place