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
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.”
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.
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).
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:
P = ERROR * GAIN = (SET_STATE - CURRENT_STATE) * GAIN
You have to play a little to adjust your gain.
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:
I = INTEGRAL(ERROR * dt) * GAIN
This helps correct unexpected disturbances that only effect the process momentarily. It’s formula is:
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.
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.
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)
steer=254-steer ' reverse the steering output