By first considering a force balance equation on the moment arm, we can determine the force, F1, exerted on the pendulum in the x direction by the cart, as well as the weight force, F2. We can then determine the net torque on the pendulum which yields the first equation below. The second equation is derived by doing a force balance on the total mass and pendulum system.
The two equations above are then substituted into the cart dynamics, described by the equation below:
Prior to the control of the full inverted pendulum, a working control design of the cart position needed to be established. For a given voltage as input and a position of the cart as output, the follow transfer function represents the cart system dynamics:
Full Derivation Here