Howdy folks, I need some help with my Xbox 360 remote. Currently I am using the Buttons to send signals to victor motor controllers and spike relays, but I would like to switch over to the left axis for my victors and right axis for my relays. Here is my current code. Any help would be greatly appreciated.
boolean buttonPressedForwardSpike = false; // these are in init.
boolean buttonPressedForwardVictor = false; // init
if (xbox.getRawButton(3)) { // tele
spike1.set(Relay.Value.kForward);
spike2.set(Relay.Value.kForward);
buttonPressedForwardSpike = true;
} else if (buttonPressedForwardSpike = true) {
spike1.set(Relay.Value.kOff);
spike2.set(Relay.Value.kOff);
buttonPressedForwardSpike = false;
}
if (xbox.getRawButton(2)) {
spike1.set(Relay.Value.kReverse);
spike2.set(Relay.Value.kReverse);
}
if (xbox.getRawButton(1)) {
victor1.set(.50);
victor2.set(.50);
buttonPressedForwardVictor = true;
} else if (buttonPressedForwardVictor = true) {
victor1.set(0);
victor2.set(0);
buttonPressedForwardVictor = false;
}
if (xbox.getRawButton(4)) {
victor1.set(-.50);
victor2.set(-.50);
}
Use the driver station to find the raw axis values of the individuals joysticks (it’s on one of the tabs on the bottom left hand side). Then, just call getRawAxis() on that axis you find.
Also, I’m sure if you look around on chiefdelphi, you’ll find that people have already posted up their xbox class.
boolean buttonPressedForwardSpike = false; // these are in init.
boolean buttonPressedForwardVictor = false; // init
if (xbox.getRawAxis(5)) { // 5 being the Y axis on right stick
spike1.set(Relay.Value.kForward);
spike2.set(Relay.Value.kForward);
buttonPressedForwardSpike = true;
} else if (buttonPressedForwardSpike = true) {
spike1.set(Relay.Value.kOff);
spike2.set(Relay.Value.kOff);
buttonPressedForwardSpike = false;
}
boolean buttonPressedForwardSpike = false; // these are in init.
boolean buttonPressedForwardVictor = false; // init
// !!The below statement doesn't evaluate to a boolean
if (xbox.getRawAxis(5)) { // 5 being the Y axis on right stick
spike1.set(Relay.Value.kForward);
spike2.set(Relay.Value.kForward);
buttonPressedForwardSpike = true;
// !!!!!!!!!!! The below staetment assigns instead of comparing
} else if (buttonPressedForwardSpike = true) {
spike1.set(Relay.Value.kOff);
spike2.set(Relay.Value.kOff);
buttonPressedForwardSpike = false;
}
If that’s the exact one, then yeah, it SHOULD be fine. Though I’d still recommend checking it, for sanity reasons.
You will need to explain more about what you want the code to do. A joystick axis in WPILib returns a floating point value (double datatype) from -1.0 to 1.0. An if statement requires a boolean, true or false.