![]() |
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:
|
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 potentiometerYou 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 |
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.
|
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. |
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 |
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 |
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? |
Re: Potentiometer and Motor Trouble
Quote:
|
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:
|
| 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