NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » How would i create a PID controller method?
March 03, 2012 by RevMoses |
Some example code would be great. for a general definition of what i'm attempting to achieve: http://en.wikipedia.org/wiki/PID_controller Assuming i have ADCinput and PWMoutput |
---|---|
March 03, 2012 by RevMoses |
P is the easy part. Its just gain...so ADCinput * GainFactor However I and D are a bit more...uh unfriendly |
March 03, 2012 by esoderberg |
Rev, Here is code for a linear servo. As you can see, it's essentially a P controller, without the ID parts of the full PID. With the gearing on most linear actuators, you get a system that effectively has very low inertia, meaning the below code gives rather accurate and precise results without the need for the I or D elements. I tried them and found no improvement at all with D feedback included, but I may yet still go back and implement an I element if I find I'm getting stuck with unacceptable steady state error. The first function sets up the PWM, the second controls an H-bridge and sets the actual PWM depending on demanded position and actual position(measured elsewhere in code via ADC).
///////////////////////////////////////////////
|
Please log in to post a reply.
Did you know that a piezoelectric buzzer can be used in reverse as a microphone? Learn more...
|