So, how well did it work? Not as well as I hoped.
There were a couple issues. The first was that I had trouble adjusting the I part of the PID controller to work properly, so I ended up with just a PD controller, which isn’t as robust. The second is that it’s hard to make it completely stable (i.e. to get it to stop moving occasionally) without also measuring the position of the motor — a pretty stable position (in the linear model, i.e. it becomes unstable in the real system) is to spin really fast constantly, so that the motor is moving as fast as the pendulum is falling.
Circuit diagram! 11 op amps and 1 inverter. Not the most efficient circuit, but for someone who had hardly touched an op amp before she started, not too bad. Things that could be combined: the PID could probably be combined into a lead-lag controller, which can be done in one or two op amps, I think the absolute value circuit could be done with just one op amp, and I probably didn’t really need the buffer. So that would have cut it down to 5 or 6 op amps. A bit more reasonable.
A video of it kind-of-working! Note how it tries to always spin in one direction, and also how it becomes unstable after several seconds. Still, better than the average human can balance it. 🙂