Keep extruders cool at the beginning of the print if the won't be used for longer than

the re-heat time.
issue: MatterHackers/MCCentral#5500
Inactive hotend cooldown does not apply at beginning of print
This commit is contained in:
Lars Brubaker 2019-05-14 14:11:37 -07:00
parent f99fa16fde
commit 29ce61e33a
2 changed files with 41 additions and 13 deletions

View file

@ -392,7 +392,12 @@ namespace MatterControl.Printing
public override PrinterMachineInstruction Instruction(int index)
{
return gCodeCommandQueue[index];
if (index < gCodeCommandQueue.Count)
{
return gCodeCommandQueue[index];
}
return new PrinterMachineInstruction("");
}
public override bool IsExtruding(int instructionIndexToCheck)

View file

@ -137,7 +137,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
// For smoothie, switch back to the extrude we were using before the temp change (smoothie switches to the specified extruder, marlin repetier do not)
queuedCommands.Enqueue($"T{activeTool}");
return $"{lineToSend.Substring(0, 4)} T{requestedToolForTempChange} S{targetTemps[requestedToolForTempChange]}";
var temp = GetNextToolTemp(requestedToolForTempChange);
return $"{lineToSend.Substring(0, 4)} T{requestedToolForTempChange} S{temp}";
}
// if we are waiting to switch to the next tool
@ -281,29 +282,51 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
else // there are more tool changes in the future
{
// get the next time we will use the current tool
var nextTimeThisTool = NextToolChange(activeTool).time;
var temp = GetNextToolTemp(activeTool);
// if we do not use this tool again
if (nextTimeThisTool == double.PositiveInfinity)
if (temp == 0)
{
// turn off its heat
gcode.AppendLine($"M104 T{activeTool} S0");
}
// If there is enough time before we will use this tool again, lower the temp by the inactive_cool_down
else if (nextTimeThisTool > timeToReheat)
// else if we need to cool down
else if (temp != targetTemps[activeTool])
{
var targetTemp = targetTemps[activeTool];
targetTemp = Math.Max(0, targetTemp - printer.Settings.GetValue<double>(SettingsKey.inactive_cool_down));
if (targetTemp != printer.Connection.GetTargetHotendTemperature(activeTool))
{
gcode.AppendLine($"M104 T{activeTool} S{targetTemp} ; INACTIVE_COOL_DOWN");
}
gcode.AppendLine($"M104 T{activeTool} S{temp} ; INACTIVE_COOL_DOWN");
}
}
}
private double GetNextToolTemp(int toolIndex)
{
var timeToReheat = printer.Settings.GetValue<double>(SettingsKey.seconds_to_reheat);
// get the next time we will use the current tool
var nextTimeThisTool = NextToolChange(toolIndex).time;
// if we do not use this tool again
if (nextTimeThisTool == double.PositiveInfinity)
{
// turn off its heat
return 0;
}
// If there is enough time before we will use this tool again, lower the temp by the inactive_cool_down
else if (nextTimeThisTool > timeToReheat)
{
var targetTemp = targetTemps[toolIndex];
targetTemp = Math.Max(0, targetTemp - printer.Settings.GetValue<double>(SettingsKey.inactive_cool_down));
if (targetTemp != targetTemps[toolIndex])
{
return targetTemp;
}
}
return targetTemps[toolIndex];
}
private void ManageReHeating(string line)
{
var timeToReheat = printer.Settings.GetValue<double>(SettingsKey.seconds_to_reheat);