Stepper Motor/Leadscrew problem

I’m using an Arduino Mega 2560 with a motor shield to control a set-up with a stepper motor connected to a lead screw, one on each axis. The problem appears to be with my code, I can get the mounts on the leadscrew to go to the commanded position of 180 degrees on the x-axis, and 45 degrees on the y-axis, but then the issue begins. I will input the y-axis to go to some location such as 50 or 60 degrees on the y-axis, but the y-axis mount always continues twice as far in the direction than what is desired. Any help is greatly appreciated. The code I’m using is below:

#include <AccelStepper.h>
#include <AFMotor.h>

//========================================
//==============  CONSTANTS  =============
//========================================
float latitude = 37.3414;      //SCU
float longitude = -121.952;
float timezone = -7;            //Timezone

float l1 = 16;        //in - L1 on mirror structure (back arm)
float l2 = 14.69;        //in - L2 on mirror structure

float pitch = 0.125;    //in - leadscrew pitch (3/8 - 12 screw)
float starts = 2;        //# start
float lead = pitch*starts;  //in - lead of screw (distance traveled in 1 rotation)
float cartwidth = 4.5;        //in - width of cart on actuator
float lx = 24;              //in - length of x actuator space
float ly = 36;              //in - length of y actuator space

float stepper_resolution = 200;    //resolution of stepper

float xlims[2], ylims[2];    //x and y max/min in form [xmin, xmax], [ymin, ymax]
float args[2] = {180, 0};
long stepsx,stepsy, stepsy_half;

float pi = 3.14159265;

//Logical holders for stepper zeroing
boolean xcal = 0;    //0 == FALSE i.e. not zeroed
boolean ycal = 0;
//========================================
//========================================


//========================================
//=============  GLOBAL VARS  ============
//========================================
int EW,NS;
float azi = 0;
float ele = 0;          //open loop azi and ele
float l3  = 0;
float x, y;             //open loop x and y
//=====================


//================== MOTOR CONFIG STUFF ================
AF_Stepper motor1(200, 1); //X motor
AF_Stepper motor2(200, 2); //Y motor

void forwardstep1() {              
  motor1.onestep(FORWARD, DOUBLE);
}
void backwardstep1() {  
  motor1.onestep(BACKWARD, DOUBLE);
}

void forwardstep2() {  
  motor2.onestep(FORWARD, DOUBLE);    
}
void backwardstep2() {  
  motor2.onestep(BACKWARD, DOUBLE);
}
// Motor shield has two motor ports, now we'll wrap them in an AccelStepper object
//AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);

int xcalpin = 19;
int ycalpin = 18;

void setup()
{  
    //setup steppers
    stepper1.setMaxSpeed(300);    //200rpm = 4in/min with 3/8-12 screw
    stepper1.setAcceleration(300);
    stepper2.setMaxSpeed(300);
    stepper2.setAcceleration(300);
    //start serial
    Serial.begin(115200);
    //interrupts for zeroing x and y
//    attachInterrupt(4, xzero, FALLING);
//    attachInterrupt(5, yzero, FALLING);
pinMode(xcalpin, INPUT);

}

char X_buffer[8];
float maxPOS = 32e3;
float setPointPOS, requestedPOS;
int j=1;

long previousMillis = 0;
long interval = 5000;

void loop() //begin main loop
{
  
  //if X and Y not calibrated, run motors until limit switch hit; will run on every restart
//   Serial.println("Zeroing X Actuator");
   while (xcal == 0){
    stepper2.moveTo(-100000);
    stepper2.run();
    Serial.println("Calibrating X");
      
      if (digitalRead(xcalpin)==0){
        xzero();
      }
      
    }
   while (ycal == 0){
    stepper1.moveTo(-100000);
    stepper1.run();
    Serial.println("Calibrating Y");
      
      if (digitalRead(ycalpin)==0){
        yzero();
        Serial.println("Both actuators properly zeroed");
        Serial.print(stepper2.currentPosition());
        Serial.print(" , ");
        Serial.print(stepper1.currentPosition());
        azi = 180;
        ele = 45;
      }
      
    }
    if (l3 >= 27 || l3 < 13){
      stepper1.moveTo(-1);
      stepper2.moveTo(-5);
      stepper1.run();
      stepper2.run();
    }
      

//Serial.println("loop!");

  
  //==========FOR X===========
if (Serial.available()){
      //make sure we have all the data
      delay(5);
      //serial data is waiting, lets extract     
      int  i=0;     
      while(i<8){
        X_buffer[i] = Serial.read();
        //Serial.println(X_buffer[i]);
        i++;
      }
     
      //flush serial buffer of extra data>9999
      Serial.flush();
      //convert numeric string to int var
      requestedPOS = atof(X_buffer);
      //check for set point greater than maxPWR limit
      if( requestedPOS < maxPOS){
        //Buffer contains a safe value, copy out to setPointPWR
        setPointPOS = requestedPOS;
//        Serial.print("Requested set point:");
//        Serial.println(setPointPOS);
      }
      
      else{
        Serial.println("'The sun don't shine here!"); //errorcode 2012, you requested a pathalogical power level
        setPointPOS = 0; //
      }
      if (j>0){
        Serial.print("Accepted AZI position:");
        Serial.println(requestedPOS);
        azi = setPointPOS;
        //stepsx = setPointPOS;
      }
      else if (j<0){
        Serial.print("Accepted ELE position:");
        Serial.println(requestedPOS);
        ele = setPointPOS;
        //stepsy = setPointPOS;
      }
      j=-j;
    }
     //calculate location on actuators
     y = aziele2y(azi, ele, l1, l2, args);
     x = aziele2x(azi, ele, l1, l2, args);
     l3 = l3_length(x, y, args);
     stepsx = disp2steps(x);
     stepsy = (disp2steps(y));
     //calculate corresponding step position
     
     
 stepper1.moveTo(stepsy);
 stepper2.moveTo(stepsx);
 stepper1.run();
 stepper2.run();
 
    unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   
    
    
    Serial.print("actuator positions: ");
//    Serial.print(steps2disp(stepper2.currentPosition()));
    Serial.print(x);
    Serial.print(" , ");
//    Serial.println(steps2disp(stepper1.currentPosition()));
    Serial.print(y);
    Serial.println(" ");
    Serial.print("Tracker Angles:");
    Serial.print(azi_pos(x, y, l1, l2, args));
    Serial.print(" , ");
    Serial.println(ele_pos(x, y, l1, l2, args));
    Serial.println("==============");
//    Serial.print(stepper2.distanceToGo());
//    Serial.print("  ,   ");
    Serial.print(stepper1.distanceToGo());
    Serial.println("X distance to go:");
    float xprog = steps2disp(stepper2.distanceToGo());
    Serial.println(xprog);
    Serial.print("Y distance to go:");
    float yprog = steps2disp(stepper1.distanceToGo());
    Serial.println(yprog);
    
//    Serial.println("================");
//    Serial.print("azi, ele: ");
//    Serial.print(azi);
//    Serial.print(" , ");
//    Serial.println(ele);
//    
//    Serial.print("x, y: ");
//    Serial.print(x);
//    Serial.print(" , ");
//    Serial.println(y);
    
//    Serial.print("X Step location:");
//    Serial.println(stepsx);
//    Serial.print("X step destination:");
//    Serial.println(stepper1.targetPosition());
//    Serial.println("++++++++++++++");
//    Serial.print("Y Step location");
//    Serial.println(stepsy);
//    Serial.print("Y step destination");
//    Serial.print(stepper2.targetPosition());
  }
  
  //now to sleep steppers if distanceToGo<0
  if(stepper1.distanceToGo() == 0 && stepper2.distanceToGo() == 0){
  stepper1.disableOutputs();
  stepper2.disableOutputs();
  }
else if(stepper1.distanceToGo() > 0 || stepper2.distanceToGo() > 0){
  stepper1.enableOutputs();
  stepper2.enableOutputs();
}
}




void xzero(){
  Serial.println("Zeroing X actuator");
  long tmppos = disp2steps(lx/2) - (cartwidth/2) * stepper_resolution / lead;
  tmppos = -tmppos;
   //calculating position based on screw and stepper info
  stepper2.setCurrentPosition(tmppos);    //makes zero in the middle of the x actuator when cart is at end...sneaky!
  Serial.print("Current position: ");
  Serial.println(stepper2.currentPosition());
  stepsx = stepper2.currentPosition();
  xcal = 1;
}

void yzero(){
  Serial.println("Zeroing Y actuator");
   //calculating position based on screw and stepper info
  long tmppos = 14.3391 * stepper_resolution / pitch;
  stepper1.setCurrentPosition(tmppos);    //makes zero in the middle of the x actuator when cart is at end...sneaky!
  Serial.print("Current position: ");
  Serial.println(stepper1.currentPosition());
  stepsy = stepper1.currentPosition();
  ycal = 1;
  
}

long disp2steps(float disp){      //actuator displacement to steps
  long steps = disp * stepper_resolution / pitch;    //will truncate; OK since 1 step = 0.00125" for .25 lead screw
  return steps;
}

float steps2disp(long isteps){
  float steps = (long)isteps;
  float disp = steps/(stepper_resolution / pitch);
  return disp;
}

The actuator calculations that go along with this are:

/// These functions convert given azimuth and elevation angles to X and Y
/// actuator positions for the low-profile T-Tracker solar tracker.
/// Copyright Team Helios 2012. Code written by Laughlin Barker BSME 2012.
/// 
/// Input arguments are as follows:

//   azi = azimuth of sun
//   ele = elevation of sun
//   l1 = l1 length of the tracker (riser arm)
//   l2 = l2 of the tracker (distance b/t two mirror mount/piviot points)
//   args = [Ori, offset]
//
//   (TRACKER TOP VIEW)
//         Oir = orientation of "T" of tracker (normally 180 deg)
//            ^
//            |
//            |
//            |
//            |   ^ +y
//            |   |
//            |  _|_
// ___________|____________
//            
//            |----> +x

//=========   FIRST TO SOLVE FOR Y POSITION   ==========
float aziele2y(float azi, float ele, float l1, float l2, float args[2])
{
//convert to theta phi values
float theta = abs(azi - 180);
float phi = 90 - ele;

//a = sec(theta)^2
float a = pow((1/cos(theta*pi/180)),2);
//b = -2 * sec(theta) * cos(phi) * l2
float b = -2 * 1/cos(theta*pi/180) * cos(phi*pi/180) * l2;
//c = l2^2 - l1^2
float c = pow(l2,2) - pow(l1,2);

//additive solution to simple quadratic eqn
float y = (-b + pow((pow(b,2) - 4 * a * c),0.5)) / (2 * a);
return y;
}

float aziele2x(float azi, float ele, float l1, float l2, float args[2])
{
//convert to theta phi values
float theta = abs(azi - 180);
float phi = 90 - ele;

//a = sec(theta)^2
float a = pow((1/cos(theta*pi/180)),2);
//b = -2 * sec(theta) * cos(phi) * l2
float b = -2 * 1/cos(theta*pi/180) * cos(phi*pi/180) * l2;
//c = l2^2 - l1^2
float c = pow(l2,2) - pow(l1,2);

//additive solution to simple quadratic eqn
float y = (-b + pow((pow(b,2) - 4 * a * c),0.5)) / (2 * a);
float x = tan(theta*pi/180) * y;

if (azi<180){
x = x;
}
else{
x = -x;
}

return x;
}

//============================================================================

float azi_pos(float x, float y, float l1, float l2, float args[]){
  
 float theta = abs(atan(x/y))*180/pi;
  
  if (x < 0){
    azi = args[0] + theta;        //if x is negative azi angle of tracker is >180 deg
  }
  else if (x > 0){
    azi = args[0] - theta;        // if x is positive azi angle of tracker is <180 deg
  }
  else if (x==0){
    azi = args[0];
  }
  return azi;
}

float ele_pos(float x, float y, float l1, float l2, float args[]){
  
   float h = pow( (pow(x,2) + pow(y,2)) ,0.5);
   float phi = acos((pow(l1,2) - pow(h,2) - pow(l2,2))/(-2 * h *l2))*180/pi;
   float  ele = 90 -  phi;
    return ele;
}

float l3_length(float x, float y, float args[]){
  float l3 = pow( pow(2*x,2) + pow(y,2), 0.5);
  return l3;
}

Please edit the post so that code tags are used for code
// like this, as explained in the sticky thread...