View Single Post
  #2   Spotlight this post!  
Unread 23-05-2010, 00:03
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: Swerve vs. Mecanum Programming

Quote:
Originally Posted by kgzak View Post
I can post some examples. I will post them later right now I am at my friends house and don't have the ability to do so.

Baisically what my code does is it compares two numbers and if the pos_in(position the feedback tells you you are in) is greater than pos_to(Position to go to) then it sets the speed to -1 and 1 if it is the other way around. I also have a lot of safeties built in such as: If the feedback isn't counting, if it is turning the wrong way, etc. You may have a few questions because I really haven't commented any of it and it even confused my dad at first, so I will be willing to answer any other questions you have.
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).
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack

Last edited by apalrd : 23-05-2010 at 00:10.