From 5e6af4b2f690df4c6407b231173b9b2f7d2f3d34 Mon Sep 17 00:00:00 2001 From: larsbrubaker Date: Sat, 1 Aug 2015 14:44:53 -0700 Subject: [PATCH] Making print leveling code go through the loaded print leveling solution (rather than the leveling plane). Refactoring. Working on a new 7 point radial print leveling solution for delta printers. --- .../PrintLeveling/LevelWizard2Point.cs | 17 +- .../PrintLeveling/LevelWizard3Point.cs | 52 ++--- .../PrintLeveling/LevelWizard7PointRadial.cs | 138 +++++++++++++ .../PrintLeveling/LevelWizardBase.cs | 6 +- .../PrintLeveling/PrintLevelPages.cs | 40 +++- .../PrintLeveling/PrintLevelingData.cs | 188 +++++++++--------- CustomWidgets/ExportPrintItemWindow.cs | 13 +- MatterControl.csproj | 1 + PrinterCommunication/ActivePrinterProfile.cs | 6 +- .../PrinterConnectionAndCommunication.cs | 29 ++- PrinterControls/EditLevelingSettingsWindow.cs | 18 +- PrinterControls/PrintLevelingPlane.cs | 25 --- .../PrinterConnections/PrinterSetupStatus.cs | 12 +- Queue/OptionsMenu/ExportToFolderProcess.cs | 26 ++- SlicerConfiguration/ActiveSliceSettings.cs | 6 +- .../PrinterSettings/SeeMeCNC/Orion/setup.ini | 2 + StaticData/Translations/Master.txt | 6 + 17 files changed, 395 insertions(+), 190 deletions(-) create mode 100644 ConfigurationPage/PrintLeveling/LevelWizard7PointRadial.cs diff --git a/ConfigurationPage/PrintLeveling/LevelWizard2Point.cs b/ConfigurationPage/PrintLeveling/LevelWizard2Point.cs index 2fa89ee30..910a3c833 100644 --- a/ConfigurationPage/PrintLeveling/LevelWizard2Point.cs +++ b/ConfigurationPage/PrintLeveling/LevelWizard2Point.cs @@ -29,6 +29,7 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg; using MatterHackers.Agg.UI; +using MatterHackers.GCodeVisualizer; using MatterHackers.Localizations; using MatterHackers.MatterControl.PrinterCommunication; using MatterHackers.VectorMath; @@ -112,6 +113,18 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling private static Vector3 probeRead1; private static Vector3 probeRead2; + public static string ApplyLeveling(string lineBeingSent, Vector3 currentDestination, PrinterMachineInstruction.MovementTypes movementMode) + { + if (PrinterConnectionAndCommunication.Instance.ActivePrinter != null + && PrinterConnectionAndCommunication.Instance.ActivePrinter.DoPrintLeveling + && (lineBeingSent.StartsWith("G0 ") || lineBeingSent.StartsWith("G1 "))) + { + lineBeingSent = PrintLevelingPlane.Instance.ApplyLeveling(currentDestination, movementMode, lineBeingSent); + } + + return lineBeingSent; + } + public static List ProcessCommand(string lineBeingSent) { int commentIndex = lineBeingSent.IndexOf(';'); @@ -239,8 +252,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling // position 0 does not change as it is the distance from the switch trigger to the extruder tip. //levelingData.sampledPosition0 = levelingData.sampledPosition0; - levelingData.sampledPosition1 = levelingData.sampledPosition0 + probeRead1; - levelingData.sampledPosition2 = levelingData.sampledPosition0 + probeRead2; + levelingData.SampledPosition1 = levelingData.SampledPosition0 + probeRead1; + levelingData.SampledPosition2 = levelingData.SampledPosition0 + probeRead2; ActivePrinterProfile.Instance.DoPrintLeveling = true; } diff --git a/ConfigurationPage/PrintLeveling/LevelWizard3Point.cs b/ConfigurationPage/PrintLeveling/LevelWizard3Point.cs index a5b13298a..baa0ad9e5 100644 --- a/ConfigurationPage/PrintLeveling/LevelWizard3Point.cs +++ b/ConfigurationPage/PrintLeveling/LevelWizard3Point.cs @@ -28,7 +28,9 @@ either expressed or implied, of the FreeBSD Project. */ using MatterHackers.Agg; +using MatterHackers.GCodeVisualizer; using MatterHackers.Localizations; +using MatterHackers.MatterControl.PrinterCommunication; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.VectorMath; using System.Collections.Generic; @@ -73,44 +75,42 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling string homingPageInstructions = string.Format("{0}:\n\n\t• {1}\n\n{2}", homingPageInstructionsTextOne, homingPageInstructionsTextTwo, homingPageInstructionsTextThree); printLevelWizard.AddPage(new HomePrinterPage(homingPageStepText, homingPageInstructions)); - Vector2 probeBackCenter = LevelWizardBase.GetPrintLevelPositionToSample(0); - - string lowPrecisionPositionLabel = LocalizedString.Get("Position"); + string positionLabel = LocalizedString.Get("Position"); string lowPrecisionLabel = LocalizedString.Get("Low Precision"); - GetCoarseBedHeight getCourseBedHeight = new GetCoarseBedHeight(printLevelWizard, - new Vector3(probeBackCenter, 10), - string.Format("{0} {1} 1 - {2}", GetStepString(), lowPrecisionPositionLabel, lowPrecisionLabel), - probePositions[0], allowLessThanZero); - - printLevelWizard.AddPage(getCourseBedHeight); - string precisionPositionLabel = LocalizedString.Get("Position"); string medPrecisionLabel = LocalizedString.Get("Medium Precision"); - printLevelWizard.AddPage(new GetFineBedHeight(string.Format("{0} {1} 1 - {2}", GetStepString(), precisionPositionLabel, medPrecisionLabel), probePositions[0], allowLessThanZero)); string highPrecisionLabel = LocalizedString.Get("High Precision"); - printLevelWizard.AddPage(new GetUltraFineBedHeight(string.Format("{0} {1} 1 - {2}", GetStepString(), precisionPositionLabel, highPrecisionLabel), probePositions[0], allowLessThanZero)); + + Vector2 probeBackCenter = LevelWizardBase.GetPrintLevelPositionToSample(0); + printLevelWizard.AddPage(new GetCoarseBedHeight(printLevelWizard, new Vector3(probeBackCenter, 10), string.Format("{0} {1} 1 - {2}", GetStepString(), positionLabel, lowPrecisionLabel), probePositions[0], allowLessThanZero)); + printLevelWizard.AddPage(new GetFineBedHeight(string.Format("{0} {1} 1 - {2}", GetStepString(), positionLabel, medPrecisionLabel), probePositions[0], allowLessThanZero)); + printLevelWizard.AddPage(new GetUltraFineBedHeight(string.Format("{0} {1} 1 - {2}", GetStepString(), positionLabel, highPrecisionLabel), probePositions[0], allowLessThanZero)); Vector2 probeFrontLeft = LevelWizardBase.GetPrintLevelPositionToSample(1); - string positionLabelTwo = LocalizedString.Get("Position"); - string lowPrecisionTwoLabel = LocalizedString.Get("Low Precision"); - string medPrecisionTwoLabel = LocalizedString.Get("Medium Precision"); - string highPrecisionTwoLabel = LocalizedString.Get("High Precision"); - printLevelWizard.AddPage(new GetCoarseBedHeight(printLevelWizard, new Vector3(probeFrontLeft, 10), string.Format("{0} {1} 2 - {2}", GetStepString(), positionLabelTwo, lowPrecisionTwoLabel), probePositions[1], allowLessThanZero)); - printLevelWizard.AddPage(new GetFineBedHeight(string.Format("{0} {1} 2 - {2}", GetStepString(), positionLabelTwo, medPrecisionTwoLabel), probePositions[1], allowLessThanZero)); - printLevelWizard.AddPage(new GetUltraFineBedHeight(string.Format("{0} {1} 2 - {2}", GetStepString(), positionLabelTwo, highPrecisionTwoLabel), probePositions[1], allowLessThanZero)); + printLevelWizard.AddPage(new GetCoarseBedHeight(printLevelWizard, new Vector3(probeFrontLeft, 10), string.Format("{0} {1} 2 - {2}", GetStepString(), positionLabel, lowPrecisionLabel), probePositions[1], allowLessThanZero)); + printLevelWizard.AddPage(new GetFineBedHeight(string.Format("{0} {1} 2 - {2}", GetStepString(), positionLabel, medPrecisionLabel), probePositions[1], allowLessThanZero)); + printLevelWizard.AddPage(new GetUltraFineBedHeight(string.Format("{0} {1} 2 - {2}", GetStepString(), positionLabel, highPrecisionLabel), probePositions[1], allowLessThanZero)); Vector2 probeFrontRight = LevelWizardBase.GetPrintLevelPositionToSample(2); - string positionLabelThree = LocalizedString.Get("Position"); - string lowPrecisionLabelThree = LocalizedString.Get("Low Precision"); - string medPrecisionLabelThree = LocalizedString.Get("Medium Precision"); - string highPrecisionLabelThree = LocalizedString.Get("High Precision"); - printLevelWizard.AddPage(new GetCoarseBedHeight(printLevelWizard, new Vector3(probeFrontRight, 10), string.Format("{0} {1} 3 - {2}", GetStepString(), positionLabelThree, lowPrecisionLabelThree), probePositions[2], allowLessThanZero)); - printLevelWizard.AddPage(new GetFineBedHeight(string.Format("{0} {1} 3 - {2}", GetStepString(), positionLabelThree, medPrecisionLabelThree), probePositions[2], allowLessThanZero)); - printLevelWizard.AddPage(new GetUltraFineBedHeight(string.Format("{0} {1} 3 - {2}", GetStepString(), positionLabelThree, highPrecisionLabelThree), probePositions[2], allowLessThanZero)); + printLevelWizard.AddPage(new GetCoarseBedHeight(printLevelWizard, new Vector3(probeFrontRight, 10), string.Format("{0} {1} 3 - {2}", GetStepString(), positionLabel, lowPrecisionLabel), probePositions[2], allowLessThanZero)); + printLevelWizard.AddPage(new GetFineBedHeight(string.Format("{0} {1} 3 - {2}", GetStepString(), positionLabel, medPrecisionLabel), probePositions[2], allowLessThanZero)); + printLevelWizard.AddPage(new GetUltraFineBedHeight(string.Format("{0} {1} 3 - {2}", GetStepString(), positionLabel, highPrecisionLabel), probePositions[2], allowLessThanZero)); string doneInstructions = string.Format("{0}\n\n\t• {1}\n\n{2}", doneInstructionsText, doneInstructionsTextTwo, doneInstructionsTextThree); printLevelWizard.AddPage(new LastPage3PointInstructions("Done".Localize(), doneInstructions, probePositions)); } + public static string ApplyLeveling(string lineBeingSent, Vector3 currentDestination, PrinterMachineInstruction.MovementTypes movementMode) + { + if (PrinterConnectionAndCommunication.Instance.ActivePrinter != null + && PrinterConnectionAndCommunication.Instance.ActivePrinter.DoPrintLeveling + && (lineBeingSent.StartsWith("G0 ") || lineBeingSent.StartsWith("G1 "))) + { + lineBeingSent = PrintLevelingPlane.Instance.ApplyLeveling(currentDestination, movementMode, lineBeingSent); + } + + return lineBeingSent; + } + public static List ProcessCommand(string lineBeingSent) { int commentIndex = lineBeingSent.IndexOf(';'); diff --git a/ConfigurationPage/PrintLeveling/LevelWizard7PointRadial.cs b/ConfigurationPage/PrintLeveling/LevelWizard7PointRadial.cs new file mode 100644 index 000000000..122279ac5 --- /dev/null +++ b/ConfigurationPage/PrintLeveling/LevelWizard7PointRadial.cs @@ -0,0 +1,138 @@ +/* +Copyright (c) 2014, Lars Brubaker +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +The views and conclusions contained in the software and documentation are those +of the authors and should not be interpreted as representing official policies, +either expressed or implied, of the FreeBSD Project. +*/ + +using MatterHackers.Agg; +using MatterHackers.GCodeVisualizer; +using MatterHackers.Localizations; +using MatterHackers.MatterControl.SlicerConfiguration; +using MatterHackers.VectorMath; +using System.Collections.Generic; + +namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling +{ + public class LevelWizard7PointRadial : LevelWizardBase + { + private string pageOneStepText = "Print Leveling Overview".Localize(); + private string pageOneInstructionsTextOne = LocalizedString.Get("Welcome to the print leveling wizard. Here is a quick overview on what we are going to do."); + private string pageOneInstructionsTextTwo = LocalizedString.Get("'Home' the printer"); + private string pageOneInstructionsTextThree = LocalizedString.Get("Sample the bed at seven points"); + private string pageOneInstructionsTextFour = LocalizedString.Get("Turn auto leveling on"); + private string pageOneInstructionsText5 = LocalizedString.Get("You should be done in about 5 minutes."); + private string pageOneInstructionsText6 = LocalizedString.Get("Note: Be sure the tip of the extrude is clean."); + private string pageOneInstructionsText7 = LocalizedString.Get("Click 'Next' to continue."); + + public LevelWizard7PointRadial(LevelWizardBase.RuningState runningState) + : base(500, 370, 9) + { + bool allowLessThanZero = ActiveSliceSettings.Instance.GetActiveValue("z_can_be_negative") == "1"; + string printLevelWizardTitle = LocalizedString.Get("MatterControl"); + string printLevelWizardTitleFull = LocalizedString.Get("Print Leveling Wizard"); + Title = string.Format("{0} - {1}", printLevelWizardTitle, printLevelWizardTitleFull); + ProbePosition[] probePositions = new ProbePosition[7]; + probePositions[0] = new ProbePosition(); + probePositions[1] = new ProbePosition(); + probePositions[2] = new ProbePosition(); + probePositions[3] = new ProbePosition(); + probePositions[4] = new ProbePosition(); + probePositions[5] = new ProbePosition(); + probePositions[6] = new ProbePosition(); + + printLevelWizard = new WizardControl(); + AddChild(printLevelWizard); + + if (runningState == LevelWizardBase.RuningState.InitialStartupCalibration) + { + string requiredPageInstructions = "{0}\n\n{1}".FormatWith(requiredPageInstructions1, requiredPageInstructions2); + printLevelWizard.AddPage(new FirstPageInstructions(initialPrinterSetupStepText, requiredPageInstructions)); + } + + string pageOneInstructions = string.Format("{0}\n\n\t• {1}\n\t• {2}\n\t• {3}\n\n{4}\n\n{5}\n\n{6}", pageOneInstructionsTextOne, pageOneInstructionsTextTwo, pageOneInstructionsTextThree, pageOneInstructionsTextFour, pageOneInstructionsText5, pageOneInstructionsText6, pageOneInstructionsText7); + printLevelWizard.AddPage(new FirstPageInstructions(pageOneStepText, pageOneInstructions)); + + string homingPageInstructions = string.Format("{0}:\n\n\t• {1}\n\n{2}", homingPageInstructionsTextOne, homingPageInstructionsTextTwo, homingPageInstructionsTextThree); + printLevelWizard.AddPage(new HomePrinterPage(homingPageStepText, homingPageInstructions)); + + string positionLabel = LocalizedString.Get("Position"); + string lowPrecisionLabel = LocalizedString.Get("Low Precision"); + string medPrecisionLabel = LocalizedString.Get("Medium Precision"); + string highPrecisionLabel = LocalizedString.Get("High Precision"); + + double bedRadius = ActiveSliceSettings.Instance.BedSize.x / 2; + + double startProbeHeight = 5; + for (int i = 0; i < 7; i++) + { + Vector2 probePosition = GetPrintLevelPositionToSample(i, bedRadius); + printLevelWizard.AddPage(new GetCoarseBedHeight(printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", GetStepString(), positionLabel, i+1, lowPrecisionLabel), probePositions[i], allowLessThanZero)); + printLevelWizard.AddPage(new GetFineBedHeight(string.Format("{0} {1} {2} - {3}", GetStepString(), positionLabel, i+1, medPrecisionLabel), probePositions[i], allowLessThanZero)); + printLevelWizard.AddPage(new GetUltraFineBedHeight(string.Format("{0} {1} {2} - {3}", GetStepString(), positionLabel, i+1, highPrecisionLabel), probePositions[i], allowLessThanZero)); + } + + string doneInstructions = string.Format("{0}\n\n\t• {1}\n\n{2}", doneInstructionsText, doneInstructionsTextTwo, doneInstructionsTextThree); + printLevelWizard.AddPage(new LastPage7PointRadialInstructions("Done".Localize(), doneInstructions, probePositions)); + } + + public static Vector2 GetPrintLevelPositionToSample(int index, double radius) + { + if(index < 6) + { + Vector2 postion = new Vector2(radius, 0); + postion.Rotate(MathHelper.Tau / 6 * index); + return postion; + } + else + { + return new Vector2(0, 0); + } + } + + + internal static string ApplyLeveling(string lineBeingSent, Vector3 currentDestination, PrinterMachineInstruction.MovementTypes movementMode) + { + throw new System.NotImplementedException(); + } + + public static List ProcessCommand(string lineBeingSent) + { + int commentIndex = lineBeingSent.IndexOf(';'); + if (commentIndex > 0) // there is content in front of the ; + { + lineBeingSent = lineBeingSent.Substring(0, commentIndex).Trim(); + } + List lines = new List(); + lines.Add(lineBeingSent); + if (lineBeingSent.StartsWith("G28")) + { + lines.Add("M114"); + } + + return lines; + } + } +} \ No newline at end of file diff --git a/ConfigurationPage/PrintLeveling/LevelWizardBase.cs b/ConfigurationPage/PrintLeveling/LevelWizardBase.cs index 2173248b3..a2fa284d1 100644 --- a/ConfigurationPage/PrintLeveling/LevelWizardBase.cs +++ b/ConfigurationPage/PrintLeveling/LevelWizardBase.cs @@ -143,7 +143,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); LevelWizardBase printLevelWizardWindow; - switch (levelingData.levelingSystem) + switch (levelingData.CurrentPrinterLevelingSystem) { case PrintLevelingData.LevelingSystem.Probe2Points: printLevelWizardWindow = new LevelWizard2Point(runningState); @@ -153,6 +153,10 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling printLevelWizardWindow = new LevelWizard3Point(runningState); break; + case PrintLevelingData.LevelingSystem.Probe7PointRadial: + printLevelWizardWindow = new LevelWizard7PointRadial(runningState); + break; + default: throw new NotImplementedException(); } diff --git a/ConfigurationPage/PrintLeveling/PrintLevelPages.cs b/ConfigurationPage/PrintLeveling/PrintLevelPages.cs index e2da2ffc8..9ca795cc3 100644 --- a/ConfigurationPage/PrintLeveling/PrintLevelPages.cs +++ b/ConfigurationPage/PrintLeveling/PrintLevelPages.cs @@ -63,9 +63,33 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling public override void PageIsBecomingActive() { PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); - levelingData.sampledPosition0 = probePositions[0].position - paperWidth; - levelingData.sampledPosition1 = probePositions[1].position - paperWidth; - levelingData.sampledPosition2 = probePositions[2].position - paperWidth; + levelingData.SampledPosition0 = probePositions[0].position - paperWidth; + levelingData.SampledPosition1 = probePositions[1].position - paperWidth; + levelingData.SampledPosition2 = probePositions[2].position - paperWidth; + + ActivePrinterProfile.Instance.DoPrintLeveling = true; + base.PageIsBecomingActive(); + } + } + + public class LastPage7PointRadialInstructions : InstructionsPage + { + private ProbePosition[] probePositions; + + public LastPage7PointRadialInstructions(string pageDescription, string instructionsText, ProbePosition[] probePositions) + : base(pageDescription, instructionsText) + { + this.probePositions = probePositions; + } + + public override void PageIsBecomingActive() + { + PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); + levelingData.SampledPositions.Clear(); + for (int i = 0; i < probePositions.Length; i++) + { + levelingData.SampledPositions.Add(probePositions[i].position - paperWidth); + } ActivePrinterProfile.Instance.DoPrintLeveling = true; base.PageIsBecomingActive(); @@ -161,12 +185,12 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling // auto back probe Vector3 probeOffset2 = probePositions[4].position; - levelingData.sampledPosition0 = userBedSample0 - paperWidth; - levelingData.sampledPosition1 = userBedSample1 - paperWidth; - levelingData.sampledPosition2 = probeOffset2 - probeOffset0 + userBedSample0 - paperWidth; + levelingData.SampledPosition0 = userBedSample0 - paperWidth; + levelingData.SampledPosition1 = userBedSample1 - paperWidth; + levelingData.SampledPosition2 = probeOffset2 - probeOffset0 + userBedSample0 - paperWidth; - levelingData.probeOffset0 = probeOffset0 - paperWidth; - levelingData.probeOffset1 = probeOffset1 - paperWidth; + levelingData.ProbeOffset0 = probeOffset0 - paperWidth; + levelingData.ProbeOffset1 = probeOffset1 - paperWidth; ActivePrinterProfile.Instance.DoPrintLeveling = true; base.PageIsBecomingActive(); diff --git a/ConfigurationPage/PrintLeveling/PrintLevelingData.cs b/ConfigurationPage/PrintLeveling/PrintLevelingData.cs index b692c423a..c8b5122ee 100644 --- a/ConfigurationPage/PrintLeveling/PrintLevelingData.cs +++ b/ConfigurationPage/PrintLeveling/PrintLevelingData.cs @@ -2,6 +2,7 @@ using MatterHackers.VectorMath; using Newtonsoft.Json; using Newtonsoft.Json.Converters; +using System.Collections.Generic; namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { @@ -9,87 +10,30 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling { private static bool activelyLoading = false; - [JsonConverter(typeof(StringEnumConverter))] - public enum LevelingSystem { Probe3Points, Probe2Points } + private static Printer activePrinter = null; - private Vector3 sampledPosition0Private; - - public Vector3 sampledPosition0 - { - get { return sampledPosition0Private; } - set - { - if (sampledPosition0Private != value) - { - sampledPosition0Private = value; - Commit(); - } - } - } - - private Vector3 probeOffset0Private; - - public Vector3 probeOffset0 - { - get { return probeOffset0Private; } - set - { - if (probeOffset0Private != value) - { - probeOffset0Private = value; - Commit(); - } - } - } - - private Vector3 probeOffset1Private; - - public Vector3 probeOffset1 - { - get { return probeOffset1Private; } - set - { - if (probeOffset1Private != value) - { - probeOffset1Private = value; - Commit(); - } - } - } - - private Vector3 sampledPosition1Private; - - public Vector3 sampledPosition1 - { - get { return sampledPosition1Private; } - set - { - if (sampledPosition1Private != value) - { - sampledPosition1Private = value; - Commit(); - } - } - } - - private Vector3 sampledPosition2Private; - - public Vector3 sampledPosition2 - { - get { return sampledPosition2Private; } - set - { - if (sampledPosition2Private != value) - { - sampledPosition2Private = value; - Commit(); - } - } - } + private static PrintLevelingData instance = null; private LevelingSystem levelingSystemPrivate = LevelingSystem.Probe3Points; - public LevelingSystem levelingSystem + private bool needsPrintLevelingPrivate; + + private Vector3 probeOffset0Private; + + private Vector3 probeOffset1Private; + + private Vector3 sampledPosition0Private; + + private Vector3 sampledPosition1Private; + + private Vector3 sampledPosition2Private; + + [JsonConverter(typeof(StringEnumConverter))] + public enum LevelingSystem { Probe3Points, Probe2Points, Probe7PointRadial } + + public List SampledPositions = new List(); + + public LevelingSystem CurrentPrinterLevelingSystem { get { return levelingSystemPrivate; } set @@ -102,9 +46,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling } } - private bool needsPrintLevelingPrivate; - - public bool needsPrintLeveling + public bool NeedsPrintLeveling { get { return needsPrintLevelingPrivate; } set @@ -117,22 +59,70 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling } } - private void Commit() + public Vector3 ProbeOffset0 { - if (!activelyLoading) + get { return probeOffset0Private; } + set { - string newLevelingInfo = Newtonsoft.Json.JsonConvert.SerializeObject(this); - - // clear the legacy value - activePrinter.PrintLevelingProbePositions = ""; - // set the new value - activePrinter.PrintLevelingJsonData = newLevelingInfo; - activePrinter.Commit(); + if (probeOffset0Private != value) + { + probeOffset0Private = value; + Commit(); + } } } - private static Printer activePrinter = null; - private static PrintLevelingData instance = null; + public Vector3 ProbeOffset1 + { + get { return probeOffset1Private; } + set + { + if (probeOffset1Private != value) + { + probeOffset1Private = value; + Commit(); + } + } + } + + public Vector3 SampledPosition0 + { + get { return sampledPosition0Private; } + set + { + if (sampledPosition0Private != value) + { + sampledPosition0Private = value; + Commit(); + } + } + } + + public Vector3 SampledPosition1 + { + get { return sampledPosition1Private; } + set + { + if (sampledPosition1Private != value) + { + sampledPosition1Private = value; + Commit(); + } + } + } + + public Vector3 SampledPosition2 + { + get { return sampledPosition2Private; } + set + { + if (sampledPosition2Private != value) + { + sampledPosition2Private = value; + Commit(); + } + } + } public static PrintLevelingData GetForPrinter(Printer printer) { @@ -152,7 +142,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling if (jsonData != null) { activelyLoading = true; - instance = (PrintLevelingData)Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData); + instance = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData); activelyLoading = false; } else if (depricatedPositionsCsv3ByXYZ != null) @@ -166,6 +156,20 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling } } + private void Commit() + { + if (!activelyLoading) + { + string newLevelingInfo = Newtonsoft.Json.JsonConvert.SerializeObject(this); + + // clear the legacy value + activePrinter.PrintLevelingProbePositions = ""; + // set the new value + activePrinter.PrintLevelingJsonData = newLevelingInfo; + activePrinter.Commit(); + } + } + /// /// Gets the 9 {3 * (x, y, z)} positions that were probed during the print leveling setup. /// diff --git a/CustomWidgets/ExportPrintItemWindow.cs b/CustomWidgets/ExportPrintItemWindow.cs index b680e0308..c2c7438d3 100644 --- a/CustomWidgets/ExportPrintItemWindow.cs +++ b/CustomWidgets/ExportPrintItemWindow.cs @@ -10,6 +10,7 @@ using MatterHackers.MatterControl.PrintQueue; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.PolygonMesh; using MatterHackers.PolygonMesh.Processors; +using MatterHackers.VectorMath; using System; using System.Collections.Generic; using System.ComponentModel; @@ -296,25 +297,31 @@ namespace MatterHackers.MatterControl GCodeFileLoaded unleveledGCode = new GCodeFileLoaded(source); if (applyLeveling.Checked) { - PrintLevelingPlane.Instance.ApplyLeveling(unleveledGCode); - PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); if (levelingData != null) { for (int lineIndex = 0; lineIndex < unleveledGCode.LineCount; lineIndex++) { PrinterMachineInstruction instruction = unleveledGCode.Instruction(lineIndex); + Vector3 currentDestination = instruction.Position; List linesToWrite = null; - switch (levelingData.levelingSystem) + switch (levelingData.CurrentPrinterLevelingSystem) { case PrintLevelingData.LevelingSystem.Probe2Points: + instruction.Line = LevelWizard2Point.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType); linesToWrite = LevelWizard2Point.ProcessCommand(instruction.Line); break; case PrintLevelingData.LevelingSystem.Probe3Points: + instruction.Line = LevelWizard3Point.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType); linesToWrite = LevelWizard3Point.ProcessCommand(instruction.Line); break; + + case PrintLevelingData.LevelingSystem.Probe7PointRadial: + instruction.Line = LevelWizard7PointRadial.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType); + linesToWrite = LevelWizard7PointRadial.ProcessCommand(instruction.Line); + break; } instruction.Line = linesToWrite[0]; diff --git a/MatterControl.csproj b/MatterControl.csproj index fe6d6f552..4e7a44c8c 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -152,6 +152,7 @@ + diff --git a/PrinterCommunication/ActivePrinterProfile.cs b/PrinterCommunication/ActivePrinterProfile.cs index 1290b1556..607332f0d 100644 --- a/PrinterCommunication/ActivePrinterProfile.cs +++ b/PrinterCommunication/ActivePrinterProfile.cs @@ -343,9 +343,9 @@ namespace MatterHackers.MatterControl { PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); PrintLevelingPlane.Instance.SetPrintLevelingEquation( - levelingData.sampledPosition0, - levelingData.sampledPosition1, - levelingData.sampledPosition2, + levelingData.SampledPosition0, + levelingData.SampledPosition1, + levelingData.SampledPosition2, ActiveSliceSettings.Instance.PrintCenter); } } diff --git a/PrinterCommunication/PrinterConnectionAndCommunication.cs b/PrinterCommunication/PrinterConnectionAndCommunication.cs index 298a101be..85e55b291 100644 --- a/PrinterCommunication/PrinterConnectionAndCommunication.cs +++ b/PrinterCommunication/PrinterConnectionAndCommunication.cs @@ -913,13 +913,13 @@ namespace MatterHackers.MatterControl.PrinterCommunication } } - private Printer ActivePrinter + public Printer ActivePrinter { get { return ActivePrinterProfile.Instance.ActivePrinter; } - set + private set { ActivePrinterProfile.Instance.ActivePrinter = value; } @@ -1275,10 +1275,10 @@ namespace MatterHackers.MatterControl.PrinterCommunication { PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); if (levelingData != null - && levelingData.needsPrintLeveling - && levelingData.sampledPosition0.z == 0 - && levelingData.sampledPosition1.z == 0 - && levelingData.sampledPosition2.z == 0) + && levelingData.NeedsPrintLeveling + && levelingData.SampledPosition0.z == 0 + && levelingData.SampledPosition1.z == 0 + && levelingData.SampledPosition2.z == 0) { LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.InitialStartupCalibration); return; @@ -2640,27 +2640,26 @@ namespace MatterHackers.MatterControl.PrinterCommunication private string RunPrintLevelingTranslations(string lineBeingSent) { - if (ActivePrinter != null - && ActivePrinter.DoPrintLeveling - && (lineBeingSent.StartsWith("G0 ") || lineBeingSent.StartsWith("G1 "))) - { - string inputLine = lineBeingSent; - lineBeingSent = PrintLevelingPlane.Instance.ApplyLeveling(currentDestination, movementMode, inputLine); - } - PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); if (levelingData != null) { List linesToWrite = null; - switch (levelingData.levelingSystem) + switch (levelingData.CurrentPrinterLevelingSystem) { case PrintLevelingData.LevelingSystem.Probe2Points: + lineBeingSent = LevelWizard2Point.ApplyLeveling(lineBeingSent, currentDestination, movementMode); linesToWrite = LevelWizard2Point.ProcessCommand(lineBeingSent); break; case PrintLevelingData.LevelingSystem.Probe3Points: + lineBeingSent = LevelWizard3Point.ApplyLeveling(lineBeingSent, currentDestination, movementMode); linesToWrite = LevelWizard3Point.ProcessCommand(lineBeingSent); break; + + case PrintLevelingData.LevelingSystem.Probe7PointRadial: + lineBeingSent = LevelWizard7PointRadial.ApplyLeveling(lineBeingSent, currentDestination, movementMode); + linesToWrite = LevelWizard7PointRadial.ProcessCommand(lineBeingSent); + break; } lineBeingSent = linesToWrite[0]; diff --git a/PrinterControls/EditLevelingSettingsWindow.cs b/PrinterControls/EditLevelingSettingsWindow.cs index 2b81db530..ab1997fc6 100644 --- a/PrinterControls/EditLevelingSettingsWindow.cs +++ b/PrinterControls/EditLevelingSettingsWindow.cs @@ -87,9 +87,9 @@ namespace MatterHackers.MatterControl // put in the movement edit controls PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); - positions[0] = levelingData.sampledPosition0; - positions[1] = levelingData.sampledPosition1; - positions[2] = levelingData.sampledPosition2; + positions[0] = levelingData.SampledPosition0; + positions[1] = levelingData.SampledPosition1; + positions[2] = levelingData.SampledPosition2; int tab_index = 0; for (int row = 0; row < 3; row++) @@ -181,14 +181,14 @@ namespace MatterHackers.MatterControl { PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); - levelingData.sampledPosition0 = positions[0]; - levelingData.sampledPosition1 = positions[1]; - levelingData.sampledPosition2 = positions[2]; + levelingData.SampledPosition0 = positions[0]; + levelingData.SampledPosition1 = positions[1]; + levelingData.SampledPosition2 = positions[2]; PrintLevelingPlane.Instance.SetPrintLevelingEquation( - levelingData.sampledPosition0, - levelingData.sampledPosition1, - levelingData.sampledPosition2, + levelingData.SampledPosition0, + levelingData.SampledPosition1, + levelingData.SampledPosition2, ActiveSliceSettings.Instance.PrintCenter); Close(); diff --git a/PrinterControls/PrintLevelingPlane.cs b/PrinterControls/PrintLevelingPlane.cs index de96d2da1..e107404ad 100644 --- a/PrinterControls/PrintLevelingPlane.cs +++ b/PrinterControls/PrintLevelingPlane.cs @@ -48,21 +48,6 @@ namespace MatterHackers.MatterControl makePointsFlatMatrix *= Matrix4X4.CreateTranslation(bedCenter.x, bedCenter.y, 0);//distanceToPlaneAtBedCenter); bedLevelMatrix = Matrix4X4.Invert(makePointsFlatMatrix); - - { - // test that the points come back as 0 zs - Vector3 outPosition0 = Vector3.TransformPosition(position0, makePointsFlatMatrix); - Vector3 outPosition1 = Vector3.TransformPosition(position1, makePointsFlatMatrix); - Vector3 outPosition2 = Vector3.TransformPosition(position2, makePointsFlatMatrix); - - Vector3 printPosition0 = new Vector3(LevelWizardBase.GetPrintLevelPositionToSample(0), 0); - Vector3 printPosition1 = new Vector3(LevelWizardBase.GetPrintLevelPositionToSample(1), 0); - Vector3 printPosition2 = new Vector3(LevelWizardBase.GetPrintLevelPositionToSample(2), 0); - - Vector3 leveledPositon0 = Vector3.TransformPosition(printPosition0, bedLevelMatrix); - Vector3 leveledPositon1 = Vector3.TransformPosition(printPosition1, bedLevelMatrix); - Vector3 leveledPositon2 = Vector3.TransformPosition(printPosition2, bedLevelMatrix); - } } public Vector3 ApplyLeveling(Vector3 inPosition) @@ -117,15 +102,5 @@ namespace MatterHackers.MatterControl return lineBeingSent; } - - public void ApplyLeveling(GCodeFile unleveledGCode) - { - for (int i = 0; i < unleveledGCode.LineCount; i++) - { - PrinterMachineInstruction instruction = unleveledGCode.Instruction(i); - Vector3 currentDestination = instruction.Position; - instruction.Line = ApplyLeveling(currentDestination, instruction.movementType, instruction.Line); - } - } } } \ No newline at end of file diff --git a/PrinterControls/PrinterConnections/PrinterSetupStatus.cs b/PrinterControls/PrinterConnections/PrinterSetupStatus.cs index c706ff9a8..a94802199 100644 --- a/PrinterControls/PrinterConnections/PrinterSetupStatus.cs +++ b/PrinterControls/PrinterConnections/PrinterSetupStatus.cs @@ -142,13 +142,21 @@ namespace MatterHackers.MatterControl string needsPrintLeveling; if (settingsDict.TryGetValue("needs_print_leveling", out needsPrintLeveling)) { - levelingData.needsPrintLeveling = true; + levelingData.NeedsPrintLeveling = true; } string printLevelingType; if (settingsDict.TryGetValue("print_leveling_type", out printLevelingType)) { - levelingData.levelingSystem = PrintLevelingData.LevelingSystem.Probe2Points; + PrintLevelingData.LevelingSystem result; + if(Enum.TryParse(printLevelingType, out result)) + { + levelingData.CurrentPrinterLevelingSystem = result; + } + else + { + levelingData.CurrentPrinterLevelingSystem = PrintLevelingData.LevelingSystem.Probe2Points; + } } string defaultSliceEngine; diff --git a/Queue/OptionsMenu/ExportToFolderProcess.cs b/Queue/OptionsMenu/ExportToFolderProcess.cs index 487794ba6..c1504f050 100644 --- a/Queue/OptionsMenu/ExportToFolderProcess.cs +++ b/Queue/OptionsMenu/ExportToFolderProcess.cs @@ -29,9 +29,11 @@ either expressed or implied, of the FreeBSD Project. using MatterHackers.Agg.UI; using MatterHackers.GCodeVisualizer; +using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling; using MatterHackers.MatterControl.DataStorage; using MatterHackers.MatterControl.SlicerConfiguration; using MatterHackers.PolygonMesh.Processors; +using MatterHackers.VectorMath; using System; using System.Collections.Generic; using System.IO; @@ -181,6 +183,8 @@ namespace MatterHackers.MatterControl.PrintQueue } } + PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); + // now copy all the gcode to the path given for (int i = 0; i < savedGCodeFileNames.Count; i++) { @@ -192,7 +196,27 @@ namespace MatterHackers.MatterControl.PrintQueue if (ActivePrinterProfile.Instance.DoPrintLeveling) { GCodeFileLoaded unleveledGCode = new GCodeFileLoaded(savedGcodeFileName); - PrintLevelingPlane.Instance.ApplyLeveling(unleveledGCode); + + for (int j = 0; j < unleveledGCode.LineCount; j++) + { + PrinterMachineInstruction instruction = unleveledGCode.Instruction(j); + Vector3 currentDestination = instruction.Position; + + switch (levelingData.CurrentPrinterLevelingSystem) + { + case PrintLevelingData.LevelingSystem.Probe2Points: + instruction.Line = LevelWizard2Point.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType); + break; + + case PrintLevelingData.LevelingSystem.Probe3Points: + instruction.Line = LevelWizard3Point.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType); + break; + + case PrintLevelingData.LevelingSystem.Probe7PointRadial: + instruction.Line = LevelWizard7PointRadial.ApplyLeveling(instruction.Line, currentDestination, instruction.movementType); + break; + } + } unleveledGCode.Save(outputPathAndName); } else diff --git a/SlicerConfiguration/ActiveSliceSettings.cs b/SlicerConfiguration/ActiveSliceSettings.cs index 63f59cff9..c0a83c1ff 100644 --- a/SlicerConfiguration/ActiveSliceSettings.cs +++ b/SlicerConfiguration/ActiveSliceSettings.cs @@ -129,9 +129,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration PrintLevelingData levelingData = PrintLevelingData.GetForPrinter(ActivePrinterProfile.Instance.ActivePrinter); PrintLevelingPlane.Instance.SetPrintLevelingEquation( - levelingData.sampledPosition0, - levelingData.sampledPosition1, - levelingData.sampledPosition2, + levelingData.SampledPosition0, + levelingData.SampledPosition1, + levelingData.SampledPosition2, ActiveSliceSettings.Instance.PrintCenter); } OnSettingsChanged(); diff --git a/StaticData/PrinterSettings/SeeMeCNC/Orion/setup.ini b/StaticData/PrinterSettings/SeeMeCNC/Orion/setup.ini index b58a38abf..499092075 100644 --- a/StaticData/PrinterSettings/SeeMeCNC/Orion/setup.ini +++ b/StaticData/PrinterSettings/SeeMeCNC/Orion/setup.ini @@ -1,4 +1,6 @@ baud_rate = 250000 default_material_presets = PLA windows_driver = MHSerial.inf +print_leveling_type = Probe7PointRadial +needs_print_leveling = true default_movement_speeds = x,3000,y,3000,z,3000,e0,150 \ No newline at end of file diff --git a/StaticData/Translations/Master.txt b/StaticData/Translations/Master.txt index c27e1999a..57e082bc7 100644 --- a/StaticData/Translations/Master.txt +++ b/StaticData/Translations/Master.txt @@ -3451,3 +3451,9 @@ Translated:Save Location English:Choose the location to save to. Translated:Choose the location to save to. +English:Sample the bed at seven points +Translated:Sample the bed at seven points + +English:You should be done in about 5 minutes. +Translated:You should be done in about 5 minutes. +