Put in baby stepping for T1 (extruder 2)

issue: MatterHackers/MCCentral#5877
Print recovery does not work correctly when the print is extruder 2 only
This commit is contained in:
LarsBrubaker 2020-08-09 12:37:37 -07:00
parent 23e7263da5
commit 7945b381f5
11 changed files with 206 additions and 61 deletions

View file

@ -39,6 +39,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public const string avoid_crossing_max_ratio = nameof(avoid_crossing_max_ratio);
public const string avoid_crossing_perimeters = nameof(avoid_crossing_perimeters);
public const string baby_step_z_offset = nameof(baby_step_z_offset);
public const string baby_step_z_offset_t1 = nameof(baby_step_z_offset_t1);
public const string backup_firmware_before_update = nameof(backup_firmware_before_update);
public const string baud_rate = nameof(baud_rate);
public const string bed_remove_part_temperature = nameof(bed_remove_part_temperature);

View file

@ -446,6 +446,17 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
RebuildGCodeOnChange = false
},
new SliceSettingData()
{
SlicerConfigName = SettingsKey.baby_step_z_offset_t1,
PresentationName = "Baby Step Offset T1".Localize(),
HelpText = "The z offset to apply to T1 to improve the first layer adhesion.".Localize(),
DataEditType = DataEditTypes.DOUBLE,
Units = "mm".Localize(),
DefaultValue = "0",
ShowIfSet = "!sla_printer",
RebuildGCodeOnChange = false
},
new SliceSettingData()
{
SlicerConfigName = SettingsKey.extruders_share_temperature,
PresentationName = "Share Temperature".Localize(),

View file

@ -261,6 +261,26 @@ namespace MatterHackers.MatterControl
});
}
if (extruderCount > 1
&& Math.Abs(settings.GetValue<double>(SettingsKey.baby_step_z_offset_t1)) > 2)
{
// Static path generation for non-SliceSettings value
var location = "Location".Localize() + ":"
+ "\n" + "Controls".Localize()
+ "\n • " + "Movement".Localize()
+ "\n • " + "Z Offset T1".Localize();
errors.Add(
new ValidationError("ZOffset0TooLarge")
{
Error = "T1 Z Offset is too large.".Localize(),
Details = string.Format(
"{0}\n\n{1}",
"The Z Offset for your second printer, sometimes called Baby Stepping, is greater than 2mm and invalid. Clear the value and re-level the bed.".Localize(),
location)
});
}
if (settings.GetValue<double>(SettingsKey.first_layer_extrusion_width) > settings.GetValue<double>(SettingsKey.nozzle_diameter) * 4)
{
errors.Add(

View file

@ -48,6 +48,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
}
private double babySteppingValue;
private double babySteppingValueT1;
private bool wizardExited;
private bool hasHardwareLeveling;
@ -74,9 +75,11 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
// remember the current baby stepping values
babySteppingValue = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
babySteppingValueT1 = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset_t1);
// clear them while we measure the offsets
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, "0");
printer.Settings.SetValue(SettingsKey.baby_step_z_offset_t1, "0");
// turn off print leveling
printer.Connection.AllowLeveling = false;
@ -135,6 +138,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
// set the baby stepping back to the last known good value
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, babySteppingValue.ToString());
printer.Settings.SetValue(SettingsKey.baby_step_z_offset_t1, babySteppingValueT1.ToString());
wizardExited = true;

View file

@ -39,6 +39,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
public class ZCalibrationWizard : PrinterSetupWizard
{
private double babySteppingValue;
private double babySteppingValueT1;
public ZCalibrationWizard(PrinterConfig printer)
: base(printer)
@ -73,6 +74,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
// set the baby stepping back to the last known good value
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, babySteppingValue.ToString());
printer.Settings.SetValue(SettingsKey.baby_step_z_offset_t1, babySteppingValue.ToString());
// make sure we raise the probe on close
if (printer.Settings.GetValue<bool>(SettingsKey.has_z_probe)
@ -132,9 +134,11 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
// remember the current baby stepping values
babySteppingValue = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
babySteppingValueT1 = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset_t1);
// clear them while we measure the offsets
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, "0");
printer.Settings.SetValue(SettingsKey.baby_step_z_offset_t1, "0");
// Require user confirmation after this point
this.RequireCancelConfirmation = true;

View file

@ -75,6 +75,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
// Invoke setter forcing persistence of leveling data
printer.Settings.Helpers.PrintLevelingData = levelingData;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, "0");
printer.Settings.SetValue(SettingsKey.baby_step_z_offset_t1, "0");
printer.Connection.AllowLeveling = true;
printer.Settings.Helpers.DoPrintLeveling(true);

View file

@ -684,13 +684,22 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
upButton.Click += (s, e) =>
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ += babyStepAmount;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
if (printer.Connection.ActiveExtruderIndex == 0)
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ += babyStepAmount;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
}
else if (printer.Connection.ActiveExtruderIndex == 1)
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset_t1);
currentZ += babyStepAmount;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset_t1, currentZ.ToString("0.##"));
}
};
// add in the current position display
var zTuning = babySteppingControls.AddChild(new ZTuningWidget(printer.Settings, theme, false)
var zTuning = babySteppingControls.AddChild(new ZTuningWidget(printer, theme, false)
{
HAnchor = HAnchor.Center | HAnchor.Fit,
VAnchor = VAnchor.Fit,
@ -716,9 +725,18 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
});
downButton.Click += (s, e) =>
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ -= babyStepAmount;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
if (printer.Connection.ActiveExtruderIndex == 0)
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ -= babyStepAmount;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
}
else if (printer.Connection.ActiveExtruderIndex == 1)
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset_t1);
currentZ -= babyStepAmount;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset_t1, currentZ.ToString("0.##"));
}
};
// build the bottom row to hold re-slice

View file

@ -42,7 +42,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private PrinterMove outputWithBabyStepping = PrinterMove.Unknown;
private PrinterMove inputNoBabyStepping = PrinterMove.Unknown;
public Vector3 BabbyStepOffset { get; private set; } = Vector3.Zero;
public Vector3 BabbyStepOffsetT0 { get; private set; } = Vector3.Zero;
public Vector3 BabbyStepOffsetT1 { get; private set; } = Vector3.Zero;
public BabyStepsStream(PrinterConfig printer, GCodeStream internalStream)
: base(printer, internalStream)
@ -51,7 +53,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
extruderIndex = printer.Connection.ActiveExtruderIndex;
BabbyStepOffset = new Vector3(0, 0, printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset));
BabbyStepOffsetT0 = new Vector3(0, 0, printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset));
BabbyStepOffsetT1 = new Vector3(0, 0, printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset_t1));
ReadExtruderOffsets();
}
@ -76,8 +79,13 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
if (e?.Data == SettingsKey.baby_step_z_offset)
{
var currentOffset = BabbyStepOffset.Z;
BabbyStepOffset = new Vector3(0, 0, printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset));
var currentOffset = BabbyStepOffsetT0.Z;
BabbyStepOffsetT0 = new Vector3(0, 0, printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset));
}
else if (e?.Data == SettingsKey.baby_step_z_offset_t1)
{
var currentOffset = BabbyStepOffsetT1.Z;
BabbyStepOffsetT1 = new Vector3(0, 0, printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset_t1));
}
else if (e?.Data == SettingsKey.extruder_offset
&& !printer.Connection.Printing
@ -94,7 +102,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
// calculate our offset to pass on to internal streams
inputNoBabyStepping = outputWithBabyStepping;
inputNoBabyStepping.position -= BabbyStepOffset;
if (extruderIndex == 1)
{
inputNoBabyStepping.position -= BabbyStepOffsetT1;
}
else
{
inputNoBabyStepping.position -= BabbyStepOffsetT0;
}
inputNoBabyStepping.position += extruderOffsets[Math.Min(extruderIndex, 4)];
internalStream.SetPrinterPosition(inputNoBabyStepping);
@ -134,7 +150,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
// it is a struct so this is making a new copy we con modify
PrinterMove moveToSend = inputNoBabyStepping;
moveToSend.position += BabbyStepOffset;
if (extruderIndex == 1)
{
moveToSend.position += BabbyStepOffsetT1;
}
else
{
moveToSend.position += BabbyStepOffsetT0;
}
moveToSend.position -= extruderOffsets[Math.Min(extruderIndex, 4)];
if (moveToSend.HaveAnyPosition)

View file

@ -34,6 +34,7 @@ using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.MatterControl.Utilities;
@ -188,7 +189,7 @@ namespace MatterHackers.MatterControl.PrinterControls
};
toolbar.AddChild(offsetStreamLabel);
var ztuningWidget = new ZTuningWidget(printer.Settings, theme);
var ztuningWidget = new ZTuningWidget(printer, theme);
toolbar.AddChild(ztuningWidget);
toolbar.AddChild(new HorizontalSpacer());
@ -265,44 +266,90 @@ namespace MatterHackers.MatterControl.PrinterControls
public Color ZColor { get; }
}
public class ZTuningWidget : GuiWidget
public class ZTuningWidget : FlowLayoutWidget
{
private GuiWidget clearZOffsetButton;
private PrinterSettings printerSettings;
private PrinterConfig printer;
private ThemeConfig theme;
private FlowLayoutWidget zOffsetStreamContainer;
private TextWidget zOffsetStreamDisplayT0;
private TextWidget zOffsetStreamDisplay;
private TextWidget zOffsetStreamDisplayT1;
public ZTuningWidget(PrinterSettings printerSettings, ThemeConfig theme, bool showClearButton = true)
public ZTuningWidget(PrinterConfig printer, ThemeConfig theme, bool showClearButton = true)
: base(FlowDirection.TopToBottom)
{
this.theme = theme;
this.printerSettings = printerSettings;
this.printer = printer;
this.HAnchor = HAnchor.Fit;
this.VAnchor = VAnchor.Fit | VAnchor.Center;
zOffsetStreamContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
{
Margin = new BorderDouble(3, 0),
Padding = new BorderDouble(3),
HAnchor = HAnchor.Fit,
VAnchor = VAnchor.Center,
Height = 20 * GuiWidget.DeviceScale
};
this.AddChild(zOffsetStreamContainer);
double zoffset = printerSettings.GetValue<double>(SettingsKey.baby_step_z_offset);
zOffsetStreamDisplay = new TextWidget(zoffset.ToString("0.##"), pointSize: theme.DefaultFontSize)
var zOffset = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
zOffsetStreamDisplayT0 = new TextWidget(zOffset.ToString("0.##"), pointSize: theme.DefaultFontSize)
{
AutoExpandBoundsToText = true,
TextColor = theme.TextColor,
Margin = new BorderDouble(5, 0, 8, 0),
VAnchor = VAnchor.Center
};
zOffsetStreamContainer.AddChild(zOffsetStreamDisplay);
AddExtruder(printer.Settings, SettingsKey.baby_step_z_offset, zOffsetStreamDisplayT0);
AddDisplay(printer.Settings, theme, showClearButton, SettingsKey.baby_step_z_offset, zOffsetStreamDisplayT0);
if (printer.Settings.GetValue<int>(SettingsKey.extruder_count) > 1)
{
zOffset = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset_t1);
zOffsetStreamDisplayT1 = new TextWidget(zOffset.ToString("0.##"), pointSize: theme.DefaultFontSize)
{
AutoExpandBoundsToText = true,
TextColor = theme.TextColor,
Margin = new BorderDouble(5, 0, 8, 0),
VAnchor = VAnchor.Center
};
AddExtruder(printer.Settings, SettingsKey.baby_step_z_offset_t1, zOffsetStreamDisplayT1);
AddDisplay(printer.Settings, theme, showClearButton, SettingsKey.baby_step_z_offset_t1, zOffsetStreamDisplayT1);
}
}
private void AddDisplay(PrinterSettings printerSettings,
ThemeConfig theme,
bool showClearButton,
string setting,
TextWidget widget)
{
GuiWidget clearZOffsetButton = null;
void Printer_SettingChanged(object s, StringEventArgs e)
{
if (e?.Data == setting)
{
double zOffset = printerSettings.GetValue<double>(setting);
bool hasOverriddenZOffset = zOffset != 0;
if (clearZOffsetButton != null)
{
clearZOffsetButton.Visible = hasOverriddenZOffset;
}
widget.Text = zOffset.ToString("0.##");
AddExtruder(printerSettings, setting, widget);
}
}
var zOffsetStreamContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
{
Margin = new BorderDouble(3, 0),
Padding = new BorderDouble(3),
HAnchor = HAnchor.Fit | HAnchor.Right,
VAnchor = VAnchor.Absolute,
Height = 20 * GuiWidget.DeviceScale
};
this.AddChild(zOffsetStreamContainer);
var zoffset = printerSettings.GetValue<double>(setting);
zOffsetStreamContainer.AddChild(widget);
if (showClearButton)
{
@ -312,36 +359,31 @@ namespace MatterHackers.MatterControl.PrinterControls
clearZOffsetButton.Visible = zoffset != 0;
clearZOffsetButton.Click += (sender, e) =>
{
printerSettings.SetValue(SettingsKey.baby_step_z_offset, "0");
printerSettings.SetValue(setting, "0");
};
zOffsetStreamContainer.AddChild(clearZOffsetButton);
}
// Register listeners
printerSettings.SettingChanged += Printer_SettingChanged;
}
public override void OnClosed(EventArgs e)
{
// Unregister listeners
printerSettings.SettingChanged -= Printer_SettingChanged;
base.OnClosed(e);
}
private void Printer_SettingChanged(object s, StringEventArgs e)
{
if (e?.Data == SettingsKey.baby_step_z_offset)
this.Closed += (s, e) =>
{
double zoffset = printerSettings.GetValue<double>(SettingsKey.baby_step_z_offset);
bool hasOverriddenZOffset = zoffset != 0;
printerSettings.SettingChanged -= Printer_SettingChanged;
};
}
if (clearZOffsetButton != null)
private static void AddExtruder(PrinterSettings printerSettings, string setting, TextWidget widget)
{
if (printerSettings.GetValue<int>(SettingsKey.extruder_count) > 1)
{
if (setting == SettingsKey.baby_step_z_offset)
{
clearZOffsetButton.Visible = hasOverriddenZOffset;
widget.Text += " E1";
}
else
{
widget.Text += " E2";
}
zOffsetStreamDisplay.Text = zoffset.ToString("0.##");
}
}
}

View file

@ -397,9 +397,19 @@ namespace MatterHackers.MatterControl
{
if (printer.Connection.CommunicationState == CommunicationStates.Printing)
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ += moveAmountPositive;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
if (printer.Connection.ActiveExtruderIndex == 0)
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ += moveAmountPositive;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
}
else if (printer.Connection.ActiveExtruderIndex == 1)
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset_t1);
currentZ += moveAmountPositive;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset_t1, currentZ.ToString("0.##"));
}
e.Handled = true;
}
else
@ -413,9 +423,18 @@ namespace MatterHackers.MatterControl
{
if (printer.Connection.CommunicationState == CommunicationStates.Printing)
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ += moveAmountPositive;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
if (printer.Connection.ActiveExtruderIndex == 0)
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset);
currentZ -= moveAmountPositive;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset, currentZ.ToString("0.##"));
}
else if (printer.Connection.ActiveExtruderIndex == 1)
{
var currentZ = printer.Settings.GetValue<double>(SettingsKey.baby_step_z_offset_t1);
currentZ -= moveAmountPositive;
printer.Settings.SetValue(SettingsKey.baby_step_z_offset_t1, currentZ.ToString("0.##"));
}
e.Handled = true;
}

View file

@ -43,6 +43,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
[SettingsKey.print_leveling_enabled] = "0",
[SettingsKey.probe_has_been_calibrated] = "0",
[SettingsKey.baby_step_z_offset] = "0",
[SettingsKey.baby_step_z_offset_t1] = "0",
[SettingsKey.xy_offsets_have_been_calibrated] = "0",
[SettingsKey.filament_has_been_loaded] = "0",
[SettingsKey.filament_1_has_been_loaded] = "0"