Go to Post You are an inquisitive rookie aren't ya - Kyle [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-02-2009, 00:35
Mr.Macdonald Mr.Macdonald is offline
Registered User
FRC #2272
 
Join Date: Jan 2009
Location: Conejo Valley Robotics
Posts: 26
Mr.Macdonald is an unknown quantity at this point
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.
  #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!
  #3   Spotlight this post!  
Unread 03-02-2009, 15:40
Mr.Macdonald Mr.Macdonald is offline
Registered User
FRC #2272
 
Join Date: Jan 2009
Location: Conejo Valley Robotics
Posts: 26
Mr.Macdonald is an unknown quantity at this point
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   Spotlight this post!  
Unread 03-02-2009, 16:11
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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   Spotlight this post!  
Unread 03-02-2009, 18:44
Mr.Macdonald Mr.Macdonald is offline
Registered User
FRC #2272
 
Join Date: Jan 2009
Location: Conejo Valley Robotics
Posts: 26
Mr.Macdonald is an unknown quantity at this point
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   Spotlight this post!  
Unread 03-02-2009, 21:20
Mr.Macdonald Mr.Macdonald is offline
Registered User
FRC #2272
 
Join Date: Jan 2009
Location: Conejo Valley Robotics
Posts: 26
Mr.Macdonald is an unknown quantity at this point
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   Spotlight this post!  
Unread 03-02-2009, 22:24
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: Potentiometer and Motor Trouble

Quote:
Originally Posted by Mr.Macdonald View Post
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?
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...

Last edited by Mike Betts : 04-02-2009 at 00:55.
  #8   Spotlight this post!  
Unread 04-02-2009, 08:44
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

Quote:
Originally Posted by Mr.Macdonald View Post
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?
  #9   Spotlight this post!  
Unread 04-02-2009, 09:07
Mike Mahar Mike Mahar is offline
Registered User
FRC #0138
 
Join Date: Jan 2007
Location: Amherst, NH
Posts: 64
Mike Mahar will become famous soon enough
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 View Post
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

Last edited by Mike Mahar : 04-02-2009 at 09:08. Reason: correct spelling
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 21:51.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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