Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Potentiometer and Motor Trouble (http://www.chiefdelphi.com/forums/showthread.php?t=73513)

Mr.Macdonald 03-02-2009 00:35

Potentiometer and Motor Trouble
 
I am trying to set up a motor with a potentiometer to act like a servo. I have another potent controlling the desired location. I can make the motor turn one way correctly but it jitters when going the other direction.

The potentiometer on the motor in magnetic and have infinite rotation, the controller in a normal potent.

My algorithm goes as follows.
PHP Code:

pot_0 controller potentiometer
pot_1 
on motor
mot_0 
motor

mot_0
.Set10 int( (pot_0.value() - pot_1.value())/10 )/1024

the 10's allow for error. 1024 is potentiometer max.

Jared Russell 03-02-2009 07:40

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!

Mr.Macdonald 03-02-2009 15:40

Re: Potentiometer and Motor Trouble
 
it jitters while approching the point, then oscillates at that point. But thats only in one direction. It works fine if moving the other direction. The directional issue isn't code, because I also did a test where I set the motor to the opposite speed (.5 -> -.5), and the directional issue was in the same direction.

Alan Anderson 03-02-2009 16:11

Re: Potentiometer and Motor Trouble
 
Are you using a Victor, or a Jaguar? Are you using the appropriately matching object in your code?

From what I've seen so far this year, Victors are more prone to asymmetric behavior because of their offset neutral point. The WPI library code does a good job of accommodating this, but any given Victor might not be exactly as the code expects. If you're using a Victor, try calibrating it before doing any more programming. Hold down the CAL button when applying power to it, send it "full forward" (+1), then "full backward" (-1), then "neutral" (0) signals, then release the button. Its LED should flicker green to let you know the calibration was successful.

Mr.Macdonald 03-02-2009 18:44

Re: Potentiometer and Motor Trouble
 
I tried both a Jaguar and a Victor

I still get the oscillating/moving to the destination behavior

EDIT: and I have tried both Objects for both controllers in code

Mr.Macdonald 03-02-2009 21:20

Re: Potentiometer and Motor Trouble
 
I found a compiler error.

based upon my motors behavior, I believe that upon compilation I get a math error.

if (a+b)/c = d
and (a/c) + (b/c) = e
then d != e

Mike Betts 03-02-2009 22:24

Re: Potentiometer and Motor Trouble
 
Quote:

Originally Posted by Mr.Macdonald (Post 813706)
I found a compiler error.

based upon my motors behavior, I believe that upon compilation I get a math error.

if (a+b)/c = d
and (a/c) + (b/c) = e
then d != e

Mr. McDonald,

You can not run code with a compiler error and what you posted above will not compile (it has multiple errors).

Just what are you attempting to do?

Jared Russell 04-02-2009 08:44

Re: Potentiometer and Motor Trouble
 
Quote:

Originally Posted by Mr.Macdonald (Post 813706)
I found a compiler error.

based upon my motors behavior, I believe that upon compilation I get a math error.

if (a+b)/c = d
and (a/c) + (b/c) = e
then d != e

I'm not sure how this algebra relates to the code snippet posted?

Mike Mahar 04-02-2009 09:07

Re: Potentiometer and Motor Trouble
 
I'll assume that this is just an example of the equation and not the actual code you are trying to compile.

This is not a compiler error. It is a characteristic of integer arithmetic. Your code at the top has a slightly different expression.
(a - b)/c
assume
a = 20
b = 9
c = 10
a - b is equal to 11
11/ 10 is equal to 1. Remember that you are working with integers

(a/c) + (b/c) with the same values is
20/10 is equal to 2
9/10 is equal to 0
2 - 0 is equal to 2

This sort of problem will happen with floats as well because floats are just approximations of real numbers. It is considered an error to test for equality in floats. If you aren't testing for equality than I recommend that you do your math in floats and only convert the end result into integers at the end.

Quote:

Originally Posted by Mr.Macdonald (Post 813706)
I found a compiler error.

based upon my motors behavior, I believe that upon compilation I get a math error.

if (a+b)/c = d
and (a/c) + (b/c) = e
then d != e



All times are GMT -5. The time now is 02:24.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi