Log in

View Full Version : Generic PID control code


Uberbots
26-02-2007, 13:42
I was asked by Adamdb of team #1583 to post a code example of what we did to execute a PID loop. The two files, pid.c and pid.h are attached below.

in order to use a pid loop, you must do a couple of things. first, you create the data structure, for example:
DT_PID arm;

in some initialization code later, you need to initialize the constants
init_pid(&arm, 100, 10, 10, 100, 5); (see the included file for the argument list)

then finally, you can execute the loop by doing this
pwm03 = pid_control(&arm, errorValue);

It really isnt that bad, and if you notice a lack of comments/explanation, please make a note of it. Also, this code doesnt go into the theory behind it, it only executes the theory. so if you dont know what a proportional coefficient is, then i suggest that you read this: PID without a PhD (http://www.embedded.com/2000/0010/0010feat3.htm)

happy control-loop-ing.

Edit: i added the default code plus the PID code for those of you who are having trouble getting started.

Tom Bottiglieri
26-02-2007, 14:06
I was going to post mine, but beside for some minor syntax differences, the drivers are identical.

Good work.

PS. It looks like the uberbots' programmers have come a long way since I last talked to you before eliminations at UTC last year.

Mike
26-02-2007, 16:32
Again, nearly identical PID code. I constructed mine from the PID without a PhD article as well.

meatmanek
26-02-2007, 16:59
I was about to make code from PID without a PhD, but then I saw this. It's always great to see teams post code for others to use.