public void ResetZRail() { while (!printer.LimitSwitchPressed()) { printer.StepStepper(PrinterControl.StepperDir.STEP_UP); } for (int i = 0; i < 39800; i++) { printer.StepStepper(PrinterControl.StepperDir.STEP_DOWN); } }
public void LimitVelocity() { int currentVelocity = 0; while (printer.StepStepper(PrinterControl.StepperDir.STEP_UP) || printer.StepStepper(PrinterControl.StepperDir.STEP_DOWN)) { while (currentVelocity < MaxZRailVelocity) { } } }
public void StepStepperUp(int steps) { int stepCount = 0; for (int i = 0; i < steps; i++) { printer.StepStepper(PrinterControl.StepperDir.STEP_UP); stepCount++; if (stepCount == 40) { Thread.Sleep(20); stepCount = 0; } } }
void RetractPlate() { ResetAccelStepper(); while (!printer.LimitSwitchPressed()) { if (!printer.StepStepper(PrinterControl.StepperDir.STEP_UP)) { break; } WaitForNextStep(); } plateZ = printer.GetPrinterHeight(); }
public void ToLimit() { var switch_pressed = printer.LimitSwitchPressed(); var delay = 0; var stepperSpeed = 1; var totalDelay = 0; //Too keep track of the number of uS before increasing speed. while (switch_pressed != true) { totalDelay += delay; if (totalDelay >= 1010000) { stepperSpeed = IncreaseStepperSpeed(stepperSpeed); totalDelay = 0; } delay = CalculateStepperDelay(stepperSpeed); printer.WaitMicroseconds(delay); printer.StepStepper(PrinterControl.StepperDir.STEP_UP); switch_pressed = printer.LimitSwitchPressed(); } }
public void GoToBuildSurface() { double currentDelay = 625; double microsecondsPassed = 0; for (int i = 0; i < 40000; i++) { printer.StepStepper(PrinterControl.StepperDir.STEP_DOWN); printer.WaitMicroseconds((long)currentDelay); microsecondsPassed = microsecondsPassed + currentDelay; if (microsecondsPassed > 1000000L) { currentDelay = currentDelay - 100; if (currentDelay < 150) { currentDelay = 150; } microsecondsPassed = 0; } } }
public void movementWithSpeed(PrinterControl printer, PrinterControl.StepperDir dir, float distance) { float velocity = 0; float distanceTraveled = 0; while (currentLocation == -1 && !(printer.LimitSwitchPressed())) { velocity += Acceleration; //Thread.Sleep(1000); for (var i = 0; i < velocity; i++) { for (var j = 0; j < 400; j++) { if (printer.LimitSwitchPressed()) { break; } printer.StepStepper(dir); distanceTraveled += (float)(1.0 / 400); } if (printer.LimitSwitchPressed()) { break; } } //printer.StepStepper(dir); } if (((dir == PrinterControl.StepperDir.STEP_DOWN) && (currentLocation - distance > 0) && (!printer.LimitSwitchPressed() || (currentLocation != -1)))) { while (distanceTraveled < distance) { if (velocity < maxVelocity && (velocity + Acceleration < maxVelocity)) { velocity += Acceleration; } else if (velocity < maxVelocity && (maxVelocity - velocity < Acceleration)) //allows us to reach max velocity without overshooting { velocity = maxVelocity; } //Thread.Sleep(1000); for (var i = 0; i < velocity; i++) { for (var j = 0; j < 400; j++) { if (distanceTraveled >= distance || (printer.LimitSwitchPressed() && (currentLocation == -1))) { break; } printer.StepStepper(dir); distanceTraveled += (float)(1.0 / 400); } if (distanceTraveled >= distance || printer.LimitSwitchPressed()) { break; } }/* * if (distanceTraveled + velocity < distance) //if we wont over shoot * { * distanceTraveled += velocity; * } * else //this happens if we're close but the velocity will over shoot it should move the rest of the way without overshooting * { * //distanceTraveled += (velocity - distance); * velocity = 0; * } */ } currentLocation -= distanceTraveled; } if ((dir == PrinterControl.StepperDir.STEP_UP) && currentLocation + distance < 100 && !printer.LimitSwitchPressed()) { while (distanceTraveled < distance) { if (velocity < maxVelocity && (velocity + Acceleration < maxVelocity)) { velocity += Acceleration; } else if (velocity < maxVelocity && (maxVelocity - velocity < Acceleration)) { velocity = maxVelocity; } // Thread.Sleep(1000); for (var i = 0; i < velocity; i++) { for (var j = 0; j < 400; j++) { if (distanceTraveled >= distance || printer.LimitSwitchPressed()) { break; } printer.StepStepper(dir); distanceTraveled += (float)(1.0 / 400); } if (distanceTraveled >= distance || printer.LimitSwitchPressed()) { break; } } } currentLocation += distanceTraveled; } }
public void executeCommand(byte command, byte[] param) { try { switch (command) { case 0x00: return; case 0x01: commandsExecuted["ResetStepper"] += 1; printer.ResetStepper(); moveStepperToTop(); moveStepperFromTopToBuildPlate(); break; case 0x02: float direction = BitConverter.ToSingle(param, 0); if (direction == 1) { Console.WriteLine("Step up"); commandsExecuted["StepStepperUp"] += 1; bool result = printer.StepStepper(PrinterControl.StepperDir.STEP_UP); } else if (direction == 0) { Console.WriteLine("Step down"); commandsExecuted["StepStepperDown"] += 1; bool result = printer.StepStepper(PrinterControl.StepperDir.STEP_DOWN); } break; case 0x03: float value = BitConverter.ToSingle(param, 0); if (value == 1) { printer.SetLaser(true); Console.WriteLine("Turned on laser"); } else if (value == 0) { printer.SetLaser(false); Console.WriteLine("Turned laser off"); } else { Console.WriteLine("Invalid laser value for on/off"); } break; case 0x04: commandsExecuted["MoveGalvonometer"] += 1; float x = BitConverter.ToSingle(param, 0); float y = BitConverter.ToSingle(param, 4); printer.MoveGalvos(x, y); Console.WriteLine("Moved galvo"); break; default: Console.WriteLine("Bad command"); break; } } catch (Exception e) { System.Console.WriteLine(e.StackTrace); } }