Okay very close with a robot

Hi I’m trying to program a robot to use the following I have the following hardware,

Everything is connected and working which is good I can run one motor with a joystick with success in a code I will post that as well I just need some help running motors on ports 2,3,4 the ideal goal would have ports 1 and 2 work in tandem on the left joystick and for ports 3 and 4 to work in tandem but work in reverse of motor ports 1 and 2.

#include <AFMotor.h>
#include <XBOXRECV.h>
USB Usb;
XBOXRECV Xbox(&Usb);
AF_DCMotor motor(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm


void setup() {
  Serial.begin(115200);
  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while(1); //halt
  }
  Serial.print(F("\r\nXbox Wireless Receiver Library Started"));
   
}
void loop() {
  Usb.Task();
  if(Xbox.XboxReceiverConnected) {
    for(uint8_t i=0;i<4;i++) {
      if(Xbox.Xbox360Connected[i]) {
        if(Xbox.getButtonPress(i,L2) || Xbox.getButtonPress(i,R2)) {
          Serial.print("L2: ");
          Serial.print(Xbox.getButtonPress(i,L2));
          Serial.print("\tR2: ");
          Serial.println(Xbox.getButtonPress(i,R2));
          Xbox.setRumbleOn(i,Xbox.getButtonPress(i,L2),Xbox.getButtonPress(i,R2));
         
        }
       
        if(Xbox.getAnalogHat(i,LeftHatX) > 7500 || Xbox.getAnalogHat(i,LeftHatX) < -7500 || Xbox.getAnalogHat(i,LeftHatY) > 7500 || Xbox.getAnalogHat(i,LeftHatY) < -7500 || Xbox.getAnalogHat(i,RightHatX) > 7500 || Xbox.getAnalogHat(i,RightHatX) < -7500 || Xbox.getAnalogHat(i,RightHatY) > 7500 || Xbox.getAnalogHat(i,RightHatY) < -7500 || Xbox.getAnalogHat(i,LeftHatY) < 7500 || Xbox.getAnalogHat(i,LeftHatY) > -7500) {
          motor.setSpeed(LeftHatY/131);
          if(Xbox.getAnalogHat(i,LeftHatX) > 7500 || Xbox.getAnalogHat(i,LeftHatX) < -7500) {
            Serial.print(F("LeftHatX: ")); 
            Serial.print(Xbox.getAnalogHat(i,LeftHatX));
            Serial.print("\t");
          } 
          if(Xbox.getAnalogHat(i,LeftHatY) > 7500) {
            Serial.print(F("LeftHatY: ")); 
            Serial.print(Xbox.getAnalogHat(i,LeftHatY));
            Serial.print(LeftHatY);
                  // set the speed to 200/255
            motor.run(FORWARD);      // turn it on going forward
            
            Serial.print("\t");
          } 
          else
          if(Xbox.getAnalogHat(i,LeftHatY) < 7500 && Xbox.getAnalogHat(i,LeftHatY) > -7500) {
            Serial.print(F("LeftHatY: ")); 
            Serial.print(Xbox.getAnalogHat(i,LeftHatY));
           // set the speed to 200/255
            motor.run(RELEASE);      // stops motor
            
            Serial.print("\t");
          }
         if(Xbox.getAnalogHat(i,LeftHatY) < -7500) {
            
           Serial.print(F("LeftHatY: ")); 
            Serial.print(Xbox.getAnalogHat(i,LeftHatY));
                // set the speed to 200/255
            motor.run(BACKWARD);      // turn it on going forward
            
            Serial.print("\t");
          } 
          else
          if(Xbox.getAnalogHat(i,LeftHatY) < 7500 && Xbox.getAnalogHat(i,LeftHatY) > -7500) {
            Serial.print(F("LeftHatY: ")); 
            Serial.print(Xbox.getAnalogHat(i,LeftHatY));
         // set the speed to 200/255
            motor.run(RELEASE);      // stops motor
            
            Serial.print("\t");
          }
          if(Xbox.getAnalogHat(i,RightHatX) > 7500 || Xbox.getAnalogHat(i,RightHatX) < -7500) {
            Serial.print(F("RightHatX: ")); 
            Serial.print(Xbox.getAnalogHat(i,RightHatX));
            Serial.print("\t");      
          } 
          if(Xbox.getAnalogHat(i,RightHatY) > 7500 || Xbox.getAnalogHat(i,RightHatY) < -7500) {
            Serial.print(F("RightHatY: ")); 
            Serial.print(Xbox.getAnalogHat(i,RightHatY));  
          }
          Serial.println();
        }

        if(Xbox.getButtonClick(i,UP)) {
          Xbox.setLedOn(i,LED1);
          Serial.println(F("Up"));
          
          
        }      
        if(Xbox.getButtonClick(i,DOWN)) {
          Xbox.setLedOn(i,LED4);
          Serial.println(F("Down"));
        }
        if(Xbox.getButtonClick(i,LEFT)) {
          Xbox.setLedOn(i,LED3);
          Serial.println(F("Left"));
        }
        if(Xbox.getButtonClick(i,RIGHT)) {
          Xbox.setLedOn(i,LED2);
          Serial.println(F("Right"));
        }        

        if(Xbox.getButtonClick(i,START)) {
          Xbox.setLedMode(i,ALTERNATING);
          Serial.println(F("Start"));
        }
        if(Xbox.getButtonClick(i,BACK)) {
          Xbox.setLedBlink(i,ALL);
          Serial.println(F("Back"));
        }
        if(Xbox.getButtonClick(i,L3))
          Serial.println(F("L3"));
        if(Xbox.getButtonClick(i,R3))
          Serial.println(F("R3"));

        if(Xbox.getButtonClick(i,L1))
          Serial.println(F("L1"));
        if(Xbox.getButtonClick(i,R1))
          Serial.println(F("R1"));
        if(Xbox.getButtonClick(i,XBOX)) {
          Xbox.setLedMode(i,ROTATING);
          Serial.print(F("Xbox (Battery: "));
          Serial.print(Xbox.getBatteryLevel(i)); // The battery level in the range 0-3
          Serial.println(F(")"));
        }
        if(Xbox.getButtonClick(i,SYNC))
          Serial.println(F("Sync"));

        if(Xbox.getButtonClick(i,A))
          Serial.println(F("A"));
        if(Xbox.getButtonClick(i,B))
          Serial.println(F("B"));
        if(Xbox.getButtonClick(i,X))
          Serial.println(F("X"));
        if(Xbox.getButtonClick(i,Y))
          Serial.println(F("Y"));
      }
    }
  }  
  delay(1);
}

The code was taken from the USB host shield library 2.0, but modified a little bit.

if(Xbox.getAnalogHat(i,LeftHatX) > 7500 || Xbox.getAnalogHat(i,LeftHatX) < -7500 || Xbox.getAnalogHat(i,LeftHatY) > 7500 || Xbox.getAnalogHat(i,LeftHatY) < -7500 || Xbox.getAnalogHat(i,RightHatX) > 7500 || Xbox.getAnalogHat(i,RightHatX) < -7500 || Xbox.getAnalogHat(i,RightHatY) > 7500 || Xbox.getAnalogHat(i,RightHatY) < -7500 || Xbox.getAnalogHat(i,LeftHatY) < 7500 || Xbox.getAnalogHat(i,LeftHatY) > -7500) {

This is not needed like this, split them up. Left side, one IF statement, and right side another.

Why do you need both X and Y directions? You should only need the Y direction for forward and reverse movements.

Also, you dont need this, “Xbox.getAnalogHat(i,LeftHatY) > 7500 || Xbox.getAnalogHat(i,LeftHatY) < -7500”, just constrain it.

Left_Y = constrain(Xbox.getAnalogHat(i,LeftHatY), -7500, 7500); Done. now do the same for Right_Y.

Movement:
if(Left_Y > deadZone(usually just 0) ) // move forward
else // move reverse