|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#4
|
|||||
|
|||||
|
Re: PID control loops - feedback is our friend!!!
PID control loops.... ahh. They seem to make sense sometimes but other times they don't... Here is the control loop that I have written up. Please take a look at it and critique it. The constants have not been tuned at all. I finally got to plug it into our second arm (with working pots!!) and somehow it was outputting numbers in the 400's....
Any help??? The two scaled values are pot values, one from our arm and one from the model. They are both scaled from 0 to 255 and are declared as unsigned longs... (don't ask, it has to do with how we scale them...) sint = signed int THIS IS WHERE IT IS CALLED: //call the control loop to set the pwm values Arm_Upper_Out = PID(scaled_highjoint_req, scaled_highjoint_act, lasthighjoint_act, sint_highjoint_errorsum); //keep track of the error for the control loop sint_highjoint_errorsum = sint_highjoint_errorsum + (scaled_highjoint_req - scaled_highjoint_act); //keep track of the last position to be able to tell how fast it is moving for the control loop lasthighjoint_act = scaled_highjoint_act; THIS IS THE CONTROL LOOP: unsigned char PID(signed int request, signed int actual, signed int lastactual, signed int sumerror) { #define PID_PROP 2 #define PID_DER 1 #define PID_INT 1 signed int pid, error; request = request - 127; actual = actual - 127; lastactual = lastactual - 127; pid = request; error = request - actual; //find the difference of the two values pid = pid + (error/PID_PROP); //add the proportional part of the error pid = pid + ((actual - lastactual)/PID_DER); // add the derivative part of the error pid = pid + (sumerror/PID_INT); //integral part of the pid pid = pid + 127; return(pid); } |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|