Go to Post We love team 71, but playing against them is not one of our favorite things to do. - Andy Baker [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 04-02-2015, 23:37
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: 89
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

Quote:
Originally Posted by Jon Stratis View Post
For example, to say "when button 4 is pressed and the limit switch is not pressed", you would do "xbox.getRawButton(4) || !limitPressed". Figuring out how to use logic like this is a very powerful tool while programming!
Just to clarify for others, the condition would have && instead of ||:
Code:
    xbox.getRawButton(4) && !limitPressed
which is what you said very clearly but we all get noise in our signal sometimes between the brain and the fingers

Reps from Ether! I am showing my students that one!!! You might have a little bit of a fan club here at Team 2485...we seriously owe a lot to you and it is a shame if I haven't said that and "thank you" before (which is probably the case as I am mainly a lurker...but I am working on it).
__________________
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
  #2   Spotlight this post!  
Unread 05-02-2015, 06:32
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Re: Limit Swtich Help

Quote:
Originally Posted by Jon Stratis View Post
The relays look good. In addition to double victor1's which have already been pointed out, consider the effect of pushing buttons 1 and 4 at the same time - you'll oscillate between full speed forward and full speed reverse. It's probably not a big deal, as your driver shouldn't be pushing them both at the same time anyways, but I personally like to prevent that sort of situation. Using some fairly simple logic, you can reduce everything dealing with the victors to a single if/else-if/else block. Something like:
Code:
if ()//the conditions you want it to go up
{
    //go up
}
else if ()//the conditions you want it to go down
{
    //go down
}
else
{
    //stop
}
You can set up the conditionals using the AND (&&) operator, the OR (||) operator, and the not (!). For example, to say "when button 4 is pressed and the limit switch is not pressed", you would do "xbox.getRawButton(4) || !limitPressed". Figuring out how to use logic like this is a very powerful tool while programming!
So when I go to add my second limit switch for the top could I use if(limit || limit2) or do I need a new if statement? Also I have been trying to figure out how to covert my victor buttons to axis would this be the correct way,
if(xbox.getRawAxis(I need to check mapping)) {
victor 1.set(1);
victor2.set(1);
}

Last edited by curtis0gj : 05-02-2015 at 06:46.
Reply With Quote
  #3   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: 89
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
  #4   Spotlight this post!  
Unread 04-02-2015, 19:15
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,089
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Limit Swtich Help

Quote:
Originally Posted by mmaunu View Post
If you are assigning to a boolean value, then you will get the newly assigned value (which would actually be a boolean of course)
That was the context for the discussion.

if (limitPressed = true)

will return a boolean: it will always return "true" regardless of the value of limitPressed prior to the test.



Last edited by Ether : 04-02-2015 at 19:41. Reason: clarity
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 13:37.

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