Joysticks Not Working Correctly

So, I have my entire program uploaded onto GitHub here:


The name of the robot is Molly, so that’s what the file is called on GitHub.

I finally got the robot to respond to the Drive Station, but it was only reacting to one joystick instead of the two of them. The wheels would both go (although it opposite directions :confused: ) when I moved the one joystick, but nothing would happen when I moved the other. I tried switching the order of the joysticks around in the driver station usb port tab, and the same thing happened, but with the joystick that was previously useless now working (so pretty much which ever joystick is in the 0 order of the drive station works).

I tried to fix that, and now all I get are error messages from the drive station. I feel like there is most likely a simple answer, but I’m so inexperienced, I’ll probably never figure it out in time. :ahh:

One problem I see is in OI:


public class OI {
    ...	
	 public JoystickButton joystickButton1;
	    public static Joystick joystick1;
	    public JoystickButton joystickButton2;
	    public static Joystick joystick2;

	    public OI() {
	        // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS

	        Joystick joystick2 = new Joystick(1);
	        
	        Button joystickButton2 = new JoystickButton(joystick2, 1);
	        joystickButton2.whileHeld(new SetDown());
	        
	        Joystick joystick1 = new Joystick(0);
	        

The red lines are problematic. You are declaring a local joystick only within the OI constructor that hides the static field definition that getJoystick() and your calls to OI.joystick1 will retrieve.

So I suspect that the default constructor for Joystick assigns 0 and you never get joystick2 assigned to 1.

Remove the red words and I suspect it may work better.

Make sure that the Joystick channels you used in the code correspond to the channels on the driver station. The first joystick plugged in should be 0, and the second is 1. Also, you can change this in the third tab on the left side of the driver station. Just reorder the usb inputs.