PID Loop Simulator/Teaching Tool

I’ve made a simple PID simulator to help teach and explain how PID loops, and how to properly tune the gains for different systems. It is a nice way to introduce PID loops to newer programmers. The model behaves surprisingly realistically, and the output vs. time graphs look almost identical to graphs from robots.

The program simulates a CIM motor driving a 1 meter long arm with a 150:1 reduction. The mass on the end of the arm can be adjusted, and gravity can be toggled on and off, so you could simulate something not affected by gravity, like a turret. The simulation takes into account an accurate motor curve (where motor torque is a function of motor speed and applied voltage), and the angular momentum of the arm.

You can download the simulator from here:
https://drive.google.com/file/d/0BzfxWVZUp3DNMG9Ld1Q4NEM5bkE/view?usp=sharing

Or look at the source code here:

http://i.imgur.com/P1PSh9U.png

Nice demo! Our students will get a crack at it this weekend.

BTW, I notice the sim crashes if the Mass is accidentally set to “0” while running and needs to be closed/restarted to work again (it cannot be reset). Other than that little quirk, you’ve got a slick tool for teaching PID principles.