diff --git a/.travis.yml b/.travis.yml index f042797d6..d869c01f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -356,7 +356,7 @@ script: # SCARA with TMC2130 and TMC2208 # - use_example_configs SCARA - - opt_enable AUTO_BED_LEVELING_BILINEAR FIX_MOUNTED_PROBE USE_ZMIN_PLUG EEPROM_SETTINGS EEPROM_CHITCHAT ULTIMAKERCONTROLLER + - opt_enable AUTO_BED_LEVELING_BILINEAR FIX_MOUNTED_PROBE USE_ZMIN_PLUG EEPROM_SETTINGS EEPROM_CHITCHAT ULTIMAKERCONTROLLER SCARA_FEEDRATE_SCALING - opt_enable_adv HAVE_TMC2130 HAVE_TMC2208 X_IS_TMC2130 Y_IS_TMC2130 Z_IS_TMC2208 E0_IS_TMC2208 - opt_enable_adv MONITOR_DRIVER_STATUS STEALTHCHOP HYBRID_THRESHOLD TMC_DEBUG SENSORLESS_HOMING TMC_Z_CALIBRATION - build_marlin diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 7be62c1f4..1795d939c 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -12848,6 +12848,20 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) { #if !UBL_SEGMENTED #if IS_KINEMATIC + #if IS_SCARA + /** + * Before raising this value, use M665 S[seg_per_sec] to decrease + * the number of segments-per-second. Default is 200. Some deltas + * do better with 160 or lower. It would be good to know how many + * segments-per-second are actually possible for SCARA on AVR. + * + * Longer segments result in less kinematic overhead + * but may produce jagged lines. Try 0.5mm, 1.0mm, and 2.0mm + * and compare the difference. + */ + #define SCARA_MIN_SEGMENT_LENGTH 0.5 + #endif + /** * Prepare a linear move in a DELTA or SCARA setup. * @@ -12892,9 +12906,9 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) { // gives the number of segments uint16_t segments = delta_segments_per_second * seconds; - // For SCARA minimum segment size is 0.25mm + // For SCARA enforce a minimum segment size #if IS_SCARA - NOMORE(segments, cartesian_mm * 4); + NOMORE(segments, cartesian_mm * (1.0 / SCARA_MIN_SEGMENT_LENGTH)); #endif // At least one segment is required @@ -12902,7 +12916,6 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) { // The approximate length of each segment const float inv_segments = 1.0 / float(segments), - cartesian_segment_mm = cartesian_mm * inv_segments, segment_distance[XYZE] = { xdiff * inv_segments, ydiff * inv_segments, @@ -12910,16 +12923,47 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) { ediff * inv_segments }; - // SERIAL_ECHOPAIR("mm=", cartesian_mm); - // SERIAL_ECHOPAIR(" seconds=", seconds); - // SERIAL_ECHOLNPAIR(" segments=", segments); - // SERIAL_ECHOLNPAIR(" segment_mm=", cartesian_segment_mm); + #if DISABLED(SCARA_FEEDRATE_SCALING) + const float cartesian_segment_mm = cartesian_mm * inv_segments; + #endif + + /* + SERIAL_ECHOPAIR("mm=", cartesian_mm); + SERIAL_ECHOPAIR(" seconds=", seconds); + SERIAL_ECHOPAIR(" segments=", segments); + #if DISABLED(SCARA_FEEDRATE_SCALING) + SERIAL_ECHOLNPAIR(" segment_mm=", cartesian_segment_mm); + #else + SERIAL_EOL(); + #endif + //*/ + + #if ENABLED(SCARA_FEEDRATE_SCALING) + // SCARA needs to scale the feed rate from mm/s to degrees/s + // i.e., Complete the angular vector in the given time. + const float segment_length = cartesian_mm * inv_segments, + inv_segment_length = 1.0 / segment_length, // 1/mm/segs + inverse_secs = inv_segment_length * _feedrate_mm_s; + + float oldA = planner.position_float[A_AXIS], + oldB = planner.position_float[B_AXIS]; + + /* + SERIAL_ECHOPGM("Scaled kinematic move: "); + SERIAL_ECHOPAIR(" segment_length (inv)=", segment_length); + SERIAL_ECHOPAIR(" (", inv_segment_length); + SERIAL_ECHOPAIR(") _feedrate_mm_s=", _feedrate_mm_s); + SERIAL_ECHOPAIR(" inverse_secs=", inverse_secs); + SERIAL_ECHOPAIR(" oldA=", oldA); + SERIAL_ECHOLNPAIR(" oldB=", oldB); + safe_delay(5); + //*/ + #endif // Get the current position as starting point float raw[XYZE]; COPY(raw, current_position); - // Calculate and execute the segments while (--segments) { @@ -12939,11 +12983,41 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) { ADJUST_DELTA(raw); // Adjust Z if bed leveling is enabled - planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], _feedrate_mm_s, active_extruder, cartesian_segment_mm); + #if ENABLED(SCARA_FEEDRATE_SCALING) + // For SCARA scale the feed rate from mm/s to degrees/s + // i.e., Complete the angular vector in the given time. + planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], raw[Z_AXIS], raw[E_AXIS], HYPOT(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB) * inverse_secs, active_extruder); + /* + SERIAL_ECHO(segments); + SERIAL_ECHOPAIR(": X=", raw[X_AXIS]); SERIAL_ECHOPAIR(" Y=", raw[Y_AXIS]); + SERIAL_ECHOPAIR(" A=", delta[A_AXIS]); SERIAL_ECHOPAIR(" B=", delta[B_AXIS]); + SERIAL_ECHOLNPAIR(" F", HYPOT(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB) * inverse_secs * 60); + safe_delay(5); + //*/ + oldA = delta[A_AXIS]; oldB = delta[B_AXIS]; + #else + planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], _feedrate_mm_s, active_extruder, cartesian_segment_mm); + #endif } // Ensure last segment arrives at target location. - planner.buffer_line_kinematic(rtarget, _feedrate_mm_s, active_extruder, cartesian_segment_mm); + #if ENABLED(SCARA_FEEDRATE_SCALING) + inverse_kinematics(rtarget); + ADJUST_DELTA(rtarget); + const float diff2 = HYPOT2(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB); + if (diff2) { + planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], rtarget[Z_AXIS], rtarget[E_AXIS], SQRT(diff2) * inverse_secs, active_extruder); + /* + SERIAL_ECHOPAIR("final: A=", delta[A_AXIS]); SERIAL_ECHOPAIR(" B=", delta[B_AXIS]); + SERIAL_ECHOPAIR(" adiff=", delta[A_AXIS] - oldA); SERIAL_ECHOPAIR(" bdiff=", delta[B_AXIS] - oldB); + SERIAL_ECHOLNPAIR(" F", (SQRT(diff2) * inverse_secs) * 60); + SERIAL_EOL(); + safe_delay(5); + //*/ + } + #else + planner.buffer_line_kinematic(rtarget, _feedrate_mm_s, active_extruder, cartesian_segment_mm); + #endif return false; // caller will update current_position } @@ -13227,6 +13301,14 @@ void prepare_move_to_destination() { millis_t next_idle_ms = millis() + 200UL; + #if ENABLED(SCARA_FEEDRATE_SCALING) + // SCARA needs to scale the feed rate from mm/s to degrees/s + const float inv_segment_length = 1.0 / (MM_PER_ARC_SEGMENT), + inverse_secs = inv_segment_length * fr_mm_s; + float oldA = planner.position_float[A_AXIS], + oldB = planner.position_float[B_AXIS]; + #endif + #if N_ARC_CORRECTION > 1 int8_t arc_recalc_count = N_ARC_CORRECTION; #endif @@ -13270,11 +13352,28 @@ void prepare_move_to_destination() { clamp_to_software_endstops(raw); - planner.buffer_line_kinematic(raw, fr_mm_s, active_extruder); + #if ENABLED(SCARA_FEEDRATE_SCALING) + // For SCARA scale the feed rate from mm/s to degrees/s + // i.e., Complete the angular vector in the given time. + inverse_kinematics(raw); + ADJUST_DELTA(raw); + planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], raw[Z_AXIS], raw[E_AXIS], HYPOT(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB) * inverse_secs, active_extruder); + oldA = delta[A_AXIS]; oldB = delta[B_AXIS]; + #else + planner.buffer_line_kinematic(raw, fr_mm_s, active_extruder); + #endif } // Ensure last segment arrives at target location. - planner.buffer_line_kinematic(cart, fr_mm_s, active_extruder); + #if ENABLED(SCARA_FEEDRATE_SCALING) + inverse_kinematics(cart); + ADJUST_DELTA(cart); + const float diff2 = HYPOT2(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB); + if (diff2) + planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], cart[Z_AXIS], cart[E_AXIS], SQRT(diff2) * inverse_secs, active_extruder); + #else + planner.buffer_line_kinematic(cart, fr_mm_s, active_extruder); + #endif // As far as the parser is concerned, the position is now == target. In reality the // motion control system might still be processing the action and the real tool position diff --git a/Marlin/example_configurations/SCARA/Configuration.h b/Marlin/example_configurations/SCARA/Configuration.h index d5fba2d20..97658bbaf 100644 --- a/Marlin/example_configurations/SCARA/Configuration.h +++ b/Marlin/example_configurations/SCARA/Configuration.h @@ -73,6 +73,7 @@ #if ENABLED(MORGAN_SCARA) || ENABLED(MAKERARM_SCARA) //#define DEBUG_SCARA_KINEMATICS + //#define SCARA_FEEDRATE_SCALING // Convert XY feedrate from mm/s to degrees/s on the fly // If movement is choppy try lowering this value #define SCARA_SEGMENTS_PER_SECOND 200 diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 94878bfb8..0ed70c3e8 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -174,8 +174,11 @@ float Planner::previous_speed[NUM_AXIS], #endif #if ENABLED(LIN_ADVANCE) - float Planner::extruder_advance_K, // Initialized by settings.load() - Planner::position_float[XYZE]; // Needed for accurate maths. Steps cannot be used! + float Planner::extruder_advance_K; // Initialized by settings.load() +#endif + +#if HAS_POSITION_FLOAT + float Planner::position_float[XYZE]; // Needed for accurate maths. Steps cannot be used! #endif #if ENABLED(ULTRA_LCD) @@ -191,7 +194,7 @@ Planner::Planner() { init(); } void Planner::init() { block_buffer_head = block_buffer_tail = 0; ZERO(position); - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT ZERO(position_float); #endif ZERO(previous_speed); @@ -734,7 +737,7 @@ void Planner::check_axes_activity() { * extruder - target extruder */ void Planner::_buffer_steps(const int32_t (&target)[XYZE] - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT , const float (&target_float)[XYZE] #endif , float fr_mm_s, const uint8_t extruder, const float &millimeters/*=0.0*/ @@ -764,7 +767,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] #if ENABLED(PREVENT_COLD_EXTRUSION) if (thermalManager.tooColdToExtrude(extruder)) { position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT position_float[E_AXIS] = target_float[E_AXIS]; #endif de = 0; // no difference @@ -775,7 +778,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] #if ENABLED(PREVENT_LENGTHY_EXTRUDE) if (labs(de * e_factor[extruder]) > (int32_t)axis_steps_per_mm[E_AXIS_N] * (EXTRUDE_MAXLENGTH)) { // It's not important to get max. extrusion length in a precision < 1mm, so save some cycles and cast to int position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT position_float[E_AXIS] = target_float[E_AXIS]; #endif de = 0; // no difference @@ -846,6 +849,10 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] block->steps[X_AXIS] = labs(da); block->steps[B_AXIS] = labs(db + dc); block->steps[C_AXIS] = labs(db - dc); + #elif IS_SCARA + block->steps[A_AXIS] = labs(da); + block->steps[B_AXIS] = labs(db); + block->steps[Z_AXIS] = labs(dc); #else // default non-h-bot planning block->steps[A_AXIS] = labs(da); @@ -881,7 +888,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] powerManager.power_on(); #endif - //enable active axes + // Enable active axes #if CORE_IS_XY if (block->steps[A_AXIS] || block->steps[B_AXIS]) { enable_X(); @@ -1452,7 +1459,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] // Update the position (only when a move was queued) static_assert(COUNT(target) > 1, "Parameter to _buffer_steps must be (&target)[XYZE]!"); COPY(position, target); - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT COPY(position_float, target_float); #endif @@ -1490,14 +1497,14 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con LROUND(e * axis_steps_per_mm[E_AXIS_N]) }; - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT const float target_float[XYZE] = { a, b, c, e }; #endif // DRYRUN prevents E moves from taking place if (DEBUGGING(DRYRUN)) { position[E_AXIS] = target[E_AXIS]; - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT position_float[E_AXIS] = e; #endif } @@ -1536,7 +1543,7 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con #define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1 const int32_t between[ABCE] = { _BETWEEN(A), _BETWEEN(B), _BETWEEN(C), _BETWEEN(E) }; - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT #define _BETWEEN_F(A) (position_float[A##_AXIS] + target_float[A##_AXIS]) * 0.5 const float between_float[ABCE] = { _BETWEEN_F(A), _BETWEEN_F(B), _BETWEEN_F(C), _BETWEEN_F(E) }; #endif @@ -1544,7 +1551,7 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con DISABLE_STEPPER_DRIVER_INTERRUPT(); _buffer_steps(between - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT , between_float #endif , fr_mm_s, extruder, millimeters * 0.5 @@ -1553,7 +1560,7 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con const uint8_t next = block_buffer_head; _buffer_steps(target - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT , target_float #endif , fr_mm_s, extruder, millimeters * 0.5 @@ -1564,7 +1571,7 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con } else _buffer_steps(target - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT , target_float #endif , fr_mm_s, extruder, millimeters @@ -1592,7 +1599,7 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c nb = position[B_AXIS] = LROUND(b * axis_steps_per_mm[B_AXIS]), nc = position[C_AXIS] = LROUND(c * axis_steps_per_mm[C_AXIS]), ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]); - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT position_float[X_AXIS] = a; position_float[Y_AXIS] = b; position_float[Z_AXIS] = c; @@ -1624,7 +1631,7 @@ void Planner::set_position_mm_kinematic(const float (&cart)[XYZE]) { void Planner::sync_from_steppers() { LOOP_XYZE(i) { position[i] = stepper.position((AxisEnum)i); - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT position_float[i] = position[i] * steps_to_mm[i #if ENABLED(DISTINCT_E_FACTORS) + (i == E_AXIS ? active_extruder : 0) @@ -1645,7 +1652,7 @@ void Planner::set_position_mm(const AxisEnum axis, const float &v) { const uint8_t axis_index = axis; #endif position[axis] = LROUND(v * axis_steps_per_mm[axis_index]); - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT position_float[axis] = v; #endif stepper.set_position(axis, v); diff --git a/Marlin/planner.h b/Marlin/planner.h index 6a76cdcaf..adebbb0f3 100644 --- a/Marlin/planner.h +++ b/Marlin/planner.h @@ -126,6 +126,8 @@ typedef struct { } block_t; +#define HAS_POSITION_FLOAT (ENABLED(LIN_ADVANCE) || ENABLED(SCARA_FEEDRATE_SCALING)) + #define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1)) class Planner { @@ -190,8 +192,11 @@ class Planner { #endif #if ENABLED(LIN_ADVANCE) - static float extruder_advance_K, - position_float[XYZE]; + static float extruder_advance_K; + #endif + + #if HAS_POSITION_FLOAT + static float position_float[XYZE]; #endif #if ENABLED(SKEW_CORRECTION) @@ -413,7 +418,7 @@ class Planner { * millimeters - the length of the movement, if known */ static void _buffer_steps(const int32_t (&target)[XYZE] - #if ENABLED(LIN_ADVANCE) + #if HAS_POSITION_FLOAT , const float (&target_float)[XYZE] #endif , float fr_mm_s, const uint8_t extruder, const float &millimeters=0.0