Go to Post I fear not the drive team who has practiced 10,000 defenses once, but I fear the drive team who has practiced one defense 10,000 times. -Bruce Lee - bEdhEd [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-02-2012, 13:47
NS_Radication's Avatar
NS_Radication NS_Radication is offline
Student
AKA: Marco Schoener
FRC #1369 (Minotaur)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Tampa
Posts: 88
NS_Radication is an unknown quantity at this point
Robots can't count: Microswitches

We are using a microswitch on our robot to add and subtract the balls. The MicroswitchesWe are plugged with GND on C and SIG on NO (normally open).

I will add the code when I get the chance but it is basically:
Code:
Int totalBalls = 2


public int microSwitch(int totalBalls)

If (addball.get() = true and totalBalls >= 0 and < 3
Then totalBalls += 1

If (minusball.get() = true and totalBalls > 0 and <= 3
Then totalBalls -= 1

Else if totalBalls > 3 || totalBalls < 0
Then totalBalls

return totalBalls

When I hit the switch, it calculates the addition or subtraction, but when the switch is released, it goes back to the original value. Why an't a robot count?
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
Reply With Quote
  #2   Spotlight this post!  
Unread 22-02-2012, 15:18
Brian Selle's Avatar
Brian Selle Brian Selle is offline
Mentor
FRC #3310 (Black Hawk Robotics)
Team Role: Engineer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Texas
Posts: 162
Brian Selle has a spectacular aura aboutBrian Selle has a spectacular aura aboutBrian Selle has a spectacular aura about
Re: Robots can't count: Microswitches

If your pseudo code matches your real code, the module level variable totalBalls defined at:

Quote:
Originally Posted by NS_Radication View Post
Int totalBalls = 2
Will never be updated because the variable totalBalls defined as a argument to your method will take precedence.

Quote:
Originally Posted by NS_Radication View Post
public int microSwitch(int totalBalls)

Try renaming the module level variable to m_totalBalls or another name. Also, you only need to check the upper limit when adding:

If (addball.get() = true and totalBalls < 3
Then totalBalls += 1

And the lower limit when subtracting:

If (minusball.get() = true and totalBalls > 0
Then totalBalls -= 1
Reply With Quote
Reply


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


All times are GMT -5. The time now is 09:53.

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