|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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:
|
|
#2
|
|||||
|
|||||
|
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 ) 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);
}
|
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
|||||
|
|||||
|
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. |
|
#5
|
|||
|
|||
|
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 Last edited by Mr.Macdonald : 03-02-2009 at 18:48. |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
||||
|
||||
|
Re: Potentiometer and Motor Trouble
Quote:
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? Last edited by Mike Betts : 04-02-2009 at 00:55. |
|
#8
|
|||||
|
|||||
|
Re: Potentiometer and Motor Trouble
I'm not sure how this algebra relates to the code snippet posted?
|
|
#9
|
|||
|
|||
|
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. Last edited by Mike Mahar : 04-02-2009 at 09:08. Reason: correct spelling |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Motor with a built in Potentiometer..? | Kaushal.K | Motors | 5 | 09-01-2007 08:31 |
| MOTOR TROUBLE!! NEED AN ASAP ANSWER!! | psycho7 | Motors | 4 | 12-02-2006 14:58 |
| Motor trouble | DHarris | Motors | 1 | 31-01-2006 19:44 |
| Potentiometer Trouble ?? | VideoMan053 | Programming | 18 | 28-01-2005 14:10 |
| External metal jacket on the Drill motor and FP motor, WHY? | Dennis Hughes | Technical Discussion | 1 | 04-06-2001 11:59 |