Transitioning Arduino Motor Shield from UNO to Mega

I’m having issues transitioning a project from an Arduino UNO to an Arduino Mega.

The code worked fine on the UNO, but moving to the MEGA results in the robot only driving straight forward (stick up or right) or turning right (stick back or left); it won’t reverse or turn left.

I might have the motors wired backward (I don’t think so), but that would result in the controls being reversed not this odd behavior.

This is a code excerpt; the full code includes a lot of irrelevant parts (like controlling sensors and servos). Please let me know if there’s something not here that you need to see.

I THINK this is a UNO/MEGA difference that I can’t figure out; all the Serial debug data shows the correct values.

I’ve checked and rechecked the wiring, but none of the pin wiring should matter since this is a shield. The battery and motor wiring is unchanged from the UNO version.

Thank you very much.

  //Drive Tracks
  float V = 0.0;
  float omega = 0.0;
  float xVal = 0.0;
  float yVal = 0.0;
  
  //Set a NULL / Dead Space for the stick
  if(rightX < 1550 && rightX > 1450) 
    {xVal = 0;}
  else 
    {xVal = myMap(rightX, 1200, 1800, negpi, pi);}
  
  if(rightY < 1550 && rightY > 1450)
    {yVal = 0;}
  else
    {yVal = myMap(rightY, 1200, 1800, negpi, pi);}
  
  //Translate stick commands into velocity and angle
  V = yVal;
  omega = xVal / pi;
  
  //Translate velocity and angle into track speed
  Vr = (((2.0 * V) + (omega * width)) / (2.0 * radius));
  Vl = (((2.0 * V) - (omega * width)) / (2.0 * radius));
  
  //Control Right Motor
  if(Vr == 0)  //STOP
  {
    digitalWrite(brakeA, HIGH);
    analogWrite(speedA, 0);
  }
  else
  {
    digitalWrite(brakeA, LOW);
    
    //Convert Radian values to PWM
    Vr = map(Vr, negpi, pi, -255, 255);
    Vr = constrain(Vr, -255, 255);
    
    if(Vr > 0)
      digitalWrite(dirA, HIGH);
    else
      digitalWrite(dirA, LOW);

    analogWrite(speedA, abs(Vr));
  }
    
  //Control Left Motor
  if(Vl == 0)  //STOP
  {
    digitalWrite(brakeB, HIGH);
    analogWrite(speedB, 0);
  }
  else
  {
    digitalWrite(brakeB, LOW);
    
    //Convert Radian values to PWM
    Vl = map(Vl, negpi, pi, -255, 255);
    Vl = constrain(Vl, -255, 255);
    
    if(Vl > 0)
      digitalWrite(dirB, HIGH);
    else
      digitalWrite(dirB, LOW);
    
    analogWrite(speedB, abs(Vl));
  }