Go to Post "The hardest part about building the robot is figuring out what to build..." - Jeff Waegelin [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 01-02-2003, 17:18
GrahamS314's Avatar
Happy Birthday! GrahamS314 GrahamS314 is offline
Registered User
FRC #0314 (Megatron Oracles)
Team Role: College Student
 
Join Date: Dec 2002
Rookie Year: 2002
Location: Flint, MI
Posts: 8
GrahamS314 is an unknown quantity at this point
Send a message via AIM to GrahamS314
Question Working with Potentiometers

Our team tried to test operating a van door motor using two pots -- one for feedback and one for control. Unfortunately, we couldn't get the motor to drive in the direction of decreasing the error. No one can figure out what's wrong. Here's the code:

if stack_pos - sw_stacker > 10 then pos_error
if abs(stack_pos - sw_stacker) < 10 then done_stack
neg_error:
error = (sw_stacker - stack_pos)
sw_stacker = 127 - (4 * error) / 10)
pos_error:
error = (stack_pos - sw_stacker)
sw_stacker = 127 + (4 * error) / 10)


Here are our pots:
PN 3825A-282-104A
  #2   Spotlight this post!  
Unread 01-02-2003, 17:30
Caleb Fulton's Avatar
Caleb Fulton Caleb Fulton is offline
Z = Z^2 + C ......WHEEEE!
AKA: aXvXiA
#0461 (West Side Boiler Invasion)
Team Role: College Student
 
Join Date: Dec 2002
Location: West Lafayette, Indiana
Posts: 205
Caleb Fulton has a spectacular aura aboutCaleb Fulton has a spectacular aura aboutCaleb Fulton has a spectacular aura about
Send a message via AIM to Caleb Fulton
sw_stacker = 127 + (4 * error) / 10) has parentheses problems
__________________
  #3   Spotlight this post!  
Unread 01-02-2003, 17:32
n[ate]vw's Avatar
n[ate]vw n[ate]vw is offline
Registered User
#0933 (Adler Attack)
 
Join Date: Jan 2003
Location: Rockford, IL
Posts: 48
n[ate]vw is an unknown quantity at this point
Send a message via AIM to n[ate]vw
Could you elaborate how the pots are connected physically and electrically?

Also, PBASIC does not handle negative numbers as you might expect. Pad your values so that you don't perform math in the negative range.
__________________
Adler Attack #933 -- Trigos
  #4   Spotlight this post!  
Unread 01-02-2003, 17:47
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
For starters, try putting a "goto done_stack" immediately before the pos_error label. Otherwise, the code in the neg_error section will "fall-through" and execute the pos_error code also. However, without knowing what variables correspond to what, there's not a whole lot I can tell you.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #5   Spotlight this post!  
Unread 01-02-2003, 18:17
GrahamS314's Avatar
Happy Birthday! GrahamS314 GrahamS314 is offline
Registered User
FRC #0314 (Megatron Oracles)
Team Role: College Student
 
Join Date: Dec 2002
Rookie Year: 2002
Location: Flint, MI
Posts: 8
GrahamS314 is an unknown quantity at this point
Send a message via AIM to GrahamS314
Believe it or not, the lack of parens was actually a copying error. I overlooked one.

Pertaining to negative numbers, I believe switching the sensor value and target value takes care of that problem.

The sensor pot is hooked up to the analog inputs, aliased to sensor1. The pot controlling the motor is on port 4, aliased to p4_x. All wires are 24 gauge.

stack_pos -- sensor potentiometer
sw_stacker -- OI input pot
  #6   Spotlight this post!  
Unread 01-02-2003, 18:30
Caleb Fulton's Avatar
Caleb Fulton Caleb Fulton is offline
Z = Z^2 + C ......WHEEEE!
AKA: aXvXiA
#0461 (West Side Boiler Invasion)
Team Role: College Student
 
Join Date: Dec 2002
Location: West Lafayette, Indiana
Posts: 205
Caleb Fulton has a spectacular aura aboutCaleb Fulton has a spectacular aura aboutCaleb Fulton has a spectacular aura about
Send a message via AIM to Caleb Fulton
See Rob's previous post...There's still the fall-through issue.
__________________
  #7   Spotlight this post!  
Unread 01-02-2003, 18:50
n[ate]vw's Avatar
n[ate]vw n[ate]vw is offline
Registered User
#0933 (Adler Attack)
 
Join Date: Jan 2003
Location: Rockford, IL
Posts: 48
n[ate]vw is an unknown quantity at this point
Send a message via AIM to n[ate]vw
I might be misunderstanding the issue, but it seems you are trying to make a servo, i.e. the motor turns until the feedback pot and the control pot give the same value.

[edit]Your code seems to be unnecessarily complex, [/edit]
...wouldn't

if feedback_pot < control_pot then [turn motor one way]
if feedback_pot > control_pot then [turn motor other way]

work for this?

[edit]
You could tweak the if...then statements a bit to allow slight error:

if feedback_pot+255 < control_pot +245 then [one way]
if feedback_pot+255 > control_pot +265 then [other way]
[/edit]
__________________
Adler Attack #933 -- Trigos

Last edited by n[ate]vw : 01-02-2003 at 18:59.
  #8   Spotlight this post!  
Unread 01-02-2003, 19:01
n[ate]vw's Avatar
n[ate]vw n[ate]vw is offline
Registered User
#0933 (Adler Attack)
 
Join Date: Jan 2003
Location: Rockford, IL
Posts: 48
n[ate]vw is an unknown quantity at this point
Send a message via AIM to n[ate]vw
With regards to your code, though, does sw_stacker get sent to the right PWM by the end of the loop?


[edit - I'm bad with the edits today...]

Let's say stack_pos=1 and sw_stacker=100

if stack_pos - sw_stacker > 10 then pos_error

Will this go to pos_error or not?
1-100= -99, which to the controller might be -99 or 157, depending on how it handles negative numbers in this situation.

[/edit]
__________________
Adler Attack #933 -- Trigos

Last edited by n[ate]vw : 01-02-2003 at 19:09.
  #9   Spotlight this post!  
Unread 02-02-2003, 00:54
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
It will be interpreted as being 157, not -99.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #10   Spotlight this post!  
Unread 02-02-2003, 01:35
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: Working with Potentiometers

if stack_pos - sw_stacker > 10 then pos_error
This statement is fine as long as stack_pos is greater than sw_stacker; and the jump will be executed when stack_pos is more than 10 greater than sw_stacker. BUT if stack_pos is less than sw_stacker, then the result of the subtraction will be negative, and since the BASIC Stamp does UNSIGNED comparisons, THE JUMP PATH WILL ALWAYS BE TAKEN. It would be safer to say "if stack_pos > sw_stacker + 10 then pos_error".

if abs(stack_pos - sw_stacker) < 10 then done_stack
To reiterate, this test will only be made when stack_pos is between sw_stacker and sw_stacker +10. And this jump will ALWAYS be taken UNLESS stack_pos EQUALS sw_stacker + 10.

Thus, the following section will only be executed when stack_pos EQUALS sw_stacker + 10:

neg_error:
error = (sw_stacker - stack_pos)
sw_stacker = 127 - (4 * error) / 10)

... and this, only when stack_pos IS GREATER THAN sw_stacker + 10:

pos_error:
error = (stack_pos - sw_stacker)
sw_stacker = 127 + (4 * error) / 10)

I don't think this is what you intended.

This should do more like what you expected:
Code:
	if abs(stack_pos - sw_stacker) < 10 then done_stack
	if stack_pos > sw_stacker + 10 then pos_error
neg_error:
	error = (sw_stacker - stack_pos)
	sw_stacker = 127 - (4 * error) / 10)
pos_error:
	error = (stack_pos - sw_stacker)
	sw_stacker = 127 + (4 * error) / 10)
Now, I'm not sure whether your code for neg_error and pos_error is correct, but this should get you closer, at least.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me

Last edited by Greg Ross : 02-02-2003 at 01:38.
  #11   Spotlight this post!  
Unread 02-02-2003, 14:17
Ken Delaney's Avatar
Ken Delaney Ken Delaney is offline
Registered User
#0357 (Royal Assault)
 
Join Date: Jan 2002
Location: Drexel Hill,PA
Posts: 40
Ken Delaney is an unknown quantity at this point
Send a message via Yahoo to Ken Delaney
If the code that everyone has suggested does not fix it ask yourself, are the pots are wired correctly? We ran into this problem last year when the pot on OI had wires to all three of the tabs, when only two should be wired. Refer to pages 13 and 15 in the Robot section of the manual.
Good Luck
  #12   Spotlight this post!  
Unread 02-02-2003, 14:34
Anthony Kesich's Avatar
Anthony Kesich Anthony Kesich is offline
Programmer Turned Engineer
AKA: SonKenshin
#1097 (Site 3 Engineernig)
Team Role: Leadership
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Sacramento, CA
Posts: 186
Anthony Kesich has a spectacular aura aboutAnthony Kesich has a spectacular aura about
Send a message via AIM to Anthony Kesich
Quote:
Originally posted by n[ate]vw
Let's say stack_pos=1 and sw_stacker=100

if stack_pos - sw_stacker > 10 then pos_error

Will this go to pos_error or not?
1-100= -99, which to the controller might be -99 or 157, depending on how it handles negative numbers in this situation.
why dont you just take a page out of innovationfirst's book and their basic programming to avoid negatives. try something like this:

if (((stack_pos + 100 - sw_stacker) Min 100) - 100) > 10 then {whatever}

anything that would be a negative number is instead turned into a zero, and all this code is looking at is whether it is less than 10 or not, not by how much it is less than ten.

-Anthony

P.S. i dont know the range of your values, so iff 100 is too little or too much, you can change it accordingly
__________________
C is screwing up my English--I'm ending all my sentences in semi-colons;

Horray for most things! -George Carlin

"Sure, I'll play rugby. Besides, I have a lot of experience running from really big guys who want to cream me." -Me, Freshman year
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
Whose working this summer? Frank(Aflak) Chit-Chat 20 28-05-2003 11:35
pic: Working Hard, As Always CD47-Bot Extra Discussion 4 14-04-2003 09:07
Are ramp blocker bots working? Jim S Regional Competitions 42 22-03-2003 20:55
Please identify these two hard working hula 'botters! archiver 2001 2 24-06-2002 03:37
Anyone working on game/mod and looking for a 3d modeller? Devil's Kid 3D Animation and Competition 5 21-04-2002 15:08


All times are GMT -5. The time now is 12:59.

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