Browse Source

Merge pull request #7894 from tcm0116/2.0.x-lcd_segmented_moves

[2.0.x] Use segmented moves when moving axis from LCD
Scott Lahteine 7 years ago
parent
commit
1f05f10346
1 changed files with 88 additions and 21 deletions
  1. 88
    21
      Marlin/src/lcd/ultralcd.cpp

+ 88
- 21
Marlin/src/lcd/ultralcd.cpp View File

461
     #define manual_move_e_index 0
461
     #define manual_move_e_index 0
462
   #endif
462
   #endif
463
 
463
 
464
+  #if IS_KINEMATIC
465
+    bool processing_manual_move = false;
466
+    float manual_move_offset = 0.0;
467
+  #else
468
+    constexpr bool processing_manual_move = false;
469
+  #endif
470
+
464
   #if PIN_EXISTS(SD_DETECT)
471
   #if PIN_EXISTS(SD_DETECT)
465
     uint8_t lcd_sd_status;
472
     uint8_t lcd_sd_status;
466
   #endif
473
   #endif
2735
    * and the planner can accept one, send immediately
2742
    * and the planner can accept one, send immediately
2736
    */
2743
    */
2737
   inline void manage_manual_move() {
2744
   inline void manage_manual_move() {
2745
+
2746
+    if (processing_manual_move) return;
2747
+
2738
     if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
2748
     if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
2739
-      planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
2740
-      manual_move_axis = (int8_t)NO_AXIS;
2749
+
2750
+      #if IS_KINEMATIC
2751
+
2752
+        const float old_feedrate = feedrate_mm_s;
2753
+        feedrate_mm_s = MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]);
2754
+
2755
+        #if EXTRUDERS > 1
2756
+          const int8_t old_extruder = active_extruder;
2757
+          active_extruder = manual_move_e_index;
2758
+        #endif
2759
+
2760
+        // Set movement on a single axis
2761
+        set_destination_to_current();
2762
+        destination[manual_move_axis] += manual_move_offset;
2763
+
2764
+        // Reset for the next move
2765
+        manual_move_offset = 0.0;
2766
+        manual_move_axis = (int8_t)NO_AXIS;
2767
+
2768
+        // Set a blocking flag so no new moves can be added until all segments are done
2769
+        processing_manual_move = true;
2770
+        prepare_move_to_destination(); // will call set_current_to_destination
2771
+        processing_manual_move = false;
2772
+
2773
+        feedrate_mm_s = old_feedrate;
2774
+        #if EXTRUDERS > 1
2775
+          active_extruder = old_extruder;
2776
+        #endif
2777
+
2778
+      #else
2779
+
2780
+        planner.buffer_line_kinematic(current_position, MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
2781
+        manual_move_axis = (int8_t)NO_AXIS;
2782
+
2783
+      #endif
2741
     }
2784
     }
2742
   }
2785
   }
2743
 
2786
 
2770
   void _lcd_move_xyz(const char* name, AxisEnum axis) {
2813
   void _lcd_move_xyz(const char* name, AxisEnum axis) {
2771
     if (lcd_clicked) { return lcd_goto_previous_menu(); }
2814
     if (lcd_clicked) { return lcd_goto_previous_menu(); }
2772
     ENCODER_DIRECTION_NORMAL();
2815
     ENCODER_DIRECTION_NORMAL();
2773
-    if (encoderPosition) {
2816
+    if (encoderPosition && !processing_manual_move) {
2774
       gcode.refresh_cmd_timeout();
2817
       gcode.refresh_cmd_timeout();
2775
 
2818
 
2776
       float min = current_position[axis] - 1000,
2819
       float min = current_position[axis] - 1000,
2788
         }
2831
         }
2789
       #endif
2832
       #endif
2790
 
2833
 
2791
-      // Get the new position
2792
-      current_position[axis] += float((int32_t)encoderPosition) * move_menu_scale;
2793
-
2794
       // Delta limits XY based on the current offset from center
2834
       // Delta limits XY based on the current offset from center
2795
       // This assumes the center is 0,0
2835
       // This assumes the center is 0,0
2796
       #if ENABLED(DELTA)
2836
       #if ENABLED(DELTA)
2800
         }
2840
         }
2801
       #endif
2841
       #endif
2802
 
2842
 
2803
-      // Limit only when trying to move towards the limit
2804
-      if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
2805
-      if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
2843
+      // Get the new position
2844
+      const float diff = float((int32_t)encoderPosition) * move_menu_scale;
2845
+      #if IS_KINEMATIC
2846
+        manual_move_offset += diff;
2847
+        // Limit only when trying to move towards the limit
2848
+        if ((int32_t)encoderPosition < 0) NOLESS(manual_move_offset, min - current_position[axis]);
2849
+        if ((int32_t)encoderPosition > 0) NOMORE(manual_move_offset, max - current_position[axis]);
2850
+      #else
2851
+        current_position[axis] += diff;
2852
+        // Limit only when trying to move towards the limit
2853
+        if ((int32_t)encoderPosition < 0) NOLESS(current_position[axis], min);
2854
+        if ((int32_t)encoderPosition > 0) NOMORE(current_position[axis], max);
2855
+      #endif
2806
 
2856
 
2807
       manual_move_to_current(axis);
2857
       manual_move_to_current(axis);
2808
 
2858
 
2809
-      encoderPosition = 0;
2810
       lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2859
       lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2811
     }
2860
     }
2812
-    if (lcdDrawUpdate)
2813
-      lcd_implementation_drawedit(name, move_menu_scale >= 0.1 ? ftostr41sign(current_position[axis]) : ftostr43sign(current_position[axis]));
2861
+    encoderPosition = 0;
2862
+    if (lcdDrawUpdate && !processing_manual_move) {
2863
+      const float pos = current_position[axis]
2864
+        #if IS_KINEMATIC
2865
+          + manual_move_offset
2866
+        #endif
2867
+      ;
2868
+      lcd_implementation_drawedit(name, move_menu_scale >= 0.1 ? ftostr41sign(pos) : ftostr43sign(pos));
2869
+    }
2814
   }
2870
   }
2815
   void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
2871
   void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
2816
   void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
2872
   void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
2823
     if (lcd_clicked) { return lcd_goto_previous_menu(); }
2879
     if (lcd_clicked) { return lcd_goto_previous_menu(); }
2824
     ENCODER_DIRECTION_NORMAL();
2880
     ENCODER_DIRECTION_NORMAL();
2825
     if (encoderPosition) {
2881
     if (encoderPosition) {
2826
-      current_position[E_AXIS] += float((int32_t)encoderPosition) * move_menu_scale;
2827
-      encoderPosition = 0;
2828
-      manual_move_to_current(E_AXIS
2829
-        #if E_MANUAL > 1
2830
-          , eindex
2882
+      if (!processing_manual_move) {
2883
+        const float diff = float((int32_t)encoderPosition) * move_menu_scale;
2884
+        #if IS_KINEMATIC
2885
+          manual_move_offset += diff;
2886
+        #else
2887
+          current_position[E_AXIS] += diff;
2831
         #endif
2888
         #endif
2832
-      );
2833
-      lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2889
+        manual_move_to_current(E_AXIS
2890
+          #if E_MANUAL > 1
2891
+            , eindex
2892
+          #endif
2893
+        );
2894
+        lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
2895
+      }
2896
+      encoderPosition = 0;
2834
     }
2897
     }
2835
-    if (lcdDrawUpdate) {
2898
+    if (lcdDrawUpdate && !processing_manual_move) {
2836
       PGM_P pos_label;
2899
       PGM_P pos_label;
2837
       #if E_MANUAL == 1
2900
       #if E_MANUAL == 1
2838
         pos_label = PSTR(MSG_MOVE_E);
2901
         pos_label = PSTR(MSG_MOVE_E);
2851
           #endif // E_MANUAL > 2
2914
           #endif // E_MANUAL > 2
2852
         }
2915
         }
2853
       #endif // E_MANUAL > 1
2916
       #endif // E_MANUAL > 1
2854
-      lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]));
2917
+      lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]
2918
+        #if IS_KINEMATIC
2919
+          + manual_move_offset
2920
+        #endif
2921
+      ));
2855
     }
2922
     }
2856
   }
2923
   }
2857
 
2924
 

Loading…
Cancel
Save