added a hotend temperature stream
In the gcode line view show time to next extruder switch refactored gcode memory file gcode render features keep track of their gcode line index issue: MatterHackers/MCCentral#4679 Turn off hot end temp if not used for remainder of print
This commit is contained in:
parent
78b01b4d21
commit
394325db97
11 changed files with 718 additions and 541 deletions
|
|
@ -128,15 +128,15 @@ namespace MatterHackers.GCodeVisualizer
|
|||
if (Math.Abs(eMovement) > 0)
|
||||
{
|
||||
// this is a retraction
|
||||
renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, eMovement, currentInstruction.ToolIndex, currentInstruction.FeedRate));
|
||||
renderFeaturesForLayer.Add(new RenderFeatureRetract(instructionIndex, currentInstruction.Position, eMovement, currentInstruction.ToolIndex, currentInstruction.FeedRate));
|
||||
}
|
||||
if (currentInstruction.Line.StartsWith("G10"))
|
||||
{
|
||||
renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, -1, currentInstruction.ToolIndex, currentInstruction.FeedRate));
|
||||
renderFeaturesForLayer.Add(new RenderFeatureRetract(instructionIndex, currentInstruction.Position, -1, currentInstruction.ToolIndex, currentInstruction.FeedRate));
|
||||
}
|
||||
else if (currentInstruction.Line.StartsWith("G11"))
|
||||
{
|
||||
renderFeaturesForLayer.Add(new RenderFeatureRetract(currentInstruction.Position, 1, currentInstruction.ToolIndex, currentInstruction.FeedRate));
|
||||
renderFeaturesForLayer.Add(new RenderFeatureRetract(instructionIndex, currentInstruction.Position, 1, currentInstruction.ToolIndex, currentInstruction.FeedRate));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -148,6 +148,7 @@ namespace MatterHackers.GCodeVisualizer
|
|||
Color extrusionColor = ExtrusionColors.GetColorForSpeed((float)currentInstruction.FeedRate);
|
||||
renderFeaturesForLayer.Add(
|
||||
new RenderFeatureExtrusion(
|
||||
instructionIndex,
|
||||
previousInstruction.Position,
|
||||
currentInstruction.Position,
|
||||
currentInstruction.ToolIndex,
|
||||
|
|
@ -162,6 +163,7 @@ namespace MatterHackers.GCodeVisualizer
|
|||
{
|
||||
renderFeaturesForLayer.Add(
|
||||
new RenderFeatureTravel(
|
||||
instructionIndex,
|
||||
previousInstruction.Position,
|
||||
currentInstruction.Position,
|
||||
currentInstruction.ToolIndex,
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ namespace MatterHackers.GCodeVisualizer
|
|||
{
|
||||
protected int toolIndex;
|
||||
|
||||
/// <summary>
|
||||
/// The actual gcode line in the sourc gcode file
|
||||
/// </summary>
|
||||
public int InstructionIndex { get; private set; }
|
||||
public static Color HighlightColor { get; set; } = new Color("#D0F476");
|
||||
|
||||
public static Color StartColor { get; set; } = Color.Red;
|
||||
|
|
@ -46,9 +50,10 @@ namespace MatterHackers.GCodeVisualizer
|
|||
|
||||
public abstract void CreateRender3DData(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> indexData, GCodeRenderInfo renderInfo);
|
||||
|
||||
public RenderFeatureBase(int extruderIndex)
|
||||
public RenderFeatureBase(int instructionIndex, int toolIndex)
|
||||
{
|
||||
this.toolIndex = extruderIndex;
|
||||
this.toolIndex = toolIndex;
|
||||
this.InstructionIndex = instructionIndex;
|
||||
}
|
||||
|
||||
static public void CreateCylinder(VectorPOD<ColorVertexData> colorVertexData, VectorPOD<int> indexData, Vector3 startPos, Vector3 endPos, double radius, int steps, Color color, double layerHeight)
|
||||
|
|
|
|||
|
|
@ -42,8 +42,8 @@ namespace MatterHackers.GCodeVisualizer
|
|||
private Color color;
|
||||
private Color gray;
|
||||
|
||||
public RenderFeatureExtrusion(Vector3 start, Vector3 end, int toolIndex, double travelSpeed, double totalExtrusionMm, double filamentDiameterMm, double layerHeight, Color color, Color gray)
|
||||
: base(start, end, toolIndex, travelSpeed)
|
||||
public RenderFeatureExtrusion(int instructionIndex, Vector3 start, Vector3 end, int toolIndex, double travelSpeed, double totalExtrusionMm, double filamentDiameterMm, double layerHeight, Color color, Color gray)
|
||||
: base(instructionIndex, start, end, toolIndex, travelSpeed)
|
||||
{
|
||||
this.color = color;
|
||||
this.gray = gray;
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ namespace MatterHackers.GCodeVisualizer
|
|||
private float mmPerSecond;
|
||||
private Vector3Float position;
|
||||
|
||||
public RenderFeatureRetract(Vector3 position, double extrusionAmount, int extruderIndex, double mmPerSecond)
|
||||
: base(extruderIndex)
|
||||
public RenderFeatureRetract(int instructionIndex, Vector3 position, double extrusionAmount, int extruderIndex, double mmPerSecond)
|
||||
: base(instructionIndex, extruderIndex)
|
||||
{
|
||||
this.extrusionAmount = (float)extrusionAmount;
|
||||
this.mmPerSecond = (float)mmPerSecond;
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ namespace MatterHackers.GCodeVisualizer
|
|||
|
||||
public Vector3Float End => end;
|
||||
|
||||
public RenderFeatureTravel(Vector3 start, Vector3 end, int toolIndex, double travelSpeed)
|
||||
: base(toolIndex)
|
||||
public RenderFeatureTravel(int instructionIndex, Vector3 start, Vector3 end, int toolIndex, double travelSpeed)
|
||||
: base(instructionIndex, toolIndex)
|
||||
{
|
||||
this.toolIndex = toolIndex;
|
||||
this.start = new Vector3Float(start);
|
||||
|
|
|
|||
|
|
@ -185,12 +185,13 @@ namespace MatterControl.Printing
|
|||
}
|
||||
else
|
||||
{
|
||||
return new GCodeMemoryFile(fileName,
|
||||
return GCodeMemoryFile.Load(fileName,
|
||||
maxAccelerationMmPerS2,
|
||||
maxVelocityMmPerS,
|
||||
velocitySameAsStopMmPerS,
|
||||
speedMultiplier,
|
||||
cancellationToken);
|
||||
cancellationToken,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -282,12 +282,13 @@ namespace MatterHackers.MatterControl.Library.Export
|
|||
|
||||
public static GCodeStream GetExportStream(PrinterConfig printer, GCodeStream gCodeBaseStream, bool applyLeveling)
|
||||
{
|
||||
var queueStream = new QueuedCommandsStream(printer, gCodeBaseStream);
|
||||
GCodeStream accumulatedStream = queueStream;
|
||||
var queuedCommandStream = new QueuedCommandsStream(printer, gCodeBaseStream);
|
||||
GCodeStream accumulatedStream = queuedCommandStream;
|
||||
|
||||
if (printer.Settings.GetValue<int>(SettingsKey.extruder_count) > 1)
|
||||
{
|
||||
accumulatedStream = new ToolChangeStream(printer, accumulatedStream, queueStream);
|
||||
accumulatedStream = new ToolChangeStream(printer, accumulatedStream, queuedCommandStream);
|
||||
accumulatedStream = new HotendTemperatureStream(printer, accumulatedStream, queuedCommandStream);
|
||||
}
|
||||
|
||||
accumulatedStream = new RelativeToAbsoluteStream(printer, accumulatedStream);
|
||||
|
|
@ -312,7 +313,7 @@ namespace MatterHackers.MatterControl.Library.Export
|
|||
}
|
||||
|
||||
// this is added to ensure we are rewriting the G0 G1 commands as needed
|
||||
accumulatedStream = new ProcessWriteRegexStream(printer, accumulatedStream, queueStream);
|
||||
accumulatedStream = new ProcessWriteRegexStream(printer, accumulatedStream, queuedCommandStream);
|
||||
|
||||
return accumulatedStream;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,8 +38,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
{
|
||||
public class GCodeDebugView : GCodeDetailsPanel
|
||||
{
|
||||
private GCodeFile gCodeFile;
|
||||
private PrinterTabPage printerTabPage;
|
||||
private ISceneContext sceneContext;
|
||||
private GCodeMemoryFile gCodeMemoryFile;
|
||||
private TextWidget startPointWidget;
|
||||
private TextWidget endPointWidget;
|
||||
private TextWidget slopeWidget;
|
||||
|
|
@ -47,20 +49,31 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
private TextWidget yInterceptWidget;
|
||||
private TextWidget xInterceptWidget;
|
||||
private TextWidget timeToToolChange;
|
||||
private TextWidget rawLine;
|
||||
|
||||
public GCodeDebugView(PrinterTabPage printerTabPage, GCodeFile gCodeMemoryFile, ISceneContext sceneContext, ThemeConfig theme)
|
||||
public GCodeDebugView(PrinterTabPage printerTabPage, GCodeFile gCodeFile, ISceneContext sceneContext, ThemeConfig theme)
|
||||
: base(theme)
|
||||
{
|
||||
this.gCodeFile = gCodeFile;
|
||||
this.printerTabPage = printerTabPage;
|
||||
this.sceneContext = sceneContext;
|
||||
|
||||
gCodeMemoryFile = gCodeFile as GCodeMemoryFile;
|
||||
if (gCodeMemoryFile != null)
|
||||
{
|
||||
rawLine = this.AddSetting("G-Code Line".Localize(), "");
|
||||
}
|
||||
|
||||
startPointWidget = this.AddSetting("Start".Localize(), "");
|
||||
endPointWidget = this.AddSetting("End".Localize(), "");
|
||||
lengthWidget = this.AddSetting("Length".Localize(), "");
|
||||
slopeWidget = this.AddSetting("Slope".Localize(), "");
|
||||
yInterceptWidget = this.AddSetting("Y Intercept".Localize(), "");
|
||||
xInterceptWidget = this.AddSetting("X Intercept".Localize(), "");
|
||||
timeToToolChange = this.AddSetting("Tool Change".Localize(), "");
|
||||
//slopeWidget = this.AddSetting("Slope".Localize(), "");
|
||||
//yInterceptWidget = this.AddSetting("Y Intercept".Localize(), "");
|
||||
//xInterceptWidget = this.AddSetting("X Intercept".Localize(), "");
|
||||
if (gCodeMemoryFile != null)
|
||||
{
|
||||
timeToToolChange = this.AddSetting("Time to Tool Change".Localize(), "");
|
||||
}
|
||||
|
||||
// Register listeners
|
||||
printerTabPage.LayerFeaturesScrollbar.SecondValueChanged += this.LayerFeaturesScrollbar_SecondValueChanged;
|
||||
|
|
@ -85,6 +98,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
|
||||
if (sceneContext.GCodeRenderer[layerIndex, activeFeatureIndex] is RenderFeatureTravel line)
|
||||
{
|
||||
if (rawLine != null)
|
||||
{
|
||||
rawLine.Text = gCodeMemoryFile.Instruction(line.InstructionIndex).Line;
|
||||
}
|
||||
|
||||
var start = line.Start;
|
||||
var end = line.End;
|
||||
|
||||
|
|
@ -101,20 +119,37 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
// n = -x_1 * (y_2 - y_1) / (x_2 - x_1) + y_1
|
||||
|
||||
var slope = (end.Y - start.Y) / (end.X - start.X);
|
||||
slopeWidget.Text = $"{slope:0.###}";
|
||||
if (slopeWidget != null)
|
||||
{
|
||||
slopeWidget.Text = $"{slope:0.###}";
|
||||
}
|
||||
|
||||
// -x_1 * (y_2 - y_1) / (x_2 - x_1) + y_1
|
||||
var yIntercept = -start.X * slope + start.Y;
|
||||
yInterceptWidget.Text = $"{yIntercept:0.###}";
|
||||
if (yInterceptWidget != null)
|
||||
{
|
||||
// -x_1 * (y_2 - y_1) / (x_2 - x_1) + y_1
|
||||
var yIntercept = -start.X * slope + start.Y;
|
||||
yInterceptWidget.Text = $"{yIntercept:0.###}";
|
||||
}
|
||||
|
||||
// x_1 - y_1*(x_2-x_1)/(y_2-y_1)
|
||||
var xIntercept = start.X - start.Y * (end.X - start.X) / (end.Y - start.Y);
|
||||
xInterceptWidget.Text = $"{xIntercept:0.###}";
|
||||
if (xInterceptWidget != null)
|
||||
{
|
||||
// x_1 - y_1*(x_2-x_1)/(y_2-y_1)
|
||||
var xIntercept = start.X - start.Y * (end.X - start.X) / (end.Y - start.Y);
|
||||
xInterceptWidget.Text = $"{xIntercept:0.###}";
|
||||
}
|
||||
|
||||
// put in the time until the next tool change
|
||||
if(timeToToolChange != null)
|
||||
if (timeToToolChange != null)
|
||||
{
|
||||
|
||||
var toolChange = gCodeMemoryFile.NextToolChange(line.InstructionIndex);
|
||||
if (toolChange.time < double.PositiveInfinity)
|
||||
{
|
||||
timeToToolChange.Text = $"T{toolChange.toolIndex} : {toolChange.time:0.00}s";
|
||||
}
|
||||
else
|
||||
{
|
||||
timeToToolChange.Text = $"No More Changes";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
Copyright (c) 2019, Lars Brubaker, John Lewin
|
||||
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.
|
||||
*/
|
||||
|
||||
using MatterControl.Printing;
|
||||
using MatterHackers.MatterControl.SlicerConfiguration;
|
||||
|
||||
namespace MatterHackers.MatterControl.PrinterCommunication.Io
|
||||
{
|
||||
public class HotendTemperatureStream : GCodeStreamProxy
|
||||
{
|
||||
private bool haveSeenMultipleExtruders;
|
||||
private int extruderIndex;
|
||||
private QueuedCommandsStream queuedCommandsStream;
|
||||
int extruderCount = 0;
|
||||
|
||||
public HotendTemperatureStream(PrinterConfig printer, GCodeStream internalStream, QueuedCommandsStream queuedCommandsStream)
|
||||
: base(printer, internalStream)
|
||||
{
|
||||
this.queuedCommandsStream = queuedCommandsStream;
|
||||
extruderCount = printer.Settings.GetValue<int>(SettingsKey.extruder_count);
|
||||
extruderIndex = printer.Connection.ActiveExtruderIndex;
|
||||
}
|
||||
|
||||
public override string DebugInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return $"";
|
||||
}
|
||||
}
|
||||
|
||||
public override string ReadLine()
|
||||
{
|
||||
string lineToSend = base.ReadLine();
|
||||
|
||||
if (lineToSend != null
|
||||
&& lineToSend.EndsWith("; NO_PROCESSING"))
|
||||
{
|
||||
return lineToSend;
|
||||
}
|
||||
|
||||
TrackExtruderState(lineToSend);
|
||||
|
||||
// when we are actively printing manage the extruder temperature
|
||||
if (haveSeenMultipleExtruders
|
||||
&& printer.Connection.Printing)
|
||||
{
|
||||
// get the time to the next extruder switch
|
||||
var toolChange = printer.Connection.NextToolChange();
|
||||
|
||||
// if we do not switch again
|
||||
if (toolChange.time == double.PositiveInfinity)
|
||||
{
|
||||
// we do not switch extruders again, turn off any that are not currently printing
|
||||
for (int i = 0; i < extruderCount; i++)
|
||||
{
|
||||
if(i != extruderIndex)
|
||||
{
|
||||
printer.Connection.SetTargetHotendTemperature(i, 0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// don't keep checking if need to turn off extruders
|
||||
haveSeenMultipleExtruders = false;
|
||||
}
|
||||
|
||||
return lineToSend;
|
||||
}
|
||||
|
||||
private void TrackExtruderState(string line)
|
||||
{
|
||||
if (line == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (line.StartsWith("G28)"))
|
||||
{
|
||||
extruderIndex = 0;
|
||||
}
|
||||
|
||||
if (line.StartsWith("T"))
|
||||
{
|
||||
var newExtruder = extruderIndex;
|
||||
GCodeFile.GetFirstNumberAfter("T", line, ref newExtruder);
|
||||
if(newExtruder != extruderIndex)
|
||||
{
|
||||
haveSeenMultipleExtruders = true;
|
||||
extruderIndex = newExtruder;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -322,6 +322,20 @@ namespace MatterHackers.MatterControl.PrinterCommunication
|
|||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// seconds until the next tool change while printing
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public (int toolIndex, double time) NextToolChange()
|
||||
{
|
||||
if (gCodeFileSwitcher.GCodeFile is GCodeMemoryFile gCodeMemoryFile)
|
||||
{
|
||||
return gCodeMemoryFile.NextToolChange(gCodeFileSwitcher.LineIndex);
|
||||
}
|
||||
|
||||
return (0, 0);
|
||||
}
|
||||
|
||||
private void ExtruderIndexSet(string line)
|
||||
{
|
||||
double extruderBeingSet = 0;
|
||||
|
|
@ -2159,6 +2173,7 @@ You will then need to logout and log back in to the computer for the changes to
|
|||
if (ExtruderCount > 1)
|
||||
{
|
||||
accumulatedStream = new ToolChangeStream(Printer, accumulatedStream, queuedCommandStream);
|
||||
accumulatedStream = new HotendTemperatureStream(Printer, accumulatedStream, queuedCommandStream);
|
||||
}
|
||||
|
||||
accumulatedStream = new BabyStepsStream(Printer, accumulatedStream);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue