View Single Post
  #2   Spotlight this post!  
Unread 03-02-2009, 07:40
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Potentiometer and Motor Trouble

You have just written a proportional (or P) controller. For more about this and the related PID controller, see http://en.wikipedia.org/wiki/PID_controller.

When you say it jitters, do you mean that it gets to where it needs to go, and then it oscillates back and forth? I'm going to show you another way to look at the code you wrote that might make it easier to tweak:

Code:
pot_0 = controller potentiometer
pot_1 = on motor
mot_0 = motor 

float Kp = 1.0;
float error = (pot_0.value() - pot_1.value())/1024
mot_0.Set( Kp * error )
This is closer to the "standard form" of a controller. Now Kp is your "gain" factor - you can tweak it so that you achieve the balance of speed and oscillation that you desire. With Kp = 1.0, this should be equivalent to the gain in the code that you showed. It sounds like since you are oscillating, you might want to reduce it. Now you might encounter some other issues, however. Use the article I linked to to see how you might resolve these.

You shouldn't need to worry about the case that Kp*error is greater than 1 (or less than -1) because the PWM::SetSpeed() function (which is called by Jaguar::Set() or Victor::Set()) will make sure it is in the right range. And if you are worried about not having any error tolerance, you can do the following in place of casting to an int:

Code:
... stuff from above here

if( mot_0.Get() > -.1 && mot_0.Get() < .1 )
{
  mot_0.Set(0.0);
}
Hope this helps!