Merge pull request #2910 from larsbrubaker/design_tools

adding ability to set acceleration on a printer profile
This commit is contained in:
Lars Brubaker 2018-01-17 14:12:15 -08:00 committed by GitHub
commit 73712eabac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 1979 additions and 1875 deletions

View file

@ -421,7 +421,16 @@ namespace MatterHackers.MatterControl
public void LoadGCode(Stream stream, CancellationToken cancellationToken, Action<double, string> progressReporter)
{
var loadedGCode = GCodeMemoryFile.Load(stream, cancellationToken, progressReporter);
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 loadedGCode = GCodeMemoryFile.Load(stream,
new Vector4(maxAcceleration, maxAcceleration, maxAcceleration, maxAcceleration),
new Vector4(maxVelocity, maxVelocity, maxVelocity, maxVelocity),
new Vector4(jerkVelocity, jerkVelocity, jerkVelocity, jerkVelocity),
cancellationToken, progressReporter);
this.GCodeRenderer = new GCodeRenderer(loadedGCode);
this.RenderInfo = new GCodeRenderInfo(
0,
@ -432,8 +441,8 @@ namespace MatterHackers.MatterControl
1,
new Vector2[]
{
this.Printer.Settings.Helpers.ExtruderOffset(0),
this.Printer.Settings.Helpers.ExtruderOffset(1)
settings.Helpers.ExtruderOffset(0),
settings.Helpers.ExtruderOffset(1)
},
this.GetRenderType,
MeshViewerWidget.GetExtruderColor);

View file

@ -43,6 +43,7 @@ using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication.Io;
using MatterHackers.MatterControl.PrintQueue;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.Library.Export
{
@ -149,7 +150,11 @@ namespace MatterHackers.MatterControl.Library.Export
{
try
{
GCodeFileStream gCodeFileStream = new GCodeFileStream(GCodeFile.Load(gcodeFilename, CancellationToken.None));
GCodeFileStream gCodeFileStream = new GCodeFileStream(GCodeFile.Load(gcodeFilename,
new Vector4(),
new Vector4(),
new Vector4(),
CancellationToken.None));
var printerSettings = ActiveSliceSettings.Instance;
bool addLevelingStream = printerSettings.GetValue<bool>(SettingsKey.print_leveling_enabled) && this.ApplyLeveling;

View file

@ -36,10 +36,6 @@ namespace MatterControl.Printing
{
public abstract class GCodeFile
{
private static readonly Vector4 MaxAccelerationMmPerS2 = new Vector4(1000, 1000, 100, 5000);
private static readonly Vector4 MaxVelocityMmPerS = new Vector4(500, 500, 5, 25);
private static readonly Vector4 VelocitySameAsStopMmPerS = new Vector4(8, 8, .4, 5);
#if __ANDROID__
protected const int Max32BitFileSize = 10000000; // 10 megs
#else
@ -173,7 +169,11 @@ namespace MatterControl.Printing
return false;
}
public static GCodeFile Load(string fileName, CancellationToken cancellationToken)
public static GCodeFile Load(string fileName,
Vector4 maxAccelerationMmPerS2,
Vector4 maxVelocityMmPerS,
Vector4 velocitySameAsStopMmPerS,
CancellationToken cancellationToken)
{
if (FileTooBigToLoad(fileName))
{
@ -181,7 +181,10 @@ namespace MatterControl.Printing
}
else
{
return new GCodeMemoryFile(fileName, cancellationToken);
return new GCodeMemoryFile(fileName,
maxAccelerationMmPerS2,
maxVelocityMmPerS,
velocitySameAsStopMmPerS, cancellationToken);
}
}
@ -206,20 +209,29 @@ namespace MatterControl.Printing
return stringWithNumber;
}
protected static double GetSecondsThisLine(Vector3 deltaPositionThisLine, double deltaEPositionThisLine, double feedRateMmPerMin)
// Vector4 maxAccelerationMmPerS2 = new Vector4(1000, 1000, 100, 5000);
// Vector4 maxVelocityMmPerS = new Vector4(500, 500, 5, 25);
// Vector4 velocitySameAsStopMmPerS = new Vector4(8, 8, .4, 5);
protected static double GetSecondsThisLine(Vector3 deltaPositionThisLine,
double deltaEPositionThisLine,
double feedRateMmPerMin,
Vector4 maxAccelerationMmPerS2,
Vector4 maxVelocityMmPerS,
Vector4 velocitySameAsStopMmPerS)
{
double startingVelocityMmPerS = VelocitySameAsStopMmPerS.X;
double endingVelocityMmPerS = VelocitySameAsStopMmPerS.X;
double maxVelocityMmPerS = Math.Min(feedRateMmPerMin / 60, MaxVelocityMmPerS.X);
double acceleration = MaxAccelerationMmPerS2.X;
double startingVelocityMmPerS = velocitySameAsStopMmPerS.X;
double endingVelocityMmPerS = velocitySameAsStopMmPerS.X;
double maxVelocityMmPerSx = Math.Min(feedRateMmPerMin / 60, maxVelocityMmPerS.X);
double acceleration = maxAccelerationMmPerS2.X;
double lengthOfThisMoveMm = Math.Max(deltaPositionThisLine.Length, deltaEPositionThisLine);
double distanceToMaxVelocity = GetDistanceToReachEndingVelocity(startingVelocityMmPerS, maxVelocityMmPerS, acceleration);
double distanceToMaxVelocity = GetDistanceToReachEndingVelocity(startingVelocityMmPerS, maxVelocityMmPerSx, acceleration);
if (distanceToMaxVelocity <= lengthOfThisMoveMm / 2)
{
// we will reach max velocity then run at it and then decelerate
double accelerationTime = GetTimeToAccelerateDistance(startingVelocityMmPerS, distanceToMaxVelocity, acceleration) * 2;
double runningTime = (lengthOfThisMoveMm - (distanceToMaxVelocity * 2)) / maxVelocityMmPerS;
double runningTime = (lengthOfThisMoveMm - (distanceToMaxVelocity * 2)) / maxVelocityMmPerSx;
return accelerationTime + runningTime;
}
else

View file

@ -261,11 +261,6 @@ namespace MatterControl.Printing
}
}
if (feedRateMmPerMin > 0)
{
instruction.secondsThisLine = (float)GetSecondsThisLine(deltaPositionThisLine, deltaEPositionThisLine, feedRateMmPerMin);
}
readLineCount++;
}
}

View file

@ -61,11 +61,19 @@ namespace MatterControl.Printing
this.gcodeHasExplicitLayerChangeInfo = gcodeHasExplicitLayerChangeInfo;
}
public GCodeMemoryFile(string pathAndFileName, CancellationToken cancellationToken, bool gcodeHasExplicitLayerChangeInfo = false)
public GCodeMemoryFile(string pathAndFileName,
Vector4 maxAccelerationMmPerS2,
Vector4 maxVelocityMmPerS,
Vector4 velocitySameAsStopMmPerS,
CancellationToken cancellationToken, bool gcodeHasExplicitLayerChangeInfo = false)
{
this.gcodeHasExplicitLayerChangeInfo = gcodeHasExplicitLayerChangeInfo;
var loadedFile = GCodeMemoryFile.Load(pathAndFileName, cancellationToken, null);
var loadedFile = GCodeMemoryFile.Load(pathAndFileName,
maxAccelerationMmPerS2,
maxVelocityMmPerS,
velocitySameAsStopMmPerS,
cancellationToken, null);
if (loadedFile != null)
{
this.indexOfChangeInZ = loadedFile.indexOfChangeInZ;
@ -108,18 +116,30 @@ namespace MatterControl.Printing
GCodeCommandQueue.Insert(insertIndex, printerMachineInstruction);
}
public static GCodeFile ParseGCodeString(string gcodeContents, CancellationToken cancellationToken)
public static GCodeFile ParseGCodeString(string gcodeContents,
Vector4 maxAccelerationMmPerS2,
Vector4 maxVelocityMmPerS,
Vector4 velocitySameAsStopMmPerS,
CancellationToken cancellationToken)
{
return ParseFileContents(gcodeContents, cancellationToken, null);
return ParseFileContents(gcodeContents,
maxAccelerationMmPerS2, maxVelocityMmPerS, velocitySameAsStopMmPerS, cancellationToken, null);
}
public static GCodeMemoryFile Load(Stream fileStream, CancellationToken cancellationToken, Action<double, string> progressReporter = null)
public static GCodeMemoryFile Load(Stream fileStream,
Vector4 maxAccelerationMmPerS2,
Vector4 maxVelocityMmPerS,
Vector4 velocitySameAsStopMmPerS,
CancellationToken cancellationToken,
Action<double, string> progressReporter = null)
{
try
{
using (var reader = new StreamReader(fileStream))
{
return ParseFileContents(reader.ReadToEnd(), cancellationToken, progressReporter);
return ParseFileContents(reader.ReadToEnd(),
maxAccelerationMmPerS2, maxVelocityMmPerS, velocitySameAsStopMmPerS,
cancellationToken, progressReporter);
}
}
catch (Exception e)
@ -130,7 +150,11 @@ namespace MatterControl.Printing
return null;
}
public static GCodeMemoryFile Load(string filePath, CancellationToken cancellationToken, Action<double, string> progressReporter)
public static GCodeMemoryFile Load(string filePath,
Vector4 maxAccelerationMmPerS2,
Vector4 maxVelocityMmPerS,
Vector4 velocitySameAsStopMmPerS,
CancellationToken cancellationToken, Action<double, string> progressReporter)
{
if (Path.GetExtension(filePath).ToUpper() == ".GCODE")
{
@ -138,7 +162,11 @@ namespace MatterControl.Printing
{
using (var stream = File.OpenRead(filePath))
{
return Load(stream, cancellationToken, progressReporter);
return Load(stream,
maxAccelerationMmPerS2,
maxVelocityMmPerS,
velocitySameAsStopMmPerS,
cancellationToken, progressReporter);
}
}
catch (Exception e)
@ -180,7 +208,11 @@ namespace MatterControl.Printing
return crCount + 1;
}
public static GCodeMemoryFile ParseFileContents(string gCodeString, CancellationToken cancellationToken, Action<double, string> progressReporter)
public static GCodeMemoryFile ParseFileContents(string gCodeString,
Vector4 maxAccelerationMmPerS2,
Vector4 maxVelocityMmPerS,
Vector4 velocitySameAsStopMmPerS,
CancellationToken cancellationToken, Action<double, string> progressReporter)
{
if (gCodeString == null)
{
@ -272,7 +304,10 @@ namespace MatterControl.Printing
lineIndex++;
}
loadedGCodeFile.AnalyzeGCodeLines(cancellationToken, progressReporter);
loadedGCodeFile.AnalyzeGCodeLines(cancellationToken, progressReporter,
maxAccelerationMmPerS2,
maxVelocityMmPerS,
velocitySameAsStopMmPerS);
loadTime.Stop();
Console.WriteLine("Time To Load Seconds: {0:0.00}".FormatWith(loadTime.Elapsed.TotalSeconds));
@ -280,7 +315,10 @@ namespace MatterControl.Printing
return loadedGCodeFile;
}
private void AnalyzeGCodeLines(CancellationToken cancellationToken, Action<double, string> progressReporter)
private void AnalyzeGCodeLines(CancellationToken cancellationToken, Action<double, string> progressReporter,
Vector4 maxAccelerationMmPerS2,
Vector4 maxVelocityMmPerS,
Vector4 velocitySameAsStopMmPerS)
{
double feedRateMmPerMin = 0;
Vector3 lastPrinterPosition = new Vector3();
@ -329,7 +367,8 @@ namespace MatterControl.Printing
if (feedRateMmPerMin > 0)
{
instruction.secondsThisLine = (float)GetSecondsThisLine(deltaPositionThisLine, deltaEPositionThisLine, feedRateMmPerMin);
instruction.secondsThisLine = (float)GetSecondsThisLine(deltaPositionThisLine, deltaEPositionThisLine, feedRateMmPerMin,
maxAccelerationMmPerS2, maxVelocityMmPerS, velocitySameAsStopMmPerS);
}
if (progressReporter != null && maxProgressReport.ElapsedMilliseconds > 200)

View file

@ -2140,7 +2140,11 @@ namespace MatterHackers.MatterControl.PrinterCommunication
GCodeStream firstStream = null;
if (gcodeFilename != null)
{
gCodeFileStream0 = new GCodeFileStream(GCodeFile.Load(gcodeFilename, CancellationToken.None));
gCodeFileStream0 = new GCodeFileStream(GCodeFile.Load(gcodeFilename,
new Vector4(),
new Vector4(),
new Vector4(),
CancellationToken.None));
if (this.RecoveryIsEnabled
&& activePrintTask != null) // We are resuming a failed print (do lots of interesting stuff).

View file

@ -178,7 +178,11 @@ namespace MatterHackers.MatterControl.PrintQueue
if (ActiveSliceSettings.Instance.GetValue<bool>(SettingsKey.print_leveling_enabled))
{
GCodeMemoryFile unleveledGCode = new GCodeMemoryFile(savedGcodeFileName, CancellationToken.None);
GCodeMemoryFile unleveledGCode = new GCodeMemoryFile(savedGcodeFileName,
new Vector4(),
new Vector4(),
new Vector4(),
CancellationToken.None);
for (int j = 0; j < unleveledGCode.LineCount; j++)
{

View file

@ -47,14 +47,16 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public const string active_quality_key = nameof(active_quality_key);
public const string active_theme_name = nameof(active_theme_name);
public const string auto_connect = nameof(auto_connect);
public const string backup_firmware_before_update = nameof(backup_firmware_before_update);
public const string auto_release_motors = nameof(auto_release_motors);
public const string baby_step_z_offset = nameof(baby_step_z_offset);
public const string backup_firmware_before_update = nameof(backup_firmware_before_update);
public const string baud_rate = nameof(baud_rate);
public const string bed_remove_part_temperature = nameof(bed_remove_part_temperature);
public const string bed_shape = nameof(bed_shape);
public const string bed_size = nameof(bed_size);
public const string bed_temperature = nameof(bed_temperature);
public const string build_height = nameof(build_height);
public const string calibration_files = nameof(calibration_files);
public const string cancel_gcode = nameof(cancel_gcode);
public const string com_port = nameof(com_port);
public const string connect_gcode = nameof(connect_gcode);
@ -63,7 +65,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public const string device_token = nameof(device_token);
public const string device_type = nameof(device_type);
public const string enable_network_printing = nameof(enable_network_printing);
public const string enable_retractions = nameof(enable_retractions);
public const string enable_sailfish_communication = nameof(enable_sailfish_communication);
public const string end_gcode = nameof(end_gcode);
public const string expand_thin_walls = nameof(expand_thin_walls);
public const string external_perimeter_extrusion_width = nameof(external_perimeter_extrusion_width);
public const string extruder_count = nameof(extruder_count);
@ -76,7 +80,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public const string filament_runout_sensor = nameof(filament_runout_sensor);
public const string fill_density = nameof(fill_density);
public const string fill_thin_gaps = nameof(fill_thin_gaps);
public const string infill_overlap_perimeter = nameof(infill_overlap_perimeter);
public const string first_layer_extrusion_width = nameof(first_layer_extrusion_width);
public const string first_layer_height = nameof(first_layer_height);
public const string first_layer_speed = nameof(first_layer_speed);
@ -86,29 +89,34 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public const string has_heated_bed = nameof(has_heated_bed);
public const string has_power_control = nameof(has_power_control);
public const string has_sd_card_reader = nameof(has_sd_card_reader);
public const string has_z_probe = nameof(has_z_probe);
public const string has_z_servo = nameof(has_z_servo);
public const string heat_extruder_before_homing = nameof(heat_extruder_before_homing);
public const string include_firmware_updater = nameof(include_firmware_updater);
public const string selector_ip_address = nameof(selector_ip_address);
public const string infill_overlap_perimeter = nameof(infill_overlap_perimeter);
public const string ip_address = nameof(ip_address);
public const string ip_port = nameof(ip_port);
public const string jerk_velocity = nameof(jerk_velocity);
public const string laser_speed_025 = nameof(laser_speed_025);
public const string laser_speed_100 = nameof(laser_speed_100);
public const string layer_gcode = nameof(layer_gcode);
public const string layer_height = nameof(layer_height);
public const string layer_name = nameof(layer_name);
public const string layer_to_pause = nameof(layer_to_pause);
public const string leveling_manual_positions = nameof(leveling_manual_positions);
public const string make = nameof(make);
public const string z_probe_z_offset = nameof(z_probe_z_offset);
public const string manual_movement_speeds = nameof(manual_movement_speeds);
public const string max_acceleration = nameof(max_acceleration);
public const string max_velocity = nameof(max_velocity);
public const string merge_overlapping_lines = nameof(merge_overlapping_lines);
public const string min_fan_speed = nameof(min_fan_speed);
public const string model = nameof(model);
public const string nozzle_diameter = nameof(nozzle_diameter);
public const string number_of_first_layers = nameof(number_of_first_layers);
public const string oem_profile_token = nameof(oem_profile_token);
public const string pause_gcode = nameof(pause_gcode);
public const string perimeter_start_end_overlap = nameof(perimeter_start_end_overlap);
public const string laser_speed_025 = nameof(laser_speed_025);
public const string laser_speed_100 = nameof(laser_speed_100);
public const string print_center = nameof(print_center);
public const string send_with_checksum = nameof(send_with_checksum);
public const string print_leveling_data = nameof(print_leveling_data);
public const string print_leveling_enabled = nameof(print_leveling_enabled);
public const string print_leveling_probe_start = nameof(print_leveling_probe_start);
@ -116,36 +124,31 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public const string print_leveling_solution = nameof(print_leveling_solution);
public const string printer_name = nameof(printer_name);
public const string publish_bed_image = nameof(publish_bed_image);
public const string read_regex = nameof(read_regex);
public const string recover_first_layer_speed = nameof(recover_first_layer_speed);
public const string number_of_first_layers = nameof(number_of_first_layers);
public const string recover_is_enabled = nameof(recover_is_enabled);
public const string recover_position_before_z_home = nameof(recover_position_before_z_home);
public const string auto_release_motors = nameof(auto_release_motors);
public const string resume_gcode = nameof(resume_gcode);
public const string selector_ip_address = nameof(selector_ip_address);
public const string send_with_checksum = nameof(send_with_checksum);
public const string show_reset_connection = nameof(show_reset_connection);
public const string sla_printer = nameof(sla_printer);
public const string validate_layer_height = nameof(validate_layer_height);
public const string spiral_vase = nameof(spiral_vase);
public const string start_gcode = nameof(start_gcode);
public const string end_gcode = nameof(end_gcode);
public const string write_regex = nameof(write_regex);
public const string read_regex = nameof(read_regex);
public const string temperature = nameof(temperature);
public const string temperature1 = nameof(temperature1);
public const string temperature2 = nameof(temperature2);
public const string temperature3 = nameof(temperature3);
public const string enable_retractions = nameof(enable_retractions);
public const string use_z_probe = nameof(use_z_probe);
public const string validate_layer_height = nameof(validate_layer_height);
public const string windows_driver = nameof(windows_driver);
public const string write_regex = nameof(write_regex);
public const string z_homes_to_max = nameof(z_homes_to_max);
public const string z_probe_samples = nameof(z_probe_samples);
public const string has_z_probe = nameof(has_z_probe);
public const string has_z_servo = nameof(has_z_servo);
public const string z_probe_xy_offset = nameof(z_probe_xy_offset);
public const string z_probe_z_offset = nameof(z_probe_z_offset);
public const string z_servo_depolyed_angle = nameof(z_servo_depolyed_angle);
public const string z_servo_retracted_angle = nameof(z_servo_retracted_angle);
public const string windows_driver = nameof(windows_driver);
public const string z_homes_to_max = nameof(z_homes_to_max);
public const string manual_movement_speeds = nameof(manual_movement_speeds);
public const string calibration_files = nameof(calibration_files);
}
public static class PrinterSettigsExtensions

View file

@ -99,6 +99,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
SettingsKey.model,
SettingsKey.enable_network_printing,
SettingsKey.enable_sailfish_communication,
SettingsKey.max_velocity,
SettingsKey.jerk_velocity,
SettingsKey.max_acceleration,
SettingsKey.ip_address,
SettingsKey.ip_port,

View file

@ -188,6 +188,9 @@ Printer
validate_layer_height
send_with_checksum
reset_long_extrusion
max_acceleration
max_velocity
jerk_velocity
Slicing
Slicing Options
output_only_first_layer

File diff suppressed because it is too large Load diff

@ -1 +1 @@
Subproject commit ab294e4dcf1ba05c3e9fd63aa467d91d02db028d
Subproject commit ecec8c48d63c0b35c96ca8988655d83d806ed00d