We can now move all the way through the initial setup on first run

Fixed a bug with timing of injecting regex replacements
moved T (extruder) tracking to queued command stream
check that we have loaded filament on extruder 1

issue: MatterHackers/MCCentral#5029
Don't do actual switch of extruders until there is a pending move command
This commit is contained in:
Lars Brubaker 2019-02-07 14:28:22 -08:00
parent 415b16fd06
commit d129a75311
16 changed files with 231 additions and 88 deletions

View file

@ -69,7 +69,7 @@ namespace MatterHackers.MatterControl.ActionBar
{
UiThread.RunOnIdle(() =>
{
LoadFilamentWizard.Start(printer, theme, extruderIndex);
LoadFilamentWizard.Start(printer, theme, extruderIndex, false);
});
};
loadUnloadButtonRow.AddChild(loadButton);

View file

@ -1590,7 +1590,8 @@ namespace MatterHackers.MatterControl
{
return LevelingValidation.NeedsToBeRun(printer)
|| ProbeCalibrationWizard.NeedsToBeRun(printer)
|| (printer.Connection.IsConnected && LoadFilamentWizard.NeedsToBeRun(printer));
|| LoadFilamentWizard.NeedsToBeRun0(printer)
|| LoadFilamentWizard.NeedsToBeRun1(printer);
}
public bool RunAnyRequiredPrinterSetup(PrinterConfig printer, ThemeConfig theme)
@ -1616,11 +1617,21 @@ namespace MatterHackers.MatterControl
}
// run load filament if we need to
if (LoadFilamentWizard.NeedsToBeRun(printer))
if (LoadFilamentWizard.NeedsToBeRun0(printer))
{
UiThread.RunOnIdle(() =>
{
LoadFilamentWizard.Start(printer, theme, 0);
LoadFilamentWizard.Start(printer, theme, 0, true);
});
return true;
}
// run load filament for extruder 1 if we need to
if (LoadFilamentWizard.NeedsToBeRun1(printer))
{
UiThread.RunOnIdle(() =>
{
LoadFilamentWizard.Start(printer, theme, 1, true);
});
return true;
}

View file

@ -43,12 +43,14 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class LoadFilamentWizard : PrinterSetupWizard
{
private bool showAlreadyLoadedButton;
public double TemperatureAtStart { get; private set; }
private int extruderIndex;
public static void Start(PrinterConfig printer, ThemeConfig theme, int extruderIndex)
public static void Start(PrinterConfig printer, ThemeConfig theme, int extruderIndex, bool showAlreadyLoadedButton)
{
var loadFilamentWizard = new LoadFilamentWizard(printer, extruderIndex);
var loadFilamentWizard = new LoadFilamentWizard(printer, extruderIndex, showAlreadyLoadedButton);
loadFilamentWizard.WindowTitle = $"{ApplicationController.Instance.ProductName} - " + "Load Filament Wizard".Localize();
@ -62,19 +64,25 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
};
}
public LoadFilamentWizard(PrinterConfig printer, int extruderIndex)
public LoadFilamentWizard(PrinterConfig printer, int extruderIndex, bool showAlreadyLoadedButton)
: base(printer)
{
this.showAlreadyLoadedButton = showAlreadyLoadedButton;
TemperatureAtStart = printer.Connection.GetTargetHotendTemperature(extruderIndex);
this.extruderIndex = extruderIndex;
}
public static bool NeedsToBeRun(PrinterConfig printer)
public static bool NeedsToBeRun0(PrinterConfig printer)
{
// we have a probe that we are using and we have not done leveling yet
return !printer.Settings.GetValue<bool>(SettingsKey.filament_has_been_loaded);
}
public static bool NeedsToBeRun1(PrinterConfig printer)
{
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
return extruderCount > 1 && !printer.Settings.GetValue<bool>(SettingsKey.filament_1_has_been_loaded);
}
protected override IEnumerator<PrinterSetupWizardPage> GetWizardSteps()
{
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
@ -83,9 +91,13 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
var title = "Load Material".Localize();
var instructions = "Please select the material you want to load.".Localize();
if(extruderCount > 1)
{
instructions = "Please select the material you want to load into extruder {0}.".Localize().FormatWith(extruderIndex + 1);
}
// select the material
yield return new SelectMaterialPage(this, title, instructions, "Select".Localize(), extruderIndex, false);
yield return new SelectMaterialPage(this, title, instructions, "Select".Localize(), extruderIndex, false, showAlreadyLoadedButton);
var theme = ApplicationController.Instance.Theme;
@ -341,7 +353,16 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
};
runningCleanPage.Closed += (s, e) =>
{
UiThread.ClearInterval(runningGCodeCommands);
switch (extruderIndex)
{
case 0:
printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1");
break;
case 1:
printer.Settings.SetValue(SettingsKey.filament_1_has_been_loaded, "1");
break;
}
printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1");
};
@ -384,7 +405,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
loadFilament2Button.Click += (s, e) =>
{
loadFilament2Button.Parents<SystemWindow>().First().Close();
LoadFilamentWizard.Start(printer, theme, 1);
LoadFilamentWizard.Start(printer, theme, 1, true);
};
theme.ApplyPrimaryActionStyle(loadFilament2Button);

View file

@ -71,18 +71,22 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
protected override IEnumerator<PrinterSetupWizardPage> GetWizardSteps()
{
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
var levelingStrings = new LevelingStrings(printer.Settings);
var title = "Unload Material".Localize();
var instructions = "Please select the material you want to unload.".Localize();
if (extruderCount > 1)
{
instructions = "Please select the material you want to unload from extruder {0}.".Localize().FormatWith(extruderIndex + 1);
}
// select the material
yield return new SelectMaterialPage(this, title, instructions, "Unload".Localize(), extruderIndex, false);
yield return new SelectMaterialPage(this, title, instructions, "Unload".Localize(), extruderIndex, false, false);
var theme = ApplicationController.Instance.Theme;
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
// wait for extruder to heat
{
var targetHotendTemp = printer.Settings.Helpers.ExtruderTargetTemperature(extruderIndex);
@ -237,7 +241,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
loadFilamentButton.Click += (s, e) =>
{
loadFilamentButton.Parents<SystemWindow>().First().Close();
LoadFilamentWizard.Start(printer, theme, extruderIndex);
LoadFilamentWizard.Start(printer, theme, extruderIndex, false);
};
theme.ApplyPrimaryActionStyle(loadFilamentButton);

View file

@ -36,7 +36,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
public class SelectMaterialPage : PrinterSetupWizardPage
{
public SelectMaterialPage(PrinterSetupWizard context, string headerText, string instructionsText, string nextButtonText, int extruderIndex, bool showLoadFilamentButton)
public SelectMaterialPage(PrinterSetupWizard context, string headerText, string instructionsText, string nextButtonText, int extruderIndex, bool showLoadFilamentButton, bool showAlreadyLoadedButton)
: base(context, headerText, instructionsText)
{
contentRow.AddChild(
@ -50,39 +50,48 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
if (showLoadFilamentButton)
{
AddLoadFilamentButton();
NextButton.Visible = false;
var loadFilamentButton = new TextButton("Load Filament".Localize(), theme)
{
Name = "Load Filament",
BackgroundColor = theme.MinimalShade,
};
loadFilamentButton.Click += (s, e) =>
{
wizardContext.ShowNextPage(this.DialogWindow);
};
this.AddPageAction(loadFilamentButton);
}
}
private void AddLoadFilamentButton()
{
NextButton.Visible = false;
var loadFilamentButton = new TextButton("Load Filament".Localize(), theme)
if (showAlreadyLoadedButton)
{
Name = "Load Filament",
BackgroundColor = theme.MinimalShade,
};
loadFilamentButton.Click += (s, e) =>
{
wizardContext.ShowNextPage(this.DialogWindow);
};
NextButton.Visible = false;
this.AddPageAction(loadFilamentButton);
var alreadyLoadedButton = new TextButton("Already Loaded".Localize(), theme)
{
Name = "Already Loaded Button",
BackgroundColor = theme.MinimalShade
};
var selectButton = new TextButton("Already Loaded".Localize(), theme)
{
Name = "Already Loaded Button",
BackgroundColor = theme.MinimalShade
};
alreadyLoadedButton.Click += (s, e) =>
{
this.DialogWindow.CloseOnIdle();
switch (extruderIndex)
{
case 0:
printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1");
break;
selectButton.Click += (s, e) =>
{
this.DialogWindow.CloseOnIdle();
printer.Settings.SetValue(SettingsKey.filament_has_been_loaded, "1");
};
case 1:
printer.Settings.SetValue(SettingsKey.filament_1_has_been_loaded, "1");
break;
}
};
this.AddPageAction(selectButton);
this.AddPageAction(alreadyLoadedButton);
}
}
public override void PageIsBecomingInactive()

View file

@ -28,11 +28,13 @@ either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
@ -45,9 +47,9 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
private TextWidget bedDoneText;
private double bedTargetTemp;
private ProgressBar hotEndProgressBar;
private TextWidget hotEndProgressBarText;
private TextWidget hotEndDoneText;
private List<ProgressBar> hotEndProgressBars = new List<ProgressBar>();
private List<TextWidget> hotEndProgressBarTexts = new List<TextWidget>();
private List<TextWidget> hotEndDoneTexts = new List<TextWidget>();
private double[] targetHotendTemps;
public WaitForTempPage(PrinterSetupWizard context,
@ -58,6 +60,8 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
this.bedTargetTemp = targetBedTemp;
this.targetHotendTemps = targetHotendTemps;
var extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
for (int i = 0; i < targetHotendTemps.Length; i++)
{
var hotEndTargetTemp = targetHotendTemps[i];
@ -68,15 +72,21 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
Margin = new BorderDouble(0, 5)
};
var lableText = "Hotend Temperature:".Localize();
if (extruderCount > 1)
{
lableText = "Hotend {0} Temperature:".Localize().FormatWith(i + 1);
}
// put in bar name
contentRow.AddChild(new TextWidget("Hotend Temperature:".Localize(), pointSize: 10, textColor: theme.TextColor)
contentRow.AddChild(new TextWidget(lableText, pointSize: 10, textColor: theme.TextColor)
{
AutoExpandBoundsToText = true,
Margin = new BorderDouble(5, 0, 5, 5),
});
// put in the progress bar
hotEndProgressBar = new ProgressBar((int)(150 * GuiWidget.DeviceScale), (int)(15 * GuiWidget.DeviceScale))
var hotEndProgressBar = new ProgressBar((int)(150 * GuiWidget.DeviceScale), (int)(15 * GuiWidget.DeviceScale))
{
FillColor = theme.PrimaryAccentColor,
BorderColor = theme.TextColor,
@ -85,24 +95,26 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
VAnchor = VAnchor.Center
};
hotEndProgressHolder.AddChild(hotEndProgressBar);
hotEndProgressBars.Add(hotEndProgressBar);
// put in the status
hotEndProgressBarText = new TextWidget("", pointSize: 10, textColor: theme.TextColor)
var hotEndProgressBarText = new TextWidget("", pointSize: 10, textColor: theme.TextColor)
{
AutoExpandBoundsToText = true,
Margin = new BorderDouble(5, 0, 5, 5),
VAnchor = VAnchor.Center
};
hotEndProgressHolder.AddChild(hotEndProgressBarText);
hotEndProgressBarTexts.Add(hotEndProgressBarText);
// message to show when done
hotEndDoneText = new TextWidget("Done!", textColor: theme.TextColor)
var hotEndDoneText = new TextWidget("Done!", textColor: theme.TextColor)
{
AutoExpandBoundsToText = true,
Visible = false,
};
hotEndProgressHolder.AddChild(hotEndDoneText);
hotEndDoneTexts.Add(hotEndDoneText);
contentRow.AddChild(hotEndProgressHolder);
}
@ -224,20 +236,20 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
{
if (targetHotendTemps[i] > 0)
{
hotEndProgressBar.Visible = true;
hotEndProgressBars[i].Visible = true;
double targetTemp = printer.Connection.GetTargetHotendTemperature(i);
double actualTemp = printer.Connection.GetActualHotendTemperature(i);
double totalDelta = targetTemp;
double currentDelta = actualTemp;
double ratioDone = hotEndDoneText.Visible ? 1 : totalDelta != 0 ? (currentDelta / totalDelta) : 1;
hotEndProgressBar.RatioComplete = Math.Min(Math.Max(0, ratioDone), 1);
hotEndProgressBarText.Text = $"{actualTemp:0} / {targetTemp:0}";
double ratioDone = hotEndDoneTexts[i].Visible ? 1 : totalDelta != 0 ? (currentDelta / totalDelta) : 1;
hotEndProgressBars[i].RatioComplete = Math.Min(Math.Max(0, ratioDone), 1);
hotEndProgressBarTexts[i].Text = $"{actualTemp:0} / {targetTemp:0}";
// if we are within 1 degree of our target
if (Math.Abs(targetTemp - actualTemp) < 2
&& hotEndDoneText.Visible == false)
&& hotEndDoneTexts[i].Visible == false)
{
hotEndDoneText.Visible = true;
hotEndDoneTexts[i].Visible = true;
NextButton.Enabled = true;
}
}
@ -264,7 +276,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage.PrintLeveling
}
if ((bedTargetTemp == 0 || bedDoneText.Visible)
&& (targetHotendTemps.All(i => i== 0) || hotEndDoneText.Visible)
&& (targetHotendTemps.All(i => i== 0) || hotEndDoneTexts.All(i => i.Visible))
&& !HasBeenClosed)
{
// advance to the next page

View file

@ -125,6 +125,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
TransformState = TrackBallTransformType.Rotation
};
TrackballTumbleWidget.GetNearFar = GetNearFar;
TrackballTumbleWidget.AnchorAll();
this.BoundsChanged += UpdateRenderView;
@ -387,6 +390,49 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
private void GetNearFar(out double zNear, out double zFar)
{
zNear = .1;
zFar = 100;
// this function did not fix the image z fighting, so for now I'm just going to return rather than have it run.
return;
var bounds = Scene.GetAxisAlignedBoundingBox();
if(bounds.XSize > 0)
{
zNear = double.PositiveInfinity;
zFar = double.NegativeInfinity;
ExpandNearAndFarToBounds(ref zNear, ref zFar, bounds);
// TODO: add in the bed bounds
// TODO: add in the print volume bounds
}
}
private void ExpandNearAndFarToBounds(ref double zNear, ref double zFar, AxisAlignedBoundingBox bounds)
{
for (int x = 0; x < 2; x++)
{
for (int y = 0; y < 2; y++)
{
for (int z = 0; z < 2; z++)
{
var cornerPoint = new Vector3((x == 0) ? bounds.MinXYZ.X : bounds.MaxXYZ.X,
(y == 0) ? bounds.MinXYZ.Y : bounds.MaxXYZ.Y,
(z == 0) ? bounds.MinXYZ.Z : bounds.MaxXYZ.Z);
Vector3 viewPosition = cornerPoint.Transform(sceneContext.World.ModelviewMatrix);
zNear = Math.Max(.1, Math.Min(zNear, -viewPosition.Z));
zFar = Math.Max(Math.Max(zFar, -viewPosition.Z), zNear + .1);
}
}
}
}
private Dictionary<IObject3D, TreeNode> keyValues = new Dictionary<IObject3D, TreeNode>();
private void RebuildTree()

View file

@ -76,9 +76,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
var lines = ProcessWriteRegEx(baseLine);
for (int i = 1; i < lines.Count; i++)
for (int i = lines.Count - 1; i >= 1; i--)
{
queueStream.Add(lines[i]);
queueStream.Add(lines[i], true);
}
var lineToSend = lines[0];

View file

@ -27,11 +27,13 @@ of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using MatterControl.Printing;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
@ -44,6 +46,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
private List<string> commandQueue = new List<string>();
private object locker = new object();
private int requestedExtruder;
private int extruderLastSwitchTo;
public QueuedCommandsStream(PrinterConfig printer, GCodeStream internalStream)
: base(printer, internalStream)
@ -63,6 +67,54 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
else
{
if (!printer.Connection.Printing)
{
if(line.StartsWith("G28)"))
{
extruderLastSwitchTo = requestedExtruder = 0;
}
if (line.StartsWith("T"))
{
GCodeFile.GetFirstNumberAfter("T", line, ref requestedExtruder);
}
else if (LineIsMovement(line)
&& extruderLastSwitchTo != requestedExtruder)
{
string gcodeToQueue = "";
switch (requestedExtruder)
{
case 0:
gcodeToQueue = printer.Settings.GetValue(SettingsKey.before_toolchange_gcode).Replace("\\n", "\n");
break;
case 1:
gcodeToQueue = printer.Settings.GetValue(SettingsKey.before_toolchange_gcode_1).Replace("\\n", "\n");
break;
}
if (gcodeToQueue.Trim().Length > 0)
{
if (gcodeToQueue.Contains("\n"))
{
string[] linesToWrite = gcodeToQueue.Split(new string[] { "\n" }, StringSplitOptions.None);
for (int i = 0; i < linesToWrite.Length; i++)
{
string gcodeLine = linesToWrite[i].Trim();
if (gcodeLine.Length > 0)
{
commandQueue.Add(gcodeLine);
}
}
}
else
{
commandQueue.Add(gcodeToQueue);
}
}
extruderLastSwitchTo = requestedExtruder;
}
}
commandQueue.Add(line);
}
}

View file

@ -1758,31 +1758,6 @@ You will then need to logout and log back in to the computer for the changes to
}
else
{
// If we are not prnting and we switch extruders, make sure we send any gcode required to switch them
if(!this.Printing
&& lineToWrite.StartsWith("T"))
{
double extruderIndex = 0;
if (GCodeFile.GetFirstNumberAfter("T", lineToWrite, ref extruderIndex))
{
if(extruderIndex != ActiveExtruderIndex)
{
string gcodeToSend = "";
switch(extruderIndex)
{
case 0:
gcodeToSend = Printer.Settings.GetValue(SettingsKey.before_toolchange_gcode).Replace("\\n", "\n");
break;
case 1:
gcodeToSend = Printer.Settings.GetValue(SettingsKey.before_toolchange_gcode_1).Replace("\\n", "\n");
break;
}
// send the pre-switch gcode
QueueLine(gcodeToSend);
}
}
}
if (lineToWrite.Trim().Length > 0)
{
// insert the command into the printing queue at the head

View file

@ -76,6 +76,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
SettingsKey.filament_cost,
SettingsKey.filament_density,
SettingsKey.filament_has_been_loaded,
SettingsKey.filament_1_has_been_loaded,
SettingsKey.filament_runout_sensor,
SettingsKey.has_fan,
SettingsKey.has_hardware_leveling,

View file

@ -42,7 +42,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
[SettingsKey.print_leveling_data] = "",
[SettingsKey.print_leveling_enabled] = "0",
[SettingsKey.probe_has_been_calibrated] = "0",
[SettingsKey.filament_has_been_loaded] = "0"
[SettingsKey.filament_has_been_loaded] = "0",
[SettingsKey.filament_1_has_been_loaded] = "0"
};
private static object writeLock = new object();