Ball-screw controlled linear run tests

Processing (java) code


import processing.serial.*;
Serial myPort;
import controlP5.*;
ScrollableList COM;
ControlP5 cp5;
float bar;
int rot;
int dir;
int mode;
String portname;
Button a;
Button b;
Button c;
Button d;
Button e;
Button f;
Button g;
Button h;
Button i;
PImage img1;
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PFont font1;
PFont font2;
PFont font3;
PrintWriter output;
Textfield Textfield1;
Textfield Textfield2;
Textfield Textfield3;
Textfield Textfield4;
Textfield Textfield5;
Textfield Textfield6;
Textfield Textfield7;
Textfield Textfield8;
Textfield Textfield9;
Textfield Textfield10;
void setup() {
  size(1366, 980);
  font1 = loadFont("Arial-Black-12.vlw");
  font2 = loadFont("Arial-Black-48.vlw");
  font3 = loadFont("Arial-Black-18.vlw");
  ControlFont Font1 = new ControlFont(font1);
  ControlFont Font2 = new ControlFont(font2); 
  ControlFont Font3 = new ControlFont(font3); 
  portname = Serial.list()[0];
  myPort = new Serial(this, portname, 38400); 
  noStroke();
  img1 = loadImage("1.png");
  img2 = loadImage("2.png");
  img3 = loadImage("3.png");
  img4 = loadImage("4.png");
  img5 = loadImage("5.png");
  cp5 = new ControlP5(this);
  a = cp5.addButton("UP")
    .setValue(1)
    .setPosition(0, 210)
    .setSize(width/2, 100)
    .setSwitch(true)
    .setOff()
    .setImages(loadImage("11.png"), loadImage("12.png"), loadImage("13.png"))
    ;
  a.getCaptionLabel();
  //a.setFont(Font2);
  b = cp5.addButton("DOWN")
    .setValue(2)
    .setPosition(width/2-200, 210)
    .setSize(width/2, 100)
    .setSwitch(true)
    .setOff()
    .setImages(loadImage("21.png"), loadImage("22.png"), loadImage("23.png"))
    ;
  b.getCaptionLabel();
  //  b.setFont(Font2);
  c = cp5.addButton("Progon")
    .setValue(2)
    .setPosition(0, 0)
    .setSize(width/6, 200)
    .setSwitch(true)
    .setOff()
    .setImages(loadImage("31.png"), loadImage("32.png"), loadImage("33.png"))
    ;
  d = cp5.addButton("Stupen'ka")
    .setValue(2)
    .setPosition(width/7, 0)
    .setSize(width/6, 200)
    .setSwitch(true)
    .setOff()
    .setImages(loadImage("41.png"), loadImage("42.png"), loadImage("43.png"))
    ;
  e = cp5.addButton("ProgonDoKonca")
    .setValue(2)
    .setPosition(2*width/7, 0)
    .setSize(width/6, 200)
    .setSwitch(true)
    .setOff()
    .setImages()
    .setImages(loadImage("51.png"), loadImage("52.png"), loadImage("53.png"))
    ;
  f = cp5.addButton("Vyrovnyat Sverhu")
    .setValue(2)
    .setPosition(3*width/7, 0)
    .setSize(width/6, 200)
    .setSwitch(true)
    .setOff()
    .setImages(loadImage("61.png"), loadImage("62.png"), loadImage("63.png"))
    ;
  g = cp5.addButton("Vyrovnyat Snizu")
    .setValue(2)
    .setPosition(4*width/7, 0)
    .setSize(width/6, 200)
    .setSwitch(true)
    .setOff()
    .setImages(loadImage("71.png"), loadImage("72.png"), loadImage("73.png"))
    ;
  h = cp5.addButton("Seredina")
    .setValue(2)
    .setPosition(5*width/7, 0)
    .setSize(width/6, 200)
    .setSwitch(true)
    .setOff()
    .setImages(loadImage("81.png"), loadImage("82.png"), loadImage("83.png"))
    ;
  i = cp5.addButton("Experiment")
    .setValue(2)
    .setPosition(6*width/7, 0)
    .setSize(width/6, 200)
    .setSwitch(true)
    .setOff();
  i.getCaptionLabel()
    .setFont(Font1)
    ;
  cp5.addButton("Start")
    .setValue(1)
    .setPosition(0, 780)
    .setSize(width, 100)
    .setImages(loadImage("91.png"), loadImage("92.png"), loadImage("93.png"))
    .getCaptionLabel()
    .setFont(Font2)
    ;
  cp5.addButton("Stop")
    .setValue(1)
    .setPosition(0, 880)
    .setSize(width, 100)
    //.setImages(loadImage("91.png"), loadImage("92.png"), loadImage("93.png"))
    .getCaptionLabel()
    .setFont(Font2)
    ;
  Textfield1 = cp5.addTextfield("Dlina")
    .setPosition(width/2-300, 320)
    .setSize(200, 50)
    .setFocus(true)
    .setFont(Font2)
    .setDefaultValue(0.0)
    .setLabel("");

  ;
  cp5.addButton("clear1")
    .setValue(0)
    .setPosition(cp5.getController("Dlina").getPosition()[0]-120, cp5.getController("Dlina").getPosition()[1]+25)
    .setSize(100, 20)
    .setLabel("Clear")
    .getCaptionLabel()
    .setFont(Font3)
    ;
  Textfield2 = cp5.addTextfield("Skorost")
    .setPosition(width/2-300, 420)
    .setSize(200, 50)
    .setFocus(false)
    .setFont(Font2)
    .setLabel("");
  ;
  cp5.addButton("clear2")
    .setValue(0)
    .setPosition(cp5.getController("Skorost").getPosition()[0]-120, cp5.getController("Skorost").getPosition()[1]+25)
    .setSize(100, 20)
    .setLabel("Clear")
    .getCaptionLabel()
    .setFont(Font3)
    ;
  Textfield3 = cp5.addTextfield("vyd")
    .setPosition(width/2-300, 520)
    .setSize(200, 50)
    .setFocus(false)
    .setFont(Font2)
    .setLabel("");
  ;
  cp5.addButton("clear3")
    .setValue(0)
    .setPosition(cp5.getController("vyd").getPosition()[0]-120, cp5.getController("vyd").getPosition()[1]+25)
    .setSize(100, 20)
    .setLabel("Clear")
    .getCaptionLabel()
    .setFont(Font3)
    ;
  Textfield4 = cp5.addTextfield("chislint")
    .setPosition(width/2-300, 620)
    .setSize(200, 50)
    .setFocus(false)
    .setFont(Font2)
    .setLabel("");
  ;
  cp5.addButton("clear4")
    .setValue(0)
    .setPosition(cp5.getController("chislint").getPosition()[0]-120, cp5.getController("chislint").getPosition()[1]+25)
    .setSize(100, 20)
    .setLabel("Clear")
    .getCaptionLabel()
    .setFont(Font3)
    ;
  Textfield5 = cp5.addTextfield("koord")
    .setPosition(width/2-300, 720)
    .setSize(200, 50)
    .setFocus(false)
    .setFont(Font2)
    .setLabel("");
  ;
  cp5.addButton("clear5")
    .setValue(0)
    .setPosition(cp5.getController("koord").getPosition()[0]-120, cp5.getController("koord").getPosition()[1]+25)
    .setSize(100, 20)
    .setLabel("Clear")
    .getCaptionLabel()
    .setFont(Font3)
    ;
  Textfield6 = cp5.addTextfield("skorost1")
    .setPosition(width/2+300, 320)
    .setSize(200, 50)
    .setFocus(false)
    .setFont(Font2)
    .setLabel("skorost1");
  ;
  cp5.addButton("clear6")
    .setValue(0)
    .setPosition(cp5.getController("skorost1").getPosition()[0]-120, cp5.getController("skorost1").getPosition()[1]+25)
    .setSize(100, 20)
    .setLabel("Clear")
    .getCaptionLabel()
    .setFont(Font3)
    ;
  Textfield7 = cp5.addTextfield("skorost2")
    .setPosition(width/2+300, 420)
    .setSize(200, 50)
    .setFocus(false)
    .setFont(Font2)
    .setLabel("skorost2");
  ;
  cp5.addButton("clear7")
    .setValue(0)
    .setPosition(cp5.getController("skorost2").getPosition()[0]-120, cp5.getController("skorost2").getPosition()[1]+25)
    .setSize(100, 20)
    .setLabel("Clear")
    .getCaptionLabel()
    .setFont(Font3)
    ;
  Textfield8 = cp5.addTextfield("skorost3")
    .setPosition(width/2+300, 520)
    .setSize(200, 50)
    .setFocus(false)
    .setFont(Font2)
    .setLabel("skorost3");
  ;
  cp5.addButton("clear8")
    .setValue(0)
    .setPosition(cp5.getController("skorost3").getPosition()[0]-120, cp5.getController("skorost3").getPosition()[1]+25)
    .setSize(100, 20)
    .setLabel("Clear")
    .getCaptionLabel()
    .setFont(Font3)
    ;
  String[] portNames =Serial.list(); 
  COM = cp5.addScrollableList("COM") 
    .setPosition(50, 500) 
    .setSize(200, 200) 
    .setBarHeight(100) 
    .setItemHeight(20) 
    .addItems(portNames) 
    .setValue(0);
  COM.getValueLabel().setFont(Font1);
  COM.getCaptionLabel().setFont(Font2);
}
void clear1() {
  Textfield1.clear();
}
void clear2() {
  Textfield2.clear();
}
void clear3() {
  Textfield3.clear();
}
void clear4() {
  Textfield4.clear();
}
void clear5() {
  Textfield5.clear();
}
void clear6() {
  Textfield6.clear();
}
void clear7() {
  Textfield7.clear();
}
void clear8() {
  Textfield8.clear();
}
public void Skorost(float her) {
  her = cp5.getController("Skorost").getValue();
  rot = int(394.53125/her);
}
void ButtonPressed()
{ 
  if (a.isPressed() == true) {
    b.setOff();
    dir = 0;
  } else if (b.isPressed() == true) {
    a.setOff();
    dir = 1;
  }
}
void ButtonNotPressed() 
{
  if (c.isPressed() == true) {
    d.setOff();
    e.setOff();
    f.setOff();
    g.setOff();
    h.setOff();
    i.setOff();
    mode = 0;
  } 
  if (d.isPressed() == true) {
    c.setOff();
    e.setOff();
    f.setOff();
    g.setOff();
    h.setOff();
    i.setOff();
    mode = 1;
  } 
  if (e.isPressed() == true) {
    d.setOff();
    c.setOff();
    f.setOff();
    g.setOff();
    h.setOff();
    i.setOff();
    mode = 2;
  } 
  if (f.isPressed() == true) {
    d.setOff();
    e.setOff();
    c.setOff();
    g.setOff();
    h.setOff();
    i.setOff();
    mode = 3;
  } 
  if (g.isPressed() == true) {
    d.setOff();
    e.setOff();
    f.setOff();
    c.setOff();
    h.setOff();
    i.setOff();
    mode = 4;
  }
  if (h.isPressed() == true) {
    d.setOff();
    e.setOff();
    f.setOff();
    g.setOff();
    c.setOff();
    i.setOff();
    mode = 5;
  }
  if (i.isPressed() == true) {
    c.setOff();
    d.setOff();
    e.setOff();
    f.setOff();
    g.setOff();
    h.setOff();
    mode = 6;
  }
}
public void Start() {
  if (Float.isNaN(float(Textfield1.getText()))) {
    bar = 0;
  } else
  {
    bar = float(Textfield1.getText());
  }
  myPort.write('<'+str(bar)+','+str(int(394.53125/float(Textfield2.getText())))+','+str(dir)+','+str(mode)+','+str(int(Textfield3.getText()))+','+str(int(Textfield4.getText()))+','+str(int(Textfield5.getText())+100)+','+str(int(394.53125/float(Textfield6.getText())))+','+str(int(394.53125/float(Textfield7.getText())))+','+str(int(394.53125/float(Textfield8.getText())))+'>');
  println('<'+str(bar)+','+str(int(394.53125/float(Textfield2.getText())))+','+str(dir)+','+str(mode)+','+str(int(Textfield3.getText()))+','+str(int(Textfield4.getText()))+','+str(int(Textfield5.getText())+100)+','+str(int(394.53125/float(Textfield6.getText())))+','+str(int(394.53125/float(Textfield7.getText())))+','+str(int(394.53125/float(Textfield8.getText())))+'>');
  println(Textfield1.getText());
}
public void Stop() {
  myPort.clear(); //delete the port
  myPort.stop(); //stop the port
  portname = Serial.list()[int(cp5.getController("COM").getValue())]; //port name is set to the selected port in the dropDownMeny
  myPort = new Serial(this, portname, 38400); //Create a new connection
}
public void draw() {
  background(0);
  fill(0xff002d5a);
  rect(0, 0, width, 200);
  fill(255);
  image(img1, 600, 320);
  image(img2, 600, 420);
  image(img3, 600, 520);
  image(img4, 600, 620);
  image(img5, 600, 720);
  ButtonPressed();
  ButtonNotPressed();
}
void COM() { //when something in the list is selected
  myPort.clear(); //delete the port
  myPort.stop(); //stop the port
  portname = Serial.list()[int(cp5.getController("COM").getValue())]; //port name is set to the selected port in the dropDownMeny
  myPort = new Serial(this, portname, 38400); //Create a new connection
  println("Serial index set to: " + COM.getValue());
}
          

Arduino (C-like) code


  // ДАННЫЕ В ТЕРМИНАЛ ПИСАТЬ В ФОРМАТЕ <ChisloOborotov,Skorost,dir,rezhim,vyd,ChisloIntervalov,koord>, например, <10,50,0,0,1,5,0,0,0,0,0,0> <111,222,333,444,555,666,777,888,999,10gg>
  //ОБРАТИ ВНИМАНИЕ НА ПЕРЕМЕННУЮ dir. Направление LOW - вверх (к двигателю),HIGH - вниз (от двигателя)
  //Подключить двигатель в соответствующие пины контроллера Arduino:
  int Enable = 4;
  int Direction = 3;
  int Step = 2;
  long Oborot = 6400;  //Число сигналов, которые нужно подать ддя полного оборота (микрошаг 1/32)
  float ChisloOborotov; //Число оборотов. Может быть дробным. Один оборот двигателя равен 5.05 мм перемещения швп.
  //Для одного полного хода на 505 мм ввести 100 (макс.ход - 520 мм).
  long i = 0; //переменные циклов
  long j = 0;
  long k = 0;
  const byte numChars = 64;
  char receivedChars[numChars];
  char tempChars[numChars];        // temporary array for use when parsing
  // variables to hold the parsed data
  boolean newData = false;
  int Skorost; //Задержка между сигналами в мкс. Регулироавние частоты вращения и линейной скорости перемещения ШВП. ЧЕМ МЕНЬШЕ ЗНАЧЕНИЕ ПЕРЕМЕННОЙ. ТЕМ БОЛЬШЕ СКОРОСТЬ
  int dir; //Направление LOW - вверх (к двигателю),HIGH - вниз (от двигателя)
  int rezhim; //Смена режима работы программы
  long vyd; //Время выдержки в ступенчатом режиме работы
  int ChisloIntervalov; //Число интервалов при ступенчатом режиме выдержки
  int koord; //Переменная для координаты в режиме перемещения на координату
  int top = 100; //Координата верхнего и нижнего положения рамы
  int bottom = 590;
  int cycle = 200;
  int ebat = map(analogRead(A0), 160.0, 807.0, 98.8, 594.0);
  int sk1;
  int sk2;
  int sk3;
  long vyd1;
  long vyd2;
  void setup() {
    // put your setup code here, to run once:
    pinMode(Enable, OUTPUT);
    pinMode(Step, OUTPUT);
    pinMode(Direction, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(A0, INPUT);
    Serial.begin(38400);
  }

  void loop() {
    // put your main code here, to run repeatedly:
    recvWithStartEndMarkers();
    if (newData == true) {
      strcpy(tempChars, receivedChars);
      // this temporary copy is necessary to protect the original data
      //   because strtok() used in parseData() replaces the commas with \0
      parseData();
      printdata();
      newData = false;
    }
  }
  void drisnya() {
    digitalWrite(Step, HIGH);
    digitalWrite(9, HIGH);
    delayMicroseconds(Skorost);
    digitalWrite(Step, LOW);
    digitalWrite(9, LOW);
    delayMicroseconds(Skorost);
  }

  void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;

    while (Serial.available() > 0 && newData == false) {
      rc = Serial.read();

      if (recvInProgress == true) {
        if (rc != endMarker) {
          receivedChars[ndx] = rc;
          ndx++;
          if (ndx >= numChars) {
            ndx = numChars - 1;
          }
        }
        else {
          receivedChars[ndx] = '\0'; // terminate the string
          recvInProgress = false;
          ndx = 0;
          newData = true;
        }
      }

      else if (rc == startMarker) {
        recvInProgress = true;
      }
    }
  }

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

  void parseData() {      // split the data into its parts

    char * strtokIndx; // this is used by strtok() as an index

    strtokIndx = strtok(tempChars, ",");     // get the first part - the string
    ChisloOborotov = atoi(strtokIndx); // copy it to messageFromPC

    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    Skorost = atoi(strtokIndx);     // convert this part to an integer

    strtokIndx = strtok(NULL, ",");
    dir = atoi(strtokIndx);     // convert this part to a float

    strtokIndx = strtok(NULL, ",");
    rezhim = atoi(strtokIndx);

    strtokIndx = strtok(NULL, ",");
    vyd = atoi(strtokIndx);

    strtokIndx = strtok(NULL, ",");
    ChisloIntervalov = atoi(strtokIndx);

    strtokIndx = strtok(NULL, ",");
    koord = atoi(strtokIndx);

    strtokIndx = strtok(NULL, ",");
    sk1 = atoi(strtokIndx);

    strtokIndx = strtok(NULL, ",");
    sk2 = atoi(strtokIndx);

    strtokIndx = strtok(NULL, ",");
    sk3 = atoi(strtokIndx);
  }
  void printdata() {
    Serial.print("ChisloOborotov ");
    Serial.println(ChisloOborotov);
    Serial.print("Skorost ");
    Serial.println(Skorost);
    Serial.print("dir ");
    Serial.println(dir);
    Serial.print("rezhim ");
    Serial.println(rezhim);
    Serial.print("vyd ");
    Serial.println(vyd);
    Serial.print("ChisloIntervalov ");
    Serial.println(ChisloIntervalov);
    Serial.print("koord1 ");
    Serial.println(koord);
    Serial.print("koord2 ");
    Serial.println(sk1);
    Serial.print("koord3 ");
    Serial.println(sk2);
    Serial.print("koord4 ");
    Serial.println(sk3);
  }

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

  void kick(int dirr) {
    digitalWrite(Direction, dirr);
    for (long k = 0; k < 6400; k++) {
      digitalWrite(Step, HIGH);

      delayMicroseconds(70);
      digitalWrite(Step, LOW);
      digitalWrite(9, LOW);
      delayMicroseconds(70);
    }
  }

  void pizdec() {
    digitalWrite(5, LOW);
    digitalWrite(Enable, HIGH);
    digitalWrite(Direction, dir);
    if (rezhim == 0) {
      digitalWrite(5, HIGH);
      for (long i = 0; i < ChisloOborotov * Oborot / cycle; i++) {
        for (long k = 0; k < cycle; k++) {
          drisnya();
        }
        k = 0;
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top || map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
          break;
        }
      }
      i = 0;
      digitalWrite(5, LOW);
    }
    else if (rezhim == 1) {
      digitalWrite(5, HIGH);
      while (j < ChisloIntervalov)
      {
        for (long i = 0; i < ChisloOborotov * Oborot / (cycle * ChisloIntervalov); i++) {
          for (long k = 0; k < cycle; k++) {
            drisnya();
          }
          k = 0;
          if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top || map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
            break;
          }
        }
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top || map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
          break;
        }
        i = 0;
        j++;
        digitalWrite(5, LOW);
        delay(vyd * 1000);
        digitalWrite(5, HIGH);
      }
      j = 0;
      digitalWrite(5, LOW);
    }
    else if (rezhim == 2) {
      digitalWrite(5, HIGH);
      while (1) {
        for (long i = 0; i < cycle; i++) {
          drisnya();
        }
        i = 0;
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top || map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
          break;
        }
      }
      digitalWrite(5, LOW);
      if (dir == 0) {
        kick(1);
      }
      else if (dir == 1) {
        kick(0);
      }
    }
    else if (rezhim == 3) {
      digitalWrite(5, HIGH);
      while (1) {
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top) {
          digitalWrite(Direction, HIGH);
          for (long i = 0; i < 200; i++) {
            digitalWrite(Step, HIGH);

            delayMicroseconds(30);
            digitalWrite(Step, LOW);

            delayMicroseconds(30);
          }
          i = 0;
        }
        else if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > top) {
          digitalWrite(Direction, LOW);
          for (long i = 0; i < 200; i++) {
            digitalWrite(Step, HIGH);

            delayMicroseconds(30);
            digitalWrite(Step, LOW);

            delayMicroseconds(30);
          }
          i = 0;
        }
        else if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) == top) {
          kick(1);
          break;
        }
      }
      digitalWrite(5, LOW);
    }
    else if (rezhim == 4) {
      digitalWrite(5, HIGH);
      while (1) {
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < bottom) {
          digitalWrite(Direction, HIGH);
          for (long i = 0; i < 200; i++) {
            digitalWrite(Step, HIGH);

            delayMicroseconds(30);
            digitalWrite(Step, LOW);

            delayMicroseconds(30);
          }
          i = 0;
        }
        else if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
          digitalWrite(Direction, LOW);
          for (long i = 0; i < 200; i++) {
            digitalWrite(Step, HIGH);

            delayMicroseconds(30);
            digitalWrite(Step, LOW);

            delayMicroseconds(30);
          }
          i = 0;
        }
        else if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) == bottom) {
          kick(0);
          break;
        }
      }
      digitalWrite(5, LOW);
    }
    else if (rezhim == 5) {
      digitalWrite(5, HIGH);
      while (1) {
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < koord) {
          digitalWrite(Direction, HIGH);
          for (long i = 0; i < cycle; i++) {
            drisnya();
          }
          i = 0;
        }
        else if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > koord) {
          digitalWrite(Direction, LOW);
          for (long i = 0; i < cycle; i++) {
            drisnya();
          }
          i = 0;
        }
        else if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) == koord) {
          break;
        }
      }
      digitalWrite(5, LOW);
      delay(vyd * 1000);
      digitalWrite(Direction, dir);
      digitalWrite(5, HIGH);
      while (1) {
        for (long i = 0; i < cycle; i++) {
          drisnya();
        }
        i = 0;
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top || map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
          break;
        }
      }
      digitalWrite(5, LOW);
    }
    else if (rezhim == 6) {
      digitalWrite(5, HIGH); //1
      digitalWrite(Direction, HIGH);
      while (1) {
        for (long i = 0; i < cycle; i++) {
          digitalWrite(Step, HIGH);

          delayMicroseconds(sk1);
          digitalWrite(Step, LOW);

          delayMicroseconds(sk1);
        }
        i = 0;
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top || map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
          break;
        }
      }
      digitalWrite(5, LOW);
      delay(vyd * 1000);
      kick(0);
      digitalWrite(5, HIGH); //2
      digitalWrite(Direction, LOW);
      while (1) {
        for (long i = 0; i < cycle; i++) {
          digitalWrite(Step, HIGH);

          delayMicroseconds(sk1);
          digitalWrite(Step, LOW);

          delayMicroseconds(sk1);
        }
        i = 0;
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top || map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
          break;
        }
      }
      digitalWrite(5, LOW);
      delay(vyd * 1000);
      kick(1);
      digitalWrite(5, HIGH); //3
      digitalWrite(Direction, HIGH);
      while (1) {
        for (long i = 0; i < cycle; i++) {
          digitalWrite(Step, HIGH);

          delayMicroseconds(sk2);
          digitalWrite(Step, LOW);

          delayMicroseconds(sk2);
        }
        i = 0;
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top || map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
          break;
        }
      }
      digitalWrite(5, LOW);
      delay(vyd * 1000);
      kick(0);
      digitalWrite(5, HIGH); //4
      digitalWrite(Direction, LOW);
      while (1) {
        for (long i = 0; i < cycle; i++) {
          digitalWrite(Step, HIGH);

          delayMicroseconds(sk2);
          digitalWrite(Step, LOW);

          delayMicroseconds(sk2);
        }
        i = 0;
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top || map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
          break;
        }
      }
      digitalWrite(5, LOW);
      delay(vyd * 1000);
      kick(1);
      digitalWrite(5, HIGH); //5
      digitalWrite(Direction, HIGH);
      while (1) {
        for (long i = 0; i < cycle; i++) {
          digitalWrite(Step, HIGH);

          delayMicroseconds(sk3);
          digitalWrite(Step, LOW);

          delayMicroseconds(sk3);
        }
        i = 0;
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top || map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
          break;
        }
      }
      digitalWrite(5, LOW);
      delay(vyd * 1000);
      kick(0);
      digitalWrite(5, HIGH); //6
      digitalWrite(Direction, LOW);
      while (1) {
        for (long i = 0; i < cycle; i++) {
          digitalWrite(Step, HIGH);

          delayMicroseconds(sk3);
          digitalWrite(Step, LOW);

          delayMicroseconds(sk3);
        }
        i = 0;
        if (map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) < top || map(analogRead(A0), 160.0, 807.0, 98.8, 594.0) > bottom) {
          break;
        }
      }
      digitalWrite(5, LOW);
      kick(1);
    }
  }