Selaa lähdekoodia

Allow UBL G29 and G26 to build without a probe

deram 7 vuotta sitten
vanhempi
commit
9239fcf0da
5 muutettua tiedostoa jossa 357 lisäystä ja 324 poistoa
  1. 7
    2
      .travis.yml
  2. 2
    7
      Marlin/G26_Mesh_Validation_Tool.cpp
  3. 1
    3
      Marlin/SanityCheck.h
  4. 5
    2
      Marlin/ubl.h
  5. 342
    310
      Marlin/ubl_G29.cpp

+ 7
- 2
.travis.yml Näytä tiedosto

@@ -96,13 +96,18 @@ script:
96 96
   - opt_set_adv FANMUX0_PIN 53
97 97
   - build_marlin
98 98
   #
99
-  # Test a simple build of AUTO_BED_LEVELING_UBL
99
+  # Test a probeless build of AUTO_BED_LEVELING_UBL
100 100
   #
101 101
   - restore_configs
102
-  - opt_enable AUTO_BED_LEVELING_UBL UBL_G26_MESH_EDITING ENABLE_LEVELING_FADE_HEIGHT FIX_MOUNTED_PROBE EEPROM_SETTINGS G3D_PANEL
102
+  - opt_enable AUTO_BED_LEVELING_UBL UBL_G26_MESH_EDITING ENABLE_LEVELING_FADE_HEIGHT EEPROM_SETTINGS G3D_PANEL
103 103
   - opt_enable_adv CUSTOM_USER_MENUS I2C_POSITION_ENCODERS BABYSTEPPING
104 104
   - build_marlin
105 105
   #
106
+  # And with a probe...
107
+  #
108
+  - opt_enable FIX_MOUNTED_PROBE
109
+  - build_marlin
110
+  #
106 111
   # Test a Sled Z Probe
107 112
   # ...with AUTO_BED_LEVELING_LINEAR, DEBUG_LEVELING_FEATURE, EEPROM_SETTINGS, and EEPROM_CHITCHAT
108 113
   #

+ 2
- 7
Marlin/G26_Mesh_Validation_Tool.cpp Näytä tiedosto

@@ -136,13 +136,8 @@
136 136
   extern float destination[XYZE];
137 137
   void set_destination_to_current();
138 138
   void prepare_move_to_destination();
139
-  #if AVR_AT90USB1286_FAMILY  // Teensyduino & Printrboard IDE extensions have compile errors without this
140
-    inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
141
-    inline void set_current_to_destination() { COPY(current_position, destination); }
142
-  #else
143
-    void sync_plan_position_e();
144
-    void set_current_to_destination();
145
-  #endif
139
+  inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
140
+  inline void set_current_to_destination() { COPY(current_position, destination); }
146 141
   #if ENABLED(NEWPANEL)
147 142
     void lcd_setstatusPGM(const char* const message, const int8_t level);
148 143
     void chirp_at_user();

+ 1
- 3
Marlin/SanityCheck.h Näytä tiedosto

@@ -647,9 +647,7 @@ static_assert(1 >= 0
647 647
   /**
648 648
    * Require some kind of probe for bed leveling and probe testing
649 649
    */
650
-  #if ENABLED(AUTO_BED_LEVELING_UBL)
651
-    #error "Unified Bed Leveling requires a probe: FIX_MOUNTED_PROBE, BLTOUCH, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, or Z Servo."
652
-  #elif HAS_ABL
650
+  #if HAS_ABL && DISABLED(AUTO_BED_LEVELING_UBL)
653 651
     #error "Auto Bed Leveling requires one of these: PROBE_MANUALLY, FIX_MOUNTED_PROBE, BLTOUCH, SOLENOID_PROBE, Z_PROBE_ALLEN_KEY, Z_PROBE_SLED, or a Z Servo."
654 652
   #endif
655 653
 

+ 5
- 2
Marlin/ubl.h Näytä tiedosto

@@ -91,13 +91,16 @@
91 91
                     g29_phase_value,
92 92
                     g29_repetition_cnt,
93 93
                     g29_storage_slot,
94
-                    g29_map_type,
95
-                    g29_grid_size;
94
+                    g29_map_type;
96 95
       static bool   g29_c_flag, g29_x_flag, g29_y_flag;
97 96
       static float  g29_x_pos, g29_y_pos,
98 97
                     g29_card_thickness,
99 98
                     g29_constant;
100 99
 
100
+      #if HAS_BED_PROBE
101
+        static int  g29_grid_size;
102
+      #endif
103
+
101 104
       #if ENABLED(UBL_G26_MESH_VALIDATION)
102 105
         static float   g26_extrusion_multiplier,
103 106
                        g26_retraction_multiplier,

+ 342
- 310
Marlin/ubl_G29.cpp Näytä tiedosto

@@ -64,8 +64,7 @@
64 64
          unified_bed_leveling::g29_phase_value,
65 65
          unified_bed_leveling::g29_repetition_cnt,
66 66
          unified_bed_leveling::g29_storage_slot = 0,
67
-         unified_bed_leveling::g29_map_type,
68
-         unified_bed_leveling::g29_grid_size;
67
+         unified_bed_leveling::g29_map_type;
69 68
   bool   unified_bed_leveling::g29_c_flag,
70 69
          unified_bed_leveling::g29_x_flag,
71 70
          unified_bed_leveling::g29_y_flag;
@@ -74,6 +73,10 @@
74 73
          unified_bed_leveling::g29_card_thickness = 0.0,
75 74
          unified_bed_leveling::g29_constant = 0.0;
76 75
 
76
+  #if HAS_BED_PROBE
77
+    int  unified_bed_leveling::g29_grid_size;
78
+  #endif
79
+
77 80
   /**
78 81
    *   G29: Unified Bed Leveling by Roxy
79 82
    *
@@ -309,6 +312,8 @@
309 312
       return;
310 313
     }
311 314
 
315
+    if (g29_parameter_parsing()) return; // abort if parsing the simple parameters causes a problem,
316
+
312 317
     // Check for commands that require the printer to be homed
313 318
     if (axis_unhomed_error()) {
314 319
       const int8_t p_val = parser.intval('P', -1);
@@ -316,8 +321,6 @@
316 321
         home_all_axes();
317 322
     }
318 323
 
319
-    if (g29_parameter_parsing()) return; // abort if parsing the simple parameters causes a problem,
320
-
321 324
     // Invalidate Mesh Points. This command is a little bit asymmetrical because
322 325
     // it directly specifies the repetition count and does not use the 'R' parameter.
323 326
     if (parser.seen('I')) {
@@ -380,40 +383,44 @@
380 383
       }
381 384
     }
382 385
 
383
-    if (parser.seen('J')) {
384
-      if (g29_grid_size) {  // if not 0 it is a normal n x n grid being probed
385
-        save_ubl_active_state_and_disable();
386
-        tilt_mesh_based_on_probed_grid(parser.seen('T'));
387
-        restore_ubl_active_state_and_leave();
388
-      }
389
-      else { // grid_size == 0 : A 3-Point leveling has been requested
390
-        float z3, z2, z1 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y), false, g29_verbose_level);
391
-        if (!isnan(z1)) {
392
-          z2 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_2_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_2_Y), false, g29_verbose_level);
393
-          if (!isnan(z2))
394
-            z3 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_3_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_3_Y), true, g29_verbose_level);
395
-        }
386
+    #if HAS_BED_PROBE
396 387
 
397
-        if (isnan(z1) || isnan(z2) || isnan(z3)) { // probe_pt will return NAN if unreachable
398
-          SERIAL_ERROR_START();
399
-          SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
400
-          goto LEAVE;
388
+      if (parser.seen('J')) {
389
+        if (g29_grid_size) {  // if not 0 it is a normal n x n grid being probed
390
+          save_ubl_active_state_and_disable();
391
+          tilt_mesh_based_on_probed_grid(parser.seen('T'));
392
+          restore_ubl_active_state_and_leave();
401 393
         }
394
+        else { // grid_size == 0 : A 3-Point leveling has been requested
395
+          float z3, z2, z1 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y), false, g29_verbose_level);
396
+          if (!isnan(z1)) {
397
+            z2 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_2_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_2_Y), false, g29_verbose_level);
398
+            if (!isnan(z2))
399
+              z3 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_3_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_3_Y), true, g29_verbose_level);
400
+          }
401
+
402
+          if (isnan(z1) || isnan(z2) || isnan(z3)) { // probe_pt will return NAN if unreachable
403
+            SERIAL_ERROR_START();
404
+            SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
405
+            goto LEAVE;
406
+          }
402 407
 
403
-        // Adjust z1, z2, z3 by the Mesh Height at these points. Just because they're non-zero
404
-        // doesn't mean the Mesh is tilted! (Compensate each probe point by what the Mesh says
405
-        // its height is.)
408
+          // Adjust z1, z2, z3 by the Mesh Height at these points. Just because they're non-zero
409
+          // doesn't mean the Mesh is tilted! (Compensate each probe point by what the Mesh says
410
+          // its height is.)
406 411
 
407
-        save_ubl_active_state_and_disable();
408
-        z1 -= get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y)) /* + zprobe_zoffset */ ;
409
-        z2 -= get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_2_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_2_Y)) /* + zprobe_zoffset */ ;
410
-        z3 -= get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_3_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_3_Y)) /* + zprobe_zoffset */ ;
412
+          save_ubl_active_state_and_disable();
413
+          z1 -= get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y)) /* + zprobe_zoffset */ ;
414
+          z2 -= get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_2_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_2_Y)) /* + zprobe_zoffset */ ;
415
+          z3 -= get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_3_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_3_Y)) /* + zprobe_zoffset */ ;
411 416
 
412
-        do_blocking_move_to_xy(0.5 * (UBL_MESH_MAX_X - (UBL_MESH_MIN_X)), 0.5 * (UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)));
413
-        tilt_mesh_based_on_3pts(z1, z2, z3);
414
-        restore_ubl_active_state_and_leave();
417
+          do_blocking_move_to_xy(0.5 * (UBL_MESH_MAX_X - (UBL_MESH_MIN_X)), 0.5 * (UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)));
418
+          tilt_mesh_based_on_3pts(z1, z2, z3);
419
+          restore_ubl_active_state_and_leave();
420
+        }
415 421
       }
416
-    }
422
+
423
+    #endif // HAS_BED_PROBE
417 424
 
418 425
     if (parser.seen('P')) {
419 426
       if (WITHIN(g29_phase_value, 0, 1) && state.storage_slot == -1) {
@@ -430,23 +437,27 @@
430 437
           SERIAL_PROTOCOLLNPGM("Mesh zeroed.");
431 438
           break;
432 439
 
433
-        case 1:
434
-          //
435
-          // Invalidate Entire Mesh and Automatically Probe Mesh in areas that can be reached by the probe
436
-          //
437
-          if (!parser.seen('C')) {
438
-            invalidate();
439
-            SERIAL_PROTOCOLLNPGM("Mesh invalidated. Probing mesh.");
440
-          }
441
-          if (g29_verbose_level > 1) {
442
-            SERIAL_PROTOCOLPAIR("Probing Mesh Points Closest to (", g29_x_pos);
443
-            SERIAL_PROTOCOLCHAR(',');
444
-            SERIAL_PROTOCOL(g29_y_pos);
445
-            SERIAL_PROTOCOLLNPGM(").\n");
446
-          }
447
-          probe_entire_mesh(g29_x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, g29_y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER,
448
-                            parser.seen('T'), parser.seen('E'), parser.seen('U'));
449
-          break;
440
+        #if HAS_BED_PROBE
441
+
442
+          case 1:
443
+            //
444
+            // Invalidate Entire Mesh and Automatically Probe Mesh in areas that can be reached by the probe
445
+            //
446
+            if (!parser.seen('C')) {
447
+              invalidate();
448
+              SERIAL_PROTOCOLLNPGM("Mesh invalidated. Probing mesh.");
449
+            }
450
+            if (g29_verbose_level > 1) {
451
+              SERIAL_PROTOCOLPAIR("Probing Mesh Points Closest to (", g29_x_pos);
452
+              SERIAL_PROTOCOLCHAR(',');
453
+              SERIAL_PROTOCOL(g29_y_pos);
454
+              SERIAL_PROTOCOLLNPGM(").\n");
455
+            }
456
+            probe_entire_mesh(g29_x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, g29_y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER,
457
+                              parser.seen('T'), parser.seen('E'), parser.seen('U'));
458
+            break;
459
+
460
+        #endif // HAS_BED_PROBE
450 461
 
451 462
         case 2: {
452 463
           #if ENABLED(NEWPANEL)
@@ -775,159 +786,161 @@
775 786
           z_values[x][y] += g29_constant;
776 787
   }
777 788
 
778
-  /**
779
-   * Probe all invalidated locations of the mesh that can be reached by the probe.
780
-   * This attempts to fill in locations closest to the nozzle's start location first.
781
-   */
782
-  void unified_bed_leveling::probe_entire_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map, const bool stow_probe, bool close_or_far) {
783
-    mesh_index_pair location;
784
-
785
-    has_control_of_lcd_panel = true;
786
-    save_ubl_active_state_and_disable();   // we don't do bed level correction because we want the raw data when we probe
787
-    DEPLOY_PROBE();
788
-
789
-    uint16_t max_iterations = GRID_MAX_POINTS;
790
-
791
-    do {
792
-      #if ENABLED(NEWPANEL)
793
-        if (ubl_lcd_clicked()) {
794
-          SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
795
-          lcd_quick_feedback();
796
-          STOW_PROBE();
797
-          while (ubl_lcd_clicked()) idle();
798
-          has_control_of_lcd_panel = false;
799
-          restore_ubl_active_state_and_leave();
800
-          safe_delay(50);  // Debounce the Encoder wheel
801
-          return;
802
-        }
803
-      #endif
804
-
805
-      location = find_closest_mesh_point_of_type(INVALID, lx, ly, USE_PROBE_AS_REFERENCE, NULL, close_or_far);
806
-
807
-      if (location.x_index >= 0) {    // mesh point found and is reachable by probe
808
-        const float rawx = mesh_index_to_xpos(location.x_index),
809
-                    rawy = mesh_index_to_ypos(location.y_index);
789
+  #if HAS_BED_PROBE
790
+    /**
791
+     * Probe all invalidated locations of the mesh that can be reached by the probe.
792
+     * This attempts to fill in locations closest to the nozzle's start location first.
793
+     */
794
+    void unified_bed_leveling::probe_entire_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map, const bool stow_probe, bool close_or_far) {
795
+      mesh_index_pair location;
810 796
 
811
-        const float measured_z = probe_pt(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy), stow_probe, g29_verbose_level); // TODO: Needs error handling
812
-        z_values[location.x_index][location.y_index] = measured_z;
813
-      }
797
+      has_control_of_lcd_panel = true;
798
+      save_ubl_active_state_and_disable();   // we don't do bed level correction because we want the raw data when we probe
799
+      DEPLOY_PROBE();
814 800
 
815
-      if (do_ubl_mesh_map) display_map(g29_map_type);
801
+      uint16_t max_iterations = GRID_MAX_POINTS;
816 802
 
817
-    } while (location.x_index >= 0 && --max_iterations);
803
+      do {
804
+        #if ENABLED(NEWPANEL)
805
+          if (ubl_lcd_clicked()) {
806
+            SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
807
+            lcd_quick_feedback();
808
+            STOW_PROBE();
809
+            while (ubl_lcd_clicked()) idle();
810
+            has_control_of_lcd_panel = false;
811
+            restore_ubl_active_state_and_leave();
812
+            safe_delay(50);  // Debounce the Encoder wheel
813
+            return;
814
+          }
815
+        #endif
818 816
 
819
-    STOW_PROBE();
820
-    restore_ubl_active_state_and_leave();
817
+        location = find_closest_mesh_point_of_type(INVALID, lx, ly, USE_PROBE_AS_REFERENCE, NULL, close_or_far);
821 818
 
822
-    do_blocking_move_to_xy(
823
-      constrain(lx - (X_PROBE_OFFSET_FROM_EXTRUDER), UBL_MESH_MIN_X, UBL_MESH_MAX_X),
824
-      constrain(ly - (Y_PROBE_OFFSET_FROM_EXTRUDER), UBL_MESH_MIN_Y, UBL_MESH_MAX_Y)
825
-    );
826
-  }
819
+        if (location.x_index >= 0) {    // mesh point found and is reachable by probe
820
+          const float rawx = mesh_index_to_xpos(location.x_index),
821
+                      rawy = mesh_index_to_ypos(location.y_index);
827 822
 
828
-  void unified_bed_leveling::tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3) {
829
-    matrix_3x3 rotation;
830
-    vector_3 v1 = vector_3( (UBL_PROBE_PT_1_X - UBL_PROBE_PT_2_X),
831
-                            (UBL_PROBE_PT_1_Y - UBL_PROBE_PT_2_Y),
832
-                            (z1 - z2) ),
823
+          const float measured_z = probe_pt(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy), stow_probe, g29_verbose_level); // TODO: Needs error handling
824
+          z_values[location.x_index][location.y_index] = measured_z;
825
+        }
833 826
 
834
-             v2 = vector_3( (UBL_PROBE_PT_3_X - UBL_PROBE_PT_2_X),
835
-                            (UBL_PROBE_PT_3_Y - UBL_PROBE_PT_2_Y),
836
-                            (z3 - z2) ),
827
+        if (do_ubl_mesh_map) display_map(g29_map_type);
837 828
 
838
-             normal = vector_3::cross(v1, v2);
829
+      } while (location.x_index >= 0 && --max_iterations);
839 830
 
840
-    normal = normal.get_normal();
831
+      STOW_PROBE();
832
+      restore_ubl_active_state_and_leave();
841 833
 
842
-    /**
843
-     * This vector is normal to the tilted plane.
844
-     * However, we don't know its direction. We need it to point up. So if
845
-     * Z is negative, we need to invert the sign of all components of the vector
846
-     */
847
-    if (normal.z < 0.0) {
848
-      normal.x = -normal.x;
849
-      normal.y = -normal.y;
850
-      normal.z = -normal.z;
834
+      do_blocking_move_to_xy(
835
+        constrain(lx - (X_PROBE_OFFSET_FROM_EXTRUDER), UBL_MESH_MIN_X, UBL_MESH_MAX_X),
836
+        constrain(ly - (Y_PROBE_OFFSET_FROM_EXTRUDER), UBL_MESH_MIN_Y, UBL_MESH_MAX_Y)
837
+      );
851 838
     }
852 839
 
853
-    rotation = matrix_3x3::create_look_at(vector_3(normal.x, normal.y, 1));
854
-
855
-    if (g29_verbose_level > 2) {
856
-      SERIAL_ECHOPGM("bed plane normal = [");
857
-      SERIAL_PROTOCOL_F(normal.x, 7);
858
-      SERIAL_PROTOCOLCHAR(',');
859
-      SERIAL_PROTOCOL_F(normal.y, 7);
860
-      SERIAL_PROTOCOLCHAR(',');
861
-      SERIAL_PROTOCOL_F(normal.z, 7);
862
-      SERIAL_ECHOLNPGM("]");
863
-      rotation.debug(PSTR("rotation matrix:"));
864
-    }
840
+    void unified_bed_leveling::tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3) {
841
+      matrix_3x3 rotation;
842
+      vector_3 v1 = vector_3( (UBL_PROBE_PT_1_X - UBL_PROBE_PT_2_X),
843
+                              (UBL_PROBE_PT_1_Y - UBL_PROBE_PT_2_Y),
844
+                              (z1 - z2) ),
845
+
846
+               v2 = vector_3( (UBL_PROBE_PT_3_X - UBL_PROBE_PT_2_X),
847
+                              (UBL_PROBE_PT_3_Y - UBL_PROBE_PT_2_Y),
848
+                              (z3 - z2) ),
849
+
850
+               normal = vector_3::cross(v1, v2);
851
+
852
+      normal = normal.get_normal();
853
+
854
+      /**
855
+       * This vector is normal to the tilted plane.
856
+       * However, we don't know its direction. We need it to point up. So if
857
+       * Z is negative, we need to invert the sign of all components of the vector
858
+       */
859
+      if (normal.z < 0.0) {
860
+        normal.x = -normal.x;
861
+        normal.y = -normal.y;
862
+        normal.z = -normal.z;
863
+      }
865 864
 
866
-    //
867
-    // All of 3 of these points should give us the same d constant
868
-    //
865
+      rotation = matrix_3x3::create_look_at(vector_3(normal.x, normal.y, 1));
869 866
 
870
-    float t = normal.x * (UBL_PROBE_PT_1_X) + normal.y * (UBL_PROBE_PT_1_Y),
871
-          d = t + normal.z * z1;
867
+      if (g29_verbose_level > 2) {
868
+        SERIAL_ECHOPGM("bed plane normal = [");
869
+        SERIAL_PROTOCOL_F(normal.x, 7);
870
+        SERIAL_PROTOCOLCHAR(',');
871
+        SERIAL_PROTOCOL_F(normal.y, 7);
872
+        SERIAL_PROTOCOLCHAR(',');
873
+        SERIAL_PROTOCOL_F(normal.z, 7);
874
+        SERIAL_ECHOLNPGM("]");
875
+        rotation.debug(PSTR("rotation matrix:"));
876
+      }
872 877
 
873
-    if (g29_verbose_level>2) {
874
-      SERIAL_ECHOPGM("D constant: ");
875
-      SERIAL_PROTOCOL_F(d, 7);
876
-      SERIAL_ECHOLNPGM(" ");
877
-    }
878
+      //
879
+      // All of 3 of these points should give us the same d constant
880
+      //
878 881
 
879
-    #if ENABLED(DEBUG_LEVELING_FEATURE)
880
-      if (DEBUGGING(LEVELING)) {
881
-        SERIAL_ECHOPGM("d from 1st point: ");
882
-        SERIAL_ECHO_F(d, 6);
883
-        SERIAL_EOL();
884
-        t = normal.x * (UBL_PROBE_PT_2_X) + normal.y * (UBL_PROBE_PT_2_Y);
885
-        d = t + normal.z * z2;
886
-        SERIAL_ECHOPGM("d from 2nd point: ");
887
-        SERIAL_ECHO_F(d, 6);
888
-        SERIAL_EOL();
889
-        t = normal.x * (UBL_PROBE_PT_3_X) + normal.y * (UBL_PROBE_PT_3_Y);
890
-        d = t + normal.z * z3;
891
-        SERIAL_ECHOPGM("d from 3rd point: ");
892
-        SERIAL_ECHO_F(d, 6);
893
-        SERIAL_EOL();
882
+      float t = normal.x * (UBL_PROBE_PT_1_X) + normal.y * (UBL_PROBE_PT_1_Y),
883
+            d = t + normal.z * z1;
884
+
885
+      if (g29_verbose_level>2) {
886
+        SERIAL_ECHOPGM("D constant: ");
887
+        SERIAL_PROTOCOL_F(d, 7);
888
+        SERIAL_ECHOLNPGM(" ");
894 889
       }
895
-    #endif
896 890
 
897
-    for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
898
-      for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
899
-        float x_tmp = mesh_index_to_xpos(i),
900
-              y_tmp = mesh_index_to_ypos(j),
901
-              z_tmp = z_values[i][j];
902
-        #if ENABLED(DEBUG_LEVELING_FEATURE)
903
-          if (DEBUGGING(LEVELING)) {
904
-            SERIAL_ECHOPGM("before rotation = [");
905
-            SERIAL_PROTOCOL_F(x_tmp, 7);
906
-            SERIAL_PROTOCOLCHAR(',');
907
-            SERIAL_PROTOCOL_F(y_tmp, 7);
908
-            SERIAL_PROTOCOLCHAR(',');
909
-            SERIAL_PROTOCOL_F(z_tmp, 7);
910
-            SERIAL_ECHOPGM("]   ---> ");
911
-            safe_delay(20);
912
-          }
913
-        #endif
914
-        apply_rotation_xyz(rotation, x_tmp, y_tmp, z_tmp);
915
-        #if ENABLED(DEBUG_LEVELING_FEATURE)
916
-          if (DEBUGGING(LEVELING)) {
917
-            SERIAL_ECHOPGM("after rotation = [");
918
-            SERIAL_PROTOCOL_F(x_tmp, 7);
919
-            SERIAL_PROTOCOLCHAR(',');
920
-            SERIAL_PROTOCOL_F(y_tmp, 7);
921
-            SERIAL_PROTOCOLCHAR(',');
922
-            SERIAL_PROTOCOL_F(z_tmp, 7);
923
-            SERIAL_ECHOLNPGM("]");
924
-            safe_delay(55);
925
-          }
926
-        #endif
927
-        z_values[i][j] += z_tmp - d;
891
+      #if ENABLED(DEBUG_LEVELING_FEATURE)
892
+        if (DEBUGGING(LEVELING)) {
893
+          SERIAL_ECHOPGM("d from 1st point: ");
894
+          SERIAL_ECHO_F(d, 6);
895
+          SERIAL_EOL();
896
+          t = normal.x * (UBL_PROBE_PT_2_X) + normal.y * (UBL_PROBE_PT_2_Y);
897
+          d = t + normal.z * z2;
898
+          SERIAL_ECHOPGM("d from 2nd point: ");
899
+          SERIAL_ECHO_F(d, 6);
900
+          SERIAL_EOL();
901
+          t = normal.x * (UBL_PROBE_PT_3_X) + normal.y * (UBL_PROBE_PT_3_Y);
902
+          d = t + normal.z * z3;
903
+          SERIAL_ECHOPGM("d from 3rd point: ");
904
+          SERIAL_ECHO_F(d, 6);
905
+          SERIAL_EOL();
906
+        }
907
+      #endif
908
+
909
+      for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
910
+        for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
911
+          float x_tmp = mesh_index_to_xpos(i),
912
+                y_tmp = mesh_index_to_ypos(j),
913
+                z_tmp = z_values[i][j];
914
+          #if ENABLED(DEBUG_LEVELING_FEATURE)
915
+            if (DEBUGGING(LEVELING)) {
916
+              SERIAL_ECHOPGM("before rotation = [");
917
+              SERIAL_PROTOCOL_F(x_tmp, 7);
918
+              SERIAL_PROTOCOLCHAR(',');
919
+              SERIAL_PROTOCOL_F(y_tmp, 7);
920
+              SERIAL_PROTOCOLCHAR(',');
921
+              SERIAL_PROTOCOL_F(z_tmp, 7);
922
+              SERIAL_ECHOPGM("]   ---> ");
923
+              safe_delay(20);
924
+            }
925
+          #endif
926
+          apply_rotation_xyz(rotation, x_tmp, y_tmp, z_tmp);
927
+          #if ENABLED(DEBUG_LEVELING_FEATURE)
928
+            if (DEBUGGING(LEVELING)) {
929
+              SERIAL_ECHOPGM("after rotation = [");
930
+              SERIAL_PROTOCOL_F(x_tmp, 7);
931
+              SERIAL_PROTOCOLCHAR(',');
932
+              SERIAL_PROTOCOL_F(y_tmp, 7);
933
+              SERIAL_PROTOCOLCHAR(',');
934
+              SERIAL_PROTOCOL_F(z_tmp, 7);
935
+              SERIAL_ECHOLNPGM("]");
936
+              safe_delay(55);
937
+            }
938
+          #endif
939
+          z_values[i][j] += z_tmp - d;
940
+        }
928 941
       }
929 942
     }
930
-  }
943
+  #endif // HAS_BED_PROBE
931 944
 
932 945
   #if ENABLED(NEWPANEL)
933 946
     float unified_bed_leveling::measure_point_with_encoder() {
@@ -1079,7 +1092,7 @@
1079 1092
       do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
1080 1093
       do_blocking_move_to_xy(lx, ly);
1081 1094
     }
1082
-  #endif
1095
+  #endif // NEWPANEL
1083 1096
 
1084 1097
   bool unified_bed_leveling::g29_parameter_parsing() {
1085 1098
     bool err_flag = false;
@@ -1113,19 +1126,34 @@
1113 1126
     }
1114 1127
 
1115 1128
     if (parser.seen('P')) {
1116
-      g29_phase_value = parser.value_int();
1117
-      if (!WITHIN(g29_phase_value, 0, 6)) {
1118
-        SERIAL_PROTOCOLLNPGM("?(P)hase value invalid (0-6).\n");
1119
-        err_flag = true;
1120
-      }
1129
+      const int pv = parser.value_int();
1130
+      #if !HAS_BED_PROBE
1131
+        if (pv == 1) {
1132
+          SERIAL_PROTOCOLLNPGM("G29 P1 requires a probe.\n");
1133
+          err_flag = true;
1134
+        }
1135
+        else
1136
+      #endif
1137
+        {
1138
+          g29_phase_value = pv;
1139
+          if (!WITHIN(g29_phase_value, 0, 6)) {
1140
+            SERIAL_PROTOCOLLNPGM("?(P)hase value invalid (0-6).\n");
1141
+            err_flag = true;
1142
+          }
1143
+        }
1121 1144
     }
1122 1145
 
1123 1146
     if (parser.seen('J')) {
1124
-      g29_grid_size = parser.has_value() ? parser.value_int() : 0;
1125
-      if (g29_grid_size && !WITHIN(g29_grid_size, 2, 9)) {
1126
-        SERIAL_PROTOCOLLNPGM("?Invalid grid size (J) specified (2-9).\n");
1147
+      #if HAS_BED_PROBE
1148
+        g29_grid_size = parser.has_value() ? parser.value_int() : 0;
1149
+        if (g29_grid_size && !WITHIN(g29_grid_size, 2, 9)) {
1150
+          SERIAL_PROTOCOLLNPGM("?Invalid grid size (J) specified (2-9).\n");
1151
+          err_flag = true;
1152
+        }
1153
+      #else
1154
+        SERIAL_PROTOCOLLNPGM("G29 J action requires a probe.\n");
1127 1155
         err_flag = true;
1128
-      }
1156
+      #endif
1129 1157
     }
1130 1158
 
1131 1159
     if (g29_x_flag != g29_y_flag) {
@@ -1625,128 +1653,66 @@
1625 1653
     }
1626 1654
   }
1627 1655
 
1628
-  void unified_bed_leveling::tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map) {
1629
-    constexpr int16_t x_min = max(MIN_PROBE_X, UBL_MESH_MIN_X),
1630
-                      x_max = min(MAX_PROBE_X, UBL_MESH_MAX_X),
1631
-                      y_min = max(MIN_PROBE_Y, UBL_MESH_MIN_Y),
1632
-                      y_max = min(MAX_PROBE_Y, UBL_MESH_MAX_Y);
1633
-
1634
-    const float dx = float(x_max - x_min) / (g29_grid_size - 1.0),
1635
-                dy = float(y_max - y_min) / (g29_grid_size - 1.0);
1636
-
1637
-    struct linear_fit_data lsf_results;
1638
-    incremental_LSF_reset(&lsf_results);
1639
-
1640
-    bool zig_zag = false;
1641
-    for (uint8_t ix = 0; ix < g29_grid_size; ix++) {
1642
-      const float x = float(x_min) + ix * dx;
1643
-      for (int8_t iy = 0; iy < g29_grid_size; iy++) {
1644
-        const float y = float(y_min) + dy * (zig_zag ? g29_grid_size - 1 - iy : iy);
1645
-        float measured_z = probe_pt(LOGICAL_X_POSITION(x), LOGICAL_Y_POSITION(y), parser.seen('E'), g29_verbose_level); // TODO: Needs error handling
1646
-        #if ENABLED(DEBUG_LEVELING_FEATURE)
1647
-          if (DEBUGGING(LEVELING)) {
1648
-            SERIAL_CHAR('(');
1649
-            SERIAL_PROTOCOL_F(x, 7);
1650
-            SERIAL_CHAR(',');
1651
-            SERIAL_PROTOCOL_F(y, 7);
1652
-            SERIAL_ECHOPGM(")   logical: ");
1653
-            SERIAL_CHAR('(');
1654
-            SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(x), 7);
1655
-            SERIAL_CHAR(',');
1656
-            SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(y), 7);
1657
-            SERIAL_ECHOPGM(")   measured: ");
1658
-            SERIAL_PROTOCOL_F(measured_z, 7);
1659
-            SERIAL_ECHOPGM("   correction: ");
1660
-            SERIAL_PROTOCOL_F(get_z_correction(LOGICAL_X_POSITION(x), LOGICAL_Y_POSITION(y)), 7);
1661
-          }
1662
-        #endif
1656
+  #if HAS_BED_PROBE
1663 1657
 
1664
-        measured_z -= get_z_correction(LOGICAL_X_POSITION(x), LOGICAL_Y_POSITION(y)) /* + zprobe_zoffset */ ;
1665
-
1666
-        #if ENABLED(DEBUG_LEVELING_FEATURE)
1667
-          if (DEBUGGING(LEVELING)) {
1668
-            SERIAL_ECHOPGM("   final >>>---> ");
1669
-            SERIAL_PROTOCOL_F(measured_z, 7);
1670
-            SERIAL_EOL();
1671
-          }
1672
-        #endif
1673
-
1674
-        incremental_LSF(&lsf_results, x, y, measured_z);
1675
-      }
1676
-
1677
-      zig_zag ^= true;
1678
-    }
1679
-
1680
-    if (finish_incremental_LSF(&lsf_results)) {
1681
-      SERIAL_ECHOPGM("Could not complete LSF!");
1682
-      return;
1683
-    }
1658
+    void unified_bed_leveling::tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map) {
1659
+      constexpr int16_t x_min = max(MIN_PROBE_X, UBL_MESH_MIN_X),
1660
+                        x_max = min(MAX_PROBE_X, UBL_MESH_MAX_X),
1661
+                        y_min = max(MIN_PROBE_Y, UBL_MESH_MIN_Y),
1662
+                        y_max = min(MAX_PROBE_Y, UBL_MESH_MAX_Y);
1684 1663
 
1685
-    if (g29_verbose_level > 3) {
1686
-      SERIAL_ECHOPGM("LSF Results A=");
1687
-      SERIAL_PROTOCOL_F(lsf_results.A, 7);
1688
-      SERIAL_ECHOPGM("  B=");
1689
-      SERIAL_PROTOCOL_F(lsf_results.B, 7);
1690
-      SERIAL_ECHOPGM("  D=");
1691
-      SERIAL_PROTOCOL_F(lsf_results.D, 7);
1692
-      SERIAL_EOL();
1693
-    }
1664
+      const float dx = float(x_max - x_min) / (g29_grid_size - 1.0),
1665
+                  dy = float(y_max - y_min) / (g29_grid_size - 1.0);
1694 1666
 
1695
-    vector_3 normal = vector_3(lsf_results.A, lsf_results.B, 1.0000).get_normal();
1667
+      struct linear_fit_data lsf_results;
1668
+      incremental_LSF_reset(&lsf_results);
1669
+
1670
+      bool zig_zag = false;
1671
+      for (uint8_t ix = 0; ix < g29_grid_size; ix++) {
1672
+        const float x = float(x_min) + ix * dx;
1673
+        for (int8_t iy = 0; iy < g29_grid_size; iy++) {
1674
+          const float y = float(y_min) + dy * (zig_zag ? g29_grid_size - 1 - iy : iy);
1675
+          float measured_z = probe_pt(LOGICAL_X_POSITION(x), LOGICAL_Y_POSITION(y), parser.seen('E'), g29_verbose_level); // TODO: Needs error handling
1676
+          #if ENABLED(DEBUG_LEVELING_FEATURE)
1677
+            if (DEBUGGING(LEVELING)) {
1678
+              SERIAL_CHAR('(');
1679
+              SERIAL_PROTOCOL_F(x, 7);
1680
+              SERIAL_CHAR(',');
1681
+              SERIAL_PROTOCOL_F(y, 7);
1682
+              SERIAL_ECHOPGM(")   logical: ");
1683
+              SERIAL_CHAR('(');
1684
+              SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(x), 7);
1685
+              SERIAL_CHAR(',');
1686
+              SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(y), 7);
1687
+              SERIAL_ECHOPGM(")   measured: ");
1688
+              SERIAL_PROTOCOL_F(measured_z, 7);
1689
+              SERIAL_ECHOPGM("   correction: ");
1690
+              SERIAL_PROTOCOL_F(get_z_correction(LOGICAL_X_POSITION(x), LOGICAL_Y_POSITION(y)), 7);
1691
+            }
1692
+          #endif
1696 1693
 
1697
-    if (g29_verbose_level > 2) {
1698
-      SERIAL_ECHOPGM("bed plane normal = [");
1699
-      SERIAL_PROTOCOL_F(normal.x, 7);
1700
-      SERIAL_PROTOCOLCHAR(',');
1701
-      SERIAL_PROTOCOL_F(normal.y, 7);
1702
-      SERIAL_PROTOCOLCHAR(',');
1703
-      SERIAL_PROTOCOL_F(normal.z, 7);
1704
-      SERIAL_ECHOLNPGM("]");
1705
-    }
1694
+          measured_z -= get_z_correction(LOGICAL_X_POSITION(x), LOGICAL_Y_POSITION(y)) /* + zprobe_zoffset */ ;
1706 1695
 
1707
-    matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
1696
+          #if ENABLED(DEBUG_LEVELING_FEATURE)
1697
+            if (DEBUGGING(LEVELING)) {
1698
+              SERIAL_ECHOPGM("   final >>>---> ");
1699
+              SERIAL_PROTOCOL_F(measured_z, 7);
1700
+              SERIAL_EOL();
1701
+            }
1702
+          #endif
1708 1703
 
1709
-    for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1710
-      for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1711
-        float x_tmp = mesh_index_to_xpos(i),
1712
-              y_tmp = mesh_index_to_ypos(j),
1713
-              z_tmp = z_values[i][j];
1714
-
1715
-        #if ENABLED(DEBUG_LEVELING_FEATURE)
1716
-          if (DEBUGGING(LEVELING)) {
1717
-            SERIAL_ECHOPGM("before rotation = [");
1718
-            SERIAL_PROTOCOL_F(x_tmp, 7);
1719
-            SERIAL_PROTOCOLCHAR(',');
1720
-            SERIAL_PROTOCOL_F(y_tmp, 7);
1721
-            SERIAL_PROTOCOLCHAR(',');
1722
-            SERIAL_PROTOCOL_F(z_tmp, 7);
1723
-            SERIAL_ECHOPGM("]   ---> ");
1724
-            safe_delay(20);
1725
-          }
1726
-        #endif
1704
+          incremental_LSF(&lsf_results, x, y, measured_z);
1705
+        }
1727 1706
 
1728
-        apply_rotation_xyz(rotation, x_tmp, y_tmp, z_tmp);
1729
-
1730
-        #if ENABLED(DEBUG_LEVELING_FEATURE)
1731
-          if (DEBUGGING(LEVELING)) {
1732
-            SERIAL_ECHOPGM("after rotation = [");
1733
-            SERIAL_PROTOCOL_F(x_tmp, 7);
1734
-            SERIAL_PROTOCOLCHAR(',');
1735
-            SERIAL_PROTOCOL_F(y_tmp, 7);
1736
-            SERIAL_PROTOCOLCHAR(',');
1737
-            SERIAL_PROTOCOL_F(z_tmp, 7);
1738
-            SERIAL_ECHOLNPGM("]");
1739
-            safe_delay(55);
1740
-          }
1741
-        #endif
1707
+        zig_zag ^= true;
1708
+      }
1742 1709
 
1743
-        z_values[i][j] += z_tmp - lsf_results.D;
1710
+      if (finish_incremental_LSF(&lsf_results)) {
1711
+        SERIAL_ECHOPGM("Could not complete LSF!");
1712
+        return;
1744 1713
       }
1745
-    }
1746 1714
 
1747
-    #if ENABLED(DEBUG_LEVELING_FEATURE)
1748
-      if (DEBUGGING(LEVELING)) {
1749
-        rotation.debug(PSTR("rotation matrix:"));
1715
+      if (g29_verbose_level > 3) {
1750 1716
         SERIAL_ECHOPGM("LSF Results A=");
1751 1717
         SERIAL_PROTOCOL_F(lsf_results.A, 7);
1752 1718
         SERIAL_ECHOPGM("  B=");
@@ -1754,21 +1720,87 @@
1754 1720
         SERIAL_ECHOPGM("  D=");
1755 1721
         SERIAL_PROTOCOL_F(lsf_results.D, 7);
1756 1722
         SERIAL_EOL();
1757
-        safe_delay(55);
1723
+      }
1758 1724
 
1725
+      vector_3 normal = vector_3(lsf_results.A, lsf_results.B, 1.0000).get_normal();
1726
+
1727
+      if (g29_verbose_level > 2) {
1759 1728
         SERIAL_ECHOPGM("bed plane normal = [");
1760 1729
         SERIAL_PROTOCOL_F(normal.x, 7);
1761 1730
         SERIAL_PROTOCOLCHAR(',');
1762 1731
         SERIAL_PROTOCOL_F(normal.y, 7);
1763 1732
         SERIAL_PROTOCOLCHAR(',');
1764 1733
         SERIAL_PROTOCOL_F(normal.z, 7);
1765
-        SERIAL_ECHOPGM("]\n");
1766
-        SERIAL_EOL();
1734
+        SERIAL_ECHOLNPGM("]");
1767 1735
       }
1768
-    #endif
1769 1736
 
1770
-    if (do_ubl_mesh_map) display_map(g29_map_type);
1771
-  }
1737
+      matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
1738
+
1739
+      for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1740
+        for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1741
+          float x_tmp = mesh_index_to_xpos(i),
1742
+                y_tmp = mesh_index_to_ypos(j),
1743
+                z_tmp = z_values[i][j];
1744
+
1745
+          #if ENABLED(DEBUG_LEVELING_FEATURE)
1746
+            if (DEBUGGING(LEVELING)) {
1747
+              SERIAL_ECHOPGM("before rotation = [");
1748
+              SERIAL_PROTOCOL_F(x_tmp, 7);
1749
+              SERIAL_PROTOCOLCHAR(',');
1750
+              SERIAL_PROTOCOL_F(y_tmp, 7);
1751
+              SERIAL_PROTOCOLCHAR(',');
1752
+              SERIAL_PROTOCOL_F(z_tmp, 7);
1753
+              SERIAL_ECHOPGM("]   ---> ");
1754
+              safe_delay(20);
1755
+            }
1756
+          #endif
1757
+
1758
+          apply_rotation_xyz(rotation, x_tmp, y_tmp, z_tmp);
1759
+
1760
+          #if ENABLED(DEBUG_LEVELING_FEATURE)
1761
+            if (DEBUGGING(LEVELING)) {
1762
+              SERIAL_ECHOPGM("after rotation = [");
1763
+              SERIAL_PROTOCOL_F(x_tmp, 7);
1764
+              SERIAL_PROTOCOLCHAR(',');
1765
+              SERIAL_PROTOCOL_F(y_tmp, 7);
1766
+              SERIAL_PROTOCOLCHAR(',');
1767
+              SERIAL_PROTOCOL_F(z_tmp, 7);
1768
+              SERIAL_ECHOLNPGM("]");
1769
+              safe_delay(55);
1770
+            }
1771
+          #endif
1772
+
1773
+          z_values[i][j] += z_tmp - lsf_results.D;
1774
+        }
1775
+      }
1776
+
1777
+      #if ENABLED(DEBUG_LEVELING_FEATURE)
1778
+        if (DEBUGGING(LEVELING)) {
1779
+          rotation.debug(PSTR("rotation matrix:"));
1780
+          SERIAL_ECHOPGM("LSF Results A=");
1781
+          SERIAL_PROTOCOL_F(lsf_results.A, 7);
1782
+          SERIAL_ECHOPGM("  B=");
1783
+          SERIAL_PROTOCOL_F(lsf_results.B, 7);
1784
+          SERIAL_ECHOPGM("  D=");
1785
+          SERIAL_PROTOCOL_F(lsf_results.D, 7);
1786
+          SERIAL_EOL();
1787
+          safe_delay(55);
1788
+
1789
+          SERIAL_ECHOPGM("bed plane normal = [");
1790
+          SERIAL_PROTOCOL_F(normal.x, 7);
1791
+          SERIAL_PROTOCOLCHAR(',');
1792
+          SERIAL_PROTOCOL_F(normal.y, 7);
1793
+          SERIAL_PROTOCOLCHAR(',');
1794
+          SERIAL_PROTOCOL_F(normal.z, 7);
1795
+          SERIAL_ECHOPGM("]\n");
1796
+          SERIAL_EOL();
1797
+        }
1798
+      #endif
1799
+
1800
+      if (do_ubl_mesh_map) display_map(g29_map_type);
1801
+    }
1802
+
1803
+  #endif // HAS_BED_PROBE
1772 1804
 
1773 1805
   #if ENABLED(UBL_G29_P31)
1774 1806
     void unified_bed_leveling::smart_fill_wlsf(const float &weight_factor) {

Loading…
Peruuta
Tallenna