Working on new probe calibration wizard

This commit is contained in:
Lars Brubaker 2018-03-09 18:22:38 -08:00
parent c98a60aed2
commit b7f3de2a0d
5 changed files with 271 additions and 56 deletions

View file

@ -13,7 +13,7 @@ namespace MatterHackers.MatterControl.PrinterControls
public class CalibrationControls : FlowLayoutWidget
{
private EventHandler unregisterEvents;
private GuiWidget configureButton;
private GuiWidget configureLevelingButton;
private TextImageButtonFactory buttonFactory;
private PrinterConfig printer;
@ -24,68 +24,71 @@ namespace MatterHackers.MatterControl.PrinterControls
this.printer = printer;
this.buttonFactory = theme.ButtonFactory;
var buttonRow = new FlowLayoutWidget()
// add in the controls for configuring auto leveling
{
Name = "AutoLevelRowItem",
HAnchor = HAnchor.Stretch,
};
buttonRow.AddChild(
new IconButton(AggContext.StaticData.LoadIcon("leveling_32x32.png", 24, 24, IconColor.Theme), theme)
var autoLevelRow = new FlowLayoutWidget()
{
Margin = new BorderDouble(right: 6),
Name = "AutoLevelRowItem",
HAnchor = HAnchor.Stretch,
};
autoLevelRow.AddChild(
new IconButton(AggContext.StaticData.LoadIcon("leveling_32x32.png", 24, 24, IconColor.Theme), theme)
{
Margin = new BorderDouble(right: 6),
VAnchor = VAnchor.Center
});
// label
autoLevelRow.AddChild(
new TextWidget("Software Print Leveling".Localize(), textColor: theme.Colors.PrimaryTextColor, pointSize: theme.DefaultFontSize)
{
AutoExpandBoundsToText = true,
VAnchor = VAnchor.Center,
});
autoLevelRow.AddChild(new HorizontalSpacer());
// configure button
var configureIcon = AggContext.StaticData.LoadIcon("fa-cog_16.png", IconColor.Theme);
configureLevelingButton = new IconButton(configureIcon, theme)
{
ToolTipText = "Configure".Localize(),
Margin = theme.ButtonSpacing,
VAnchor = VAnchor.Center
});
// label
buttonRow.AddChild(
new TextWidget("Software Print Leveling".Localize(), textColor: theme.Colors.PrimaryTextColor, pointSize: theme.DefaultFontSize)
};
configureLevelingButton.Click += (s, e) =>
{
AutoExpandBoundsToText = true,
VAnchor = VAnchor.Center,
});
UiThread.RunOnIdle(() =>
{
DialogWindow.Show(new EditLevelingSettingsPage(printer));
});
};
autoLevelRow.AddChild(configureLevelingButton);
buttonRow.AddChild(new HorizontalSpacer());
// configure button
var configureIcon = AggContext.StaticData.LoadIcon("fa-cog_16.png", IconColor.Theme);
configureButton = new IconButton(configureIcon, theme)
{
ToolTipText = "Configure".Localize(),
Margin = theme.ButtonSpacing,
VAnchor = VAnchor.Center
};
configureButton.Click += (s, e) =>
{
UiThread.RunOnIdle(() =>
// put in the switch
CheckBox printLevelingSwitch = ImageButtonFactory.CreateToggleSwitch(printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled));
printLevelingSwitch.VAnchor = VAnchor.Center;
printLevelingSwitch.Margin = new BorderDouble(left: 16);
printLevelingSwitch.CheckedStateChanged += (sender, e) =>
{
DialogWindow.Show(new EditLevelingSettingsPage(printer));
});
};
buttonRow.AddChild(configureButton);
printer.Settings.Helpers.DoPrintLeveling(printLevelingSwitch.Checked);
};
// put in the switch
CheckBox printLevelingSwitch = ImageButtonFactory.CreateToggleSwitch(printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled));
printLevelingSwitch.VAnchor = VAnchor.Center;
printLevelingSwitch.Margin = new BorderDouble(left: 16);
printLevelingSwitch.CheckedStateChanged += (sender, e) =>
{
printer.Settings.Helpers.DoPrintLeveling(printLevelingSwitch.Checked);
};
printer.Settings.PrintLevelingEnabledChanged.RegisterEvent((sender, e) =>
{
printLevelingSwitch.Checked = printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled);
}, ref unregisterEvents);
printer.Settings.PrintLevelingEnabledChanged.RegisterEvent((sender, e) =>
{
printLevelingSwitch.Checked = printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled);
}, ref unregisterEvents);
// only show the switch if leveling can be turned off (it can't if it is required).
if (!printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print))
{
autoLevelRow.AddChild(printLevelingSwitch);
}
// only show the switch if leveling can be turned off (it can't if it is required).
if (!printer.Settings.GetValue<bool>(SettingsKey.print_leveling_required_to_print))
{
buttonRow.AddChild(printLevelingSwitch);
this.AddChild(autoLevelRow);
}
this.AddChild(buttonRow);
printer.Connection.CommunicationStateChanged.RegisterEvent(PrinterStatusChanged, ref unregisterEvents);
printer.Connection.EnableChanged.RegisterEvent(PrinterStatusChanged, ref unregisterEvents);
@ -119,12 +122,12 @@ namespace MatterHackers.MatterControl.PrinterControls
|| printer.Connection.PrinterIsPaused)
{
this.Enabled = false;
configureButton.Enabled = true; // setting this true when the element is disabled makes the colors stay correct
configureLevelingButton.Enabled = true; // setting this true when the element is disabled makes the colors stay correct
}
else
{
this.Enabled = true;
configureButton.Enabled = printer.Connection.IsConnected;
configureLevelingButton.Enabled = printer.Connection.IsConnected;
}
}
}

View file

@ -215,6 +215,41 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
}
}
public class CalibrateProbeLastPagelInstructions : InstructionsPage
{
protected WizardControl container;
private List<ProbePosition> autoProbePositions;
private List<ProbePosition> manualProbePositions;
public CalibrateProbeLastPagelInstructions(PrinterConfig printer, WizardControl container, string pageDescription, string instructionsText,
List<ProbePosition> autoProbePositions,
List<ProbePosition> manualProbePositions)
: base(printer, pageDescription, instructionsText)
{
this.autoProbePositions = autoProbePositions;
this.manualProbePositions = manualProbePositions;
this.container = container;
}
public override void PageIsBecomingActive()
{
PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData();
levelingData.SampledPositions.Clear();
double newProbeOffset = autoProbePositions[0].position.Z - manualProbePositions[0].position.Z;
printer.Settings.SetValue(SettingsKey.z_probe_z_offset, newProbeOffset.ToString("0.###"));
if (printer.Settings.GetValue<bool>(SettingsKey.z_homes_to_max))
{
printer.Connection.HomeAxis(PrinterConnection.Axis.XYZ);
}
container.backButton.Enabled = false;
base.PageIsBecomingActive();
}
}
public class GettingThirdPointFor2PointCalibration : InstructionsPage
{
protected Vector3 probeStartPosition;

View file

@ -0,0 +1,137 @@
/*
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 MatterControl.Printing;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.MeshVisualizer;
using MatterHackers.VectorMath;
using System;
using System.Collections.Generic;
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class ProbeCalibrationWizard : SystemWindow
{
protected WizardControl printLevelWizard;
protected int totalSteps { get; private set; }
protected PrinterConfig printer;
private LevelingStrings levelingStrings;
public ProbeCalibrationWizard(PrinterConfig printer)
: base(500, 370)
{
this.printer = printer;
AlwaysOnTopOfMain = true;
this.totalSteps = 3;
levelingStrings = new LevelingStrings(printer.Settings);
string printLevelWizardTitle = ApplicationController.Instance.ProductName;
string printLevelWizardTitleFull = "Probe Calibration Wizard".Localize();
Title = string.Format("{0} - {1}", printLevelWizardTitle, printLevelWizardTitleFull);
List<ProbePosition> autoProbePositions = new List<ProbePosition>(3);
List<ProbePosition> manualProbePositions = new List<ProbePosition>(3);
autoProbePositions.Add(new ProbePosition());
manualProbePositions.Add(new ProbePosition());
printLevelWizard = new WizardControl();
AddChild(printLevelWizard);
printLevelWizard.AddPage(new FirstPageInstructions(printer, levelingStrings.OverviewText, levelingStrings.WelcomeText(3, 3)));
printLevelWizard.AddPage(new HomePrinterPage(printer, printLevelWizard, levelingStrings.homingPageStepText, levelingStrings.homingPageInstructions));
string positionLabel = "Position".Localize();
string autoCalibrateLabel = "Auto Calibrate".Localize();
string lowPrecisionLabel = "Low Precision".Localize();
string medPrecisionLabel = "Medium Precision".Localize();
string highPrecisionLabel = "High Precision".Localize();
double startProbeHeight = printer.Settings.GetValue<double>(SettingsKey.print_leveling_probe_start);
Vector2 probePosition = printer.Settings.GetValue<Vector2>(SettingsKey.print_center);
int i = 0;
// do the automatic probing of the center position
var stepString = string.Format("{0} {1} {2} {3}:", levelingStrings.stepTextBeg, i + 1, levelingStrings.stepTextEnd, 3);
printLevelWizard.AddPage(new AutoProbeFeedback(printer, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", stepString, positionLabel, i + 1, autoCalibrateLabel), autoProbePositions, i));
// do the manual prob of the same position
printLevelWizard.AddPage(new GetCoarseBedHeight(printer, printLevelWizard, new Vector3(probePosition, startProbeHeight), string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, lowPrecisionLabel), manualProbePositions, i, levelingStrings));
printLevelWizard.AddPage(new GetFineBedHeight(printer, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, medPrecisionLabel), manualProbePositions, i, levelingStrings));
printLevelWizard.AddPage(new GetUltraFineBedHeight(printer, printLevelWizard, string.Format("{0} {1} {2} - {3}", levelingStrings.GetStepString(totalSteps), positionLabel, i + 1, highPrecisionLabel), manualProbePositions, i, levelingStrings));
printLevelWizard.AddPage(new CalibrateProbeLastPagelInstructions(printer, printLevelWizard, "Done".Localize(), levelingStrings.DoneInstructions, autoProbePositions, manualProbePositions));
}
private static SystemWindow probeCalibrationWizardWindow;
public static void ShowProbeCalibrationWizard(PrinterConfig printer)
{
if (probeCalibrationWizardWindow == null)
{
bool levelingWasOn = printer.Settings.GetValue<bool>(SettingsKey.print_leveling_enabled);
// turn off print leveling
printer.Settings.Helpers.DoPrintLeveling(false);
probeCalibrationWizardWindow = new ProbeCalibrationWizard(printer);
probeCalibrationWizardWindow.ShowAsSystemWindow();
probeCalibrationWizardWindow.Closed += (s, e) =>
{
// If leveling was on when we started, make sure it is on when we are done.
if (levelingWasOn)
{
printer.Settings.Helpers.DoPrintLeveling(true);
}
probeCalibrationWizardWindow = null;
// make sure we raise the probe on close
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))
{
// make sure the servo is retracted
var servoRetract = printer.Settings.GetValue<double>(SettingsKey.z_servo_retracted_angle);
printer.Connection.QueueLine($"M280 P0 S{servoRetract}");
}
};
}
else
{
probeCalibrationWizardWindow.BringToFront();
}
}
}
}