Made probe calibration happen automatically if required

This commit is contained in:
Lars Brubaker 2018-04-06 14:58:25 -07:00
parent 49024f92fc
commit d3818471c5
14 changed files with 96 additions and 51 deletions

View file

@ -782,10 +782,7 @@ namespace MatterHackers.MatterControl
var printer = ApplicationController.Instance.ActivePrinters.Where(p => p.Connection == s).FirstOrDefault();
if (printer != null)
{
if (PrintLevelingData.NeedsToBeRun(printer))
{
UiThread.RunOnIdle(() => LevelWizardBase.ShowPrintLevelWizard(printer));
}
ApplicationController.Instance.RunAnyRequiredCalibration(printer);
}
}, ref unregisterEvents);
@ -807,6 +804,31 @@ namespace MatterHackers.MatterControl
}
}
public bool RunAnyRequiredCalibration(PrinterConfig printer)
{
if (PrintLevelingData.NeedsToBeRun(printer))
{
// run probe calibration first if we need to
if (ProbeCalibrationWizard.NeedsToBeRun(printer))
{
UiThread.RunOnIdle(() =>
{
ProbeCalibrationWizard.ShowProbeCalibrationWizard(printer);
});
}
else // run the leveling wizard
{
UiThread.RunOnIdle(() =>
{
LevelWizardBase.ShowPrintLevelWizard(printer);
});
}
return true;
}
return false;
}
public HashSet<IObject3DEditor> GetEditorsForType(Type selectedItemType)
{
HashSet<IObject3DEditor> mappedEditors;
@ -1408,14 +1430,10 @@ namespace MatterHackers.MatterControl
try
{
// If leveling is required or is currently on
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_required_to_print)
|| ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_enabled))
if(ApplicationController.Instance.RunAnyRequiredCalibration(printer))
{
if (PrintLevelingData.NeedsToBeRun(printer))
{
LevelWizardBase.ShowPrintLevelWizard(printer);
return;
}
// We need to calibrate. So, don't print this part.
return;
}
//if (!string.IsNullOrEmpty(partFilePath) && File.Exists(partFilePath))

View file

@ -60,7 +60,7 @@ namespace MatterHackers.MatterControl.PrinterControls
{
UiThread.RunOnIdle(() =>
{
LevelWizardBase.ShowPrintLevelWizard(printer, LevelWizardBase.RunningState.UserRequestedCalibration);
LevelWizardBase.ShowPrintLevelWizard(printer);
});
};
@ -93,8 +93,7 @@ namespace MatterHackers.MatterControl.PrinterControls
// add in the controls for configuring probe offset
if (printer.Settings.GetValue<bool>(SettingsKey.has_z_probe)
&& printer.Settings.GetValue<bool>(SettingsKey.use_z_probe)
&& printer.Settings.GetValue<bool>(SettingsKey.has_z_servo))
&& printer.Settings.GetValue<bool>(SettingsKey.use_z_probe))
{
var probeCalibrationRow = new FlowLayoutWidget()
{

View file

@ -36,8 +36,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class LevelWizard13PointRadial : LevelWizardBase
{
public LevelWizard13PointRadial(PrinterConfig printer, LevelWizardBase.RunningState runningState)
: base(printer, runningState)
public LevelWizard13PointRadial(PrinterConfig printer)
: base(printer)
{
}

View file

@ -40,8 +40,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class LevelWizard3Point : LevelWizardBase
{
public LevelWizard3Point(PrinterConfig printer, LevelWizardBase.RunningState runningState)
: base(printer, runningState)
public LevelWizard3Point(PrinterConfig printer)
: base(printer)
{
}

View file

@ -37,8 +37,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class LevelWizard3x3Mesh : LevelWizardBase
{
public LevelWizard3x3Mesh(PrinterConfig printer, LevelWizardBase.RunningState runningState)
: base(printer, runningState)
public LevelWizard3x3Mesh(PrinterConfig printer)
: base(printer)
{
}

View file

@ -37,8 +37,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class LevelWizard5x5Mesh : LevelWizardBase
{
public LevelWizard5x5Mesh(PrinterConfig printer, LevelWizardBase.RunningState runningState)
: base(printer, runningState)
public LevelWizard5x5Mesh(PrinterConfig printer)
: base(printer)
{
}

View file

@ -36,8 +36,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class LevelWizard7PointRadial : LevelWizardBase
{
public LevelWizard7PointRadial(PrinterConfig printer, LevelWizardBase.RunningState runningState)
: base(printer, runningState)
public LevelWizard7PointRadial(PrinterConfig printer)
: base(printer)
{
}

View file

@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private static SystemWindow printLevelWizardWindow;
private LevelingStrings levelingStrings;
public LevelWizardBase(PrinterConfig printer, RunningState runningState)
public LevelWizardBase(PrinterConfig printer)
: base(500, 370)
{
levelingStrings = new LevelingStrings(printer.Settings);
@ -65,10 +65,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
printLevelWizard = new WizardControl();
AddChild(printLevelWizard);
if (runningState == LevelWizardBase.RunningState.InitialStartupCalibration)
// If no leveling data has been calculated
bool showWelcomeScreen = printer.Settings.Helpers.GetPrintLevelingData().SampledPositions.Count == 0
&& !ProbeCalibrationWizard.UsingZProbe(printer);
if (showWelcomeScreen)
{
string part1 = "Congratulations on connecting to your new printer. Before starting your first print we need to run a simple calibration procedure.".Localize();
string part2 = "The next few screens will walk your through the print leveling wizard.".Localize();
string part1 = "Congratulations on connecting to your printer. Before starting your first print we need to run a simple calibration procedure.".Localize();
string part2 = "The next few screens will walk your through calibrating your printer.".Localize();
string requiredPageInstructions = $"{part1}\n\n{part2}";
printLevelWizard.AddPage(new FirstPageInstructions(printer, levelingStrings.initialPrinterSetupStepText, requiredPageInstructions));
}
@ -138,32 +142,17 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
printLevelWizard.AddPage(new LastPagelInstructions(printer, printLevelWizard, "Done".Localize(), levelingStrings.DoneInstructions, probePositions));
}
public enum RunningState { InitialStartupCalibration, UserRequestedCalibration }
public abstract int ProbeCount { get; }
public int TotalSteps => ProbeCount * 3;
public static void ShowPrintLevelWizard(PrinterConfig printer)
{
LevelWizardBase.RunningState runningState = LevelWizardBase.RunningState.UserRequestedCalibration;
if (printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print))
{
// run in the first run state
runningState = LevelWizardBase.RunningState.InitialStartupCalibration;
}
ShowPrintLevelWizard(printer, runningState);
}
public static void ShowPrintLevelWizard(PrinterConfig printer, LevelWizardBase.RunningState runningState)
{
if (printLevelWizardWindow == null)
{
// turn off print leveling
PrintLevelingStream.AllowLeveling = false;
printLevelWizardWindow = LevelWizardBase.CreateAndShowWizard(printer, runningState);
printLevelWizardWindow = LevelWizardBase.CreateAndShowWizard(printer);
printLevelWizardWindow.Closed += (sender, e) =>
{
@ -191,7 +180,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public abstract IEnumerable<Vector2> GetPrintLevelPositionToSample();
private static LevelWizardBase CreateAndShowWizard(PrinterConfig printer, LevelWizardBase.RunningState runningState)
private static LevelWizardBase CreateAndShowWizard(PrinterConfig printer)
{
// clear any data that we are going to be acquiring (sampled positions, after z home offset)
PrintLevelingData levelingData = new PrintLevelingData()
@ -205,23 +194,23 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
switch (levelingData.LevelingSystem)
{
case LevelingSystem.Probe3Points:
printLevelWizardWindow = new LevelWizard3Point(printer, runningState);
printLevelWizardWindow = new LevelWizard3Point(printer);
break;
case LevelingSystem.Probe7PointRadial:
printLevelWizardWindow = new LevelWizard7PointRadial(printer, runningState);
printLevelWizardWindow = new LevelWizard7PointRadial(printer);
break;
case LevelingSystem.Probe13PointRadial:
printLevelWizardWindow = new LevelWizard13PointRadial(printer, runningState);
printLevelWizardWindow = new LevelWizard13PointRadial(printer);
break;
case LevelingSystem.Probe3x3Mesh:
printLevelWizardWindow = new LevelWizard3x3Mesh(printer, runningState);
printLevelWizardWindow = new LevelWizard3x3Mesh(printer);
break;
case LevelingSystem.Probe5x5Mesh:
printLevelWizardWindow = new LevelWizard5x5Mesh(printer, runningState);
printLevelWizardWindow = new LevelWizard5x5Mesh(printer);
break;
default:

View file

@ -264,6 +264,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
// make sure we don't have leveling data
double newProbeOffset = autoProbePositions[0].position.Z - manualProbePositions[0].position.Z;
printer.Settings.SetValue(SettingsKey.z_probe_z_offset, newProbeOffset.ToString("0.###"));
printer.Settings.SetValue(SettingsKey.probe_has_been_calibrated, "1");
if (printer.Settings.GetValue<bool>(SettingsKey.z_homes_to_max))
{
@ -272,6 +273,12 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
container.backButton.Enabled = false;
Closed += (s, e) =>
{
// move from this wizard to the print leveling wizard if needed
ApplicationController.Instance.RunAnyRequiredCalibration(printer);
};
base.PageIsBecomingActive();
}
}

View file

@ -67,6 +67,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
printLevelWizard = new WizardControl();
AddChild(printLevelWizard);
if (printer.Settings.GetValue<bool>(SettingsKey.probe_has_been_calibrated))
{
string part1 = "Congratulations on connecting to your printer. Before starting your first print we need to run a simple calibration procedure.".Localize();
string part2 = "The next few screens will walk your through calibrating your printer.".Localize();
string requiredPageInstructions = $"{part1}\n\n{part2}";
printLevelWizard.AddPage(new FirstPageInstructions(printer, levelingStrings.initialPrinterSetupStepText, requiredPageInstructions));
}
var CalibrateProbeWelcomText = "{0}\n\n\t• {1}\n\t• {2}\n\t• {3}\n\n{4}\n\n{5}".FormatWith(
"Welcome to the probe calibration wizard. Here is a quick overview on what we are going to do.".Localize(),
"Home the printer".Localize(),
@ -116,6 +124,19 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private static SystemWindow probeCalibrationWizardWindow;
public static bool UsingZProbe(PrinterConfig printer)
{
// we have a probe that we are using and we have not done leveling yet
return printer.Settings.GetValue<bool>(SettingsKey.has_z_probe)
&& printer.Settings.GetValue<bool>(SettingsKey.use_z_probe);
}
public static bool NeedsToBeRun(PrinterConfig printer)
{
// we have a probe that we are using and we have not done leveling yet
return UsingZProbe(printer) && !printer.Settings.GetValue<bool>(SettingsKey.probe_has_been_calibrated);
}
public static void ShowProbeCalibrationWizard(PrinterConfig printer)
{
if (probeCalibrationWizardWindow == null)

View file

@ -120,6 +120,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public const string print_leveling_data = nameof(print_leveling_data);
public const string print_leveling_enabled = nameof(print_leveling_enabled);
public const string print_leveling_probe_start = nameof(print_leveling_probe_start);
public const string probe_has_been_calibrated = nameof(probe_has_been_calibrated);
public const string print_leveling_required_to_print = nameof(print_leveling_required_to_print);
public const string print_leveling_solution = nameof(print_leveling_solution);
public const string printer_name = nameof(printer_name);

View file

@ -73,6 +73,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
SettingsKey.z_servo_retracted_angle,
SettingsKey.pause_gcode,
SettingsKey.print_leveling_probe_start,
SettingsKey.probe_has_been_calibrated,
SettingsKey.print_leveling_required_to_print,
SettingsKey.print_leveling_solution,
SettingsKey.recover_first_layer_speed,

View file

@ -799,6 +799,15 @@
"DefaultValue": "0",
"RebuildGCodeOnChange": false
},
{
"SlicerConfigName": "probe_has_been_calibrated",
"PresentationName": "Probe Has Been Calibrated",
"HelpText": "Flag keeping track if probe calibration wizard has been run.",
"DataEditType": "CHECK_BOX",
"ShowIfSet": "!has_hardware_leveling",
"DefaultValue": "0",
"RebuildGCodeOnChange": false
},
{
"SlicerConfigName": "print_leveling_probe_start",
"PresentationName": "Start Height",

View file

@ -20,7 +20,7 @@ namespace MatterControl.Tests.MatterControl
{
AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));
LevelWizard3Point levelingSolution = new LevelWizard3Point(ActiveSliceSettings.Instance.printer, LevelWizardBase.RunningState.InitialStartupCalibration);
LevelWizard3Point levelingSolution = new LevelWizard3Point(ActiveSliceSettings.Instance.printer);
var printerSettings = ActiveSliceSettings.Instance;
{