Generalizing the pendulum PID controller

I recently came across the pendulum PID example here. I would like to generalize this for a plant that is not a pendulum. Could someone explain 1) How the current step function is built (the reasoning and theory behind it) 2) How should I modify the step function/build one for scratch for a different plant?