View Single Post
  #17   Spotlight this post!  
Unread 04-02-2015, 19:03
mmaunu's Avatar
mmaunu mmaunu is offline
Registered User
FRC #2485 (W.A.R. Lords)
Team Role: Mentor
 
Join Date: Mar 2013
Rookie Year: 2010
Location: San Diego, CA
Posts: 87
mmaunu is a jewel in the roughmmaunu is a jewel in the roughmmaunu is a jewel in the roughmmaunu is a jewel in the rough
Re: Limit Swtich Help

Edit: ninja'd by Jon Stratis. I think that we are saying the same basic things. I'll leave it in case...


Quote:
Originally Posted by Ether View Post
You don't need "==" to return a Boolean: a single "=" inside an if() statement will indeed return a Boolean. But as you said above, not what the OP was expecting.
Actually, in Java, a single "=" does not return a boolean value. If you are assigning to a boolean value, then you will get the newly assigned value (which would actually be a boolean of course), but if you are assigning to an int or some other type, then the result is actually the value assigned.

For example:
Code:
boolean b = < something >

if( b = true )
The boolean expression evaluates to true in Java because you assigned true to the variable.

A different example:
Code:
int x = < something >

if( x = 8 )
The above will not compile because the value of the expression "x = 8" is actually the integer 8. This is what also allows you to do things like:

Code:
int a = < something >

int b = a = 9;
This gives a the value of 9 and then uses that assigned value to assign 9 to b. (Replace "a = 9" with 9.)

As for the original question/concern, have you tested that the get() method on the limit switch returns true when the limit switch is pushed? Depending on how you wire it (at least the ones that we have used in the past), you can get either true when the switch is triggered and false when it is not OR you can get false when the switch is triggered and true when it is not.

You also never set the limitPressed variable back to false; once set to true, limitPressed seems to remain true until you restart the robot.

Finally, if the limit switch is supposed to cancel the action that the joystick's button is performing, then you might want to change:

Code:
if (xbox.getRawButton(4)) {
            	
            	victor1.set(1);
            	victor2.set(1);
            	buttonPressedForwardVictor = true;
            	
 }
so that it includes a test for the limit switch. Assuming that limitPressed is only true when the limit switch is activated, you could try a condition like:

Code:
if (xbox.getRawButton(4)  &&  limitPressed == false) {
Without that extra condition, your logic is setting the motors to stop (above this line, where you check for the limitPressed value) and then you re-check the button...which re-sets the motors to run at full speed if the button is still engaged. The condition for running the motors needs to check the state of the button and the state of the limit switch. Another option is to use an else-if on the button condition so that you either set the victors to a value of 0 or set them to a value of 1 but not both.

Code:
if(limitPressed = true) {
            	
       	victor1.set(0);
       	victor2.set(0);
            	
}
            
else if (xbox.getRawButton(4)) {
            	
       	victor1.set(1);
       	victor2.set(1);
       	buttonPressedForwardVictor = true;
            	
}
I apologize if that was a bit scattered. Good luck and ask if anything/everything is unclear.
__________________
2014 Las Vegas (Winners with 987, 2478; Excellence in Engineering)
2014 San Diego (Finalists with 987, 3250; Quality Award)
2013 Inland Empire (Winners with 1538, 968; Excellence in Engineering Award)
2013 San Diego (Finalists with 2984, 4322; Creativity Award)
2012 Las Vegas (Finalists with 2034, 3187; Quality Award)
Reply With Quote