An inverted pendulum is the canonical hard problem of control: open-loop unstable, underactuated, non-minimum-phase. Left alone it always falls — the unstable mode roughly doubles the tilt every fifth of a second, faster than a hand can correct.
A feedback controller reads the tilt and drives the cart under the falling bob. Kp is stiffness, Kd is damping; together they must be fast enough to outrun the unstable pole yet not so hot the loop rings itself over — a narrow bandwidth window.
A slow outer loop on Kx nudges the cart back to centre so it never runs off the finite rail. The real measure of the design is not holding a still pole but rejecting a kick.
The same maths keeps a Segway upright, a rocket on its thrust vector, and a quadrotor level. Get the sign of the derivative gain wrong and feedback accelerates the fall instead of arresting it.
Something in the simulation stopped unexpectedly — the lesson continues without it. You can move on; nothing you did was wrong.