|
Re: Need help programming our swerve with feedback?
Have you tried a PID loop? We faced a similar problem with our arms. We needed to drive the motors just enough to reach a position and fight gravity, but not enough to overshoot. The trick is to set your motor value proportional to the distance you want to go.
A solution (run through this every so often with timers):
1) Find the difference between your current pot position and your target position. This is your error value.
2) You want your motor value to be proportional to the error. Multiply the error by a constant (you'll have to figure it out through experimentation). This gives you your proportional value.
3) As your wheels approach the right orientaion, your motor value will decrease more and more. To compensate for this, integrate the error (ie add the current error to a running total). Multiply this by another constant (again, you'll have to figure it out). This will give you your integral value.
4) Add the two values together to get your motor value.
It sounds a little complicated, but the code is actually pretty simple. The object does tend to overshoot some, and then oscillate a little. This can be minimized by adjusting the constants.
This system may allow you to plug in a certain angle and have your wheels find that position automatically. On our robot, we use this to create preset arm positions. You might be able to do the same with wheel positions.
EDIT: On second thought, using an integral probably wouldn't be best for you. Instead, you might want to just use a proportional value. To get the wheel to its target position when the proportional drops too low, you could have a range close to the target with a different constant (to multiply by).
Last edited by Cyris12 : 22-03-2004 at 02:58.
|