Go to Post Our behavior – both good and bad – is contagious. Set a good example, behave in a mature, reasoned, professional manner and we will find that others around us will too. - dlavery [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 13-02-2015, 10:22
SirGibbs SirGibbs is offline
Registered User
FRC #5676 (Hornets)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2015
Location: USA
Posts: 11
SirGibbs is an unknown quantity at this point
Pneumatics, getting XBox input

Hey, I am from Team 5676 and we have some problems with the programming. I looked in some pneumatic threads, but I didn't found anything similar.

We want to work with pneumatics who get controlled by the Xbox controller.
When the XBox controller and all the buttons are defined, what is the best way to get the Xbox Input to let the pneumatics start working?

Code:
if(XboxController.button[0] == true)
		{
			pistonArm.set(DoubleSolenoid.Value.kForward);	
		
			System.out.println("'A' button is pressed: Piston moves forward");}
That is what we have, but it isn't working. It doesn't get the input. We would highly appreciate any input, ideas or solutions to make this better and solve it.

with best wishes

The Hornets
Reply With Quote
  #2   Spotlight this post!  
Unread 13-02-2015, 10:39
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Re: Pneumatics, getting XBox input

Quote:
Originally Posted by SirGibbs View Post
Hey, I am from Team 5676 and we have some problems with the programming. I looked in some pneumatic threads, but I didn't found anything similar.

We want to work with pneumatics who get controlled by the Xbox controller.
When the XBox controller and all the buttons are defined, what is the best way to get the Xbox Input to let the pneumatics start working?

Code:
if(XboxController.button[0] == true)
		{
			pistonArm.set(DoubleSolenoid.Value.kForward);	
		
			System.out.println("'A' button is pressed: Piston moves forward");}
That is what we have, but it isn't working. It doesn't get the input. We would highly appreciate any input, ideas or solutions to make this better and solve it.

with best wishes

The Hornets
Your button getter method is kind of odd;

Code:
if(XboxController.getRawButton(0))
{
pistonArm.set(DoubleSolenoid.Value.kForward);
System.out.println("'A' button is pressed: Piston moves forward");}
Also, the == true part isn't essential -- if your expression will return true you don't have to add that.

For example:

Code:
// if 5 is bigger than 4 will evaluate to true
if(5 > 4) {
System.out.println("5 is bigger than 4!");
}

// less efficient way of doing the same thing posted above
if((5 > 4) == true) {
System.out.println("5 is bigger than 4!");
}
Your pneumatic control looks good, but here's a toggle function I have been using (that I know works):

Code:
public void toggleSolenoid1() {
    	if(solenoid1.get() == DoubleSolenoid.Value.kForward) {
    		solenoid1.set(DoubleSolenoid.Value.kReverse);
    	} else {
    		solenoid1.set(DoubleSolenoid.Value.kForward);
    	}
    }
Reply With Quote
  #3   Spotlight this post!  
Unread 13-02-2015, 10:40
Oromus's Avatar
Oromus Oromus is online now
Lead Programmer, Community Liason
AKA: Ryan
FRC #1902 (Exploding Bacon)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Florida
Posts: 82
Oromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to behold
Re: Pneumatics, getting XBox input

The issue is that you need to change
Code:
if(XboxController.button[0] == true)
to
Code:
if(XboxController.button[0].get() == true)
The key change there being the addition of ".get()". What your code is doing is saying "If this button is true, run my code". A button won't be equal to true because it's a Button, not a boolean. Using "XboxController.button[0].get()" changes that line of code to "If this button's STATE is true (pressed), run my code". This should fix your problem.
Reply With Quote
  #4   Spotlight this post!  
Unread 13-02-2015, 11:01
Rakusan2 Rakusan2 is offline
Registered User
AKA: Tomas Rakusan
FRC #3571 (Milton Mustangs)
Team Role: Programmer
 
Join Date: May 2014
Rookie Year: 2011
Location: Milton, ON, Canada
Posts: 22
Rakusan2 is an unknown quantity at this point
Re: Pneumatics, getting XBox input

This is something my team is using
Code:
if (DriverButtons.X.changedDown)
{
	
	if (HighGear)
	{
		Shifter.set(Value.kReverse);
	} else {
		Shifter.set(Value.kForward);
	}
	HighGear=!HighGear;
}
That involves our own code for the XboxControler which detects if it has changed state this run and consists of compering the last state with the current,
but if do not want a toggle then you can easily do
Code:
		if (DriverButtons.X.current)
		{
			pistonArm.set(Value.kReverse);
		}
		else {
			pistonArm.set(Value.kForward);
		}
And do not forget to change DriverButtons.X.current to your own code that gets the current value of your button
Reply With Quote
  #5   Spotlight this post!  
Unread 13-02-2015, 13:52
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: Pneumatics, getting XBox input

Quote:
Originally Posted by Oromus View Post
The issue is that you need to change
Code:
if(XboxController.button[0] == true)
to
Code:
if(XboxController.button[0].get() == true)
The key change there being the addition of ".get()". What your code is doing is saying "If this button is true, run my code". A button won't be equal to true because it's a Button, not a boolean. Using "XboxController.button[0].get()" changes that line of code to "If this button's STATE is true (pressed), run my code". This should fix your problem.
In addition to what he stated, this would be as good a time to learn java operators as any.
A few common ones include

Code:
if (leftStick.getRawButton(5)) {} // if the button is held(or true) it would run the code
if (!leftStick.getRawButton(5)) {} // the ! operator inverts your boolean, so when the 5 button is not held it would run this code using the == true is a bit redundant when java interprets true as the default for running your if anyway and using ! would invert it to false.
if (leftStick.getRawButton(5) && rightStick.getRawButton(5)) {} // this would only run the if when left and(&&) right stick are both held
Reply With Quote
  #6   Spotlight this post!  
Unread 14-02-2015, 12:07
SirGibbs SirGibbs is offline
Registered User
FRC #5676 (Hornets)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2015
Location: USA
Posts: 11
SirGibbs is an unknown quantity at this point
Re: Pneumatics, getting XBox input

Thank you all so much!!! So we changed all this staff but I just donīt get it to read the buttons. It tells me that XboxController.button would not be visible. But itīs all declared as public and the XboxController and the buttons are all imported. Any suggestions or ideas???
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 10:47.

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