Log in

View Full Version : Xbox Axis Help


curtis0gj
31-01-2015, 12:16
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);
}

kinganu123
31-01-2015, 13:10
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.

curtis0gj
31-01-2015, 16:51
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.

Could I use this picture http://team358.org/files/programming/ControlSystem2009-/XBoxControlMapping.jpg for the values or do I need to check the actual readings?

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;
}

kinganu123
31-01-2015, 17:06
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.

RufflesRidge
31-01-2015, 17:37
Could I use this picture http://team358.org/files/programming/ControlSystem2009-/XBoxControlMapping.jpg for the values or do I need to check the actual readings?


Check them. That picture looks like the old 2014 and earlier mapping.

curtis0gj
31-01-2015, 19:22
Check them. That picture looks like the old 2014 and earlier mapping.

Yeah it was, I found 2015 http://team358.org/files/programming/ControlSystem2015-2019/images/XBoxControlMapping.jpg

curtis0gj
31-01-2015, 20:44
I may need some further assistance the getRawAxis is giving me an error saying that it cannot covert from double to boolean.

boolean buttonPressedForwardSpike = 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;
}

RufflesRidge
31-01-2015, 21:18
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.

kinganu123
01-02-2015, 10:19
Check my second post.I've already put comments in there as to what you should change