Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Code for Potentiometer (http://www.chiefdelphi.com/forums/showthread.php?t=15008)

wonderdog5 06-11-2002 06:50

Code for Potentiometer
 
On our team, we are thinking about using a potentiometer as a feedback mechanism to control our arms movement. I know this is possible but the problem is that I need some help with the program. If anyone knows where I could find some samples for code like this, that would be excellent. The programs function would be just to keep the arm where it should be without falling. I am aware that we should use mechanical counterweights as well and we plan on it. Thanks for the help

srawls 06-11-2002 13:24

It sounds like what you need is some sort of control loop. The one I am most comfortable with is the PID (Proportional Integral Derivitive) Control loop. This will fight back drive for you (i.e. "keep the arm where it should be without falling").

If that sounds like what you need, either e-mail me for more info, or post here and I'll see about putting a white paper up. In the meantime, I'm sure you can google search for "PID control."

Good Luck!
Stephen

wonderdog5 06-11-2002 13:39

re: pot code
 
That sounds like what we need: A pid Loop. IF you could put up some info on that it would be great. thanks so much.

srawls 06-11-2002 14:03

Ok, a PID loop adds the three terms (Proportional, Integral, and Deravitive) to get a drive percentage. 0 percent, don't supply any power, 100 percent, supply full power. (there are certainly other conventions, but this is the one I chose for this post).

Proportional Term:
This is the easiest to understand. You drive the motor proportionally to the distance from the current state to the set point (desired state). The formula for this term is:
Code:

P = ERROR * GAIN = (SET_STATE - CURRENT_STATE) * GAIN
You have to play a little to adjust your gain.

Integral Term:
This is a little harder to understand, perhaps. You are going to take the error, and integrate it over time, and then scale it by some gain (possibly different from the gain above). I won't get too deep into theory, but this term helps to adjust for long term, unexpected impedences to the process you are controlling.

The formula is:
Code:

I = INTEGRAL(ERROR * dt) * GAIN
Derivitive Term:
This helps correct unexpected disturbances that only effect the process momentarily. It's formula is:
Code:

D = d[ERROR] * GAIN
Where d[ERROR] is change in error, or (LAST_ERROR - CURRENT_ERROR).

Then the total drive would be P+I+D

Sorry I don't have time to explain more thouroughly. Interestingly enough, I wrote a paper on this this summer, so I could talk a lot about it :) But I'll be brief, and I recomend doing some research online or at a library.

Stephen

PS. Sorry, that is only theory above. I'll work on getting some sample code later, but I'm in class right now, so that's all I have time for.

Matt Reiland 06-11-2002 15:19

This is the actual code from our Swerve robot using feedback for the steering. Use the Steer_Gain variable to increase the speed that it closes in on the value . temp1 is the value that you are requesting the arm or steering to go to


' The following is for the output to the steering motor
' Some motion planning is being accomplished by slowing the motor
' as the actual steering angle is approaching the desired
' angle. This will lead to less overshoot
'
' currentsteer is the value from the steering pot on the robot

IF NOT(currentsteer > temp1) THEN STEERFWD
steer=127 - (((currentsteer - temp1)*STEER_GAIN) MAX 60)
goto EndSteeringFeedbackControl

:STEERFWD

steer=127 + (((temp1 - currentsteer)*STEER_GAIN) MAX 60)

EndSteeringFeedbackControl

steer=254-steer ' reverse the steering output


All times are GMT -5. The time now is 06:40.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi