2017-06-21 23:26:20 -07:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2014, Lars Brubaker
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
#define DUMP_SLOW_TIMES
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.IO;
|
2017-06-30 16:09:31 -07:00
|
|
|
|
using System.Threading;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
|
2018-01-05 12:44:57 -08:00
|
|
|
|
namespace MatterControl.Printing
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2017-06-29 14:22:04 -07:00
|
|
|
|
public class GCodeMemoryFile : GCodeFile
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2018-05-08 15:19:06 -07:00
|
|
|
|
private double diameterOfFilamentUsedMmCache = 0;
|
2019-03-05 17:55:44 -08:00
|
|
|
|
private double filamentDiameterCache = 0;
|
|
|
|
|
|
private double filamentUsedMmCache = 0;
|
|
|
|
|
|
private bool foundFirstLayerMarker;
|
2019-05-03 12:29:51 -07:00
|
|
|
|
private readonly List<PrinterMachineInstruction> gCodeCommandQueue = new List<PrinterMachineInstruction>();
|
|
|
|
|
|
private readonly bool gcodeHasExplicitLayerChangeInfo = false;
|
2019-03-05 17:55:44 -08:00
|
|
|
|
private int lastPrintLine;
|
2019-05-03 12:29:51 -07:00
|
|
|
|
private readonly List<double> layerHeights = new List<double>();
|
2019-03-05 17:55:44 -08:00
|
|
|
|
private double parsingLastZ;
|
2019-05-03 12:29:51 -07:00
|
|
|
|
private readonly List<int> toolChanges = new List<int>();
|
2018-05-30 16:42:17 -07:00
|
|
|
|
|
2017-06-29 14:22:04 -07:00
|
|
|
|
public GCodeMemoryFile(bool gcodeHasExplicitLayerChangeInfo = false)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
|
|
|
|
|
this.gcodeHasExplicitLayerChangeInfo = gcodeHasExplicitLayerChangeInfo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public List<int> IndexOfLayerStart { get; private set; } = new List<int>();
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override int LayerCount
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
get { return IndexOfLayerStart.Count; }
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
public override int LineCount => gCodeCommandQueue.Count;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public HashSet<float> Speeds { get; private set; }
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2018-12-11 14:10:27 -08:00
|
|
|
|
public override double TotalSecondsInPrint => Instruction(0).SecondsToEndFromHere;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2018-12-06 17:01:26 -08:00
|
|
|
|
public static GCodeMemoryFile Load(Stream fileStream,
|
2018-01-17 14:03:56 -08:00
|
|
|
|
Vector4 maxAccelerationMmPerS2,
|
|
|
|
|
|
Vector4 maxVelocityMmPerS,
|
|
|
|
|
|
Vector4 velocitySameAsStopMmPerS,
|
2018-02-02 09:47:06 -08:00
|
|
|
|
Vector4 speedMultiplier,
|
2018-01-17 14:03:56 -08:00
|
|
|
|
CancellationToken cancellationToken,
|
|
|
|
|
|
Action<double, string> progressReporter = null)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var reader = new StreamReader(fileStream))
|
|
|
|
|
|
{
|
2018-12-06 17:01:26 -08:00
|
|
|
|
var gcodeMemoryFile = ParseFileContents(reader.ReadToEnd(),
|
2019-05-03 12:29:51 -07:00
|
|
|
|
maxAccelerationMmPerS2,
|
|
|
|
|
|
maxVelocityMmPerS,
|
|
|
|
|
|
velocitySameAsStopMmPerS,
|
|
|
|
|
|
speedMultiplier,
|
|
|
|
|
|
cancellationToken,
|
|
|
|
|
|
progressReporter);
|
2018-10-29 16:38:31 -07:00
|
|
|
|
|
|
|
|
|
|
return gcodeMemoryFile;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-30 12:23:27 -07:00
|
|
|
|
catch (Exception e)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
|
|
|
|
|
Debug.Print(e.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-30 12:23:27 -07:00
|
|
|
|
return null;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-17 14:03:56 -08:00
|
|
|
|
public static GCodeMemoryFile Load(string filePath,
|
|
|
|
|
|
Vector4 maxAccelerationMmPerS2,
|
|
|
|
|
|
Vector4 maxVelocityMmPerS,
|
|
|
|
|
|
Vector4 velocitySameAsStopMmPerS,
|
2018-02-02 09:47:06 -08:00
|
|
|
|
Vector4 speedMultiplier,
|
2019-05-03 12:29:51 -07:00
|
|
|
|
CancellationToken cancellationToken,
|
|
|
|
|
|
Action<double, string> progressReporter)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2017-06-30 12:23:27 -07:00
|
|
|
|
if (Path.GetExtension(filePath).ToUpper() == ".GCODE")
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2017-06-30 12:23:27 -07:00
|
|
|
|
using (var stream = File.OpenRead(filePath))
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2018-12-06 17:01:26 -08:00
|
|
|
|
return Load(stream,
|
2018-01-17 14:03:56 -08:00
|
|
|
|
maxAccelerationMmPerS2,
|
|
|
|
|
|
maxVelocityMmPerS,
|
|
|
|
|
|
velocitySameAsStopMmPerS,
|
2018-02-02 09:47:06 -08:00
|
|
|
|
speedMultiplier,
|
2019-05-03 12:29:51 -07:00
|
|
|
|
cancellationToken,
|
|
|
|
|
|
progressReporter);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-30 12:23:27 -07:00
|
|
|
|
catch (Exception e)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
|
|
|
|
|
Debug.Print(e.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public void Add(PrinterMachineInstruction printerMachineInstruction)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
Insert(LineCount, printerMachineInstruction);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override void Clear()
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
IndexOfLayerStart.Clear();
|
2019-05-03 12:29:51 -07:00
|
|
|
|
gCodeCommandQueue.Clear();
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override RectangleDouble GetBounds()
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
var bounds = new RectangleDouble(double.MaxValue, double.MaxValue, double.MinValue, double.MinValue);
|
|
|
|
|
|
foreach (PrinterMachineInstruction state in gCodeCommandQueue)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
bounds.Left = Math.Min(state.Position.X, bounds.Left);
|
|
|
|
|
|
bounds.Right = Math.Max(state.Position.X, bounds.Right);
|
|
|
|
|
|
bounds.Bottom = Math.Min(state.Position.Y, bounds.Bottom);
|
|
|
|
|
|
bounds.Top = Math.Max(state.Position.Y, bounds.Top);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return bounds;
|
|
|
|
|
|
}
|
2018-03-30 21:14:45 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override double GetFilamentCubicMm(double filamentDiameterMm)
|
|
|
|
|
|
{
|
|
|
|
|
|
double filamentUsedMm = GetFilamentUsedMm(filamentDiameterMm);
|
|
|
|
|
|
double filamentRadius = filamentDiameterMm / 2;
|
|
|
|
|
|
double areaSquareMm = (filamentRadius * filamentRadius) * Math.PI;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return areaSquareMm * filamentUsedMm;
|
|
|
|
|
|
}
|
2018-05-30 16:42:17 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override double GetFilamentDiameter()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (filamentDiameterCache == 0)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
// check the beginning of the file for the filament diameter
|
2019-05-03 12:29:51 -07:00
|
|
|
|
for (int i = 0; i < Math.Min(100, gCodeCommandQueue.Count); i++)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
|
|
|
|
|
if (FindDiameter(i, ref filamentDiameterCache))
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
// check the end of the file for the filament diameter
|
|
|
|
|
|
if (filamentDiameterCache == 0)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
// didn't find it, so look at the end of the file for filament_diameter =
|
2019-05-03 12:29:51 -07:00
|
|
|
|
for (int i = gCodeCommandQueue.Count - 1; i > Math.Max(0, gCodeCommandQueue.Count - 100); i--)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (FindDiameter(i, ref filamentDiameterCache))
|
|
|
|
|
|
{
|
2017-06-21 23:26:20 -07:00
|
|
|
|
break;
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (filamentDiameterCache == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
// it is still 0 so set it to something so we render
|
|
|
|
|
|
filamentDiameterCache = 1.75;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return filamentDiameterCache;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override double GetFilamentUsedMm(double filamentDiameter)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (filamentUsedMmCache == 0 || filamentDiameter != diameterOfFilamentUsedMmCache)
|
|
|
|
|
|
{
|
|
|
|
|
|
double lastEPosition = 0;
|
|
|
|
|
|
double filamentMm = 0;
|
2019-05-03 12:29:51 -07:00
|
|
|
|
for (int i = 0; i < gCodeCommandQueue.Count; i++)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
PrinterMachineInstruction instruction = gCodeCommandQueue[i];
|
|
|
|
|
|
// filamentMm += instruction.EPosition;
|
2019-03-05 17:55:44 -08:00
|
|
|
|
|
|
|
|
|
|
string lineToParse = instruction.Line;
|
|
|
|
|
|
if (lineToParse.StartsWith("G0") || lineToParse.StartsWith("G1"))
|
|
|
|
|
|
{
|
|
|
|
|
|
double ePosition = lastEPosition;
|
|
|
|
|
|
if (GetFirstNumberAfter("E", lineToParse, ref ePosition))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (instruction.MovementType == PrinterMachineInstruction.MovementTypes.Absolute)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
double deltaEPosition = ePosition - lastEPosition;
|
|
|
|
|
|
filamentMm += deltaEPosition;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
2019-03-05 17:55:44 -08:00
|
|
|
|
else
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
filamentMm += ePosition;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
lastEPosition = ePosition;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
2019-03-05 17:55:44 -08:00
|
|
|
|
else if (lineToParse.StartsWith("G92"))
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
double ePosition = 0;
|
|
|
|
|
|
if (GetFirstNumberAfter("E", lineToParse, ref ePosition))
|
|
|
|
|
|
{
|
|
|
|
|
|
lastEPosition = ePosition;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
filamentUsedMmCache = filamentMm;
|
|
|
|
|
|
diameterOfFilamentUsedMmCache = filamentDiameter;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return filamentUsedMmCache;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override double GetFilamentWeightGrams(double filamentDiameterMm, double densityGramsPerCubicCm)
|
|
|
|
|
|
{
|
|
|
|
|
|
double cubicMmPerCubicCm = 1000;
|
|
|
|
|
|
double gramsPerCubicMm = densityGramsPerCubicCm / cubicMmPerCubicCm;
|
|
|
|
|
|
double cubicMms = GetFilamentCubicMm(filamentDiameterMm);
|
|
|
|
|
|
return cubicMms * gramsPerCubicMm;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override int GetFirstLayerInstruction(int layerIndex)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (layerIndex < IndexOfLayerStart.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
return IndexOfLayerStart[layerIndex];
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
// else return the last instruction
|
2019-05-03 12:29:51 -07:00
|
|
|
|
return gCodeCommandQueue.Count - 1;
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
/// <summary>
|
2019-05-03 12:29:51 -07:00
|
|
|
|
/// Get the height of the bottom of this layer as measure from the bed.
|
2019-03-05 17:55:44 -08:00
|
|
|
|
/// </summary>
|
2019-05-03 12:29:51 -07:00
|
|
|
|
/// <param name="layerIndex">The layer index to get the distance to the bottom of.</param>
|
|
|
|
|
|
/// <returns>The bottom of the layer requested.</returns>
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public double GetLayerBottom(int layerIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
double total = 0;
|
|
|
|
|
|
for (int i = 0; i < layerIndex; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
total += GetLayerHeight(i);
|
|
|
|
|
|
}
|
2019-05-03 12:29:51 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return total;
|
|
|
|
|
|
}
|
2019-03-04 08:04:29 -08:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get the height of this layer (from the top of the previous layer to the top of this layer).
|
|
|
|
|
|
/// </summary>
|
2019-05-03 12:29:51 -07:00
|
|
|
|
/// <param name="layerIndex">The layer index to get the height of.</param>
|
|
|
|
|
|
/// <returns>The height of the layer index requested.</returns>
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override double GetLayerHeight(int layerIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (layerHeights.Count > 0)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (layerIndex < layerHeights.Count)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return layerHeights[layerIndex];
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-05-03 12:17:28 -07:00
|
|
|
|
// set it to a number that might be reasonable
|
|
|
|
|
|
var layerHeight = .2;
|
|
|
|
|
|
if (IndexOfLayerStart.Count > layerIndex + 1)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
layerHeight = gCodeCommandQueue[IndexOfLayerStart[layerIndex + 1]].Z - gCodeCommandQueue[IndexOfLayerStart[layerIndex]].Z;
|
2019-05-03 12:17:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if (IndexOfLayerStart.Count > 2)
|
|
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
layerHeight = gCodeCommandQueue[IndexOfLayerStart[2]].Z - gCodeCommandQueue[IndexOfLayerStart[1]].Z;
|
2019-05-03 12:17:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (layerHeight < .01)
|
|
|
|
|
|
{
|
|
|
|
|
|
layerIndex--;
|
|
|
|
|
|
while (layerIndex >= 0
|
|
|
|
|
|
&& layerHeight < .01)
|
|
|
|
|
|
{
|
|
|
|
|
|
// walk back to find a layer height that seems like it might be right
|
|
|
|
|
|
if (layerHeight < IndexOfLayerStart.Count - 2)
|
|
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
layerHeight = gCodeCommandQueue[IndexOfLayerStart[layerIndex + 1]].Z - gCodeCommandQueue[IndexOfLayerStart[layerIndex]].Z;
|
2019-05-03 12:17:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
layerIndex--;
|
|
|
|
|
|
}
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-05-03 12:17:28 -07:00
|
|
|
|
return layerHeight;
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override int GetLayerIndex(int instructionIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (instructionIndex >= 0
|
|
|
|
|
|
&& instructionIndex <= LineCount)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (var i = IndexOfLayerStart.Count - 1; i >= 0; i--)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
var lineStart = IndexOfLayerStart[i];
|
|
|
|
|
|
|
|
|
|
|
|
if (instructionIndex >= lineStart)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return i;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-05-03 12:29:51 -07:00
|
|
|
|
/// Get the height of the top of this layer as measured from the bed.
|
2019-03-05 17:55:44 -08:00
|
|
|
|
/// </summary>
|
2019-05-03 12:29:51 -07:00
|
|
|
|
/// <param name="layerIndex">The layer index to get the top of.</param>
|
|
|
|
|
|
/// <returns>The height of the given layer index in mm.</returns>
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override double GetLayerTop(int layerIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
double total = 0;
|
|
|
|
|
|
for (int i = 0; i <= layerIndex; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
total += GetLayerHeight(i);
|
|
|
|
|
|
}
|
2019-05-03 12:29:51 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return total;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Vector2 GetWeightedCenter()
|
|
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
var total = default(Vector2);
|
|
|
|
|
|
foreach (PrinterMachineInstruction state in gCodeCommandQueue)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
total += new Vector2(state.Position.X, state.Position.Y);
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
return total / gCodeCommandQueue.Count;
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public void Insert(int insertIndex, PrinterMachineInstruction printerMachineInstruction)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < IndexOfLayerStart.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (insertIndex < IndexOfLayerStart[i])
|
2019-03-04 08:04:29 -08:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
IndexOfLayerStart[i]++;
|
2019-03-04 08:04:29 -08:00
|
|
|
|
}
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
2019-03-04 08:04:29 -08:00
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
gCodeCommandQueue.Insert(insertIndex, printerMachineInstruction);
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
2018-09-19 18:20:05 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override PrinterMachineInstruction Instruction(int index)
|
|
|
|
|
|
{
|
2019-05-14 14:11:37 -07:00
|
|
|
|
if (index < gCodeCommandQueue.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
return gCodeCommandQueue[index];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new PrinterMachineInstruction("");
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
2018-09-19 18:20:05 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public override bool IsExtruding(int instructionIndexToCheck)
|
|
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
if (instructionIndexToCheck > 1 && instructionIndexToCheck < gCodeCommandQueue.Count)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
double extrusionLength = gCodeCommandQueue[instructionIndexToCheck].EPosition - gCodeCommandQueue[instructionIndexToCheck - 1].EPosition;
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (extrusionLength > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-06 10:19:35 -08:00
|
|
|
|
public (int toolIndex, double time) NextToolChange(int instructionIndex, int currentToolIndex = -1, int toolToLookFor = -1)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
if (gCodeCommandQueue.Count > 0)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
2019-03-06 14:55:00 -08:00
|
|
|
|
int nextToolChange = -1;
|
|
|
|
|
|
// find the first tool change that we are less than
|
|
|
|
|
|
for (int i = 0; i < toolChanges.Count; i++)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
2019-03-06 14:55:00 -08:00
|
|
|
|
if (instructionIndex < toolChanges[i]
|
2019-05-03 12:29:51 -07:00
|
|
|
|
&& gCodeCommandQueue[toolChanges[i]].ToolIndex != currentToolIndex
|
|
|
|
|
|
&& (toolToLookFor == -1 || gCodeCommandQueue[toolChanges[i]].ToolIndex == toolToLookFor))
|
2019-03-06 14:55:00 -08:00
|
|
|
|
{
|
|
|
|
|
|
nextToolChange = i;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-06 14:55:00 -08:00
|
|
|
|
if (nextToolChange >= 0)
|
|
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
var toolIndex = gCodeCommandQueue[toolChanges[nextToolChange]].ToolIndex;
|
|
|
|
|
|
var time = gCodeCommandQueue[instructionIndex].SecondsToEndFromHere - gCodeCommandQueue[toolChanges[nextToolChange]].SecondsToEndFromHere;
|
2019-03-06 14:55:00 -08:00
|
|
|
|
return (toolIndex, time);
|
|
|
|
|
|
}
|
2019-03-08 13:48:00 -08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// don't turn of extruders if we will end the print within 10 minutes
|
2019-05-03 12:29:51 -07:00
|
|
|
|
if (instructionIndex < gCodeCommandQueue.Count
|
|
|
|
|
|
&& gCodeCommandQueue[instructionIndex].SecondsToEndFromHere < 60 * 10)
|
2019-03-08 13:48:00 -08:00
|
|
|
|
{
|
|
|
|
|
|
return (toolToLookFor, 60 * 10);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
2019-03-05 17:55:44 -08:00
|
|
|
|
|
|
|
|
|
|
// there are no more tool changes
|
|
|
|
|
|
return (currentToolIndex, double.PositiveInfinity);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override double PercentComplete(int instructionIndex)
|
|
|
|
|
|
{
|
2019-05-12 21:00:37 -07:00
|
|
|
|
if (gCodeCommandQueue.Count > 0
|
|
|
|
|
|
&& instructionIndex < gCodeCommandQueue.Count)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-05-12 21:00:37 -07:00
|
|
|
|
return Math.Min(99.9, (gCodeCommandQueue[0].SecondsToEndFromHere - gCodeCommandQueue[instructionIndex].SecondsToEndFromHere) / gCodeCommandQueue[0].SecondsToEndFromHere * 100);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 100;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-19 20:10:28 -07:00
|
|
|
|
public override double Ratio0to1IntoContainedLayerSeconds(int instructionIndex)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
int currentLayer = GetLayerIndex(instructionIndex);
|
|
|
|
|
|
|
|
|
|
|
|
if (currentLayer > -1)
|
2018-05-08 15:19:06 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
int startIndex = IndexOfLayerStart[currentLayer];
|
|
|
|
|
|
|
|
|
|
|
|
int endIndex = LineCount - 1;
|
|
|
|
|
|
|
|
|
|
|
|
if (currentLayer < LayerCount - 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
endIndex = IndexOfLayerStart[currentLayer + 1];
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// Improved last layer percent complete - seek endIndex to 'MatterSlice Completed' line, otherwise leave at LineCount - 1
|
|
|
|
|
|
if (lastPrintLine == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastPrintLine = instructionIndex;
|
2019-05-03 12:29:51 -07:00
|
|
|
|
string line;
|
2019-03-05 17:55:44 -08:00
|
|
|
|
do
|
|
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
line = gCodeCommandQueue[Math.Min(gCodeCommandQueue.Count - 1, lastPrintLine)].Line;
|
2019-03-05 17:55:44 -08:00
|
|
|
|
lastPrintLine++;
|
2019-05-03 12:29:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
while (line != "; MatterSlice Completed Successfully"
|
2019-03-05 17:55:44 -08:00
|
|
|
|
&& lastPrintLine < endIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
endIndex = lastPrintLine;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-12 21:00:37 -07:00
|
|
|
|
if (instructionIndex < gCodeCommandQueue.Count)
|
2019-03-14 11:45:49 -07:00
|
|
|
|
{
|
2019-05-12 21:00:37 -07:00
|
|
|
|
var deltaFromStart = Math.Max(0, gCodeCommandQueue[startIndex].SecondsToEndFromHere - gCodeCommandQueue[instructionIndex].SecondsToEndFromHere);
|
|
|
|
|
|
var length = gCodeCommandQueue[startIndex].SecondsToEndFromHere - gCodeCommandQueue[endIndex].SecondsToEndFromHere;
|
|
|
|
|
|
if (length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return deltaFromStart / length;
|
|
|
|
|
|
}
|
2019-03-14 11:45:49 -07:00
|
|
|
|
}
|
2018-05-08 15:19:06 -07:00
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-14 11:45:49 -07:00
|
|
|
|
return 1;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-19 20:10:28 -07:00
|
|
|
|
public override double Ratio0to1IntoContainedLayerInstruction(int instructionIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
int currentLayer = GetLayerIndex(instructionIndex);
|
|
|
|
|
|
|
|
|
|
|
|
if (currentLayer > -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
int startIndex = IndexOfLayerStart[currentLayer];
|
|
|
|
|
|
|
|
|
|
|
|
int endIndex = LineCount - 1;
|
|
|
|
|
|
|
|
|
|
|
|
if (currentLayer < LayerCount - 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
endIndex = IndexOfLayerStart[currentLayer + 1];
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// Improved last layer percent complete - seek endIndex to 'MatterSlice Completed' line, otherwise leave at LineCount - 1
|
|
|
|
|
|
if (lastPrintLine == -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastPrintLine = instructionIndex;
|
|
|
|
|
|
string line;
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
line = gCodeCommandQueue[Math.Min(gCodeCommandQueue.Count - 1, lastPrintLine)].Line;
|
|
|
|
|
|
lastPrintLine++;
|
|
|
|
|
|
}
|
|
|
|
|
|
while (line != "; MatterSlice Completed Successfully"
|
|
|
|
|
|
&& lastPrintLine < endIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
endIndex = lastPrintLine;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int deltaFromStart = Math.Max(0, instructionIndex - startIndex);
|
|
|
|
|
|
var length = endIndex - startIndex;
|
|
|
|
|
|
if (length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return deltaFromStart / (double)length;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
public void Save(string dest)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
using (var file = new StreamWriter(dest))
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
foreach (PrinterMachineInstruction instruction in gCodeCommandQueue)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
|
|
|
|
|
file.WriteLine(instruction.Line);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
private static int CountNumLines(string gCodeString)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
int crCount = 0;
|
|
|
|
|
|
foreach (char testCharacter in gCodeString)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (testCharacter == '\n')
|
|
|
|
|
|
{
|
|
|
|
|
|
crCount++;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return crCount + 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static IEnumerable<string> CustomSplit(string newtext, char splitChar)
|
|
|
|
|
|
{
|
|
|
|
|
|
int endOfLastFind = 0;
|
|
|
|
|
|
int positionOfSplitChar = newtext.IndexOf(splitChar);
|
|
|
|
|
|
while (positionOfSplitChar != -1)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
string text = newtext.Substring(endOfLastFind, positionOfSplitChar - endOfLastFind).Trim();
|
|
|
|
|
|
yield return text;
|
|
|
|
|
|
endOfLastFind = positionOfSplitChar + 1;
|
|
|
|
|
|
positionOfSplitChar = newtext.IndexOf(splitChar, endOfLastFind);
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
string lastText = newtext.Substring(endOfLastFind);
|
|
|
|
|
|
yield return lastText;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
private static GCodeMemoryFile ParseFileContents(string gCodeString,
|
|
|
|
|
|
Vector4 maxAccelerationMmPerS2,
|
|
|
|
|
|
Vector4 maxVelocityMmPerS,
|
|
|
|
|
|
Vector4 velocitySameAsStopMmPerS,
|
|
|
|
|
|
Vector4 speedMultiplier,
|
2019-05-03 12:29:51 -07:00
|
|
|
|
CancellationToken cancellationToken,
|
|
|
|
|
|
Action<double, string> progressReporter)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
|
|
|
|
|
if (gCodeString == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
var loadTime = Stopwatch.StartNew();
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
var maxProgressReport = new Stopwatch();
|
2019-03-05 17:55:44 -08:00
|
|
|
|
maxProgressReport.Start();
|
2019-05-03 12:29:51 -07:00
|
|
|
|
var machineInstructionForLine = new PrinterMachineInstruction("None");
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
bool gcodeHasExplicitLayerChangeInfo = false;
|
|
|
|
|
|
if (gCodeString.Contains("LAYER:")
|
|
|
|
|
|
|| gCodeString.Contains("; layer"))
|
|
|
|
|
|
{
|
|
|
|
|
|
gcodeHasExplicitLayerChangeInfo = true;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
PrinterMachineInstruction previousInstruction = null;
|
|
|
|
|
|
var speeds = new HashSet<float>();
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
var loadedGCodeFile = new GCodeMemoryFile(gcodeHasExplicitLayerChangeInfo);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
// Add the first start index (of 0)
|
|
|
|
|
|
loadedGCodeFile.IndexOfLayerStart.Add(0);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
int crCount = CountNumLines(gCodeString);
|
|
|
|
|
|
int lineIndex = 0;
|
|
|
|
|
|
foreach (string outputString in CustomSplit(gCodeString, '\n'))
|
|
|
|
|
|
{
|
|
|
|
|
|
string lineString = outputString.Trim();
|
|
|
|
|
|
machineInstructionForLine = new PrinterMachineInstruction(lineString, machineInstructionForLine, false);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (lineString.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (lineString[0])
|
|
|
|
|
|
{
|
|
|
|
|
|
case 'G':
|
|
|
|
|
|
loadedGCodeFile.ParseGLine(lineString, machineInstructionForLine);
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case 'M':
|
2019-05-03 12:29:51 -07:00
|
|
|
|
loadedGCodeFile.ParseMLine(lineString);
|
2019-03-05 17:55:44 -08:00
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case 'T':
|
|
|
|
|
|
double extruderIndex = 0;
|
|
|
|
|
|
if (GetFirstNumberAfter("T", lineString, ref extruderIndex))
|
|
|
|
|
|
{
|
|
|
|
|
|
machineInstructionForLine.ToolIndex = (int)extruderIndex;
|
|
|
|
|
|
}
|
2019-05-03 12:29:51 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case ';':
|
|
|
|
|
|
if (gcodeHasExplicitLayerChangeInfo && IsLayerChange(lineString))
|
|
|
|
|
|
{
|
|
|
|
|
|
// The first "layer" statement in the gcode file is after the start gcode and we ignore
|
|
|
|
|
|
// it because we already added a marker for the start of the file (before start gcode)
|
|
|
|
|
|
if (!loadedGCodeFile.foundFirstLayerMarker)
|
|
|
|
|
|
{
|
|
|
|
|
|
loadedGCodeFile.foundFirstLayerMarker = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
loadedGCodeFile.IndexOfLayerStart.Add(loadedGCodeFile.gCodeCommandQueue.Count);
|
2019-03-05 17:55:44 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (lineString.StartsWith("; LAYER_HEIGHT:"))
|
|
|
|
|
|
{
|
|
|
|
|
|
double layerWidth = 0;
|
|
|
|
|
|
if (GetFirstNumberAfter("LAYER_HEIGHT:", lineString, ref layerWidth, 0, ""))
|
|
|
|
|
|
{
|
|
|
|
|
|
loadedGCodeFile.layerHeights.Add(layerWidth);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-05-03 12:29:51 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case '@':
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
loadedGCodeFile.gCodeCommandQueue.Add(machineInstructionForLine);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
// Accumulate speeds for extruded moves
|
|
|
|
|
|
if (previousInstruction != null
|
|
|
|
|
|
&& machineInstructionForLine.EPosition > previousInstruction.EPosition
|
|
|
|
|
|
&& (machineInstructionForLine.Line.IndexOf('X') != -1 || machineInstructionForLine.Line.IndexOf('Y') != -1))
|
|
|
|
|
|
{
|
|
|
|
|
|
speeds.Add((float)machineInstructionForLine.FeedRate);
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (progressReporter != null && maxProgressReport.ElapsedMilliseconds > 200)
|
|
|
|
|
|
{
|
|
|
|
|
|
progressReporter((double)lineIndex / crCount / 2, "");
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (cancellationToken.IsCancellationRequested)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
maxProgressReport.Restart();
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
previousInstruction = machineInstructionForLine;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
lineIndex++;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
loadedGCodeFile.AnalyzeGCodeLines(cancellationToken,
|
|
|
|
|
|
progressReporter,
|
2019-03-05 17:55:44 -08:00
|
|
|
|
maxAccelerationMmPerS2,
|
|
|
|
|
|
maxVelocityMmPerS,
|
|
|
|
|
|
velocitySameAsStopMmPerS,
|
|
|
|
|
|
speedMultiplier);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
loadedGCodeFile.Speeds = speeds;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
loadTime.Stop();
|
|
|
|
|
|
Console.WriteLine("Time To Load Seconds: {0:0.00}".FormatWith(loadTime.Elapsed.TotalSeconds));
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
return loadedGCodeFile;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
private void AnalyzeGCodeLines(CancellationToken cancellationToken,
|
|
|
|
|
|
Action<double, string> progressReporter,
|
2019-03-05 17:55:44 -08:00
|
|
|
|
Vector4 maxAccelerationMmPerS2,
|
|
|
|
|
|
Vector4 maxVelocityMmPerS,
|
|
|
|
|
|
Vector4 velocitySameAsStopMmPerS,
|
|
|
|
|
|
Vector4 speedMultiplier)
|
|
|
|
|
|
{
|
|
|
|
|
|
double feedRateMmPerMin = 0;
|
2019-05-03 12:29:51 -07:00
|
|
|
|
var lastPrinterPosition = default(Vector3);
|
2019-03-05 17:55:44 -08:00
|
|
|
|
double lastEPosition = 0;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
var maxProgressReport = new Stopwatch();
|
2019-03-05 17:55:44 -08:00
|
|
|
|
maxProgressReport.Start();
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
int currentTool = 0;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
for (int lineIndex = 0; lineIndex < gCodeCommandQueue.Count; lineIndex++)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
PrinterMachineInstruction instruction = gCodeCommandQueue[lineIndex];
|
2019-03-05 17:55:44 -08:00
|
|
|
|
string line = instruction.Line;
|
2019-05-03 12:29:51 -07:00
|
|
|
|
var deltaPositionThisLine = default(Vector3);
|
2019-03-05 17:55:44 -08:00
|
|
|
|
double deltaEPositionThisLine = 0;
|
|
|
|
|
|
string lineToParse = line.ToUpper().Trim();
|
|
|
|
|
|
if (lineToParse.StartsWith("G0") || lineToParse.StartsWith("G1"))
|
|
|
|
|
|
{
|
|
|
|
|
|
double newFeedRateMmPerMin = 0;
|
|
|
|
|
|
if (GetFirstNumberAfter("F", lineToParse, ref newFeedRateMmPerMin))
|
|
|
|
|
|
{
|
|
|
|
|
|
feedRateMmPerMin = newFeedRateMmPerMin;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
Vector3 attemptedDestination = lastPrinterPosition;
|
|
|
|
|
|
GetFirstNumberAfter("X", lineToParse, ref attemptedDestination.X);
|
|
|
|
|
|
GetFirstNumberAfter("Y", lineToParse, ref attemptedDestination.Y);
|
|
|
|
|
|
GetFirstNumberAfter("Z", lineToParse, ref attemptedDestination.Z);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
double ePosition = lastEPosition;
|
|
|
|
|
|
GetFirstNumberAfter("E", lineToParse, ref ePosition);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
deltaPositionThisLine = attemptedDestination - lastPrinterPosition;
|
|
|
|
|
|
deltaEPositionThisLine = Math.Abs(ePosition - lastEPosition);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
lastPrinterPosition = attemptedDestination;
|
|
|
|
|
|
lastEPosition = ePosition;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (lineToParse.StartsWith("G92"))
|
|
|
|
|
|
{
|
|
|
|
|
|
double ePosition = 0;
|
|
|
|
|
|
if (GetFirstNumberAfter("E", lineToParse, ref ePosition))
|
|
|
|
|
|
{
|
|
|
|
|
|
lastEPosition = ePosition;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (instruction.ToolIndex != currentTool)
|
|
|
|
|
|
{
|
|
|
|
|
|
toolChanges.Add(lineIndex);
|
|
|
|
|
|
currentTool = instruction.ToolIndex;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (feedRateMmPerMin > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var timeForE = Estimator.GetSecondsForMovement(deltaEPositionThisLine,
|
|
|
|
|
|
feedRateMmPerMin / 60.0,
|
|
|
|
|
|
maxAccelerationMmPerS2[3],
|
|
|
|
|
|
maxVelocityMmPerS[3],
|
|
|
|
|
|
velocitySameAsStopMmPerS[3],
|
|
|
|
|
|
speedMultiplier[3]);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
var timeForPosition = Estimator.GetSecondsForMovement(deltaPositionThisLine,
|
|
|
|
|
|
feedRateMmPerMin / 60.0,
|
|
|
|
|
|
new Vector3(maxAccelerationMmPerS2),
|
|
|
|
|
|
new Vector3(maxVelocityMmPerS),
|
|
|
|
|
|
new Vector3(velocitySameAsStopMmPerS),
|
|
|
|
|
|
new Vector3(speedMultiplier));
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
instruction.SecondsThisLine = (float)Math.Max(timeForE, timeForPosition);
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (progressReporter != null && maxProgressReport.ElapsedMilliseconds > 200)
|
|
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
progressReporter(((double)lineIndex / gCodeCommandQueue.Count / 2) + .5, "");
|
2019-03-05 17:55:44 -08:00
|
|
|
|
if (cancellationToken.IsCancellationRequested)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
maxProgressReport.Restart();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-06 17:01:26 -08:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
double accumulatedTime = 0;
|
2019-05-03 12:29:51 -07:00
|
|
|
|
for (int i = gCodeCommandQueue.Count - 1; i >= 0; i--)
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
PrinterMachineInstruction line = gCodeCommandQueue[i];
|
2019-03-05 17:55:44 -08:00
|
|
|
|
accumulatedTime += line.SecondsThisLine;
|
|
|
|
|
|
line.SecondsToEndFromHere = (float)accumulatedTime;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
private bool FindDiameter(int lineIndex, ref double filamentDiameterCache)
|
|
|
|
|
|
{
|
2019-05-03 12:29:51 -07:00
|
|
|
|
if (GetFirstNumberAfter("filamentDiameter = ", gCodeCommandQueue[lineIndex].Line, ref filamentDiameterCache, 0, ""))
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
if (GetFirstNumberAfter("; filament_diameter = ", gCodeCommandQueue[lineIndex].Line, ref filamentDiameterCache, 0, ""))
|
2019-03-05 17:55:44 -08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-21 23:26:20 -07:00
|
|
|
|
private void ParseGLine(string lineString, PrinterMachineInstruction processingMachineState)
|
|
|
|
|
|
{
|
|
|
|
|
|
// take off any comments before we check its length
|
|
|
|
|
|
int commentIndex = lineString.IndexOf(';');
|
|
|
|
|
|
if (commentIndex != -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
lineString = lineString.Substring(0, commentIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string[] splitOnSpace = lineString.Split(' ');
|
|
|
|
|
|
string onlyNumber = splitOnSpace[0].Substring(1).Trim();
|
|
|
|
|
|
switch (onlyNumber)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "0":
|
|
|
|
|
|
goto case "1";
|
|
|
|
|
|
|
|
|
|
|
|
case "4":
|
|
|
|
|
|
case "04":
|
2018-07-12 22:49:39 -07:00
|
|
|
|
// wait a given number of milliseconds
|
2017-06-21 23:26:20 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "1":
|
|
|
|
|
|
// get the x y z to move to
|
|
|
|
|
|
{
|
2018-12-11 14:10:27 -08:00
|
|
|
|
double ePosition = processingMachineState.EPosition;
|
|
|
|
|
|
var position = processingMachineState.Position;
|
|
|
|
|
|
if (processingMachineState.MovementType == PrinterMachineInstruction.MovementTypes.Relative)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2018-12-11 14:10:27 -08:00
|
|
|
|
position = Vector3.Zero;
|
|
|
|
|
|
ePosition = 0;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
2018-12-11 14:10:27 -08:00
|
|
|
|
|
|
|
|
|
|
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))
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2018-12-11 14:10:27 -08:00
|
|
|
|
processingMachineState.FeedRate = (float)feedrate;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
2018-12-11 14:10:27 -08:00
|
|
|
|
|
|
|
|
|
|
if (processingMachineState.MovementType == PrinterMachineInstruction.MovementTypes.Absolute)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2018-12-11 14:10:27 -08:00
|
|
|
|
processingMachineState.Position = position;
|
|
|
|
|
|
processingMachineState.EPosition = (float)ePosition;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
2018-12-11 14:10:27 -08:00
|
|
|
|
else
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2018-12-11 14:10:27 -08:00
|
|
|
|
processingMachineState.Position += position;
|
|
|
|
|
|
processingMachineState.EPosition += (float)ePosition;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!gcodeHasExplicitLayerChangeInfo)
|
|
|
|
|
|
{
|
2018-05-30 16:42:17 -07:00
|
|
|
|
if (processingMachineState.Z != parsingLastZ || IndexOfLayerStart.Count == 0)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
|
|
|
|
|
// if we changed z or there is a movement and we have never started a layer index
|
2019-05-03 12:29:51 -07:00
|
|
|
|
IndexOfLayerStart.Add(gCodeCommandQueue.Count);
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-05-03 12:29:51 -07:00
|
|
|
|
|
2017-10-31 12:51:16 -07:00
|
|
|
|
parsingLastZ = processingMachineState.Position.Z;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "10": // firmware retract
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "11": // firmware unretract
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "21":
|
|
|
|
|
|
// set to metric
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "28":
|
|
|
|
|
|
// G28 Return to home position (machine zero, aka machine reference point)
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "29":
|
|
|
|
|
|
// G29 Probe the z-bed in 3 places
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "30":
|
|
|
|
|
|
// G30 Probe z in current position
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "90": // G90 is Absolute Distance Mode
|
2018-12-11 14:10:27 -08:00
|
|
|
|
processingMachineState.MovementType = PrinterMachineInstruction.MovementTypes.Absolute;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "91": // G91 is Incremental Distance Mode
|
2018-12-11 14:10:27 -08:00
|
|
|
|
processingMachineState.MovementType = PrinterMachineInstruction.MovementTypes.Relative;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "92":
|
2018-12-11 14:10:27 -08:00
|
|
|
|
{
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
}
|
2019-05-03 12:29:51 -07:00
|
|
|
|
|
2018-12-11 14:10:27 -08:00
|
|
|
|
if (GCodeFile.GetFirstNumberAfter("Y", lineString, ref value))
|
|
|
|
|
|
{
|
|
|
|
|
|
processingMachineState.PositionSet |= PositionSet.Y;
|
|
|
|
|
|
processingMachineState.Y = value;
|
|
|
|
|
|
}
|
2019-05-03 12:29:51 -07:00
|
|
|
|
|
2018-12-11 14:10:27 -08:00
|
|
|
|
if (GCodeFile.GetFirstNumberAfter("Z", lineString, ref value))
|
|
|
|
|
|
{
|
|
|
|
|
|
processingMachineState.PositionSet |= PositionSet.Z;
|
|
|
|
|
|
processingMachineState.Z = value;
|
|
|
|
|
|
}
|
2019-05-03 12:29:51 -07:00
|
|
|
|
|
2018-12-11 14:10:27 -08:00
|
|
|
|
if (GCodeFile.GetFirstNumberAfter("E", lineString, ref value))
|
|
|
|
|
|
{
|
|
|
|
|
|
processingMachineState.PositionSet |= PositionSet.E;
|
|
|
|
|
|
processingMachineState.EPosition = (float)value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-05-03 12:29:51 -07:00
|
|
|
|
|
2017-06-21 23:26:20 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
2018-12-06 17:01:26 -08:00
|
|
|
|
case "130":
|
2019-05-03 12:29:51 -07:00
|
|
|
|
// Set Digital Potentiometer value
|
2018-12-06 17:01:26 -08:00
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
|
|
|
|
|
case "161":
|
|
|
|
|
|
// home x,y axis minimum
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "162":
|
|
|
|
|
|
// home z axis maximum
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2018-12-06 17:01:26 -08:00
|
|
|
|
default:
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
private void ParseMLine(string lineString)
|
2017-06-21 23:26:20 -07:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
// take off any comments before we check its length
|
|
|
|
|
|
int commentIndex = lineString.IndexOf(';');
|
|
|
|
|
|
if (commentIndex != -1)
|
2018-01-22 13:59:43 -08:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
lineString = lineString.Substring(0, commentIndex);
|
2018-01-22 13:59:43 -08:00
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
string[] splitOnSpace = lineString.Split(' ');
|
|
|
|
|
|
switch (splitOnSpace[0].Substring(1).Trim())
|
2018-01-22 13:59:43 -08:00
|
|
|
|
{
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "01":
|
|
|
|
|
|
// show a message?
|
|
|
|
|
|
break;
|
2018-01-22 13:59:43 -08:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "6":
|
|
|
|
|
|
// wait for tool to heat up (wait for condition?)
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "101":
|
|
|
|
|
|
// extrude on, forward
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "18":
|
|
|
|
|
|
// turn off steppers
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "42":
|
|
|
|
|
|
// Stop on material exhausted / Switch I/O pin
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "72":
|
|
|
|
|
|
// makerbot, Play tone or song
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "73":
|
|
|
|
|
|
// makerbot, Manually set build percentage
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "82":
|
|
|
|
|
|
// set extruder to absolute mode
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "83":
|
2019-05-03 12:29:51 -07:00
|
|
|
|
// Set extruder to relative mode
|
2019-03-05 17:55:44 -08:00
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "84":
|
|
|
|
|
|
// lineString = "M84 ; disable motors\r"
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "92":
|
|
|
|
|
|
// set steps per mm
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "102":
|
|
|
|
|
|
// extrude on reverse
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "103":
|
|
|
|
|
|
// extrude off
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "104":
|
|
|
|
|
|
// set extruder temperature
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "105":
|
|
|
|
|
|
// M105 Custom code for temperature reading. (Not used)
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "106":
|
|
|
|
|
|
// turn fan on
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "107":
|
|
|
|
|
|
// turn fan off
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "108":
|
|
|
|
|
|
// set extruder speed
|
|
|
|
|
|
break;
|
2018-06-12 11:11:28 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "109":
|
|
|
|
|
|
// set heated platform temperature
|
|
|
|
|
|
break;
|
2018-06-12 11:11:28 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "114":
|
|
|
|
|
|
break;
|
2018-06-12 11:11:28 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "117":
|
|
|
|
|
|
// in Marlin: Display Message
|
|
|
|
|
|
break;
|
2018-05-08 15:19:06 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "126":
|
|
|
|
|
|
// enable fan (makerbot)
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "127":
|
|
|
|
|
|
// disable fan (makerbot)
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "132":
|
|
|
|
|
|
// recall stored home offsets for axis xyzab
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "133":
|
|
|
|
|
|
// MakerBot wait for toolhead to heat
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "134":
|
|
|
|
|
|
// MakerBot wait for platform to reach target temp
|
|
|
|
|
|
break;
|
2018-09-21 13:29:39 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "135":
|
|
|
|
|
|
// MakerBot change toolhead
|
|
|
|
|
|
break;
|
2018-02-16 14:20:15 -08:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "140":
|
|
|
|
|
|
// set bed temperature
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "190":
|
|
|
|
|
|
// wait for bed temperature to be reached
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "200":
|
|
|
|
|
|
// M200 sets the filament diameter.
|
|
|
|
|
|
break;
|
2018-02-16 14:20:15 -08:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "201":
|
|
|
|
|
|
// set axis acceleration
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "204": // - Set default acceleration
|
|
|
|
|
|
break;
|
2018-02-16 14:20:15 -08:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "207": // M207: calibrate z axis by detecting z max length
|
|
|
|
|
|
break;
|
2018-02-16 14:20:15 -08:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "208": // M208: set axis max travel
|
|
|
|
|
|
break;
|
2018-02-16 14:20:15 -08:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "209": // M209: enable automatic retract
|
|
|
|
|
|
break;
|
2018-02-16 14:20:15 -08:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "210": // Set homing rate
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "226": // user request pause
|
|
|
|
|
|
break;
|
2017-06-21 23:26:20 -07:00
|
|
|
|
|
2019-03-05 17:55:44 -08:00
|
|
|
|
case "227": // Enable Automatic Reverse and Prime
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "301":
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "400": // Wait for current moves to finish
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case "565": // M565: Set Z probe offset
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
case "1200": // M1200 Makerbot Fake gCode command for start build notification
|
2019-03-05 17:55:44 -08:00
|
|
|
|
break;
|
|
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
case "1201": // M1201 Makerbot Fake gCode command for end build notification
|
2019-03-05 17:55:44 -08:00
|
|
|
|
break;
|
|
|
|
|
|
|
2019-05-03 12:29:51 -07:00
|
|
|
|
case "1202": // M1202 Makerbot Fake gCode command for reset board
|
2019-03-05 17:55:44 -08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-06-21 23:26:20 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|