diff options
author | Enrico Turri <enricoturri@seznam.cz> | 2017-12-11 16:03:29 +0300 |
---|---|---|
committer | Enrico Turri <enricoturri@seznam.cz> | 2017-12-11 16:03:29 +0300 |
commit | 34a0a2cb5e2d2ec94f9458248fa6076b4a842ee0 (patch) | |
tree | 1d5d754f5327de6e510349542fd5eb99fd3d5afc /xs/src/libslic3r | |
parent | 50a45949d1a2878e114cd5e8728275c2586a60e2 (diff) |
GCodeTimeEstimator - added process of M82 and M83 gcodes
Diffstat (limited to 'xs/src/libslic3r')
-rw-r--r-- | xs/src/libslic3r/GCodeTimeEstimator.cpp | 77 | ||||
-rw-r--r-- | xs/src/libslic3r/GCodeTimeEstimator.hpp | 22 |
2 files changed, 73 insertions, 26 deletions
diff --git a/xs/src/libslic3r/GCodeTimeEstimator.cpp b/xs/src/libslic3r/GCodeTimeEstimator.cpp index 6c0762021..d71156458 100644 --- a/xs/src/libslic3r/GCodeTimeEstimator.cpp +++ b/xs/src/libslic3r/GCodeTimeEstimator.cpp @@ -250,14 +250,24 @@ namespace Slic3r { return _state.units; } - void GCodeTimeEstimator::set_positioningType(GCodeTimeEstimator::EPositioningType type) + void GCodeTimeEstimator::set_positioning_xyz_type(GCodeTimeEstimator::EPositioningType type) { - _state.positioningType = type; + _state.positioning_xyz_type = type; } - GCodeTimeEstimator::EPositioningType GCodeTimeEstimator::get_positioningType() const + GCodeTimeEstimator::EPositioningType GCodeTimeEstimator::get_positioning_xyz_type() const { - return _state.positioningType; + return _state.positioning_xyz_type; + } + + void GCodeTimeEstimator::set_positioning_e_type(GCodeTimeEstimator::EPositioningType type) + { + _state.positioning_e_type = type; + } + + GCodeTimeEstimator::EPositioningType GCodeTimeEstimator::get_positioning_e_type() const + { + return _state.positioning_e_type; } void GCodeTimeEstimator::add_additional_time(float timeSec) @@ -279,7 +289,8 @@ namespace Slic3r { { set_units(Millimeters); set_dialect(Unknown); - set_positioningType(Absolute); + set_positioning_xyz_type(Absolute); + set_positioning_e_type(Relative); set_feedrate(DEFAULT_FEEDRATE); set_acceleration(DEFAULT_ACCELERATION); @@ -406,6 +417,16 @@ namespace Slic3r { { switch (::atoi(&line.cmd[1])) { + case 82: // Set extruder to absolute mode + { + _processM82(line); + break; + } + case 83: // Set extruder to relative mode + { + _processM83(line); + break; + } case 109: // Set Extruder Temperature and Wait { _processM109(line); @@ -439,27 +460,29 @@ namespace Slic3r { } } + // Returns the new absolute position on the given axis in dependence of the given parameters + float axis_absolute_position_from_G1_line(GCodeTimeEstimator::EAxis axis, const GCodeReader::GCodeLine& lineG1, GCodeTimeEstimator::EUnits units, GCodeTimeEstimator::EPositioningType type, float current_absolute_position) + { + float lengthsScaleFactor = (units == GCodeTimeEstimator::Inches) ? INCHES_TO_MM : 1.0f; + if (lineG1.has(AXIS_STR[axis])) + { + float ret = lineG1.get_float(AXIS_STR[axis]) * lengthsScaleFactor; + return (type == GCodeTimeEstimator::Absolute) ? ret : current_absolute_position + ret; + } + else + return current_absolute_position; + } + void GCodeTimeEstimator::_processG1(const GCodeReader::GCodeLine& line) { float lengthsScaleFactor = (get_units() == Inches) ? INCHES_TO_MM : 1.0f; - // gets position changes from line, if present + // updates axes positions from line + EUnits units = get_units(); float new_pos[Num_Axis]; - - if (get_positioningType() == Absolute) - { - for (unsigned char a = X; a < Num_Axis; ++a) - { - new_pos[a] = line.has(AXIS_STR[a]) ? line.get_float(AXIS_STR[a]) * lengthsScaleFactor : get_axis_position((EAxis)a); - } - } - else // get_positioningType() == Relative + for (unsigned char a = X; a < Num_Axis; ++a) { - for (unsigned char a = X; a < Num_Axis; ++a) - { - new_pos[a] = get_axis_position((EAxis)a); - new_pos[a] += (line.has(AXIS_STR[a]) ? line.get_float(AXIS_STR[a]) * lengthsScaleFactor : 0.0f); - } + new_pos[a] = axis_absolute_position_from_G1_line((EAxis)a, line, units, (a == E) ? get_positioning_e_type() : get_positioning_xyz_type(), get_axis_position((EAxis)a)); } // updates feedrate from line, if present @@ -682,14 +705,24 @@ namespace Slic3r { void GCodeTimeEstimator::_processG90(const GCodeReader::GCodeLine& line) { - set_positioningType(Absolute); + set_positioning_xyz_type(Absolute); } void GCodeTimeEstimator::_processG91(const GCodeReader::GCodeLine& line) { // >>>>>>>> THERE ARE DIALECT VARIANTS - set_positioningType(Relative); + set_positioning_xyz_type(Relative); + } + + void GCodeTimeEstimator::_processM82(const GCodeReader::GCodeLine& line) + { + set_positioning_e_type(Absolute); + } + + void GCodeTimeEstimator::_processM83(const GCodeReader::GCodeLine& line) + { + set_positioning_e_type(Relative); } void GCodeTimeEstimator::_processG92(const GCodeReader::GCodeLine& line) diff --git a/xs/src/libslic3r/GCodeTimeEstimator.hpp b/xs/src/libslic3r/GCodeTimeEstimator.hpp index 4f8d0b31f..36d66f435 100644 --- a/xs/src/libslic3r/GCodeTimeEstimator.hpp +++ b/xs/src/libslic3r/GCodeTimeEstimator.hpp @@ -67,7 +67,8 @@ namespace Slic3r { { EDialect dialect; EUnits units; - EPositioningType positioningType; + EPositioningType positioning_xyz_type; + EPositioningType positioning_e_type; Axis axis[Num_Axis]; float feedrate; // mm/s float acceleration; // mm/s^2 @@ -178,15 +179,19 @@ namespace Slic3r { // Adds the given gcode line void add_gcode_line(const std::string& gcode_line); - // Calculates the time estimate from gcode lines added using add_gcode_line() + // Calculates the time estimate from the gcode lines added using add_gcode_line() void calculate_time(); + // Set current position on the given axis with the given value void set_axis_position(EAxis axis, float position); + void set_axis_max_feedrate(EAxis axis, float feedrate_mm_sec); void set_axis_max_acceleration(EAxis axis, float acceleration); void set_axis_max_jerk(EAxis axis, float jerk); + // Returns current position on the given axis float get_axis_position(EAxis axis) const; + float get_axis_max_feedrate(EAxis axis) const; float get_axis_max_acceleration(EAxis axis) const; float get_axis_max_jerk(EAxis axis) const; @@ -206,8 +211,11 @@ namespace Slic3r { void set_units(EUnits units); EUnits get_units() const; - void set_positioningType(EPositioningType type); - EPositioningType get_positioningType() const; + void set_positioning_xyz_type(EPositioningType type); + EPositioningType get_positioning_xyz_type() const; + + void set_positioning_e_type(EPositioningType type); + EPositioningType get_positioning_e_type() const; void add_additional_time(float timeSec); void set_additional_time(float timeSec); @@ -257,6 +265,12 @@ namespace Slic3r { // Set Position void _processG92(const GCodeReader::GCodeLine& line); + // Set extruder to absolute mode + void _processM82(const GCodeReader::GCodeLine& line); + + // Set extruder to relative mode + void _processM83(const GCodeReader::GCodeLine& line); + // Set Extruder Temperature and Wait void _processM109(const GCodeReader::GCodeLine& line); |