Left when pushing right on joystick and vice-versa. Please respond

Now the problem is that when we turn the joystick left the robot goes right and vice-versa. Though it goes back and forth perfectly. Any input would be appreciated. When running the program no errors show up.

package edu.wpi.first.wpilibj.templates;
 
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
 
public class RobotTemplate extends SimpleRobot {
    
    RobotDrive chassis = new RobotDrive(1,2);
    Joystick mainStick = new Joystick(1);
    
    public void autonomous() {
        
    }
    
    public void operatorControl() {
        chassis.setSafetyEnabled(true);
        while (isOperatorControl() && isEnabled()) {
            double speed;
            double rot;
            speed = mainStick.getY();
            rot = mainStick.getX();
            chassis.arcadeDrive (speed, rot);
    }
    }
   
    public void test() {
       
    }
}

Think about what’s happening - when you tell both sides of the drive to go forward, they go forward, and backward they go backward. It’s only when telling them to go in different directions that they get it wrong.

Basically, your robot thinks left is right and right is left. So… I would fix it by telling the robot to turn right when you really want it to go left, and left when you really want it to go right, that way it goes the way you really want it to go.

rot = -mainStick.getX();

Jon got it right.

Small thing worth noting - you should have a delay in your while loop. The standard is 20ms. You can do that with Timer.delay(0.02)

Thank you Joel and Jon. By adding the negative sign we were able to fix our problem.