Better tracking of extrusion and position in consideration of relative moves

Reset position tracking correctly for G92 s
Render G92 instructions correctly (don't show as filament change)
Remove dead code

issue: MatterHackers/MCCentral#4688
Don't force tool change on layer change
This commit is contained in:
Lars Brubaker 2018-12-11 14:10:27 -08:00
parent 5e1cbf7db0
commit e9c4ba5d28
7 changed files with 93 additions and 59 deletions

View file

@ -113,10 +113,16 @@ namespace MatterHackers.GCodeVisualizer
if (currentInstruction.Position == previousInstruction.Position)
{
if (Math.Abs(currentInstruction.EPosition - previousInstruction.EPosition) > 0)
double eMovement = 0;
if (currentInstruction.PositionSet != PositionSet.E)
{
eMovement = currentInstruction.EPosition - previousInstruction.EPosition;
}
if (Math.Abs(eMovement) > 0)
{
// this is a retraction
renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, currentInstruction.EPosition - previousInstruction.EPosition, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, eMovement, currentInstruction.ExtruderIndex, currentInstruction.FeedRate));
}
if (currentInstruction.Line.StartsWith("G10"))
{

View file

@ -93,7 +93,7 @@ namespace MatterControl.Printing
GCodeCommandQueue.Clear();
}
public override double TotalSecondsInPrint => Instruction(0).secondsToEndFromHere;
public override double TotalSecondsInPrint => Instruction(0).SecondsToEndFromHere;
public void Add(PrinterMachineInstruction printerMachineInstruction)
{
@ -404,7 +404,7 @@ namespace MatterControl.Printing
new Vector3(velocitySameAsStopMmPerS),
new Vector3(speedMultiplier));
instruction.secondsThisLine = (float)Math.Max(timeForE, timeForPosition);
instruction.SecondsThisLine = (float)Math.Max(timeForE, timeForPosition);
}
if (progressReporter != null && maxProgressReport.ElapsedMilliseconds > 200)
@ -423,8 +423,8 @@ namespace MatterControl.Printing
for (int i = GCodeCommandQueue.Count - 1; i >= 0; i--)
{
PrinterMachineInstruction line = GCodeCommandQueue[i];
accumulatedTime += line.secondsThisLine;
line.secondsToEndFromHere = (float)accumulatedTime;
accumulatedTime += line.SecondsThisLine;
line.SecondsToEndFromHere = (float)accumulatedTime;
}
}
@ -657,30 +657,34 @@ namespace MatterControl.Printing
case "1":
// get the x y z to move to
{
double valueX = 0;
if (GCodeFile.GetFirstNumberAfter("X", lineString, ref valueX))
double ePosition = processingMachineState.EPosition;
var position = processingMachineState.Position;
if (processingMachineState.MovementType == PrinterMachineInstruction.MovementTypes.Relative)
{
processingMachineState.X = valueX;
position = Vector3.Zero;
ePosition = 0;
}
double valueY = 0;
if (GCodeFile.GetFirstNumberAfter("Y", lineString, ref valueY))
GCodeFile.GetFirstNumberAfter("X", lineString, ref position.X);
GCodeFile.GetFirstNumberAfter("Y", lineString, ref position.Y);
GCodeFile.GetFirstNumberAfter("Z", lineString, ref position.Z);
GCodeFile.GetFirstNumberAfter("E", lineString, ref ePosition);
double feedrate = 0;
if (GCodeFile.GetFirstNumberAfter("F", lineString, ref feedrate))
{
processingMachineState.Y = valueY;
processingMachineState.FeedRate = (float)feedrate;
}
double valueZ = 0;
if (GCodeFile.GetFirstNumberAfter("Z", lineString, ref valueZ))
if (processingMachineState.MovementType == PrinterMachineInstruction.MovementTypes.Absolute)
{
processingMachineState.Z = valueZ;
processingMachineState.Position = position;
processingMachineState.EPosition = (float)ePosition;
}
double valueE = 0;
if (GCodeFile.GetFirstNumberAfter("E", lineString, ref valueE))
else
{
processingMachineState.EPosition = (float)valueE;
}
double valueF = 0;
if (GCodeFile.GetFirstNumberAfter("F", lineString, ref valueF))
{
processingMachineState.FeedRate = (float)valueF;
processingMachineState.Position += position;
processingMachineState.EPosition += (float)ePosition;
}
}
@ -718,15 +722,38 @@ namespace MatterControl.Printing
break;
case "90": // G90 is Absolute Distance Mode
processingMachineState.movementType = PrinterMachineInstruction.MovementTypes.Absolute;
processingMachineState.MovementType = PrinterMachineInstruction.MovementTypes.Absolute;
break;
case "91": // G91 is Incremental Distance Mode
processingMachineState.movementType = PrinterMachineInstruction.MovementTypes.Relative;
processingMachineState.MovementType = PrinterMachineInstruction.MovementTypes.Relative;
break;
case "92":
{
// set current head position values (used to reset origin)
double value = 0;
if (GCodeFile.GetFirstNumberAfter("X", lineString, ref value))
{
processingMachineState.PositionSet |= PositionSet.X;
processingMachineState.X = value;
}
if (GCodeFile.GetFirstNumberAfter("Y", lineString, ref value))
{
processingMachineState.PositionSet |= PositionSet.Y;
processingMachineState.Y = value;
}
if (GCodeFile.GetFirstNumberAfter("Z", lineString, ref value))
{
processingMachineState.PositionSet |= PositionSet.Z;
processingMachineState.Z = value;
}
if (GCodeFile.GetFirstNumberAfter("E", lineString, ref value))
{
processingMachineState.PositionSet |= PositionSet.E;
processingMachineState.EPosition = (float)value;
}
}
break;
case "130":
@ -802,7 +829,7 @@ namespace MatterControl.Printing
double ePosition = lastEPosition;
if (GetFirstNumberAfter("E", lineToParse, ref ePosition))
{
if (instruction.movementType == PrinterMachineInstruction.MovementTypes.Absolute)
if (instruction.MovementType == PrinterMachineInstruction.MovementTypes.Absolute)
{
double deltaEPosition = ePosition - lastEPosition;
filamentMm += deltaEPosition;

View file

@ -28,22 +28,33 @@ either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.VectorMath;
using System;
using System.Text;
namespace MatterControl.Printing
{
[Flags]
public enum PositionSet
{
None = 0,
X = 2,
Y = 4,
Z = 8,
E = 16,
}
public class PrinterMachineInstruction
{
public byte[] byteLine;
public bool clientInsertion;
// Absolute is the RepRap default
public MovementTypes movementType = MovementTypes.Absolute;
public MovementTypes MovementType = MovementTypes.Absolute;
public float secondsThisLine;
public float SecondsThisLine;
public float secondsToEndFromHere;
public float SecondsToEndFromHere;
public PositionSet PositionSet;
private Vector3Float xyzPosition = new Vector3Float();
@ -58,10 +69,9 @@ namespace MatterControl.Printing
xyzPosition = copy.xyzPosition;
FeedRate = copy.FeedRate;
EPosition = copy.EPosition;
movementType = copy.movementType;
secondsToEndFromHere = copy.secondsToEndFromHere;
MovementType = copy.MovementType;
SecondsToEndFromHere = copy.SecondsToEndFromHere;
ExtruderIndex = copy.ExtruderIndex;
this.clientInsertion = clientInsertion;
}
public enum MovementTypes { Absolute, Relative };
@ -88,6 +98,12 @@ namespace MatterControl.Printing
public Vector3 Position
{
get { return new Vector3(xyzPosition); }
set
{
xyzPosition.x = (float)value.X;
xyzPosition.y = (float)value.Y;
xyzPosition.z = (float)value.Z;
}
}
public double X
@ -95,7 +111,7 @@ namespace MatterControl.Printing
get { return xyzPosition.x; }
set
{
if (movementType == MovementTypes.Absolute)
if (MovementType == MovementTypes.Absolute)
{
xyzPosition.x = (float)value;
}
@ -111,7 +127,7 @@ namespace MatterControl.Printing
get { return xyzPosition.y; }
set
{
if (movementType == MovementTypes.Absolute)
if (MovementType == MovementTypes.Absolute)
{
xyzPosition.y = (float)value;
}
@ -127,7 +143,7 @@ namespace MatterControl.Printing
get { return xyzPosition.z; }
set
{
if (movementType == MovementTypes.Absolute)
if (MovementType == MovementTypes.Absolute)
{
xyzPosition.z = (float)value;
}

View file

@ -57,7 +57,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
return "---";
}
return SecondsToTime(loadedGCode.Instruction(0).secondsToEndFromHere);
return SecondsToTime(loadedGCode.Instruction(0).SecondsToEndFromHere);
}
private static string InstructionTime(this GCodeFile loadedGCode, int startLayer, int endLayer)
@ -69,8 +69,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
int startInstruction = loadedGCode.GetFirstLayerInstruction(startLayer);
int endInstruction = loadedGCode.GetFirstLayerInstruction(endLayer);
var secondsToEndFromStart = loadedGCode.Instruction(startInstruction).secondsToEndFromHere;
var secondsToEndFromEnd = loadedGCode.Instruction(endInstruction).secondsToEndFromHere;
var secondsToEndFromStart = loadedGCode.Instruction(startInstruction).SecondsToEndFromHere;
var secondsToEndFromEnd = loadedGCode.Instruction(endInstruction).SecondsToEndFromHere;
return SecondsToTime(secondsToEndFromStart - secondsToEndFromEnd);
}
@ -103,7 +103,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
return 0;
}
return loadedGCode.Instruction(0).secondsToEndFromHere;
return loadedGCode.Instruction(0).SecondsToEndFromHere;
}
public static string FilamentUsed(this GCodeFile loadedGCode, PrinterConfig printer)

View file

@ -301,7 +301,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication
#endregion hardware failure callbacks
WriteLineStartCallBacks.Register("G90", MovementWasSetToAbsoluteMode);
WriteLineStartCallBacks.Register("G91", MovementWasSetToRelativeMode);
WriteLineStartCallBacks.Register("M80", AtxPowerUpWasWritenToPrinter);
WriteLineStartCallBacks.Register("M81", AtxPowerDownWasWritenToPrinter);
WriteLineStartCallBacks.Register("M104", HotendTemperatureWasWritenToPrinter);
@ -2052,10 +2051,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication
|| lineBeingSent.StartsWith("G3 "))
{
PrinterMove newDestination = currentDestination;
if (movementMode == PrinterMachineInstruction.MovementTypes.Relative)
{
newDestination.position = Vector3.Zero;
}
GCodeFile.GetFirstNumberAfter("X", lineBeingSent, ref newDestination.position.X);
GCodeFile.GetFirstNumberAfter("Y", lineBeingSent, ref newDestination.position.Y);
@ -2064,11 +2059,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication
GCodeFile.GetFirstNumberAfter("E", lineBeingSent, ref newDestination.extrusion);
GCodeFile.GetFirstNumberAfter("F", lineBeingSent, ref newDestination.feedRate);
if (movementMode == PrinterMachineInstruction.MovementTypes.Relative)
{
newDestination.position += currentDestination.position;
}
if (currentDestination.position != newDestination.position
|| currentDestination.extrusion != newDestination.extrusion)
{
@ -2191,11 +2181,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication
movementMode = PrinterMachineInstruction.MovementTypes.Absolute;
}
private void MovementWasSetToRelativeMode(string line)
{
movementMode = PrinterMachineInstruction.MovementTypes.Relative;
}
private void AtxPowerUpWasWritenToPrinter(string line)
{
OnAtxPowerStateChanged(true);

@ -1 +1 @@
Subproject commit 71ba630bb75a4ac2a8a780d33c9557c17fc422a6
Subproject commit f89d966b2faa5dd74bfc7945339f9f55946d56d8

@ -1 +1 @@
Subproject commit b974656370cd9e4f03fae610965db3048a7be758
Subproject commit 24c7898f669faf5e407c13514407a781647b8706