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?
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.
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:
// 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):
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.
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
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
In addition to what he stated, this would be as good a time to learn java operators as any.
A few common ones include
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
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???