Make sure we have printer move speeds in loaded gcode

This commit is contained in:
Lars Brubaker 2019-03-06 13:44:33 -08:00
parent d8d8e78a98
commit 1bd7e525ad
4 changed files with 50 additions and 24 deletions

View file

@ -352,16 +352,22 @@ namespace MatterHackers.MatterControl.Library.Export
{
try
{
var settings = this.printer.Settings;
var maxAcceleration = settings.GetValue<double>(SettingsKey.max_acceleration);
var maxVelocity = settings.GetValue<double>(SettingsKey.max_velocity);
var jerkVelocity = settings.GetValue<double>(SettingsKey.jerk_velocity);
var multiplier = settings.GetValue<double>(SettingsKey.print_time_estimate_multiplier) / 100.0;
this.ApplyStreamPipelineAndExport(
new GCodeFileStream(
GCodeFile.Load(
gcodeFilename,
new Vector4(),
new Vector4(),
new Vector4(),
Vector4.One,
CancellationToken.None)
, printer),
new Vector4(maxAcceleration, maxAcceleration, maxAcceleration, maxAcceleration),
new Vector4(maxVelocity, maxVelocity, maxVelocity, maxVelocity),
new Vector4(jerkVelocity, jerkVelocity, jerkVelocity, jerkVelocity),
new Vector4(multiplier, multiplier, multiplier, multiplier),
CancellationToken.None),
printer),
outputPath);
}
catch (Exception e)

View file

@ -31,6 +31,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MatterControl.Printing;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PrinterCommunication.Io
@ -46,12 +47,18 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
public GCodeSwitcher(string gcodeFilename, PrinterConfig printer, int startLine = 0)
: base(printer)
{
var settings = this.printer.Settings;
var maxAcceleration = settings.GetValue<double>(SettingsKey.max_acceleration);
var maxVelocity = settings.GetValue<double>(SettingsKey.max_velocity);
var jerkVelocity = settings.GetValue<double>(SettingsKey.jerk_velocity);
var multiplier = settings.GetValue<double>(SettingsKey.print_time_estimate_multiplier) / 100.0;
var fileStreaming = GCodeFile.Load(gcodeFilename,
new Vector4(),
new Vector4(),
new Vector4(),
Vector4.One,
CancellationToken.None);
new Vector4(maxAcceleration, maxAcceleration, maxAcceleration, maxAcceleration),
new Vector4(maxVelocity, maxVelocity, maxVelocity, maxVelocity),
new Vector4(jerkVelocity, jerkVelocity, jerkVelocity, jerkVelocity),
new Vector4(multiplier, multiplier, multiplier, multiplier),
CancellationToken.None);
this.GCodeFile = fileStreaming;
LineIndex = startLine;
@ -151,11 +158,17 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
Task.Run(() =>
{
var settings = this.printer.Settings;
var maxAcceleration = settings.GetValue<double>(SettingsKey.max_acceleration);
var maxVelocity = settings.GetValue<double>(SettingsKey.max_velocity);
var jerkVelocity = settings.GetValue<double>(SettingsKey.jerk_velocity);
var multiplier = settings.GetValue<double>(SettingsKey.print_time_estimate_multiplier) / 100.0;
var switchToGCode = GCodeFile.Load(gcodeFilename,
new Vector4(),
new Vector4(),
new Vector4(),
Vector4.One,
new Vector4(maxAcceleration, maxAcceleration, maxAcceleration, maxAcceleration),
new Vector4(maxVelocity, maxVelocity, maxVelocity, maxVelocity),
new Vector4(jerkVelocity, jerkVelocity, jerkVelocity, jerkVelocity),
new Vector4(multiplier, multiplier, multiplier, multiplier),
CancellationToken.None);
if (switchToGCode is GCodeMemoryFile memoryFile)

View file

@ -79,14 +79,19 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
var timeToReheat = printer.Settings.GetValue<double>(SettingsKey.seconds_to_reheat);
// check if any extruders need to start heating back up
for (int i = 0; i < toolCount; i++)
// check if we need to turn on extruders while printing
if (printer.Connection.Printing)
{
var timeUntilUsed = printer.Connection.NextToolChange(i).time;
var targetTemp = printer.Settings.Helpers.ExtruderTargetTemperature(i);
if (timeUntilUsed < timeToReheat)
// check if any extruders need to start heating back up
for (int i = 0; i < toolCount; i++)
{
printer.Connection.SetTargetHotendTemperature(i, targetTemp);
var timeUntilUsed = printer.Connection.NextToolChange(i).time;
var targetTemp = printer.Settings.Helpers.ExtruderTargetTemperature(i);
if (timeUntilUsed < timeToReheat
&& printer.Connection.GetTargetHotendTemperature(i) != targetTemp)
{
printer.Connection.SetTargetHotendTemperature(i, targetTemp);
}
}
}
@ -94,7 +99,8 @@ namespace MatterHackers.MatterControl.PrinterCommunication.Io
{
var nextToolIndex = currentToolIndex;
GCodeFile.GetFirstNumberAfter("T", line, ref nextToolIndex);
if(nextToolIndex != currentToolIndex)
if(printer.Connection.Printing
&& nextToolIndex != currentToolIndex)
{
// get the time to the next tool switch
var timeToNextToolChange = printer.Connection.NextToolChange().time;

View file

@ -328,12 +328,13 @@ namespace MatterHackers.MatterControl.PrinterCommunication
/// <returns></returns>
public (int toolIndex, double time) NextToolChange(int toolToLookFor = -1)
{
if (gCodeFileSwitcher.GCodeFile is GCodeMemoryFile gCodeMemoryFile)
if (gCodeFileSwitcher != null
&& gCodeFileSwitcher.GCodeFile is GCodeMemoryFile gCodeMemoryFile)
{
return gCodeMemoryFile.NextToolChange(gCodeFileSwitcher.LineIndex, -1, toolToLookFor);
}
return (0, 0);
return (-1, 0);
}
private void ExtruderIndexSet(string line)