fixing warnings

This commit is contained in:
Lars Brubaker 2019-04-26 10:01:02 -07:00
parent 4d6e3c375d
commit db6ff0dca3
5 changed files with 111 additions and 19 deletions

View file

@ -463,7 +463,7 @@ namespace MatterControl.Printing
var length = endIndex - startIndex;
if (length > 0)
{
return deltaFromStart / (double)(length);
return deltaFromStart / (double)length;
}
}

View file

@ -47,7 +47,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
public abstract void Dispose();
bool useG0ForMovement = false;
private readonly bool useG0ForMovement = false;
protected PrinterConfig printer { get; }

View file

@ -105,6 +105,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
this.Add(line);
}
}
return;
}

View file

@ -47,8 +47,15 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private Vector3 preSwitchPosition;
private QueuedCommandsStream queuedCommandsStream;
private int requestedTool;
enum SendStates { Normal, WaitingForMove, SendingBefore }
private SendStates SendState = SendStates.Normal;
private enum SendStates
{
Normal,
WaitingForMove,
SendingBefore
}
private SendStates sendState = SendStates.Normal;
private double[] targetTemps = new double[4];
private Queue<string> queuedCommands = new Queue<string>();
@ -105,7 +112,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
if (lineToSend == completedBeforeGCodeString)
{
activeTool = requestedTool;
SendState = SendStates.Normal;
sendState = SendStates.Normal;
QueueAfterGCode();
}
@ -120,6 +127,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
queuedCommands.Enqueue($"T{activeTool}");
return $"{lineToSend.Substring(0, 4)} T{requestedToolForTempChange} S{targetTemps[requestedToolForTempChange]}";
}
// if we are waiting to switch to the next tool
else if (activeTool != requestedTool)
{
@ -128,12 +136,14 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
queuedCommands.Enqueue($"T{requestedTool}");
}
// 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}");
// then send the heat command
return lineToSend;
}
}
// if this is a tool change request
else if (lineToSend.StartsWith("T"))
{
@ -142,11 +152,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
if (changeCommandTool == activeTool)
{
if(SendState == SendStates.WaitingForMove)
if (sendState == SendStates.WaitingForMove)
{
// we have switch back to our starting tool without a move
// change back to normal processing and don't change tools
SendState = SendStates.Normal;
sendState = SendStates.Normal;
var lastRequestedTool = requestedTool;
// set the requested tool
requestedTool = changeCommandTool;
@ -156,9 +166,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
else // we are switching tools
{
if (SendState == SendStates.Normal)
if (sendState == SendStates.Normal)
{
SendState = SendStates.WaitingForMove;
sendState = SendStates.WaitingForMove;
// set the requested tool
requestedTool = changeCommandTool;
// don't queue the tool change until after the before gcode has been sent
@ -167,8 +177,9 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
}
}
}
// if it is only an extrusion move
if (SendState == SendStates.WaitingForMove
if (sendState == SendStates.WaitingForMove
&& activeTool != requestedTool // is different than the last extruder set
&& (lineNoComment.StartsWith("G0 ") || lineNoComment.StartsWith("G1 ")) // is a G1 or G0
&& lineNoComment.Contains("E") // it is an extrusion move
@ -192,6 +203,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
// On Smoothie E is stored per extruder and this makes it behave the same as Marlin
queuedCommands.Enqueue($"G92 E{lastDestination.extrusion}");
}
// send the extrusion
queuedCommands.Enqueue(lineNoComment + " ; NO_PROCESSING");
// switch back
@ -360,7 +372,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
private bool QueueBeforeIfNeedToSwitchExtruders(string lineIn, string lineNoComment)
{
// check if there is a travel
if (SendState == SendStates.WaitingForMove
if (sendState == SendStates.WaitingForMove
&& activeTool != requestedTool // is different than the last extruder set
&& (lineNoComment.StartsWith("G0 ") || lineNoComment.StartsWith("G1 ")) // is a G1 or G0
&& (lineNoComment.Contains("X") || lineNoComment.Contains("Y") || lineNoComment.Contains("Z"))) // has a move axis in it
@ -401,7 +413,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
queuedCommandsStream.Add(gcode.ToString());
SendState = SendStates.SendingBefore;
sendState = SendStates.SendingBefore;
return true;
}

View file

@ -237,8 +237,6 @@ namespace MatterControl.Tests.MatterControl.ToolChanges
G1 X10 Y10 Z10 E0
T0
G1 X10 Y10 Z10 E0");
// now do the same thing with a long enough print to cause
// cooling and heating);
// Validate
var expectedLines = new string[]
@ -274,6 +272,87 @@ namespace MatterControl.Tests.MatterControl.ToolChanges
Assert.AreEqual(expectedLines, sentLines);
}
[Test]
public async Task ToolChangeWithCoolDown()
{
var printer = ToolChangeTests.CreatePrinter();
// set cool down temp and time so the extruder will do a cool down on switch
printer.Settings.SetValue(SettingsKey.inactive_cool_down, $"{30}");
printer.Settings.SetValue(SettingsKey.seconds_to_reheat, $"{1}");
// Collect gcode sent through stream processors
var sentLines = await printer.RunSimulatedPrint(
@"T0
; tell the printer to heat up
M104 T1 S240 ; start with T0 to test smoothie temp change code
M104 T0 S230
; send some movement commands with tool switching
; the printer is moving normally
G1 X10 Y10 Z10 E0 F2500
T1
G1 X20 Y10 Z10 E10 F10 ; a long move with extrusion, will need to cool T0
T0
G1 X30 Y10 Z10 E10 F10 ; a long move with extrusion, will need to cool T1
T1
G1 X10 Y10 Z10 E0");
// Validate
var expectedLines = new string[]
{
"M114",
"T0",
"M114",
"M104 T1 S240", // T1 to 240
"T0",
"M114",
"M104 T1 S240",
"T0",
"M114",
"M104 T0 S230", // T0 to 230
"G1 X10 Y10 Z10 F2500",
"G1 Y111",
"M114",
"M104 T0 S200", // T0 to cool down temp
"T0",
"M114",
"T1",
"M114",
"M104 T1 S240",
"G1 Y222",
"M114",
"G1 X19 Y8 F3000",
"G1 Z7 F315",
"G1 F2500",
"G1 E10 F10",
"G1 X111",
"M114",
"M104 T1 S210", // T1 to cool down temp 210
"T1",
"M114",
"T0",
"M114",
"M104 T0 S230", // T0 back up to 230
"G1 X222",
"M114",
"G1 X30 Y10 F3000",
"G1 Z10 F315",
"G1 F10",
"G1 Y111",
"M114",
"T1",
"M114",
"M104 T1 S240", // T1 back up to 240
"G1 Y222",
"M114",
"G1 X9 Y8 F3000",
"G1 Z7 F315",
"G1 F10",
"G1 E0",
};
Assert.AreEqual(expectedLines, sentLines);
}
[Test]
public async Task ToolChangeHeatOnlyT0()
{