View Single Post
  #14   Spotlight this post!  
Unread 23-05-2010, 20:00
kgzak's Avatar
kgzak kgzak is offline
Registered User
AKA: Kris
FRC #4392 (Decievers) FRC #2075 (Enigma)
Team Role: College Student
 
Join Date: Dec 2008
Rookie Year: 2008
Location: Grand Rapids, Michigan
Posts: 418
kgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to beholdkgzak is a splendid one to behold
Re: Swerve vs. Mecanum Programming

Quote:
Originally Posted by apalrd View Post
a simpler way to do this exists.
it's called proportional control. p from pid.

Basically, you say;
Code:
error = setpoint - process_variable
output = error * Kp
And Kp (gain) is constant. Nice and easy. You should only need a safety at the left/right boundaries to cut off the output when it gets out of range, and possibly some functions to invert motor and rotate inverse. You tune the gain so that it goes as fast as it can without oscillating.

Edit: Forgot to talk about I and D:
Integral (I):
Basically you integrate the error and add it to the output:
Code:
integral += error
output += integral * kI
Ki is Integral Gain. You also need to reset integral to prevent integral windup. Generally you do not need to implement I unless you cannot get enough accuracy with P alone.

Derivative (D):
You calculate the derivative of the previous action to determine how momentum will affect the stopping ability. Basically, it works against P and I to slow it down when it nears the end, allowing a higher P gain. You will almost certainly not need this with crab steering, as the friction of turning the pods will probably slow their rotation very quickly (D would be useful for, say, a 6' arm that has a lot of mass at the end).
I do know there are other ways of doing this but I like the challenge of completely writing code from scratch. The safeties are in there because one of our mentors was afraid we were going to break his swerve drive. He was afraid that the encoder/pot was going to fall off and since our drive could not continually rotate without breaking the frame, he was always afraid when we made changes to the code. My code is actually based off the code my dad uses for his drives at his work, minus he torque controllers. I have speed and position/distance controllers.