2014-06-05 11:45:40 -07:00
|
|
|
|
/*
|
2018-05-23 18:23:38 -07:00
|
|
|
|
Copyright (c) 2018, Lars Brubaker, John Lewin
|
2014-06-05 11:45:40 -07:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
2015-04-08 15:20:10 -07:00
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2014-06-05 11:45:40 -07:00
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
2015-04-08 15:20:10 -07:00
|
|
|
|
list of conditions and the following disclaimer.
|
2014-06-05 11:45:40 -07:00
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2015-04-08 15:20:10 -07:00
|
|
|
|
and/or other materials provided with the distribution.
|
2014-06-05 11:45:40 -07:00
|
|
|
|
|
|
|
|
|
|
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
|
2015-04-08 15:20:10 -07:00
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
2014-06-05 11:45:40 -07:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2018-05-23 17:54:31 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2018-03-29 12:31:36 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2014-06-05 11:45:40 -07:00
|
|
|
|
using MatterHackers.Localizations;
|
|
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using MatterHackers.VectorMath;
|
2014-06-05 11:45:40 -07:00
|
|
|
|
|
2014-06-06 16:05:18 -07:00
|
|
|
|
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
|
2014-06-05 11:45:40 -07:00
|
|
|
|
{
|
2018-05-23 19:12:46 -07:00
|
|
|
|
public class PrintLevelingWizard : LevelingWizard
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-05-23 17:54:31 -07:00
|
|
|
|
private LevelingPlan levelingPlan;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2018-05-23 18:36:25 -07:00
|
|
|
|
public PrintLevelingWizard(LevelingPlan levelingPlan, PrinterConfig printer)
|
2018-05-23 18:01:09 -07:00
|
|
|
|
: base (printer)
|
2018-05-23 17:54:31 -07:00
|
|
|
|
{
|
|
|
|
|
|
this.levelingPlan = levelingPlan;
|
|
|
|
|
|
}
|
2018-03-29 12:31:36 -07:00
|
|
|
|
|
2018-05-23 17:54:31 -07:00
|
|
|
|
protected override IEnumerator<LevelingWizardPage> GetWizardSteps()
|
|
|
|
|
|
{
|
|
|
|
|
|
var probePositions = new List<ProbePosition>(levelingPlan.ProbeCount);
|
|
|
|
|
|
for (int j = 0; j < levelingPlan.ProbeCount; j++)
|
|
|
|
|
|
{
|
|
|
|
|
|
probePositions.Add(new ProbePosition());
|
|
|
|
|
|
}
|
2018-04-10 14:40:19 -07:00
|
|
|
|
|
2018-05-23 18:23:38 -07:00
|
|
|
|
var levelingStrings = new LevelingStrings(printer.Settings);
|
2018-04-10 17:59:15 -07:00
|
|
|
|
|
2018-05-23 17:54:31 -07:00
|
|
|
|
// If no leveling data has been calculated
|
2018-05-23 18:23:38 -07:00
|
|
|
|
bool showWelcomeScreen = printer.Settings.Helpers.GetPrintLevelingData().SampledPositions.Count == 0
|
2018-05-24 09:10:41 -07:00
|
|
|
|
&& !ProbeCalibrationWizard.UsingZProbe(printer);
|
2018-05-23 11:40:11 -07:00
|
|
|
|
|
2018-05-23 17:54:31 -07:00
|
|
|
|
if (showWelcomeScreen)
|
|
|
|
|
|
{
|
2018-05-23 12:19:21 -07:00
|
|
|
|
yield return new LevelingWizardPage(
|
2018-05-23 17:54:31 -07:00
|
|
|
|
this,
|
2018-05-24 09:34:23 -07:00
|
|
|
|
levelingStrings.InitialPrinterSetupStepText,
|
2018-05-23 17:54:31 -07:00
|
|
|
|
string.Format(
|
|
|
|
|
|
"{0}\n\n{1}",
|
|
|
|
|
|
"Congratulations on connecting to your printer. Before starting your first print we need to run a simple calibration procedure.".Localize(),
|
|
|
|
|
|
"The next few screens will walk your through calibrating your printer.".Localize()));
|
|
|
|
|
|
}
|
2018-04-10 17:59:15 -07:00
|
|
|
|
|
2018-05-23 17:54:31 -07:00
|
|
|
|
// To make sure the bed is at the correct temp, put in a filament selection page.
|
2018-05-23 18:23:38 -07:00
|
|
|
|
bool hasHeatedBed = printer.Settings.GetValue<bool>(SettingsKey.has_heated_bed);
|
|
|
|
|
|
bool useZProbe = printer.Settings.Helpers.UseZProbe();
|
|
|
|
|
|
int zProbeSamples = printer.Settings.GetValue<int>(SettingsKey.z_probe_samples);
|
2018-05-23 17:54:31 -07:00
|
|
|
|
|
|
|
|
|
|
var secondsPerManualSpot = 10 * 3;
|
|
|
|
|
|
var secondsPerAutomaticSpot = 3 * zProbeSamples;
|
|
|
|
|
|
var secondsToCompleteWizard = levelingPlan.ProbeCount * (useZProbe ? secondsPerAutomaticSpot : secondsPerManualSpot);
|
|
|
|
|
|
secondsToCompleteWizard += (hasHeatedBed ? 60 * 3 : 0);
|
|
|
|
|
|
|
|
|
|
|
|
yield return new LevelingWizardPage(
|
|
|
|
|
|
this,
|
|
|
|
|
|
"Print Leveling Overview".Localize(),
|
|
|
|
|
|
levelingStrings.WelcomeText(levelingPlan.ProbeCount, (int)Math.Round(secondsToCompleteWizard / 60.0)));
|
2018-04-03 12:10:33 -07:00
|
|
|
|
|
2018-05-23 17:54:31 -07:00
|
|
|
|
// If we need to heat the bed or the extruder, select the current material
|
|
|
|
|
|
if (hasHeatedBed || !useZProbe)
|
|
|
|
|
|
{
|
|
|
|
|
|
yield return new SelectMaterialPage(
|
2018-05-23 11:40:11 -07:00
|
|
|
|
this,
|
2018-05-23 17:54:31 -07:00
|
|
|
|
"Select Material".Localize(),
|
|
|
|
|
|
"Please select the material you will be printing with, so we can accurately calibrate the printer.".Localize());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
yield return new HomePrinterPage(
|
|
|
|
|
|
this,
|
2018-05-23 19:26:04 -07:00
|
|
|
|
"Homing The Printer".Localize(),
|
2018-05-23 17:54:31 -07:00
|
|
|
|
levelingStrings.HomingPageInstructions(useZProbe, hasHeatedBed),
|
|
|
|
|
|
useZProbe);
|
|
|
|
|
|
|
|
|
|
|
|
// figure out the heating requirements
|
|
|
|
|
|
double targetBedTemp = 0;
|
|
|
|
|
|
double targetHotendTemp = 0;
|
|
|
|
|
|
if (hasHeatedBed)
|
|
|
|
|
|
{
|
2018-05-23 18:23:38 -07:00
|
|
|
|
targetBedTemp = printer.Settings.GetValue<double>(SettingsKey.bed_temperature);
|
2018-05-23 17:54:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!useZProbe)
|
|
|
|
|
|
{
|
2018-05-23 18:23:38 -07:00
|
|
|
|
targetHotendTemp = printer.Settings.Helpers.ExtruderTemperature(0);
|
2018-05-23 17:54:31 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (targetBedTemp > 0 || targetHotendTemp > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
string heatingInstructions = "";
|
|
|
|
|
|
if (targetBedTemp > 0 && targetHotendTemp > 0)
|
2018-04-10 14:40:19 -07:00
|
|
|
|
{
|
2018-05-23 17:54:31 -07:00
|
|
|
|
// heating both the bed and the hotend
|
2018-06-08 14:04:34 -07:00
|
|
|
|
heatingInstructions = "Waiting for the bed to heat to ".Localize() + targetBedTemp +"\n"
|
|
|
|
|
|
+ "and the hotend to heat to ".Localize() + targetHotendTemp + ".\n"
|
2018-05-23 17:54:31 -07:00
|
|
|
|
+ "\n"
|
2018-08-06 15:28:56 -07:00
|
|
|
|
+ "This will improve the accuracy of print leveling ".Localize()
|
2018-05-23 17:54:31 -07:00
|
|
|
|
+ "and ensure no filament is stuck to the tip of the extruder.".Localize() + "\n"
|
|
|
|
|
|
+ "\n"
|
|
|
|
|
|
+ "Warning! The tip of the nozzle will be HOT!".Localize() + "\n"
|
|
|
|
|
|
+ "Avoid contact with your skin.".Localize();
|
2018-04-10 14:40:19 -07:00
|
|
|
|
}
|
2018-05-23 17:54:31 -07:00
|
|
|
|
else if (targetBedTemp > 0)
|
2018-04-10 14:40:19 -07:00
|
|
|
|
{
|
2018-05-23 17:54:31 -07:00
|
|
|
|
// only heating the bed
|
2018-06-08 14:04:34 -07:00
|
|
|
|
heatingInstructions = "Waiting for the bed to heat to ".Localize() + targetBedTemp + ".\n"
|
2018-05-23 17:54:31 -07:00
|
|
|
|
+ "This will improve the accuracy of print leveling.".Localize();
|
2018-04-10 14:40:19 -07:00
|
|
|
|
}
|
2018-05-23 17:54:31 -07:00
|
|
|
|
else // targetHotendTemp > 0
|
2018-04-10 14:40:19 -07:00
|
|
|
|
{
|
2018-05-23 17:54:31 -07:00
|
|
|
|
// only heating the hotend
|
2018-06-08 14:04:34 -07:00
|
|
|
|
heatingInstructions += "Waiting for the hotend to heat to ".Localize() + targetHotendTemp + ".\n"
|
2018-05-23 17:54:31 -07:00
|
|
|
|
+ "This will ensure no filament is stuck to the tip.".Localize() + "\n"
|
|
|
|
|
|
+ "\n"
|
|
|
|
|
|
+ "Warning! The tip of the nozzle will be HOT!".Localize() + "\n"
|
|
|
|
|
|
+ "Avoid contact with your skin.".Localize();
|
2018-04-10 14:40:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-05-23 17:54:31 -07:00
|
|
|
|
yield return new WaitForTempPage(
|
|
|
|
|
|
this,
|
2018-05-23 18:23:38 -07:00
|
|
|
|
"Waiting For Printer To Heat".Localize(),
|
2018-05-23 17:54:31 -07:00
|
|
|
|
heatingInstructions,
|
|
|
|
|
|
targetBedTemp, targetHotendTemp);
|
|
|
|
|
|
}
|
2018-03-29 12:31:36 -07:00
|
|
|
|
|
2018-05-23 18:23:38 -07:00
|
|
|
|
double bedRadius = Math.Min(printer.Settings.GetValue<Vector2>(SettingsKey.bed_size).X, printer.Settings.GetValue<Vector2>(SettingsKey.bed_size).Y) / 2;
|
|
|
|
|
|
double startProbeHeight = printer.Settings.GetValue<double>(SettingsKey.print_leveling_probe_start);
|
2018-07-29 16:49:15 -07:00
|
|
|
|
|
2018-05-23 17:54:31 -07:00
|
|
|
|
int i = 0;
|
|
|
|
|
|
foreach (var goalProbePosition in levelingPlan.GetPrintLevelPositionToSample())
|
|
|
|
|
|
{
|
2018-05-23 18:23:38 -07:00
|
|
|
|
var validProbePosition = EnsureInPrintBounds(printer.Settings, goalProbePosition);
|
2018-04-11 17:35:34 -07:00
|
|
|
|
|
2018-05-23 18:23:38 -07:00
|
|
|
|
if (printer.Settings.Helpers.UseZProbe())
|
2018-04-11 17:35:34 -07:00
|
|
|
|
{
|
2018-05-23 17:54:31 -07:00
|
|
|
|
yield return new AutoProbeFeedback(
|
|
|
|
|
|
this,
|
|
|
|
|
|
new Vector3(validProbePosition, startProbeHeight),
|
|
|
|
|
|
string.Format(
|
|
|
|
|
|
"{0} {1} {2} - {3}",
|
|
|
|
|
|
$"{"Step".Localize()} {i + 1} {"of".Localize()} {levelingPlan.ProbeCount}:",
|
2018-07-29 16:49:15 -07:00
|
|
|
|
"Position".Localize(),
|
2018-05-23 17:54:31 -07:00
|
|
|
|
i + 1,
|
2018-07-29 16:49:15 -07:00
|
|
|
|
"Auto Calibrate".Localize()),
|
2018-05-23 17:54:31 -07:00
|
|
|
|
probePositions,
|
|
|
|
|
|
i);
|
2018-04-11 17:35:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-05-23 17:54:31 -07:00
|
|
|
|
yield return new GetCoarseBedHeight(
|
|
|
|
|
|
this,
|
|
|
|
|
|
new Vector3(validProbePosition, startProbeHeight),
|
|
|
|
|
|
string.Format(
|
|
|
|
|
|
"{0} {1} {2} - {3}",
|
|
|
|
|
|
levelingStrings.GetStepString(levelingPlan.TotalSteps),
|
2018-07-29 16:49:15 -07:00
|
|
|
|
"Position".Localize(),
|
2018-05-23 17:54:31 -07:00
|
|
|
|
i + 1,
|
2018-07-29 16:49:15 -07:00
|
|
|
|
"Low Precision".Localize()),
|
2018-05-23 17:54:31 -07:00
|
|
|
|
probePositions,
|
|
|
|
|
|
i,
|
|
|
|
|
|
levelingStrings);
|
|
|
|
|
|
|
|
|
|
|
|
yield return new GetFineBedHeight(
|
|
|
|
|
|
this,
|
|
|
|
|
|
string.Format(
|
|
|
|
|
|
"{0} {1} {2} - {3}",
|
|
|
|
|
|
levelingStrings.GetStepString(levelingPlan.TotalSteps),
|
2018-07-29 16:49:15 -07:00
|
|
|
|
"Position".Localize(),
|
2018-05-23 17:54:31 -07:00
|
|
|
|
i + 1,
|
2018-07-29 16:49:15 -07:00
|
|
|
|
"Medium Precision".Localize()),
|
2018-05-23 17:54:31 -07:00
|
|
|
|
probePositions,
|
|
|
|
|
|
i,
|
|
|
|
|
|
levelingStrings);
|
|
|
|
|
|
|
|
|
|
|
|
yield return new GetUltraFineBedHeight(
|
|
|
|
|
|
this,
|
|
|
|
|
|
string.Format(
|
|
|
|
|
|
"{0} {1} {2} - {3}",
|
|
|
|
|
|
levelingStrings.GetStepString(levelingPlan.TotalSteps),
|
2018-07-29 16:49:15 -07:00
|
|
|
|
"Position".Localize(),
|
2018-05-23 17:54:31 -07:00
|
|
|
|
i + 1,
|
2018-07-29 16:49:15 -07:00
|
|
|
|
"High Precision".Localize()),
|
2018-05-23 17:54:31 -07:00
|
|
|
|
probePositions,
|
|
|
|
|
|
i,
|
|
|
|
|
|
levelingStrings);
|
2018-04-11 17:35:34 -07:00
|
|
|
|
}
|
2018-05-23 17:54:31 -07:00
|
|
|
|
i++;
|
|
|
|
|
|
}
|
2018-04-11 17:35:34 -07:00
|
|
|
|
|
2018-05-23 18:24:19 -07:00
|
|
|
|
yield return new LastPageInstructions(
|
2018-05-23 17:54:31 -07:00
|
|
|
|
this,
|
2018-05-30 15:55:07 -07:00
|
|
|
|
"Print Leveling Wizard".Localize(),
|
2018-05-24 09:12:04 -07:00
|
|
|
|
string.Format(
|
2018-06-08 14:15:01 -07:00
|
|
|
|
"{0}! {1}\n\n{2}\n{3}\n\n{4}",
|
|
|
|
|
|
"Congratulations".Localize(),
|
2018-05-24 09:12:04 -07:00
|
|
|
|
"Print Leveling is now configured and enabled.".Localize(),
|
2018-05-24 23:15:48 -07:00
|
|
|
|
useZProbe ? "" : $"\t• {"Remove the paper".Localize()}\n",
|
2018-05-24 09:12:04 -07:00
|
|
|
|
"If you need to recalibrate the printer in the future, the print leveling controls can be found under: Controls, Calibration".Localize(),
|
|
|
|
|
|
"Click 'Done' to close this window.".Localize()),
|
2018-05-23 17:54:31 -07:00
|
|
|
|
probePositions);
|
2018-04-10 17:59:15 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Vector2 EnsureInPrintBounds(PrinterSettings printerSettings, Vector2 probePosition)
|
|
|
|
|
|
{
|
2018-07-12 22:49:39 -07:00
|
|
|
|
// check that the position is within the printing area and if not move it back in
|
2018-04-10 17:59:15 -07:00
|
|
|
|
if (printerSettings.Helpers.UseZProbe())
|
2018-03-29 12:31:36 -07:00
|
|
|
|
{
|
2018-05-23 18:23:38 -07:00
|
|
|
|
var probeOffset = printer.Settings.GetValue<Vector2>(SettingsKey.z_probe_xy_offset);
|
2018-04-10 17:59:15 -07:00
|
|
|
|
var actualNozzlePosition = probePosition - probeOffset;
|
2018-03-29 12:31:36 -07:00
|
|
|
|
|
2018-04-10 17:59:15 -07:00
|
|
|
|
// clamp this to the bed bounds
|
2018-05-23 18:23:38 -07:00
|
|
|
|
Vector2 bedSize = printer.Settings.GetValue<Vector2>(SettingsKey.bed_size);
|
|
|
|
|
|
Vector2 printCenter = printer.Settings.GetValue<Vector2>(SettingsKey.print_center);
|
2018-04-10 17:59:15 -07:00
|
|
|
|
RectangleDouble bedBounds = new RectangleDouble(printCenter - bedSize / 2, printCenter + bedSize / 2);
|
|
|
|
|
|
Vector2 adjustedPosition = bedBounds.Clamp(actualNozzlePosition);
|
|
|
|
|
|
|
|
|
|
|
|
// and push it back into the probePosition
|
|
|
|
|
|
probePosition = adjustedPosition + probeOffset;
|
2017-05-19 14:39:57 -07:00
|
|
|
|
}
|
2018-03-29 12:31:36 -07:00
|
|
|
|
|
2018-04-10 17:59:15 -07:00
|
|
|
|
return probePosition;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-29 18:12:02 -07:00
|
|
|
|
// this class is so that it is not passed by value
|
|
|
|
|
|
public class ProbePosition
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-03-29 18:12:02 -07:00
|
|
|
|
public Vector3 position;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|