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.
This commit is contained in:
larsbrubaker 2015-08-01 14:44:53 -07:00
parent 87f2934cf3
commit 5e6af4b2f6
17 changed files with 395 additions and 190 deletions

View file

@ -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<string> 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;
}

View file

@ -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<string> ProcessCommand(string lineBeingSent)
{
int commentIndex = lineBeingSent.IndexOf(';');

View file

@ -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<string> ProcessCommand(string lineBeingSent)
{
int commentIndex = lineBeingSent.IndexOf(';');
if (commentIndex > 0) // there is content in front of the ;
{
lineBeingSent = lineBeingSent.Substring(0, commentIndex).Trim();
}
List<string> lines = new List<string>();
lines.Add(lineBeingSent);
if (lineBeingSent.StartsWith("G28"))
{
lines.Add("M114");
}
return lines;
}
}
}

View file

@ -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();
}

View file

@ -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();

View file

@ -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<Vector3> SampledPositions = new List<Vector3>();
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<PrintLevelingData>(jsonData);
instance = Newtonsoft.Json.JsonConvert.DeserializeObject<PrintLevelingData>(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();
}
}
/// <summary>
/// Gets the 9 {3 * (x, y, z)} positions that were probed during the print leveling setup.
/// </summary>

View file

@ -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<string> 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];

View file

@ -152,6 +152,7 @@
<Compile Include="ConfigurationPage\PrinterSettings\PrinterSettingsView.cs" />
<Compile Include="ConfigurationPage\PrintLeveling\LevelWizard2Point.cs" />
<Compile Include="ConfigurationPage\PrintLeveling\InstructionsPage.cs" />
<Compile Include="ConfigurationPage\PrintLeveling\LevelWizard7PointRadial.cs" />
<Compile Include="ConfigurationPage\PrintLeveling\LevelWizard3Point.cs" />
<Compile Include="ConfigurationPage\PrintLeveling\LevelWizardBase.cs" />
<Compile Include="ConfigurationPage\PrintLeveling\PrintLevelingData.cs" />

View file

@ -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);
}
}

View file

@ -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<string> 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];

View file

@ -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();

View file

@ -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);
}
}
}
}

View file

@ -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<PrintLevelingData.LevelingSystem>(printLevelingType, out result))
{
levelingData.CurrentPrinterLevelingSystem = result;
}
else
{
levelingData.CurrentPrinterLevelingSystem = PrintLevelingData.LevelingSystem.Probe2Points;
}
}
string defaultSliceEngine;

View file

@ -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

View file

@ -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();

View file

@ -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

View file

@ -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.