public override Vector3 SetPrinterPosition(Vector3 position) { Vector3 positionFromInternalStream = internalStream.SetPrinterPosition(position); lastDestination = new PrinterMove(positionFromInternalStream, 0, 0); return(position); }
public override void SetPrinterPosition(PrinterMove position) { if (LevelingActive && position.PositionFullyKnown) { string lineBeingSent = CreateMovementLine(position); string leveledPosition = GetLeveledPosition(lineBeingSent, position); PrinterMove leveledDestination = GetPosition(leveledPosition, PrinterMove.Unknown); PrinterMove deltaToLeveledPosition = leveledDestination - position; PrinterMove withoutLevelingOffset = position - deltaToLeveledPosition; _lastDestination = withoutLevelingOffset; _lastDestination.extrusion = position.extrusion; _lastDestination.feedRate = position.feedRate; internalStream.SetPrinterPosition(_lastDestination); } else { this._lastDestination.CopyKnowSettings(position); internalStream.SetPrinterPosition(position); } }
public override Vector3 SetPrinterPosition(Vector3 position) { Vector3 positionFromInternalStream = internalStream.SetPrinterPosition(position); lastDestination = new PrinterMove(positionFromInternalStream, 0, 0); return positionFromInternalStream; }
public static string CreateMovementLine(PrinterMove destination, PrinterMove start) { string lineBeingSent; StringBuilder newLine = new StringBuilder("G1 "); if (destination.position.x != start.position.x || destination.position.y != start.position.y || destination.position.z != start.position.z) { newLine = newLine.Append(String.Format("X{0:0.##} ", destination.position.x)); newLine = newLine.Append(String.Format("Y{0:0.##} ", destination.position.y)); newLine = newLine.Append(String.Format("Z{0:0.###} ", destination.position.z)); } if (destination.extrusion != start.extrusion) { newLine = newLine.Append(String.Format("E{0:0.###} ", destination.extrusion)); } if (destination.feedRate != start.feedRate) { newLine = newLine.Append(String.Format("F{0:0.##}", destination.feedRate)); } lineBeingSent = newLine.ToString(); return(lineBeingSent.Trim()); }
public override void SetPrinterPosition(PrinterMove outputPosition) { var outputWithLeveling = PrinterMove.Unknown; outputWithLeveling.CopyKnowSettings(outputPosition); if (LevelingActive && outputPosition.PositionFullyKnown) { string expectedOutput = CreateMovementLine(outputPosition); string doubleLeveledOutput = GetLeveledPosition(expectedOutput, outputPosition); PrinterMove doubleLeveledDestination = GetPosition(doubleLeveledOutput, PrinterMove.Unknown); PrinterMove deltaToLeveledPosition = doubleLeveledDestination - outputPosition; this.inputUnleveled = outputPosition - deltaToLeveledPosition; // clean up settings that we don't want to be subtracted this.inputUnleveled.extrusion = outputPosition.extrusion; this.inputUnleveled.feedRate = outputPosition.feedRate; internalStream.SetPrinterPosition(this.inputUnleveled); } else { this.inputUnleveled = outputPosition; internalStream.SetPrinterPosition(this.inputUnleveled); } }
public override string ReadLine() { string lineFromChild = base.ReadLine(); if (lineFromChild != null && PrintLevelingStream.Enabled && PrinterConnectionAndCommunication.Instance.ActivePrinter.GetValue <bool>(SettingsKey.print_leveling_enabled) && !PrinterConnectionAndCommunication.Instance.ActivePrinter.GetValue <bool>(SettingsKey.has_hardware_leveling)) { if (LineIsMovement(lineFromChild)) { PrinterMove currentDestination = GetPosition(lineFromChild, lastDestination); lineFromChild = RunPrintLevelingTranslations(lineFromChild, currentDestination); lastDestination = currentDestination; return(lineFromChild); } else if (lineFromChild.StartsWith("G29")) { // remove G29 (machine prob bed) if we are running our own leveling. lineFromChild = base.ReadLine(); // get the next line instead } } return(lineFromChild); }
public override string ReadLine() { string lineToSend = base.ReadLine(); if (lineToSend != null && lineToSend.EndsWith("; NO_PROCESSING")) { return(lineToSend); } if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentMove = GetPosition(lineToSend, lastDestination); if (currentMove.HaveAnyPosition) { ClampToPrinter(ref currentMove); lineToSend = CreateMovementLine(currentMove, lastDestination); } lastDestination = currentMove; return(lineToSend); } return(lineToSend); }
public override string ReadLine() { string lineToSend = null; // lock queue lock (locker) { if (commandQueue.Count > 0) { lineToSend = commandQueue[0]; commandQueue.RemoveAt(0); } } if (lineToSend == null) { lineToSend = base.ReadLine(); } // keep track of the position if (lineToSend != null && LineIsMovement(lineToSend)) { lastDestination = GetPosition(lineToSend, lastDestination); } return(lineToSend); }
private string RunPrintLevelingTranslations(string lineBeingSent, PrinterMove currentDestination) { PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); if (levelingData != null) { switch (levelingData.CurrentPrinterLevelingSystem) { case PrintLevelingData.LevelingSystem.Probe2Points: lineBeingSent = LevelWizard2Point.ApplyLeveling(lineBeingSent, currentDestination.position, PrinterMachineInstruction.MovementTypes.Absolute); break; case PrintLevelingData.LevelingSystem.Probe3Points: lineBeingSent = LevelWizard3Point.ApplyLeveling(lineBeingSent, currentDestination.position, PrinterMachineInstruction.MovementTypes.Absolute); break; case PrintLevelingData.LevelingSystem.Probe7PointRadial: lineBeingSent = LevelWizard7PointRadial.ApplyLeveling(lineBeingSent, currentDestination.position, PrinterMachineInstruction.MovementTypes.Absolute); break; case PrintLevelingData.LevelingSystem.Probe13PointRadial: lineBeingSent = LevelWizard13PointRadial.ApplyLeveling(lineBeingSent, currentDestination.position, PrinterMachineInstruction.MovementTypes.Absolute); break; default: throw new NotImplementedException(); } } return(lineBeingSent); }
public string CreateMovementLine(PrinterMove destination, PrinterMove start) { bool moveHasExtrusion = destination.extrusion != start.extrusion; string command = (useG0ForMovement && !moveHasExtrusion) ? "G0 " : "G1 "; var sb = new StringBuilder(command); if (destination.position.X != start.position.X) { sb.AppendFormat("X{0:0.##} ", destination.position.X); } if (destination.position.Y != start.position.Y) { sb.AppendFormat("Y{0:0.##} ", destination.position.Y); } if (destination.position.Z != start.position.Z) { sb.AppendFormat("Z{0:0.###} ", destination.position.Z); } if (moveHasExtrusion) { sb.AppendFormat("E{0:0.###} ", destination.extrusion); } if (destination.feedRate != start.feedRate) { sb.AppendFormat("F{0:0.##}", destination.feedRate); } return(sb.ToString().Trim()); }
public override string ReadLine() { string lineFromChild = base.ReadLine(); if (lineFromChild != null) { if (LineIsMovement(lineFromChild)) { PrinterMove currentDestination = GetPosition(lineFromChild, lastDestination); if (PrinterConnectionAndCommunication.Instance.ActivePrinter.DoPrintLeveling) { lineFromChild = RunPrintLevelingTranslations(lineFromChild, currentDestination); } lastDestination = currentDestination; return(lineFromChild); } else if (lineFromChild.StartsWith("G29")) { // remove G29 (machine prob bed) if we are running our own leveling. lineFromChild = base.ReadLine(); // get the next line instead } } return(lineFromChild); }
public override string ReadLine() { string lineToSend = null; // lock queue lock(locker) { if (commandQueue.Count > 0) { lineToSend = commandQueue[0]; commandQueue.RemoveAt(0); } } if (lineToSend == null) { lineToSend = base.ReadLine(); } // keep track of the position if (lineToSend != null && LineIsMovement(lineToSend)) { lastDestination = GetPosition(lineToSend, lastDestination); } return lineToSend; }
public override string ReadLine() { string lineToSend = internalStream.ReadLine(); if (lineToSend != null && lineToSend.EndsWith("; NO_PROCESSING")) { return(lineToSend); } if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentMove = GetPosition(lineToSend, this.lastDestination); PrinterMove moveToSend = currentMove; moveToSend.feedRate *= FeedRateRatio; if (moveToSend.HaveAnyPosition) { lineToSend = CreateMovementLine(moveToSend, this.lastDestination); } this.lastDestination = currentMove; return(lineToSend); } return(lineToSend); }
public override string ReadLine() { string lineFromChild = base.ReadLine(); if (lineFromChild != null) { if (LineIsMovement(lineFromChild)) { PrinterMove currentDestination = GetPosition(lineFromChild, lastDestination); if (PrinterConnectionAndCommunication.Instance.ActivePrinter.DoPrintLeveling) { lineFromChild = RunPrintLevelingTranslations(lineFromChild, currentDestination); } lastDestination = currentDestination; return lineFromChild; } else if (lineFromChild.StartsWith("G29")) { // remove G29 (machine prob bed) if we are running our own leveling. lineFromChild = base.ReadLine(); // get the next line instead } } return lineFromChild; }
public static string CreateMovementLine(PrinterMove destination, PrinterMove start) { string lineBeingSent; StringBuilder newLine = new StringBuilder("G1 "); if (destination.position.x != start.position.x) { newLine = newLine.Append(String.Format("X{0:0.##} ", destination.position.x)); } if (destination.position.y != start.position.y) { newLine = newLine.Append(String.Format("Y{0:0.##} ", destination.position.y)); } if (destination.position.z != start.position.z) { newLine = newLine.Append(String.Format("Z{0:0.###} ", destination.position.z)); } if (destination.extrusion != start.extrusion) { newLine = newLine.Append(String.Format("E{0:0.###} ", destination.extrusion)); } if (destination.feedRate != start.feedRate) { newLine = newLine.Append(String.Format("F{0:0.##}", destination.feedRate)); } lineBeingSent = newLine.ToString(); return lineBeingSent.Trim(); }
public override string ReadLine() { string lineToSend = null; // lock queue lock (locker) { if (commandQueue.Count > 0) { lineToSend = commandQueue[0]; commandQueue.RemoveAt(0); } } if (lineToSend == null) { lineToSend = base.ReadLine(); lineToSend = relativeToAbsoluteConverter.ProcessLine(lineToSend); if (lineToSend == null) { return(lineToSend); } } if (lineToSend.StartsWith("; LAYER:")) { string layerNumber = lineToSend.Split(':')[1]; if (PauseOnLayer(layerNumber)) { DoPause(); } } else if (lineToSend.StartsWith("M226") || lineToSend.StartsWith("@pause")) { DoPause(); } else if (lineToSend == "MH_PAUSE") { if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting) { // remember where we were after we ran the pause gcode moveLocationAtEndOfPauseCode = LastDestination; PrinterConnectionAndCommunication.Instance.CommunicationState = PrinterConnectionAndCommunication.CommunicationStates.Paused; } lineToSend = ""; } // keep track of the position if (lineToSend != null && LineIsMovement(lineToSend)) { lastDestination = GetPosition(lineToSend, lastDestination); } return(lineToSend); }
public override void SetPrinterPosition(PrinterMove position) { this.lastDestination.CopyKnowSettings(position); if (extruderIndex < 4) { lastDestination.position -= BabbyStepOffset; lastDestination.position += extruderOffsets[extruderIndex]; } internalStream.SetPrinterPosition(lastDestination); }
public override Vector3 SetPrinterPosition(Vector3 position) { Vector3 positionFromInternalStream = internalStream.SetPrinterPosition(position); lastDestination = new PrinterMove(positionFromInternalStream, 0, 0); string lineBeingSent = CreateMovementLine(lastDestination); string leveledPosition = RunPrintLevelingTranslations(lineBeingSent, lastDestination); PrinterMove leveledDestination = GetPosition(leveledPosition, lastDestination); return leveledDestination.position; }
public static PrinterMove GetPosition(string lineBeingSent, PrinterMove startPositionPosition) { PrinterMove currentDestination = startPositionPosition; GCodeFile.GetFirstNumberAfter("X", lineBeingSent, ref currentDestination.position.x); GCodeFile.GetFirstNumberAfter("Y", lineBeingSent, ref currentDestination.position.y); GCodeFile.GetFirstNumberAfter("Z", lineBeingSent, ref currentDestination.position.z); GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref currentDestination.extrusion); GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref currentDestination.feedRate); return currentDestination; }
public static PrinterMove GetPosition(string lineBeingSent, PrinterMove startPositionPosition) { PrinterMove currentDestination = startPositionPosition; GCodeFile.GetFirstNumberAfter("X", lineBeingSent, ref currentDestination.position.x); GCodeFile.GetFirstNumberAfter("Y", lineBeingSent, ref currentDestination.position.y); GCodeFile.GetFirstNumberAfter("Z", lineBeingSent, ref currentDestination.position.z); GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref currentDestination.extrusion); GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref currentDestination.feedRate); return(currentDestination); }
public override Vector3 SetPrinterPosition(Vector3 position) { Vector3 positionFromInternalStream = internalStream.SetPrinterPosition(position); lastDestination = new PrinterMove(positionFromInternalStream, 0, 0); string lineBeingSent = CreateMovementLine(lastDestination); PrinterMove leveledDestination = new PrinterMove(lastDestination.position + offset, 0, 0); return(leveledDestination.position); }
public override void SetPrinterPosition(PrinterMove outputPosition) { outputWithBabyStepping.CopyKnowSettings(outputPosition); // calculate our offset to pass on to internal streams inputNoBabyStepping = outputWithBabyStepping; inputNoBabyStepping.position -= BabbyStepOffset; inputNoBabyStepping.position += extruderOffsets[Math.Min(extruderIndex, 4)]; internalStream.SetPrinterPosition(inputNoBabyStepping); }
public override Vector3 SetPrinterPosition(Vector3 position) { Vector3 positionFromInternalStream = internalStream.SetPrinterPosition(position); lastDestination = new PrinterMove(positionFromInternalStream, 0, 0); string lineBeingSent = CreateMovementLine(lastDestination); string leveledPosition = RunPrintLevelingTranslations(lineBeingSent, lastDestination); PrinterMove leveledDestination = GetPosition(leveledPosition, lastDestination); return(leveledDestination.position); }
public override string ReadLine() { string lineToSend = base.ReadLine(); if (lineToSend != null && lineToSend.EndsWith("; NO_PROCESSING")) { return(lineToSend); } if (lineToSend != null && lineToSend.StartsWith("T")) { int extruder = 0; if (GCodeFile.GetFirstNumberAfter("T", lineToSend, ref extruder)) { extruderIndex = extruder; } } if (lineToSend != null && LineIsMovement(lineToSend)) { inputNoBabyStepping = GetPosition(lineToSend, inputNoBabyStepping); // it is a struct so this is making a new copy we con modify PrinterMove moveToSend = inputNoBabyStepping; printer.Settings.ForTools <double>(SettingsKey.baby_step_z_offset, (key, value, i) => { if (extruderIndex == i) { moveToSend.position = new Vector3(moveToSend.position.X, moveToSend.position.Y, moveToSend.position.Z + GetBabbyStepOffset(i)); } }); moveToSend.position -= extruderOffsets[Math.Min(extruderIndex, 4)]; if (moveToSend.HaveAnyPosition) { lineToSend = CreateMovementLine(moveToSend, outputWithBabyStepping); } outputWithBabyStepping = moveToSend; return(lineToSend); } return(lineToSend); }
public override string ReadLine() { var baseLine = base.ReadLine(); if (baseLine == null) { return(null); } if (baseLine.EndsWith("; NO_PROCESSING")) { return(baseLine); } // if the line has no content don't process it if (baseLine.Length == 0 || baseLine.Trim().Length == 0) { return(baseLine); } var lines = ProcessWriteRegEx(baseLine, printer); for (int i = lines.Count - 1; i >= 1; i--) { queueStream.Add(lines[i], true); } var lineToSend = lines[0]; if (lineToSend != null && LineIsMovement(lineToSend)) { currentMove = GetPosition(lineToSend, currentMove); } // is it a position set? if (lineToSend.StartsWith("G92")) { GCodeFile.GetFirstNumberAfter("X", lineToSend, ref this.currentMove.position.X); GCodeFile.GetFirstNumberAfter("Y", lineToSend, ref this.currentMove.position.Y); GCodeFile.GetFirstNumberAfter("Z", lineToSend, ref this.currentMove.position.Z); GCodeFile.GetFirstNumberAfter("E", lineToSend, ref this.currentMove.extrusion); // tell the stream pipeline what the actual printer position is this.SetPrinterPosition(this.currentMove); } return(lineToSend); }
public override void SetPrinterPosition(PrinterMove position) { string lineBeingSent = CreateMovementLine(position); string leveledPosition = RunPrintLevelingTranslations(lineBeingSent, position); PrinterMove leveledDestination = GetPosition(leveledPosition, PrinterMove.Nowhere); PrinterMove deltaToLeveledPosition = leveledDestination - position; PrinterMove withoutLevelingOffset = position - deltaToLeveledPosition; lastDestination = withoutLevelingOffset; lastDestination.extrusion = position.extrusion; lastDestination.feedRate = position.feedRate; internalStream.SetPrinterPosition(lastDestination); }
public override string ReadLine() { if (hadZHome) { hadZHome = false; // only add this when exporting to gcode if (!activePrinting) { // return the correct G92 double zOffset = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.z_offset_after_home); if (zOffset != 0) { double newHomePosition = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.printer_z_after_home) + zOffset; return $"G92 Z{newHomePosition}"; } } } string lineFromChild = base.ReadLine(); if (lineFromChild != null && LineIsZHoming(lineFromChild)) { hadZHome = true; } if (lineFromChild != null && PrinterConnectionAndCommunication.Instance.ActivePrinter.GetValue<bool>(SettingsKey.print_leveling_enabled)) { if (LineIsMovement(lineFromChild)) { PrinterMove currentDestination = GetPosition(lineFromChild, lastDestination); lineFromChild = RunPrintLevelingTranslations(lineFromChild, currentDestination); lastDestination = currentDestination; return lineFromChild; } else if (lineFromChild.StartsWith("G29")) { // remove G29 (machine prob bed) if we are running our own leveling. lineFromChild = base.ReadLine(); // get the next line instead } } return lineFromChild; }
public override string ReadLine() { if (hadZHome) { hadZHome = false; // only add this when exporting to gcode if (!activePrinting) { // return the correct G92 double zOffset = ActiveSliceSettings.Instance.GetValue <double>(SettingsKey.z_offset_after_home); if (zOffset != 0) { double newHomePosition = ActiveSliceSettings.Instance.GetValue <double>(SettingsKey.printer_z_after_home) + zOffset; return($"G92 Z{newHomePosition}"); } } } string lineFromChild = base.ReadLine(); if (lineFromChild != null && LineIsZHoming(lineFromChild)) { hadZHome = true; } if (lineFromChild != null && PrinterConnectionAndCommunication.Instance.ActivePrinter.GetValue <bool>(SettingsKey.print_leveling_enabled)) { if (LineIsMovement(lineFromChild)) { PrinterMove currentDestination = GetPosition(lineFromChild, lastDestination); lineFromChild = RunPrintLevelingTranslations(lineFromChild, currentDestination); lastDestination = currentDestination; return(lineFromChild); } else if (lineFromChild.StartsWith("G29")) { // remove G29 (machine prob bed) if we are running our own leveling. lineFromChild = base.ReadLine(); // get the next line instead } } return(lineFromChild); }
public override string ReadLine() { // G91 Relative // G90 Absolute string lineToSend = base.ReadLine(); if (lineToSend != null && lineToSend.StartsWith("G9")) { if (lineToSend.StartsWith("G91")) { absoluteMode = false; return(""); } else if (lineToSend.StartsWith("G90")) { absoluteMode = true; } } if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentDestination; if (absoluteMode) { currentDestination = GetPosition(lineToSend, lastDestination); } else { currentDestination = GetPosition(lineToSend, PrinterMove.Zero); double feedRate = currentDestination.feedRate; currentDestination += lastDestination; currentDestination.feedRate = feedRate; lineToSend = CreateMovementLine(currentDestination, lastDestination); } // send the first one lastDestination = currentDestination; return(lineToSend); } return(lineToSend); }
public override string ReadLine() { if (!wroteLevelingStatus && LevelingActive) { wroteLevelingStatus = true; return("; Software Leveling Applied"); } string lineToSend = base.ReadLine(); if (lineToSend != null && lineToSend.EndsWith("; NO_PROCESSING")) { return(lineToSend); } if (lineToSend == "; Software Leveling Applied") { gcodeAlreadyLeveled = true; } if (lineToSend != null && LevelingActive && !gcodeAlreadyLeveled) { if (LineIsMovement(lineToSend)) { PrinterMove currentUnleveledDestination = GetPosition(lineToSend, inputUnleveled); var leveledLine = GetLeveledPosition(lineToSend, currentUnleveledDestination); // TODO: clamp to 0 - baby stepping - extruder z-offset, so we don't go below the bed (for the active extruder) inputUnleveled = currentUnleveledDestination; return(leveledLine); } else if (lineToSend.StartsWith("G29")) { // remove G29 (machine prob bed) if we are running our own leveling. lineToSend = base.ReadLine(); // get the next line instead } } return(lineToSend); }
public override string ReadLine() { string lineToSend = base.ReadLine(); if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentMove = GetPosition(lineToSend, lastDestination); PrinterMove moveToSend = currentMove; moveToSend.position += Offset; lineToSend = CreateMovementLine(moveToSend, lastDestination); lastDestination = currentMove; return(lineToSend); } return(lineToSend); }
public static PrinterMove GetPosition(string lineBeingSent, PrinterMove startPositionPosition) { if (lineBeingSent.StartsWith("G28") || lineBeingSent.StartsWith("G29") || lineBeingSent.StartsWith("G30")) { return(PrinterMove.Unknown); } PrinterMove currentDestination = startPositionPosition; GCodeFile.GetFirstNumberAfter("X", lineBeingSent, ref currentDestination.position.X); GCodeFile.GetFirstNumberAfter("Y", lineBeingSent, ref currentDestination.position.Y); GCodeFile.GetFirstNumberAfter("Z", lineBeingSent, ref currentDestination.position.Z); GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref currentDestination.extrusion); GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref currentDestination.feedRate); return(currentDestination); }
public override string ReadLine() { string lineToSend = internalStream.ReadLine(); if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentMove = GetPosition(lineToSend, this.LastDestination); PrinterMove moveToSend = currentMove; moveToSend.feedRate *= FeedRateRatio; lineToSend = CreateMovementLine(moveToSend, this.LastDestination); this.LastDestination = currentMove; return(lineToSend); } return(lineToSend); }
public override string ReadLine() { string lineToSend = base.ReadLine(); if (lineToSend != null && lineToSend.EndsWith("; NO_PROCESSING")) { return(lineToSend); } if (lineToSend != null && lineToSend.StartsWith("T")) { int extruder = 0; if (GCodeFile.GetFirstNumberAfter("T", lineToSend, ref extruder)) { extruderIndex = extruder; } } if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentMove = GetPosition(lineToSend, lastDestination); PrinterMove moveToSend = currentMove; if (extruderIndex < 4) { moveToSend.position += BabbyStepOffset; moveToSend.position -= extruderOffsets[extruderIndex]; } if (moveToSend.HaveAnyPosition) { lineToSend = CreateMovementLine(moveToSend, lastDestination); } lastDestination = currentMove; return(lineToSend); } return(lineToSend); }
public override string ReadLine() { string lineToSend = base.ReadLine(); if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentMove = GetPosition(lineToSend, lastDestination); PrinterMove moveToSend = currentMove; moveToSend.position += offset; lineToSend = CreateMovementLine(moveToSend, lastDestination); lastDestination = currentMove; return lineToSend; } return lineToSend; }
public override string ReadLine() { string lineToSend = internalStream.ReadLine(); if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentMove = GetPosition(lineToSend, lastDestination); PrinterMove moveToSend = currentMove; moveToSend.feedRate *= FeedRateRatio; lineToSend = CreateMovementLine(moveToSend, lastDestination); lastDestination = currentMove; return lineToSend; } return lineToSend; }
public override string ReadLine() { string lineToSend = base.ReadLine(); if (lineToSend != null && lineToSend.EndsWith("; NO_PROCESSING")) { return(lineToSend); } if (lineToSend != null && lineToSend.StartsWith("T")) { int extruder = 0; if (GCodeFile.GetFirstNumberAfter("T", lineToSend, ref extruder)) { extruderIndex = extruder; } } if (lineToSend != null && LineIsMovement(lineToSend)) { inputNoBabyStepping = GetPosition(lineToSend, inputNoBabyStepping); // it is a struct so this is making a new copy we con modify PrinterMove moveToSend = inputNoBabyStepping; moveToSend.position += BabbyStepOffset; moveToSend.position -= extruderOffsets[Math.Min(extruderIndex, 4)]; if (moveToSend.HaveAnyPosition) { lineToSend = CreateMovementLine(moveToSend, outputWithBabyStepping); } outputWithBabyStepping = moveToSend; return(lineToSend); } return(lineToSend); }
public override string ReadLine() { string lineToSend = base.ReadLine(); if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentDestination = GetPosition(lineToSend, lastDestination); // send the first one PrinterMove positionToSend = currentDestination; positionToSend.position += offset; lineToSend = CreateMovementLine(positionToSend, lastDestination); lastDestination = currentDestination; return(lineToSend); } return(lineToSend); }
private void ClampToPrinter(ref PrinterMove moveToSend) { var bounds = extruderBounds[printer.Connection.ActiveExtruderIndex]; // clamp to each axis for (int i = 0; i < 3; i++) { if (moveToSend.position[i] < bounds.MinXYZ[i]) { moveToSend.position[i] = bounds.MinXYZ[i]; // If we clamp, than do not do any extrusion at all moveToSend.extrusion = lastDestination.extrusion; } else if (moveToSend.position[i] > bounds.MaxXYZ[i]) { moveToSend.position[i] = bounds.MaxXYZ[i]; // If we clamp, than do not do any extrusion at all moveToSend.extrusion = lastDestination.extrusion; } } }
public override string ReadLine() { // Send any commands that are queue before moving on to the internal stream. string nextCommand = queuedCommands.ReadLine(); if (nextCommand != null) { return nextCommand; } switch (recoveryState) { // heat the extrude to remove it from the part case RecoveryState.RemoveHeating: // TODO: make sure we heat up all the extruders that we need to (all that are used) queuedCommands.Add("G21; set units to millimeters"); queuedCommands.Add("M107; fan off"); queuedCommands.Add("T0; set the active extruder to 0"); queuedCommands.Add("G90; use absolute coordinates"); queuedCommands.Add("G92 E0; reset the expected extruder position"); queuedCommands.Add("M82; use absolute distance for extrusion"); queuedCommands.Add("M109 S{0}".FormatWith(ActiveSliceSettings.Instance.Helpers.ExtruderTemperature(0))); recoveryState = RecoveryState.Raising; return ""; // remove it from the part case RecoveryState.Raising: queuedCommands.Add("M114 ; get current position"); queuedCommands.Add("G91 ; move relative"); queuedCommands.Add("G1 Z10 F{0}".FormatWith(MovementControls.ZSpeed)); queuedCommands.Add("G90 ; move absolute"); recoveryState = RecoveryState.Homing; return ""; // if top homing, home the extruder case RecoveryState.Homing: if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.z_homes_to_max)) { queuedCommands.Add("G28"); } else { // home x queuedCommands.Add("G28 X0"); // home y queuedCommands.Add("G28 Y0"); // move to the place we can home z from Vector2 recoveryPositionXy = ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.recover_position_before_z_home); queuedCommands.Add("G1 X{0:0.###}Y{1:0.###}F{2}".FormatWith(recoveryPositionXy.x, recoveryPositionXy.y, MovementControls.XSpeed)); // home z queuedCommands.Add("G28 Z0"); } recoveryState = RecoveryState.FindingRecoveryLayer; return ""; // This is to recover printing if an out a filament occurs. // Help the user move the extruder down to just touching the part case RecoveryState.FindingRecoveryLayer: if (false) // help the user get the head to the right position { // move to above the completed print // move over a know good part of the model at the current top layer (extrude vertex from gcode) // let the user move down until they like the height // calculate that position and continue } else // we are resuming because of disconnect or reset, skip this { recoveryState = RecoveryState.SkippingGCode; goto case RecoveryState.SkippingGCode; } case RecoveryState.SkippingGCode: // run through the gcode that the device expected looking for things like temp // and skip everything else until we get to the point we left off last time int commandCount = 0; boundsOfSkippedLayers = RectangleDouble.ZeroIntersection; while (internalStream.FileStreaming.PercentComplete(internalStream.LineIndex) < percentDone) { string line = internalStream.ReadLine(); if(line == null) { break; } commandCount++; // make sure we don't parse comments if(line.Contains(";")) { line = line.Split(';')[0]; } lastDestination = GetPosition(line, lastDestination); if (commandCount > 100) { boundsOfSkippedLayers.ExpandToInclude(lastDestination.position.Xy); if (boundsOfSkippedLayers.Bottom < 10) { int a = 0; } } // check if the line is something we want to send to the printer (like a temp) if (line.StartsWith("M109") || line.StartsWith("M104") || line.StartsWith("T") || line.StartsWith("M106") || line.StartsWith("M107")) { return line; } } recoveryState = RecoveryState.PrimingAndMovingToStart; // make sure we always- pick up the last movement boundsOfSkippedLayers.ExpandToInclude(lastDestination.position.Xy); return ""; case RecoveryState.PrimingAndMovingToStart: { if (ActiveSliceSettings.Instance.GetValue("z_homes_to_max") == "0") // we are homed to the bed { // move to the height we can recover printing from Vector2 recoverPositionXy = ActiveSliceSettings.Instance.GetValue<Vector2>(SettingsKey.recover_position_before_z_home); queuedCommands.Add(CreateMovementLine(new PrinterMove(new VectorMath.Vector3(recoverPositionXy.x, recoverPositionXy.y, lastDestination.position.z), 0, MovementControls.ZSpeed))); } double extruderWidth = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.nozzle_diameter); // move to a position outside the printed bounds queuedCommands.Add(CreateMovementLine(new PrinterMove( new Vector3(boundsOfSkippedLayers.Left - extruderWidth*2, boundsOfSkippedLayers.Bottom + boundsOfSkippedLayers.Height / 2, lastDestination.position.z), 0, MovementControls.XSpeed))); // let's prime the extruder queuedCommands.Add("G1 E10 F{0}".FormatWith(MovementControls.EFeedRate(0))); // extrude 10 queuedCommands.Add("G1 E9"); // and retract a bit // move to the actual print position queuedCommands.Add(CreateMovementLine(new PrinterMove(lastDestination.position, 0, MovementControls.XSpeed))); /// reset the printer to know where the filament should be queuedCommands.Add("G92 E{0}".FormatWith(lastDestination.extrusion)); recoveryState = RecoveryState.PrintingSlow; } return ""; case RecoveryState.PrintingSlow: { string lineToSend = internalStream.ReadLine(); if (lineToSend == null) { return null; } if (!GCodeFile.IsLayerChange(lineToSend)) { // have not seen the end of this layer so keep printing slow if (LineIsMovement(lineToSend)) { PrinterMove currentMove = GetPosition(lineToSend, lastDestination); PrinterMove moveToSend = currentMove; moveToSend.feedRate = recoverFeedRate; lineToSend = CreateMovementLine(moveToSend, lastDestination); lastDestination = currentMove; return lineToSend; } return lineToSend; } } // we only fall through to here after seeing the next "; Layer:" recoveryState = RecoveryState.PrintingToEnd; return ""; case RecoveryState.PrintingToEnd: return internalStream.ReadLine(); } return null; }
public override string ReadLine() { string lineToSend = null; // lock queue lock (locker) { if (commandQueue.Count > 0) { lineToSend = commandQueue[0]; commandQueue.RemoveAt(0); } } if (lineToSend == null) { lineToSend = base.ReadLine(); lineToSend = relativeToAbsoluteConverter.ProcessLine(lineToSend); if(lineToSend == null) { return lineToSend; } } if (lineToSend.StartsWith("; LAYER:")) { string layerNumber = lineToSend.Split(':')[1]; if (PauseOnLayer(layerNumber)) { DoPause(); } } else if (lineToSend.StartsWith("M226") || lineToSend.StartsWith("@pause")) { DoPause(); } else if (lineToSend == "MH_PAUSE") { if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting) { // remember where we were after we ran the pause gcode moveLocationAtEndOfPauseCode = LastDestination; PrinterConnectionAndCommunication.Instance.CommunicationState = PrinterConnectionAndCommunication.CommunicationStates.Paused; } lineToSend = ""; } // keep track of the position if (lineToSend != null && LineIsMovement(lineToSend)) { lastDestination = GetPosition(lineToSend, lastDestination); } return lineToSend; }
public override string ReadLine() { string nextCommand = queuedCommands.ReadLine(); if (nextCommand != null) { return nextCommand; } switch (resumeState) { // heat the extrude to remove it from the part case ResumeState.RemoveHeating: // TODO: make sure we heat up all the extruders that we need to (all that are used) queuedCommands.Add("G21; set units to millimeters"); queuedCommands.Add("M107; fan off"); queuedCommands.Add("T0; set the active extruder to 0"); queuedCommands.Add("G90; use absolute coordinates"); queuedCommands.Add("G92 E0; reset the expected extruder position"); queuedCommands.Add("M82; use absolute distance for extrusion"); queuedCommands.Add("M109 S{0}".FormatWith(ActiveSliceSettings.Instance.GetExtruderTemperature(1))); resumeState = ResumeState.Raising; return ""; // remove it from the part case ResumeState.Raising: queuedCommands.Add("M114 ; get current position"); queuedCommands.Add("G91 ; move relative"); queuedCommands.Add("G1 Z10 F{0}".FormatWith(MovementControls.ZSpeed)); queuedCommands.Add("G90 ; move absolute"); resumeState = ResumeState.Homing; return ""; // if top homing, home the extruder case ResumeState.Homing: if (ActiveSliceSettings.Instance.GetActiveValue("z_homes_to_max") == "1") { queuedCommands.Add("G28"); } else { // home x queuedCommands.Add("G28 X0"); // home y queuedCommands.Add("G28 Y0"); // move to the place we can home z from Vector2 resumePositionXy = ActiveSliceSettings.Instance.GetActiveVector2("resume_position_before_z_home"); queuedCommands.Add("G1 X{0:0.000}Y{1:0.000}F{2}".FormatWith(resumePositionXy.x, resumePositionXy.y, MovementControls.XSpeed)); // home z queuedCommands.Add("G28 Z0"); } resumeState = ResumeState.FindingResumeLayer; return ""; // This is to resume printing if an out a filament occurs. // Help the user move the extruder down to just touching the part case ResumeState.FindingResumeLayer: if (false) // help the user get the head to the right position { // move to above the completed print // move over a know good part of the model at the current top layer (extrude vertex from gcode) // let the user move down until they like the height // calculate that position and continue } else // we are resuming because of disconnect or reset, skip this { resumeState = ResumeState.SkippingGCode; goto case ResumeState.SkippingGCode; } case ResumeState.SkippingGCode: // run through the gcode that the device expected looking for things like temp // and skip everything else until we get to the point we left off last time while (internalStream.FileStreaming.PercentComplete(internalStream.LineIndex) < percentDone) { string line = internalStream.ReadLine(); lastDestination = GetPosition(line, lastDestination); // check if the line is something we want to send to the printer (like a temp) if (line.StartsWith("M109") || line.StartsWith("M104") || line.StartsWith("T") || line.StartsWith("M106") || line.StartsWith("M107")) { return line; } } resumeState = ResumeState.PrimingAndMovingToStart; return ""; case ResumeState.PrimingAndMovingToStart: { // let's prime the extruder, move to a good position over the part, then start printing queuedCommands.Add("G1 E5"); queuedCommands.Add("G1 E4"); if (ActiveSliceSettings.Instance.GetActiveValue("z_homes_to_max") == "0") // we are homed to the bed { // move to the height we can resume printing from Vector2 resumePositionXy = ActiveSliceSettings.Instance.GetActiveVector2("resume_position_before_z_home"); queuedCommands.Add(CreateMovementLine(new PrinterMove(new VectorMath.Vector3(resumePositionXy.x, resumePositionXy.y, lastDestination.position.z + 5), 0, MovementControls.ZSpeed))); // move just above the actual print position queuedCommands.Add(CreateMovementLine(new PrinterMove(lastDestination.position + new VectorMath.Vector3(0, 0, 5), 0, MovementControls.XSpeed))); // move down to part queuedCommands.Add(CreateMovementLine(new PrinterMove(lastDestination.position, 0, MovementControls.ZSpeed))); } else { // move to the actual print position queuedCommands.Add(CreateMovementLine(new PrinterMove(lastDestination.position, 0, MovementControls.ZSpeed))); } // extrude back to our filament start queuedCommands.Add("G1 E5"); /// reset the printer to know where the filament should be queuedCommands.Add("G92 E{0}".FormatWith(lastDestination.extrusion)); resumeState = ResumeState.PrintingSlow; } return ""; case ResumeState.PrintingSlow: { string lineToSend = internalStream.ReadLine(); if (!lineToSend.StartsWith("; LAYER:")) { if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentMove = GetPosition(lineToSend, lastDestination); PrinterMove moveToSend = currentMove; double feedRate; string firstLayerSpeed = ActiveSliceSettings.Instance.GetActiveValue("resume_first_layer_speed"); if (!double.TryParse(firstLayerSpeed, out feedRate)) { feedRate = 10; } feedRate *= 60; moveToSend.feedRate = feedRate; lineToSend = CreateMovementLine(moveToSend, lastDestination); lastDestination = currentMove; return lineToSend; } return lineToSend; } } resumeState = ResumeState.PrintingToEnd; return ""; case ResumeState.PrintingToEnd: return internalStream.ReadLine(); } return null; }
public override string ReadLine() { // G91 Relative // G90 Absolute string lineToSend = base.ReadLine(); if (lineToSend != null && lineToSend.StartsWith("G9")) { if (lineToSend.StartsWith("G91")) { absoluteMode = false; return ""; } else if (lineToSend.StartsWith("G90")) { absoluteMode = true; } } if (lineToSend != null && LineIsMovement(lineToSend)) { PrinterMove currentDestination; if (absoluteMode) { currentDestination = GetPosition(lineToSend, lastDestination); } else { currentDestination = GetPosition(lineToSend, PrinterMove.Zero); double feedRate = currentDestination.feedRate; currentDestination += lastDestination; currentDestination.feedRate = feedRate; lineToSend = CreateMovementLine(currentDestination, lastDestination); } // send the first one lastDestination = currentDestination; return lineToSend; } return lineToSend; }
public void ReadTargetPositions(object sender, EventArgs e) { FoundStringEventArgs foundStringEventArgs = e as FoundStringEventArgs; string lineToParse = foundStringEventArgs.LineToCheck; GCodeFile.GetFirstNumberAfter("X:", lineToParse, ref lastReportedPosition.position.x); GCodeFile.GetFirstNumberAfter("Y:", lineToParse, ref lastReportedPosition.position.y); GCodeFile.GetFirstNumberAfter("Z:", lineToParse, ref lastReportedPosition.position.z); GCodeFile.GetFirstNumberAfter("E:", lineToParse, ref lastReportedPosition.extrusion); //if (currentDestination != positionRead) { currentDestination = lastReportedPosition; DestinationChanged.CallEvents(this, null); if (totalGCodeStream != null) { totalGCodeStream.SetPrinterPosition(currentDestination); } } PositionRead.CallEvents(this, null); waitingForPosition.Stop(); waitingForPosition.Reset(); }
public string CreateMovementLine(PrinterMove currentDestination) { return CreateMovementLine(currentDestination, PrinterMove.Nowhere); }
public abstract void SetPrinterPosition(PrinterMove position);
public override void SetPrinterPosition(PrinterMove position) { }
public override void SetPrinterPosition(PrinterMove position) { lastDestination = position; internalStream.SetPrinterPosition(lastDestination); }
private void KeepTrackOfAbsolutePostionAndDestination(string lineBeingSent) { if (lineBeingSent.StartsWith("G0 ") || lineBeingSent.StartsWith("G1 ") || lineBeingSent.StartsWith("G2 ") || lineBeingSent.StartsWith("G3 ")) { PrinterMove newDestination = currentDestination; if (movementMode == PrinterMachineInstruction.MovementTypes.Relative) { newDestination.position = Vector3.Zero; } GCodeFile.GetFirstNumberAfter("X", lineBeingSent, ref newDestination.position.x); GCodeFile.GetFirstNumberAfter("Y", lineBeingSent, ref newDestination.position.y); GCodeFile.GetFirstNumberAfter("Z", lineBeingSent, ref newDestination.position.z); GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref newDestination.extrusion); GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref newDestination.feedRate); if (movementMode == PrinterMachineInstruction.MovementTypes.Relative) { newDestination.position += currentDestination.position; } if (currentDestination.position != newDestination.position) { currentDestination = newDestination; DestinationChanged.CallEvents(this, null); } } }
public string ProcessLine(string lineToProcess) { if (lineToProcess != null && lineToProcess.StartsWith("G9")) { if (lineToProcess.StartsWith("G91")) { absoluteMode = false; return ""; } else if (lineToProcess.StartsWith("G90")) { absoluteMode = true; } } if (lineToProcess != null && LineIsMovement(lineToProcess)) { PrinterMove currentDestination; if (absoluteMode) { currentDestination = GetPosition(lineToProcess, lastDestination); } else { currentDestination = GetPosition(lineToProcess, PrinterMove.Zero); double feedRate = currentDestination.feedRate; currentDestination += lastDestination; currentDestination.feedRate = feedRate; lineToProcess = CreateMovementLine(currentDestination, lastDestination); } // send the first one lastDestination = currentDestination; } return lineToProcess; }
public void ReadTargetPositions(object sender, EventArgs e) { FoundStringEventArgs foundStringEventArgs = e as FoundStringEventArgs; string lineToParse = foundStringEventArgs.LineToCheck; GCodeFile.GetFirstNumberAfter("X:", lineToParse, ref lastReportedPosition.position.x); GCodeFile.GetFirstNumberAfter("Y:", lineToParse, ref lastReportedPosition.position.y); GCodeFile.GetFirstNumberAfter("Z:", lineToParse, ref lastReportedPosition.position.z); GCodeFile.GetFirstNumberAfter("E:", lineToParse, ref lastReportedPosition.extrusion); //if (currentDestination != positionRead) { currentDestination = lastReportedPosition; DestinationChanged.CallEvents(this, null); if (totalGCodeStream != null) { totalGCodeStream.SetPrinterPosition(currentDestination); } } PositionRead.CallEvents(this, null); waitingForPosition.Stop(); waitingForPosition.Reset(); if(storePositionToPrinterZAfterHome) { storePositionToPrinterZAfterHome = false; double storedHomePosition = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.printer_z_after_home); // if printer_z_after_home != current z position if (storedHomePosition != LastReportedPosition.z) { ActiveSliceSettings.Instance.SetValue(SettingsKey.printer_z_after_home, LastReportedPosition.z.ToString()); ApplicationController.Instance.ReloadAdvancedControlsPanel(); } // now send a G92 to set the position that we want to think is home double zOffset = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.z_offset_after_home); if (zOffset != 0) { double newHomePosition = ActiveSliceSettings.Instance.GetValue<double>(SettingsKey.printer_z_after_home) + zOffset; SendLineToPrinterNow($"G92 Z{newHomePosition}"); } } }
public override string ReadLine() { if (movesToSend.Count == 0) { string lineFromChild = base.ReadLine(); // disable this for a test //return lineFromChild; if (lineFromChild != null && LineIsMovement(lineFromChild)) { PrinterMove currentDestination = GetPosition(lineFromChild, lastDestination); PrinterMove deltaToDestination = currentDestination - lastDestination; deltaToDestination.feedRate = 0; // remove the changing of the federate (we'll set it initialy) double lengthSquared = deltaToDestination.LengthSquared; if (lengthSquared > MaxSegmentLength * MaxSegmentLength) { // create the line segments to send double length = Math.Sqrt(lengthSquared); int numSegmentsToCutInto = (int)Math.Ceiling(length / MaxSegmentLength); // segments = (((mm/min) / (60s/min))mm/s / s/segment)segments*mm / mm double maxSegmentsCanTransmit = 1 / (((currentDestination.feedRate / 60) * maxSecondsPerSegment) / length); int numSegmentsToSend = Math.Max(1, Math.Min(numSegmentsToCutInto, (int)maxSegmentsCanTransmit)); if (numSegmentsToSend > 1) { PrinterMove deltaForSegment = deltaToDestination / numSegmentsToSend; PrinterMove nextPoint = lastDestination + deltaForSegment; nextPoint.feedRate = currentDestination.feedRate; for (int i = 0; i < numSegmentsToSend; i++) { movesToSend.Add(nextPoint); nextPoint += deltaForSegment; } // send the first one PrinterMove positionToSend = movesToSend[0]; movesToSend.RemoveAt(0); string altredLineToSend = CreateMovementLine(positionToSend, lastDestination); lastDestination = positionToSend; return altredLineToSend; } } lastDestination = currentDestination; } return lineFromChild; } else { PrinterMove positionToSend = movesToSend[0]; movesToSend.RemoveAt(0); string lineToSend = CreateMovementLine(positionToSend, lastDestination); lastDestination = positionToSend; return lineToSend; } }
private string RunPrintLevelingTranslations(string lineBeingSent, PrinterMove currentDestination) { PrintLevelingData levelingData = ActiveSliceSettings.Instance.Helpers.GetPrintLevelingData(); if (levelingData != null) { switch (levelingData.CurrentPrinterLevelingSystem) { case PrintLevelingData.LevelingSystem.Probe3Points: lineBeingSent = LevelWizard3Point.ApplyLeveling(lineBeingSent, currentDestination.position, PrinterMachineInstruction.MovementTypes.Absolute); break; case PrintLevelingData.LevelingSystem.Probe7PointRadial: lineBeingSent = LevelWizard7PointRadial.ApplyLeveling(lineBeingSent, currentDestination.position, PrinterMachineInstruction.MovementTypes.Absolute); break; case PrintLevelingData.LevelingSystem.Probe13PointRadial: lineBeingSent = LevelWizard13PointRadial.ApplyLeveling(lineBeingSent, currentDestination.position, PrinterMachineInstruction.MovementTypes.Absolute); break; default: throw new NotImplementedException(); } } return lineBeingSent; }
public override void SetPrinterPosition(PrinterMove position) { internalStream.SetPrinterPosition(position); }