Browse Source

Merge pull request #6697 from thinkyhead/bf_wednesday_cleanup

Wednesday-Thursday cleaning up after
Scott Lahteine 8 years ago
parent
commit
0d48fd4b6b

+ 6
- 7
Marlin/Conditionals_post.h View File

@@ -731,15 +731,12 @@
731 731
    * Set granular options based on the specific type of leveling
732 732
    */
733 733
 
734
-  #if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(DELTA)
735
-    #define UBL_DELTA
736
-  #endif
737
-
734
+  #define UBL_DELTA  (ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(DELTA))
738 735
   #define ABL_PLANAR (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT))
739 736
   #define ABL_GRID   (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR))
740 737
   #define HAS_ABL    (ABL_PLANAR || ABL_GRID || ENABLED(AUTO_BED_LEVELING_UBL))
741 738
   #define HAS_LEVELING          (HAS_ABL || ENABLED(MESH_BED_LEVELING))
742
-  #define PLANNER_LEVELING      (ABL_PLANAR || ABL_GRID || ENABLED(MESH_BED_LEVELING) || ENABLED(UBL_DELTA))
739
+  #define PLANNER_LEVELING      (ABL_PLANAR || ABL_GRID || ENABLED(MESH_BED_LEVELING) || UBL_DELTA)
743 740
   #define HAS_PROBING_PROCEDURE (HAS_ABL || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
744 741
   #if HAS_PROBING_PROCEDURE
745 742
     #define PROBE_BED_WIDTH abs(RIGHT_PROBE_BED_POSITION - (LEFT_PROBE_BED_POSITION))
@@ -823,8 +820,7 @@
823 820
   /**
824 821
    * DELTA_SEGMENT_MIN_LENGTH for UBL_DELTA
825 822
    */
826
-
827
-  #if ENABLED(UBL_DELTA)
823
+  #if UBL_DELTA
828 824
     #ifndef DELTA_SEGMENT_MIN_LENGTH
829 825
       #if IS_SCARA
830 826
         #define DELTA_SEGMENT_MIN_LENGTH 0.25 // SCARA minimum segment size is 0.25mm
@@ -836,4 +832,7 @@
836 832
     #endif
837 833
   #endif
838 834
 
835
+  // Shorthand
836
+  #define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))
837
+
839 838
 #endif // CONDITIONALS_POST_H

+ 24
- 48
Marlin/G26_Mesh_Validation_Tool.cpp View File

@@ -100,7 +100,7 @@
100 100
    *                    'n' can be used instead if your host program does not appreciate you using 'N'.
101 101
    *
102 102
    *   O #  Ooooze      How much your nozzle will Ooooze filament while getting in position to print.  This
103
-   *                    is over kill, but using this parameter will let you get the very first 'cicle' perfect
103
+   *                    is over kill, but using this parameter will let you get the very first 'circle' perfect
104 104
    *                    so you have a trophy to peel off of the bed and hang up to show how perfectly you have your
105 105
    *                    Mesh calibrated.  If not specified, a filament length of .3mm is assumed.
106 106
    *
@@ -152,7 +152,7 @@
152 152
   bool turn_on_heaters();
153 153
   bool prime_nozzle();
154 154
 
155
-  static uint16_t circle_flags[16], horizontal_mesh_line_flags[16], vertical_mesh_line_flags[16], continue_with_closest = 0;
155
+  static uint16_t circle_flags[16], horizontal_mesh_line_flags[16], vertical_mesh_line_flags[16];
156 156
   float g26_e_axis_feedrate = 0.020,
157 157
         random_deviation = 0.0,
158 158
         layer_height = LAYER_HEIGHT;
@@ -176,7 +176,7 @@
176 176
 
177 177
   static int8_t prime_flag = 0;
178 178
 
179
-  static bool keep_heaters_on = false;
179
+  static bool continue_with_closest, keep_heaters_on;
180 180
 
181 181
   static int16_t g26_repeats;
182 182
 
@@ -278,8 +278,7 @@
278 278
 
279 279
         // If this mesh location is outside the printable_radius, skip it.
280 280
 
281
-        if ( ! position_is_reachable_raw_xy( circle_x, circle_y ))
282
-          continue;
281
+        if (!position_is_reachable_raw_xy(circle_x, circle_y)) continue;
283 282
 
284 283
         xi = location.x_index;  // Just to shrink the next few lines and make them easier to understand
285 284
         yi = location.y_index;
@@ -329,9 +328,7 @@
329 328
                 ye = circle_y + sin_table[tmp_div_30 + 1];
330 329
           #if IS_KINEMATIC
331 330
             // Check to make sure this segment is entirely on the bed, skip if not.
332
-            if (( ! position_is_reachable_raw_xy( x , y  )) ||
333
-                ( ! position_is_reachable_raw_xy( xe, ye )))
334
-              continue;
331
+            if (!position_is_reachable_raw_xy(x, y) || !position_is_reachable_raw_xy(xe, ye)) continue;
335 332
           #else                                              // not, we need to skip
336 333
             x  = constrain(x, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops
337 334
             y  = constrain(y, Y_MIN_POS + 1, Y_MAX_POS - 1);
@@ -361,7 +358,7 @@
361 358
 
362 359
       //debug_current_and_destination(PSTR("Done with current circle."));
363 360
 
364
-    } while (location.x_index >= 0 && location.y_index >= 0 && g26_repeats--);
361
+    } while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0);
365 362
 
366 363
     LEAVE:
367 364
     lcd_reset_alert_level();
@@ -459,8 +456,7 @@
459 456
               sy = ey = constrain(pgm_read_float(&ubl.mesh_index_to_ypos[j]), Y_MIN_POS + 1, Y_MAX_POS - 1);
460 457
               ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
461 458
 
462
-              if (( position_is_reachable_raw_xy( sx, sy )) &&
463
-                  ( position_is_reachable_raw_xy( ex, ey ))) {
459
+              if (position_is_reachable_raw_xy(sx, sy) && position_is_reachable_raw_xy(ex, ey)) {
464 460
 
465 461
                 if (ubl.g26_debug_flag) {
466 462
                   SERIAL_ECHOPAIR(" Connecting with horizontal line (sx=", sx);
@@ -494,8 +490,7 @@
494 490
                 sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1);
495 491
                 ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
496 492
 
497
-                if (( position_is_reachable_raw_xy( sx, sy )) &&
498
-                    ( position_is_reachable_raw_xy( ex, ey ))) {
493
+                if (position_is_reachable_raw_xy(sx, sy) && position_is_reachable_raw_xy(ex, ey)) {
499 494
 
500 495
                   if (ubl.g26_debug_flag) {
501 496
                     SERIAL_ECHOPAIR(" Connecting with vertical line (sx=", sx);
@@ -623,8 +618,8 @@
623 618
 
624 619
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  Z bumping by 0.500 to minimize scraping.");
625 620
       //todo:  parameterize the bump height with a define
626
-      move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]+0.500, 0.0);  // Z bump to minimize scraping
627
-      move_to(sx, sy, sz+0.500, 0.0); // Get to the starting point with no extrusion while bumped
621
+      move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + 0.500, 0.0);  // Z bump to minimize scraping
622
+      move_to(sx, sy, sz + 0.500, 0.0); // Get to the starting point with no extrusion while bumped
628 623
     }
629 624
 
630 625
     move_to(sx, sy, sz, 0.0); // Get to the starting point with no extrusion / un-Z bump
@@ -655,9 +650,11 @@
655 650
     prime_length          = PRIME_LENGTH;
656 651
     bed_temp              = BED_TEMP;
657 652
     hotend_temp           = HOTEND_TEMP;
658
-    ooze_amount           = OOZE_AMOUNT;
659 653
     prime_flag            = 0;
660
-    keep_heaters_on       = false;
654
+
655
+    ooze_amount           = code_seen('O') && code_has_value() ? code_value_linear_units() : OOZE_AMOUNT;
656
+    keep_heaters_on       = code_seen('K') && code_value_bool();
657
+    continue_with_closest = code_seen('C') && code_value_bool();
661 658
 
662 659
     if (code_seen('B')) {
663 660
       bed_temp = code_value_temp_abs();
@@ -667,8 +664,6 @@
667 664
       }
668 665
     }
669 666
 
670
-    if (code_seen('C')) continue_with_closest++;
671
-
672 667
     if (code_seen('L')) {
673 668
       layer_height = code_value_linear_units();
674 669
       if (!WITHIN(layer_height, 0.0, 2.0)) {
@@ -691,7 +686,7 @@
691 686
       }
692 687
     }
693 688
 
694
-    if (code_seen('N') || code_seen('n')) {
689
+    if (code_seen('N') || code_seen('n')) { // Warning! Use of 'N' / lowercase flouts established standards.
695 690
       nozzle = code_value_float();
696 691
       if (!WITHIN(nozzle, 0.1, 1.0)) {
697 692
         SERIAL_PROTOCOLLNPGM("?Specified nozzle size not plausible.");
@@ -699,11 +694,6 @@
699 694
       }
700 695
     }
701 696
 
702
-    if (code_seen('K')) keep_heaters_on++;
703
-
704
-    if (code_seen('O') && code_has_value())
705
-      ooze_amount = code_value_linear_units();
706
-
707 697
     if (code_seen('P')) {
708 698
       if (!code_has_value())
709 699
         prime_flag = -1;
@@ -738,35 +728,21 @@
738 728
       }
739 729
     }
740 730
 
741
-    if (code_seen('M')) {
731
+    if (code_seen('M')) { // Warning! Use of 'M' flouts established standards.
742 732
       randomSeed(millis());
733
+      // This setting will persist for the next G26
743 734
       random_deviation = code_has_value() ? code_value_float() : 50.0;
744 735
     }
745 736
 
746
-    if (code_seen('R')) {
747
-      g26_repeats = code_has_value() ? code_value_int() : 999;
748
-
749
-      if (g26_repeats <= 0) {
750
-        SERIAL_PROTOCOLLNPGM("?(R)epeat value not plausible; must be greater than 0.");
751
-        return UBL_ERR;
752
-      }
753
-
754
-      g26_repeats--;
755
-    }
756
-
757
-
758
-    x_pos = current_position[X_AXIS];
759
-    y_pos = current_position[Y_AXIS];
760
-
761
-    if (code_seen('X')) {
762
-      x_pos = code_value_float();
763
-    }
764
-
765
-    if (code_seen('Y')) {
766
-      y_pos = code_value_float();
737
+    g26_repeats = code_seen('R') ? (code_has_value() ? code_value_int() : 999) : 1;
738
+    if (g26_repeats < 1) {
739
+      SERIAL_PROTOCOLLNPGM("?(R)epeat value not plausible; must be at least 1.");
740
+      return UBL_ERR;
767 741
     }
768 742
 
769
-    if ( ! position_is_reachable_xy( x_pos, y_pos )) {
743
+    x_pos = code_seen('X') ? code_value_linear_units() : current_position[X_AXIS];
744
+    y_pos = code_seen('Y') ? code_value_linear_units() : current_position[Y_AXIS];
745
+    if (!position_is_reachable_xy(x_pos, y_pos)) {
770 746
       SERIAL_PROTOCOLLNPGM("?Specified X,Y coordinate out of bounds.");
771 747
       return UBL_ERR;
772 748
     }

+ 72
- 72
Marlin/Marlin_main.cpp View File

@@ -56,6 +56,8 @@
56 56
  * G12 - Clean tool
57 57
  * G20 - Set input units to inches
58 58
  * G21 - Set input units to millimeters
59
+ * G26 - Mesh Validation Pattern (Requires UBL_G26_MESH_EDITING)
60
+ * G27 - Park Nozzle (Requires NOZZLE_PARK_FEATURE)
59 61
  * G28 - Home one or more axes
60 62
  * G29 - Detailed Z probe, probes the bed at 3 or more points.  Will fail if you haven't homed yet.
61 63
  * G30 - Single Z probe, probes bed at X Y location (defaults to current XY location)
@@ -97,14 +99,15 @@
97 99
  * M76  - Pause the print job timer.
98 100
  * M77  - Stop the print job timer.
99 101
  * M78  - Show statistical information about the print jobs. (Requires PRINTCOUNTER)
100
- * M80  - Turn on Power Supply. (Requires POWER_SUPPLY)
101
- * M81  - Turn off Power Supply. (Requires POWER_SUPPLY)
102
+ * M80  - Turn on Power Supply. (Requires POWER_SUPPLY > 0)
103
+ * M81  - Turn off Power Supply. (Requires POWER_SUPPLY > 0)
102 104
  * M82  - Set E codes absolute (default).
103 105
  * M83  - Set E codes relative while in Absolute (G90) mode.
104 106
  * M84  - Disable steppers until next move, or use S<seconds> to specify an idle
105 107
  *        duration after which steppers should turn off. S0 disables the timeout.
106 108
  * M85  - Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
107 109
  * M92  - Set planner.axis_steps_per_mm for one or more axes.
110
+ * M100 - Watch Free Memory (for debugging) (Requires M100_FREE_MEMORY_WATCHER)
108 111
  * M104 - Set extruder target temp.
109 112
  * M105 - Report current temperatures.
110 113
  * M106 - Fan on.
@@ -210,7 +213,6 @@
210 213
  * M364 - SCARA calibration: Move to cal-position PSIC (90 deg to Theta calibration position)
211 214
  *
212 215
  * ************ Custom codes - This can change to suit future G-code regulations
213
- * M100 - Watch Free Memory (For Debugging). (Requires M100_FREE_MEMORY_WATCHER)
214 216
  * M928 - Start SD logging: "M928 filename.gco". Stop with M29. (Requires SDSUPPORT)
215 217
  * M999 - Restart after being stopped by error
216 218
  *
@@ -2425,9 +2427,12 @@ static void clean_up_after_endstop_or_probe_move() {
2425 2427
 
2426 2428
     #elif ENABLED(AUTO_BED_LEVELING_UBL)
2427 2429
 
2428
-      #if ENABLED(UBL_DELTA)
2429
-        if (( ubl.state.active ) && ( ! enable )) {   // leveling from on to off
2430
-          planner.unapply_leveling(current_position);
2430
+      #if PLANNER_LEVELING
2431
+        if (ubl.state.active != enable) {
2432
+          if (!enable)   // leveling from on to off
2433
+            planner.apply_leveling(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);
2434
+          else
2435
+            planner.unapply_leveling(current_position);
2431 2436
         }
2432 2437
       #endif
2433 2438
 
@@ -3729,7 +3734,7 @@ inline void gcode_G28() {
3729 3734
   // Disable the leveling matrix before homing
3730 3735
   #if HAS_LEVELING
3731 3736
     #if ENABLED(AUTO_BED_LEVELING_UBL)
3732
-      const bool bed_leveling_state_at_entry = ubl.state.active;
3737
+      const bool ubl_state_at_entry = ubl.state.active;
3733 3738
     #endif
3734 3739
     set_bed_leveling_enabled(false);
3735 3740
   #endif
@@ -3872,8 +3877,9 @@ inline void gcode_G28() {
3872 3877
     // move to a height where we can use the full xy-area
3873 3878
     do_blocking_move_to_z(delta_clip_start_height);
3874 3879
   #endif
3880
+
3875 3881
   #if ENABLED(AUTO_BED_LEVELING_UBL)
3876
-    set_bed_leveling_enabled(bed_leveling_state_at_entry);
3882
+    set_bed_leveling_enabled(ubl_state_at_entry);
3877 3883
   #endif
3878 3884
 
3879 3885
   clean_up_after_endstop_or_probe_move();
@@ -4028,7 +4034,7 @@ void home_all_axes() { gcode_G28(); }
4028 4034
           #endif
4029 4035
         }
4030 4036
         // If there's another point to sample, move there with optional lift.
4031
-        if (mbl_probe_index < (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)) {
4037
+        if (mbl_probe_index < GRID_MAX_POINTS) {
4032 4038
           mbl.zigzag(mbl_probe_index, px, py);
4033 4039
           _manual_goto_xy(mbl.index_to_xpos[px], mbl.index_to_ypos[py]);
4034 4040
 
@@ -4247,8 +4253,6 @@ void home_all_axes() { gcode_G28(); }
4247 4253
       ABL_VAR int left_probe_bed_position, right_probe_bed_position, front_probe_bed_position, back_probe_bed_position;
4248 4254
       ABL_VAR float xGridSpacing, yGridSpacing;
4249 4255
 
4250
-      #define ABL_GRID_MAX (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
4251
-
4252 4256
       #if ABL_PLANAR
4253 4257
         ABL_VAR uint8_t abl_grid_points_x = GRID_MAX_POINTS_X,
4254 4258
                         abl_grid_points_y = GRID_MAX_POINTS_Y;
@@ -4262,7 +4266,7 @@ void home_all_axes() { gcode_G28(); }
4262 4266
         #if ABL_PLANAR
4263 4267
           ABL_VAR int abl2;
4264 4268
         #else // 3-point
4265
-          int constexpr abl2 = ABL_GRID_MAX;
4269
+          int constexpr abl2 = GRID_MAX_POINTS;
4266 4270
         #endif
4267 4271
       #endif
4268 4272
 
@@ -4274,8 +4278,8 @@ void home_all_axes() { gcode_G28(); }
4274 4278
 
4275 4279
         ABL_VAR int indexIntoAB[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
4276 4280
 
4277
-        ABL_VAR float eqnAMatrix[ABL_GRID_MAX * 3], // "A" matrix of the linear system of equations
4278
-                     eqnBVector[ABL_GRID_MAX],     // "B" vector of Z points
4281
+        ABL_VAR float eqnAMatrix[GRID_MAX_POINTS * 3], // "A" matrix of the linear system of equations
4282
+                     eqnBVector[GRID_MAX_POINTS],     // "B" vector of Z points
4279 4283
                      mean;
4280 4284
       #endif
4281 4285
 
@@ -7619,7 +7623,6 @@ inline void gcode_M205() {
7619 7623
     if (code_seen('H')) {
7620 7624
       home_offset[Z_AXIS] = code_value_linear_units() - DELTA_HEIGHT;
7621 7625
       current_position[Z_AXIS] += code_value_linear_units() - DELTA_HEIGHT - home_offset[Z_AXIS];
7622
-      home_offset[Z_AXIS] = code_value_linear_units() - DELTA_HEIGHT;
7623 7626
       update_software_endstops(Z_AXIS);
7624 7627
     }
7625 7628
     if (code_seen('L')) delta_diagonal_rod = code_value_linear_units();
@@ -8413,17 +8416,15 @@ void quickstop_stepper() {
8413 8416
    * Use either 'M421 X<linear> Y<linear> Z<linear>' or 'M421 I<xindex> J<yindex> Z<linear>'
8414 8417
    */
8415 8418
   inline void gcode_M421() {
8416
-    int8_t px = 0, py = 0;
8417
-    float z = 0;
8418
-    bool hasX, hasY, hasZ, hasI, hasJ;
8419
-    if ((hasX = code_seen('X'))) px = mbl.probe_index_x(code_value_linear_units());
8420
-    if ((hasY = code_seen('Y'))) py = mbl.probe_index_y(code_value_linear_units());
8421
-    if ((hasI = code_seen('I'))) px = code_value_linear_units();
8422
-    if ((hasJ = code_seen('J'))) py = code_value_linear_units();
8423
-    if ((hasZ = code_seen('Z'))) z = code_value_linear_units();
8424 8419
 
8425
-    if (hasX && hasY && hasZ) {
8420
+    const bool hasX = code_seen('X'), hasI = !hasX && code_seen('I');
8421
+    const int8_t px = hasX || hasI ? mbl.probe_index_x(code_value_linear_units()) : 0;
8422
+    const bool hasY = code_seen('Y'), hasJ = !hasY && code_seen('J');
8423
+    const int8_t py = hasY || hasJ ? mbl.probe_index_y(code_value_linear_units()) : 0;
8424
+    const bool hasZ = code_seen('Z');
8425
+    const float z = hasZ ? code_value_linear_units() : 0;
8426 8426
 
8427
+    if (hasX && hasY && hasZ) {
8427 8428
       if (px >= 0 && py >= 0)
8428 8429
         mbl.set_z(px, py, z);
8429 8430
       else {
@@ -8450,18 +8451,18 @@ void quickstop_stepper() {
8450 8451
   /**
8451 8452
    * M421: Set a single Mesh Bed Leveling Z coordinate
8452 8453
    *
8454
+   * Usage:
8453 8455
    *   M421 I<xindex> J<yindex> Z<linear>
8454
-   *   or
8455 8456
    *   M421 I<xindex> J<yindex> Q<offset>
8456 8457
    */
8457 8458
   inline void gcode_M421() {
8458
-    int8_t px = 0, py = 0;
8459
-    float z = 0;
8460
-    bool hasI, hasJ, hasZ, hasQ;
8461
-    if ((hasI = code_seen('I'))) px = code_value_int();
8462
-    if ((hasJ = code_seen('J'))) py = code_value_int();
8463
-    if ((hasZ = code_seen('Z'))) z = code_value_linear_units();
8464
-    if ((hasQ = code_seen('Q'))) z = code_value_linear_units();
8459
+
8460
+    const bool hasI = code_seen('I');
8461
+    const int8_t px = hasI ? code_value_int() : 0;
8462
+    const bool hasJ = code_seen('J');
8463
+    const int8_t py = hasJ ? code_value_int() : 0;
8464
+    const bool hasZ = code_seen('Z'), hasQ = !hasZ && code_seen('Q');
8465
+    const float z = hasZ || hasQ ? code_value_linear_units() : 0;
8465 8466
 
8466 8467
     if (!hasI || !hasJ || (hasQ && hasZ) || (!hasQ && !hasZ)) {
8467 8468
       SERIAL_ERROR_START;
@@ -8494,35 +8495,33 @@ void quickstop_stepper() {
8494 8495
   /**
8495 8496
    * M421: Set a single Mesh Bed Leveling Z coordinate
8496 8497
    *
8498
+   * Usage:
8497 8499
    *   M421 I<xindex> J<yindex> Z<linear>
8498
-   *   or
8499 8500
    *   M421 I<xindex> J<yindex> Q<offset>
8501
+   *   M421 C Z<linear>
8502
+   *   M421 C Q<offset>
8500 8503
    */
8501 8504
 
8502
-  //todo:  change multiple points simultaneously?
8503
-
8504 8505
   inline void gcode_M421() {
8505
-    int8_t px = 0, py = 0;
8506
-    float z = 0;
8507
-    bool hasI, hasJ, hasZ, hasQ, hasC;
8508
-    if ((hasI = code_seen('I'))) px = code_value_int();
8509
-    if ((hasJ = code_seen('J'))) py = code_value_int();
8510
-    if ((hasZ = code_seen('Z'))) z = code_value_linear_units();
8511
-    if ((hasQ = code_seen('Q'))) z = code_value_linear_units();
8512
-    hasC = code_seen('C');
8513
-
8514
-    if ( (!(hasI && hasJ) && !hasC) || (hasQ && hasZ) || (!hasQ && !hasZ)) {
8506
+
8507
+    // Get the closest position for 'C', if needed
8508
+    const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, current_position[X_AXIS], current_position[Y_AXIS], USE_NOZZLE_AS_REFERENCE, NULL, false);
8509
+
8510
+    const bool hasC = code_seen('C'), hasI = code_seen('I');
8511
+    const int8_t px = hasC ? location.x_index : hasI ? code_value_int() : 0;
8512
+
8513
+    const bool hasJ = code_seen('J');
8514
+    const int8_t py = hasC ? location.y_index : hasJ ? code_value_int() : 0;
8515
+
8516
+    const bool hasZ = code_seen('Z'), hasQ = !hasZ && code_seen('Q');
8517
+    const float z = hasZ || hasQ ? code_value_linear_units() : 0;
8518
+
8519
+    if ( ((hasI && hasJ) == hasC) || (hasQ && hasZ) || (!hasQ && !hasZ)) {
8515 8520
       SERIAL_ERROR_START;
8516 8521
       SERIAL_ERRORLNPGM(MSG_ERR_M421_PARAMETERS);
8517 8522
       return;
8518 8523
     }
8519 8524
 
8520
-    if (hasC) { // get closest position
8521
-      const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, current_position[X_AXIS], current_position[Y_AXIS], USE_NOZZLE_AS_REFERENCE, NULL, false);
8522
-      px = location.x_index;
8523
-      py = location.y_index;
8524
-    }
8525
-
8526 8525
     if (WITHIN(px, 0, GRID_MAX_POINTS_X - 1) && WITHIN(py, 0, GRID_MAX_POINTS_Y - 1)) {
8527 8526
       if (hasZ) // doing an absolute mesh value
8528 8527
         ubl.z_values[px][py] = z;
@@ -8534,7 +8533,8 @@ void quickstop_stepper() {
8534 8533
       SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY);
8535 8534
     }
8536 8535
   }
8537
-#endif
8536
+
8537
+#endif // AUTO_BED_LEVELING_UBL
8538 8538
 
8539 8539
 #if HAS_M206_COMMAND
8540 8540
 
@@ -11106,7 +11106,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
11106 11106
 
11107 11107
 #endif // AUTO_BED_LEVELING_BILINEAR
11108 11108
 
11109
-#if IS_KINEMATIC && DISABLED(UBL_DELTA)
11109
+#if IS_KINEMATIC && !UBL_DELTA
11110 11110
 
11111 11111
   /**
11112 11112
    * Prepare a linear move in a DELTA or SCARA setup.
@@ -11117,7 +11117,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
11117 11117
   inline bool prepare_kinematic_move_to(float ltarget[XYZE]) {
11118 11118
 
11119 11119
     // Get the top feedrate of the move in the XY plane
11120
-    float _feedrate_mm_s = MMS_SCALED(feedrate_mm_s);
11120
+    const float _feedrate_mm_s = MMS_SCALED(feedrate_mm_s);
11121 11121
 
11122 11122
     // If the move is only in Z/E don't split up the move
11123 11123
     if (ltarget[X_AXIS] == current_position[X_AXIS] && ltarget[Y_AXIS] == current_position[Y_AXIS]) {
@@ -11126,7 +11126,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
11126 11126
     }
11127 11127
 
11128 11128
     // Fail if attempting move outside printable radius
11129
-    if ( ! position_is_reachable_xy( ltarget[X_AXIS], ltarget[Y_AXIS] )) return true;
11129
+    if (!position_is_reachable_xy(ltarget[X_AXIS], ltarget[Y_AXIS])) return true;
11130 11130
 
11131 11131
     // Get the cartesian distances moved in XYZE
11132 11132
     float difference[XYZE];
@@ -11142,7 +11142,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
11142 11142
     if (UNEAR_ZERO(cartesian_mm)) return true;
11143 11143
 
11144 11144
     // Minimum number of seconds to move the given distance
11145
-    float seconds = cartesian_mm / _feedrate_mm_s;
11145
+    const float seconds = cartesian_mm / _feedrate_mm_s;
11146 11146
 
11147 11147
     // The number of segments-per-second times the duration
11148 11148
     // gives the number of segments
@@ -11227,7 +11227,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
11227 11227
     return false;
11228 11228
   }
11229 11229
 
11230
-#else // !IS_KINEMATIC
11230
+#else // !IS_KINEMATIC || UBL_DELTA
11231 11231
 
11232 11232
   /**
11233 11233
    * Prepare a linear move in a Cartesian setup.
@@ -11265,7 +11265,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
11265 11265
     return false;
11266 11266
   }
11267 11267
 
11268
-#endif // !IS_KINEMATIC
11268
+#endif // !IS_KINEMATIC || UBL_DELTA
11269 11269
 
11270 11270
 #if ENABLED(DUAL_X_CARRIAGE)
11271 11271
 
@@ -11377,21 +11377,21 @@ void prepare_move_to_destination() {
11377 11377
 
11378 11378
   #endif
11379 11379
 
11380
-  #if IS_KINEMATIC
11381
-    #if ENABLED(UBL_DELTA)
11382
-      if (ubl_prepare_linear_move_to(destination,feedrate_mm_s)) return;
11383
-    #else
11384
-      if (prepare_kinematic_move_to(destination)) return;
11385
-    #endif
11386
-  #else
11387
-    #if ENABLED(DUAL_X_CARRIAGE)
11388
-      if (prepare_move_to_destination_dualx()) return;
11389
-    #elif ENABLED(UBL_DELTA) // will work for CARTESIAN too (smaller segments follow mesh more closely)
11390
-      if (ubl_prepare_linear_move_to(destination,feedrate_mm_s)) return;
11380
+  if (
11381
+    #if IS_KINEMATIC
11382
+      #if UBL_DELTA
11383
+        ubl_prepare_linear_move_to(destination, feedrate_mm_s)
11384
+      #else
11385
+        prepare_kinematic_move_to(destination)
11386
+      #endif
11387
+    #elif ENABLED(DUAL_X_CARRIAGE)
11388
+      prepare_move_to_destination_dualx()
11389
+    #elif UBL_DELTA // will work for CARTESIAN too (smaller segments follow mesh more closely)
11390
+      ubl_prepare_linear_move_to(destination, feedrate_mm_s)
11391 11391
     #else
11392
-      if (prepare_move_to_destination_cartesian()) return;
11392
+      prepare_move_to_destination_cartesian()
11393 11393
     #endif
11394
-  #endif
11394
+  ) return;
11395 11395
 
11396 11396
   set_current_to_destination();
11397 11397
 }
@@ -11432,7 +11432,7 @@ void prepare_move_to_destination() {
11432 11432
     if (angular_travel == 0 && current_position[X_AXIS] == logical[X_AXIS] && current_position[Y_AXIS] == logical[Y_AXIS])
11433 11433
       angular_travel += RADIANS(360);
11434 11434
 
11435
-    float mm_of_travel = HYPOT(angular_travel * radius, fabs(linear_travel));
11435
+    const float mm_of_travel = HYPOT(angular_travel * radius, fabs(linear_travel));
11436 11436
     if (mm_of_travel < 0.001) return;
11437 11437
 
11438 11438
     uint16_t segments = floor(mm_of_travel / (MM_PER_ARC_SEGMENT));

+ 8
- 21
Marlin/SanityCheck.h View File

@@ -248,11 +248,9 @@
248 248
 #if ENABLED(DELTA)
249 249
   #if DISABLED(USE_XMAX_PLUG) && DISABLED(USE_YMAX_PLUG) && DISABLED(USE_ZMAX_PLUG)
250 250
     #error "You probably want to use Max Endstops for DELTA!"
251
-  #endif
252
-  #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(UBL_DELTA)
253
-    #error "ENABLE_LEVELING_FADE_HEIGHT for DELTA requires UBL_DELTA and AUTO_BED_LEVELING_UBL."
254
-  #endif
255
-  #if ABL_GRID
251
+  #elif ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(AUTO_BED_LEVELING_BILINEAR) && !UBL_DELTA
252
+    #error "ENABLE_LEVELING_FADE_HEIGHT on DELTA requires AUTO_BED_LEVELING_BILINEAR or AUTO_BED_LEVELING_UBL."
253
+  #elif ABL_GRID
256 254
     #if (GRID_MAX_POINTS_X & 1) == 0 || (GRID_MAX_POINTS_Y & 1) == 0
257 255
       #error "DELTA requires GRID_MAX_POINTS_X and GRID_MAX_POINTS_Y to be odd numbers."
258 256
     #elif GRID_MAX_POINTS_X < 3
@@ -431,20 +429,11 @@ static_assert(1 >= 0
431 429
  * Unified Bed Leveling
432 430
  */
433 431
 #if ENABLED(AUTO_BED_LEVELING_UBL)
434
-  #if IS_KINEMATIC
435
-    #if ENABLED(DELTA)
436
-      #if DISABLED(UBL_DELTA)
437
-        #error "AUTO_BED_LEVELING_UBL requires UBL_DELTA for DELTA printers."
438
-      #endif
439
-    #else // SCARA
440
-      #error "AUTO_BED_LEVELING_UBL not supported for SCARA printers."
441
-    #endif
442
-  #endif
443
-  #if DISABLED(NEWPANEL)
432
+  #if IS_SCARA
433
+    #error "AUTO_BED_LEVELING_UBL does not yet support SCARA printers."
434
+  #elif DISABLED(NEWPANEL)
444 435
     #error "AUTO_BED_LEVELING_UBL requires an LCD controller."
445 436
   #endif
446
-#elif ENABLED(UBL_DELTA)
447
-  #error "UBL_DELTA requires AUTO_BED_LEVELING_UBL."
448 437
 #endif
449 438
 
450 439
 /**
@@ -603,10 +592,8 @@ static_assert(1 >= 0
603 592
   /**
604 593
    * Delta and SCARA have limited bed leveling options
605 594
    */
606
-  #if IS_KINEMATIC
607
-    #if DISABLED(AUTO_BED_LEVELING_BILINEAR) && DISABLED(UBL_DELTA)
608
-      #error "Only AUTO_BED_LEVELING_BILINEAR or AUTO_BED_LEVELING_UBL with UBL_DELTA support DELTA and SCARA bed leveling."
609
-    #endif
595
+  #if IS_SCARA && DISABLED(AUTO_BED_LEVELING_BILINEAR)
596
+    #error "Only AUTO_BED_LEVELING_BILINEAR currently supports SCARA bed leveling."
610 597
   #endif
611 598
 
612 599
   /**

+ 2
- 2
Marlin/configuration_store.cpp View File

@@ -342,7 +342,7 @@ void MarlinSettings::postprocess() {
342 342
     #if ENABLED(MESH_BED_LEVELING)
343 343
       // Compile time test that sizeof(mbl.z_values) is as expected
344 344
       static_assert(
345
-        sizeof(mbl.z_values) == (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y) * sizeof(mbl.z_values[0][0]),
345
+        sizeof(mbl.z_values) == GRID_MAX_POINTS * sizeof(mbl.z_values[0][0]),
346 346
         "MBL Z array is the wrong size."
347 347
       );
348 348
       const bool leveling_is_on = TEST(mbl.status, MBL_STATUS_HAS_MESH_BIT);
@@ -386,7 +386,7 @@ void MarlinSettings::postprocess() {
386 386
     #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
387 387
       // Compile time test that sizeof(z_values) is as expected
388 388
       static_assert(
389
-        sizeof(z_values) == (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y) * sizeof(z_values[0][0]),
389
+        sizeof(z_values) == GRID_MAX_POINTS * sizeof(z_values[0][0]),
390 390
         "Bilinear Z array is the wrong size."
391 391
       );
392 392
       const uint8_t grid_max_x = GRID_MAX_POINTS_X, grid_max_y = GRID_MAX_POINTS_Y;

+ 10
- 10
Marlin/planner.cpp View File

@@ -534,12 +534,12 @@ void Planner::check_axes_activity() {
534 534
    */
535 535
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
536 536
 
537
-    #if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_DELTA)  // probably should also be enabled for UBL without UBL_DELTA
537
+    #if ENABLED(AUTO_BED_LEVELING_UBL) && UBL_DELTA  // probably should also be enabled for UBL without UBL_DELTA
538 538
       if (!ubl.state.active) return;
539 539
       #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
540 540
         // if z_fade_height enabled (nonzero) and raw_z above it, no leveling required
541 541
         if ((planner.z_fade_height) && (planner.z_fade_height <= RAW_Z_POSITION(lz))) return;
542
-        lz += ubl.state.z_offset + ( ubl.get_z_correction(lx,ly) * ubl.fade_scaling_factor_for_z(lz));
542
+        lz += ubl.state.z_offset + ubl.get_z_correction(lx,ly) * ubl.fade_scaling_factor_for_z(lz);
543 543
       #else // no fade
544 544
         lz += ubl.state.z_offset + ubl.get_z_correction(lx,ly);
545 545
       #endif // FADE
@@ -598,13 +598,13 @@ void Planner::check_axes_activity() {
598 598
 
599 599
   void Planner::unapply_leveling(float logical[XYZ]) {
600 600
 
601
-    #if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_DELTA)
601
+    #if ENABLED(AUTO_BED_LEVELING_UBL) && UBL_DELTA
602 602
 
603
-      if ( ubl.state.active ) {
603
+      if (ubl.state.active) {
604 604
 
605
-        float z_leveled = RAW_Z_POSITION(logical[Z_AXIS]);
606
-        float z_ublmesh = ubl.get_z_correction(logical[X_AXIS],logical[Y_AXIS]);
607
-        float z_unlevel = z_leveled - ubl.state.z_offset - z_ublmesh;
605
+        const float z_leveled = RAW_Z_POSITION(logical[Z_AXIS]),
606
+                    z_ublmesh = ubl.get_z_correction(logical[X_AXIS], logical[Y_AXIS]);
607
+              float z_unlevel = z_leveled - ubl.state.z_offset - z_ublmesh;
608 608
 
609 609
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
610 610
 
@@ -616,9 +616,9 @@ void Planner::check_axes_activity() {
616 616
           //    so U(1-M/H)==L-O-M
617 617
           //    so U==(L-O-M)/(1-M/H) for U<H
618 618
 
619
-          if ( planner.z_fade_height ) {
620
-            float z_unfaded = z_unlevel / ( 1.0 - ( z_ublmesh * planner.inverse_z_fade_height ));
621
-            if ( z_unfaded < planner.z_fade_height )  // don't know until after compute
619
+          if (planner.z_fade_height) {
620
+            float z_unfaded = z_unlevel / (1.0 - z_ublmesh * planner.inverse_z_fade_height);
621
+            if (z_unfaded < planner.z_fade_height)  // don't know until after compute
622 622
               z_unlevel = z_unfaded;
623 623
           }
624 624
 

+ 13
- 12
Marlin/ubl_G29.cpp View File

@@ -209,7 +209,7 @@
209 209
    *                    Mesh Validation Pattern phase.   Please note that you are populating your mesh with unverified
210 210
    *                    numbers.  You should use some scrutiny and caution.
211 211
    *
212
-   *   P4    Phase 4    Fine tune the Mesh. The Delta Mesh Compensation System assume the existance of
212
+   *   P4    Phase 4    Fine tune the Mesh. The Delta Mesh Compensation System assume the existence of
213 213
    *                    an LCD Panel. It is possible to fine tune the mesh without the use of an LCD Panel.
214 214
    *                    (More work and details on doing this later!)
215 215
    *                    The System will search for the closest Mesh Point to the nozzle. It will move the
@@ -328,7 +328,8 @@
328 328
       return;
329 329
     }
330 330
 
331
-    if (!code_seen('N') && axis_unhomed_error(true, true, true))  // Don't allow auto-leveling without homing first
331
+    // Don't allow auto-leveling without homing first
332
+    if (!code_seen('N') && axis_unhomed_error(true, true, true)) // Warning! Use of 'N' flouts established standards.
332 333
       home_all_axes();
333 334
 
334 335
     if (g29_parameter_parsing()) return; // abort if parsing the simple parameters causes a problem,
@@ -385,7 +386,7 @@
385 386
 
386 387
     if (code_seen('J')) {
387 388
       ubl.save_ubl_active_state_and_disable();
388
-      ubl.tilt_mesh_based_on_probed_grid(code_seen('O') || code_seen('M'));
389
+      ubl.tilt_mesh_based_on_probed_grid(code_seen('O') || code_seen('M')); // Warning! Use of 'M' flouts established standards.
389 390
       ubl.restore_ubl_active_state_and_leave();
390 391
     }
391 392
 
@@ -419,7 +420,7 @@
419 420
             SERIAL_PROTOCOLLNPGM(").\n");
420 421
           }
421 422
           ubl.probe_entire_mesh(x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER,
422
-                            code_seen('O') || code_seen('M'), code_seen('E'), code_seen('U'));
423
+                            code_seen('O') || code_seen('M'), code_seen('E'), code_seen('U')); // Warning! Use of 'M' flouts established standards.
423 424
           break;
424 425
 
425 426
         case 2: {
@@ -468,7 +469,7 @@
468 469
             return;
469 470
           }
470 471
 
471
-          manually_probe_remaining_mesh(x_pos, y_pos, height, card_thickness, code_seen('O') || code_seen('M'));
472
+          manually_probe_remaining_mesh(x_pos, y_pos, height, card_thickness, code_seen('O') || code_seen('M')); // Warning! Use of 'M' flouts established standards.
472 473
           SERIAL_PROTOCOLLNPGM("G29 P2 finished.");
473 474
         } break;
474 475
 
@@ -504,7 +505,7 @@
504 505
           //
505 506
           // Fine Tune (i.e., Edit) the Mesh
506 507
           //
507
-          fine_tune_mesh(x_pos, y_pos, code_seen('O') || code_seen('M'));
508
+          fine_tune_mesh(x_pos, y_pos, code_seen('O') || code_seen('M')); // Warning! Use of 'M' flouts established standards.
508 509
           break;
509 510
 
510 511
         case 5: ubl.find_mean_mesh_height(); break;
@@ -549,7 +550,7 @@
549 550
     // When we are fully debugged, the EEPROM dump command will get deleted also. But
550 551
     // right now, it is good to have the extra information. Soon... we prune this.
551 552
     //
552
-    if (code_seen('j')) g29_eeprom_dump();   // EEPROM Dump
553
+    if (code_seen('j')) g29_eeprom_dump(); // Warning! Use of lowercase flouts established standards.
553 554
 
554 555
     //
555 556
     // When we are fully debugged, this may go away. But there are some valid
@@ -613,7 +614,7 @@
613 614
       SERIAL_PROTOCOLLNPGM("Done.\n");
614 615
     }
615 616
 
616
-    if (code_seen('O') || code_seen('M'))
617
+    if (code_seen('O') || code_seen('M')) // Warning! Use of 'M' flouts established standards.
617 618
       ubl.display_map(code_has_value() ? code_value_int() : 0);
618 619
 
619 620
     if (code_seen('Z')) {
@@ -1048,8 +1049,8 @@
1048 1049
 
1049 1050
     repeat_flag = code_seen('R');
1050 1051
     if (repeat_flag) {
1051
-      repetition_cnt = code_has_value() ? code_value_int() : (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y);
1052
-      repetition_cnt = min(repetition_cnt, (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y));
1052
+      repetition_cnt = code_has_value() ? code_value_int() : GRID_MAX_POINTS;
1053
+      NOMORE(repetition_cnt, GRID_MAX_POINTS);
1053 1054
       if (repetition_cnt < 1) {
1054 1055
         SERIAL_PROTOCOLLNPGM("?(R)epetition count invalid (1+).\n");
1055 1056
         return UBL_ERR;
@@ -1128,8 +1129,8 @@
1128 1129
       SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1129 1130
       return UBL_ERR;
1130 1131
     }
1131
-
1132
-    if (code_seen('M')) {     // Check if a map type was specified
1132
+    // Check if a map type was specified
1133
+    if (code_seen('M')) { // Warning! Use of 'M' flouts established standards.
1133 1134
       map_type = code_has_value() ? code_value_int() : 0;
1134 1135
       if (!WITHIN(map_type, 0, 1)) {
1135 1136
         SERIAL_PROTOCOLLNPGM("Invalid map type.\n");

+ 68
- 81
Marlin/ubl_motion.cpp View File

@@ -474,20 +474,10 @@
474 474
     set_current_to_destination();
475 475
   }
476 476
 
477
-
478
-  #ifdef UBL_DELTA
479
-
480
-    #define COPY_XYZE( target, source ) { \
481
-                target[X_AXIS] = source[X_AXIS]; \
482
-                target[Y_AXIS] = source[Y_AXIS]; \
483
-                target[Z_AXIS] = source[Z_AXIS]; \
484
-                target[E_AXIS] = source[E_AXIS]; \
485
-            }
477
+  #if UBL_DELTA
486 478
 
487 479
     #if IS_SCARA // scale the feed rate from mm/s to degrees/s
488
-      static float scara_feed_factor;
489
-      static float scara_oldA;
490
-      static float scara_oldB;
480
+      static float scara_feed_factor, scara_oldA, scara_oldB;
491 481
     #endif
492 482
 
493 483
     // We don't want additional apply_leveling() performed by regular buffer_line or buffer_line_kinematic, 
@@ -501,18 +491,18 @@
501 491
         float feedrate = fr_mm_s;
502 492
 
503 493
         #if IS_SCARA // scale the feed rate from mm/s to degrees/s
504
-          float adiff = abs(delta[A_AXIS] - scara_oldA);
505
-          float bdiff = abs(delta[B_AXIS] - scara_oldB);
494
+          float adiff = abs(delta[A_AXIS] - scara_oldA),
495
+                bdiff = abs(delta[B_AXIS] - scara_oldB);
506 496
           scara_oldA = delta[A_AXIS];
507 497
           scara_oldB = delta[B_AXIS];
508 498
           feedrate = max(adiff, bdiff) * scara_feed_factor;
509 499
         #endif
510 500
 
511
-        planner._buffer_line( delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], ltarget[E_AXIS], feedrate, extruder );
501
+        planner._buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], ltarget[E_AXIS], feedrate, extruder);
512 502
 
513 503
       #else // cartesian
514 504
 
515
-        planner._buffer_line( ltarget[X_AXIS], ltarget[Y_AXIS], ltarget[Z_AXIS], ltarget[E_AXIS], fr_mm_s, extruder );
505
+        planner._buffer_line(ltarget[X_AXIS], ltarget[Y_AXIS], ltarget[Z_AXIS], ltarget[E_AXIS], fr_mm_s, extruder);
516 506
 
517 507
       #endif
518 508
     }
@@ -525,7 +515,7 @@
525 515
 
526 516
     static bool ubl_prepare_linear_move_to(const float ltarget[XYZE], const float &feedrate) {
527 517
 
528
-      if ( ! position_is_reachable_xy( ltarget[X_AXIS], ltarget[Y_AXIS] ))  // fail if moving outside reachable boundary
518
+      if (!position_is_reachable_xy(ltarget[X_AXIS], ltarget[Y_AXIS]))  // fail if moving outside reachable boundary
529 519
         return true; // did not move, so current_position still accurate
530 520
 
531 521
       const float difference[XYZE] = {    // cartesian distances moved in XYZE
@@ -533,21 +523,21 @@
533 523
                     ltarget[Y_AXIS] - current_position[Y_AXIS],
534 524
                     ltarget[Z_AXIS] - current_position[Z_AXIS],
535 525
                     ltarget[E_AXIS] - current_position[E_AXIS]
536
-                    };
526
+                  };
537 527
 
538
-      float cartesian_xy_mm = sqrtf( sq(difference[X_AXIS]) + sq(difference[Y_AXIS]) ); // total horizontal xy distance
528
+      const float cartesian_xy_mm = HYPOT(difference[X_AXIS], difference[Y_AXIS]);        // total horizontal xy distance
539 529
 
540 530
       #if IS_KINEMATIC
541
-        float    seconds  = cartesian_xy_mm / feedrate;                                   // seconds to move xy distance at requested rate
542
-        uint16_t segments = lroundf( delta_segments_per_second * seconds );               // preferred number of segments for distance @ feedrate
543
-        uint16_t seglimit = lroundf( cartesian_xy_mm * (1.0/(DELTA_SEGMENT_MIN_LENGTH))); // number of segments at minimum segment length
544
-        NOMORE( segments, seglimit );                                                     // limit to minimum segment length (fewer segments)
531
+        const float seconds = cartesian_xy_mm / feedrate;                                 // seconds to move xy distance at requested rate
532
+        uint16_t segments = lroundf(delta_segments_per_second * seconds),                // preferred number of segments for distance @ feedrate
533
+                 seglimit = lroundf(cartesian_xy_mm * (1.0 / (DELTA_SEGMENT_MIN_LENGTH))); // number of segments at minimum segment length
534
+        NOMORE(segments, seglimit);                                                     // limit to minimum segment length (fewer segments)
545 535
       #else
546
-        uint16_t segments = lroundf( cartesian_xy_mm * (1.0/(DELTA_SEGMENT_MIN_LENGTH))); // cartesian fixed segment length
536
+        uint16_t segments = lroundf(cartesian_xy_mm * (1.0 / (DELTA_SEGMENT_MIN_LENGTH))); // cartesian fixed segment length
547 537
       #endif
548 538
 
549
-      NOLESS( segments, 1 );                // must have at least one segment
550
-      float inv_segments = 1.0 / segments;  // divide once, multiply thereafter
539
+      NOLESS(segments, 1);                        // must have at least one segment
540
+      const float inv_segments = 1.0 / segments;  // divide once, multiply thereafter
551 541
 
552 542
       #if IS_SCARA // scale the feed rate from mm/s to degrees/s
553 543
         scara_feed_factor = cartesian_xy_mm * inv_segments * feedrate;
@@ -560,57 +550,53 @@
560 550
                     difference[Y_AXIS] * inv_segments,
561 551
                     difference[Z_AXIS] * inv_segments,
562 552
                     difference[E_AXIS] * inv_segments 
563
-                    };
553
+                  };
564 554
 
565 555
       // Note that E segment distance could vary slightly as z mesh height
566 556
       // changes for each segment, but small enough to ignore.
567 557
 
568
-      bool above_fade_height = false;
569
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
570
-        if (( planner.z_fade_height != 0 ) && 
571
-            ( planner.z_fade_height < RAW_Z_POSITION(ltarget[Z_AXIS]) )) {
572
-          above_fade_height = true;
573
-          }
574
-      #endif
558
+      const bool above_fade_height = (
559
+        #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
560
+          planner.z_fade_height != 0 && planner.z_fade_height < RAW_Z_POSITION(ltarget[Z_AXIS])
561
+        #else
562
+          false
563
+        #endif
564
+      );
575 565
 
576 566
       // Only compute leveling per segment if ubl active and target below z_fade_height.
577 567
 
578
-      if (( ! ubl.state.active ) || ( above_fade_height )) {   // no mesh leveling
568
+      if (!ubl.state.active || above_fade_height) {   // no mesh leveling
579 569
 
580 570
         const float z_offset = ubl.state.active ? ubl.state.z_offset : 0.0;
581 571
 
582
-        float seg_dest[XYZE];                     // per-segment destination,
583
-        COPY_XYZE( seg_dest, current_position );  // starting from current position
572
+        float seg_dest[XYZE];              // per-segment destination,
573
+        COPY(seg_dest, current_position);  // starting from current position
584 574
 
585 575
         while (--segments) {
586 576
           LOOP_XYZE(i) seg_dest[i] += segment_distance[i];
587 577
           float ztemp = seg_dest[Z_AXIS];
588 578
           seg_dest[Z_AXIS] += z_offset;
589
-          ubl_buffer_line_segment( seg_dest, feedrate, active_extruder );
579
+          ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
590 580
           seg_dest[Z_AXIS] = ztemp;
591 581
         }
592 582
 
593 583
         // Since repeated adding segment_distance accumulates small errors, final move to exact destination.
594
-        COPY_XYZE( seg_dest, ltarget );
584
+        COPY(seg_dest, ltarget);
595 585
         seg_dest[Z_AXIS] += z_offset;
596
-        ubl_buffer_line_segment( seg_dest, feedrate, active_extruder );
586
+        ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
597 587
         return false; // moved but did not set_current_to_destination();
598 588
       }
599 589
 
600 590
       // Otherwise perform per-segment leveling
601 591
 
602
-      #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
603
-        float fade_scaling_factor = ubl.fade_scaling_factor_for_z(ltarget[Z_AXIS]);
604
-      #endif
605
-
606 592
       float seg_dest[XYZE];  // per-segment destination, initialize to first segment
607 593
       LOOP_XYZE(i) seg_dest[i] = current_position[i] + segment_distance[i];
608 594
 
609 595
       const float& dx_seg = segment_distance[X_AXIS];  // alias for clarity
610 596
       const float& dy_seg = segment_distance[Y_AXIS];
611 597
 
612
-      float rx = RAW_X_POSITION(seg_dest[X_AXIS]);  // assume raw vs logical coordinates shifted but not scaled.
613
-      float ry = RAW_Y_POSITION(seg_dest[Y_AXIS]);
598
+      float rx = RAW_X_POSITION(seg_dest[X_AXIS]),  // assume raw vs logical coordinates shifted but not scaled.
599
+            ry = RAW_Y_POSITION(seg_dest[Y_AXIS]);
614 600
 
615 601
       do {  // for each mesh cell encountered during the move
616 602
 
@@ -621,74 +607,75 @@
621 607
         // in top of loop and again re-find same adjacent cell and use it, just less efficient
622 608
         // for mesh inset area.
623 609
 
624
-        int8_t cell_xi = (rx - (UBL_MESH_MIN_X)) * (1.0 / (MESH_X_DIST));
625
-               cell_xi = constrain( cell_xi, 0, (GRID_MAX_POINTS_X) - 1 );
610
+        int8_t cell_xi = (rx - (UBL_MESH_MIN_X)) * (1.0 / (MESH_X_DIST)),
611
+               cell_yi = (ry - (UBL_MESH_MIN_Y)) * (1.0 / (MESH_X_DIST));
626 612
 
627
-        int8_t cell_yi = (ry - (UBL_MESH_MIN_Y)) * (1.0 / (MESH_X_DIST));
628
-               cell_yi = constrain( cell_yi, 0, (GRID_MAX_POINTS_Y) - 1 );
613
+        cell_xi = constrain(cell_xi, 0, (GRID_MAX_POINTS_X) - 1);
614
+        cell_yi = constrain(cell_yi, 0, (GRID_MAX_POINTS_Y) - 1);
629 615
 
630 616
         // float x0 = (UBL_MESH_MIN_X) + ((MESH_X_DIST) * cell_xi );         // lower left cell corner
631 617
         // float y0 = (UBL_MESH_MIN_Y) + ((MESH_Y_DIST) * cell_yi );         // lower left cell corner
632 618
         // float x1 = x0 + MESH_X_DIST;                                      // upper right cell corner
633 619
         // float y1 = y0 + MESH_Y_DIST;                                      // upper right cell corner
634 620
 
635
-        float x0 = pgm_read_float(&(ubl.mesh_index_to_xpos[cell_xi  ]));  // 64 byte table lookup avoids mul+add
636
-        float y0 = pgm_read_float(&(ubl.mesh_index_to_ypos[cell_yi  ]));  // 64 byte table lookup avoids mul+add
637
-        float x1 = pgm_read_float(&(ubl.mesh_index_to_xpos[cell_xi+1]));  // 64 byte table lookup avoids mul+add
638
-        float y1 = pgm_read_float(&(ubl.mesh_index_to_ypos[cell_yi+1]));  // 64 byte table lookup avoids mul+add
621
+        const float x0 = pgm_read_float(&(ubl.mesh_index_to_xpos[cell_xi  ])),  // 64 byte table lookup avoids mul+add
622
+                    y0 = pgm_read_float(&(ubl.mesh_index_to_ypos[cell_yi  ])),  // 64 byte table lookup avoids mul+add
623
+                    x1 = pgm_read_float(&(ubl.mesh_index_to_xpos[cell_xi+1])),  // 64 byte table lookup avoids mul+add
624
+                    y1 = pgm_read_float(&(ubl.mesh_index_to_ypos[cell_yi+1])),  // 64 byte table lookup avoids mul+add
625
+
626
+                    cx = rx - x0,   // cell-relative x
627
+                    cy = ry - y0;   // cell-relative y
639 628
 
640
-        float cx = rx - x0;   // cell-relative x
641
-        float cy = ry - y0;   // cell-relative y
629
+        float z_x0y0 = ubl.z_values[cell_xi  ][cell_yi  ],  // z at lower left corner
630
+              z_x1y0 = ubl.z_values[cell_xi+1][cell_yi  ],  // z at upper left corner
631
+              z_x0y1 = ubl.z_values[cell_xi  ][cell_yi+1],  // z at lower right corner
632
+              z_x1y1 = ubl.z_values[cell_xi+1][cell_yi+1];  // z at upper right corner
642 633
 
643
-        float z_x0y0 = ubl.z_values[cell_xi  ][cell_yi  ];  // z at lower left corner
644
-        float z_x1y0 = ubl.z_values[cell_xi+1][cell_yi  ];  // z at upper left corner
645
-        float z_x0y1 = ubl.z_values[cell_xi  ][cell_yi+1];  // z at lower right corner
646
-        float z_x1y1 = ubl.z_values[cell_xi+1][cell_yi+1];  // z at upper right corner
634
+        if (isnan(z_x0y0)) z_x0y0 = 0;              // ideally activating ubl.state.active (G29 A) 
635
+        if (isnan(z_x1y0)) z_x1y0 = 0;              //   should refuse if any invalid mesh points
636
+        if (isnan(z_x0y1)) z_x0y1 = 0;              //   in order to avoid isnan tests per cell,
637
+        if (isnan(z_x1y1)) z_x1y1 = 0;              //   thus guessing zero for undefined points
647 638
 
648
-        if ( isnan( z_x0y0 )) z_x0y0 = 0;     // ideally activating ubl.state.active (G29 A) 
649
-        if ( isnan( z_x1y0 )) z_x1y0 = 0;     //   should refuse if any invalid mesh points
650
-        if ( isnan( z_x0y1 )) z_x0y1 = 0;     //   in order to avoid isnan tests per cell,
651
-        if ( isnan( z_x1y1 )) z_x1y1 = 0;     //   thus guessing zero for undefined points
639
+        const float z_xmy0 = (z_x1y0 - z_x0y0) * (1.0 / (MESH_X_DIST)),   // z slope per x along y0 (lower left to lower right)
640
+                    z_xmy1 = (z_x1y1 - z_x0y1) * (1.0 / (MESH_X_DIST));   // z slope per x along y1 (upper left to upper right)
652 641
 
653
-        float z_xmy0 = (z_x1y0 - z_x0y0) * (1.0/MESH_X_DIST);   // z slope per x along y0 (lower left to lower right)
654
-        float z_xmy1 = (z_x1y1 - z_x0y1) * (1.0/MESH_X_DIST);   // z slope per x along y1 (upper left to upper right)
642
+              float z_cxy0 = z_x0y0 + z_xmy0 * cx;          // z height along y0 at cx
655 643
 
656
-        float z_cxy0 = z_x0y0 + z_xmy0 * cx;        // z height along y0 at cx
657
-        float z_cxy1 = z_x0y1 + z_xmy1 * cx;        // z height along y1 at cx
658
-        float z_cxyd = z_cxy1 - z_cxy0;             // z height difference along cx from y0 to y1
644
+        const float z_cxy1 = z_x0y1 + z_xmy1 * cx,          // z height along y1 at cx
645
+                    z_cxyd = z_cxy1 - z_cxy0;               // z height difference along cx from y0 to y1
659 646
 
660
-        float z_cxym = z_cxyd * (1.0/MESH_Y_DIST);  // z slope per y along cx from y0 to y1
661
-        float z_cxcy = z_cxy0 + z_cxym * cy;        // z height along cx at cy
647
+              float z_cxym = z_cxyd * (1.0 / (MESH_Y_DIST)),  // z slope per y along cx from y0 to y1
648
+                    z_cxcy = z_cxy0 + z_cxym * cy;          // z height along cx at cy
662 649
 
663 650
         // As subsequent segments step through this cell, the z_cxy0 intercept will change
664 651
         // and the z_cxym slope will change, both as a function of cx within the cell, and
665 652
         // each change by a constant for fixed segment lengths.
666 653
 
667
-        float z_sxy0 = z_xmy0 * dx_seg;                                   // per-segment adjustment to z_cxy0
668
-        float z_sxym = ( z_xmy1 - z_xmy0 ) * (1.0/MESH_Y_DIST) * dx_seg;  // per-segment adjustment to z_cxym
654
+        const float z_sxy0 = z_xmy0 * dx_seg,                                     // per-segment adjustment to z_cxy0
655
+                    z_sxym = (z_xmy1 - z_xmy0) * (1.0 / (MESH_Y_DIST)) * dx_seg;  // per-segment adjustment to z_cxym
669 656
 
670 657
         do {  // for all segments within this mesh cell
671 658
 
672 659
           z_cxcy += ubl.state.z_offset;
673 660
 
674
-          if ( --segments == 0 ) {          // this is last segment, use ltarget for exact
675
-            COPY_XYZE( seg_dest, ltarget );
661
+          if (--segments == 0) {          // this is last segment, use ltarget for exact
662
+            COPY(seg_dest, ltarget);
676 663
             seg_dest[Z_AXIS] += z_cxcy;
677
-            ubl_buffer_line_segment( seg_dest, feedrate, active_extruder );
664
+            ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
678 665
             return false;   // did not set_current_to_destination()
679 666
           }
680 667
 
681
-          float z_orig = seg_dest[Z_AXIS];    // remember the pre-leveled segment z value
682
-          seg_dest[Z_AXIS] = z_orig + z_cxcy; // adjust segment z height per mesh leveling
683
-          ubl_buffer_line_segment( seg_dest, feedrate, active_extruder );
684
-          seg_dest[Z_AXIS] = z_orig;          // restore pre-leveled z before incrementing
668
+          const float z_orig = seg_dest[Z_AXIS];  // remember the pre-leveled segment z value
669
+          seg_dest[Z_AXIS] = z_orig + z_cxcy;     // adjust segment z height per mesh leveling
670
+          ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
671
+          seg_dest[Z_AXIS] = z_orig;              // restore pre-leveled z before incrementing
685 672
 
686 673
           LOOP_XYZE(i) seg_dest[i] += segment_distance[i];  // adjust seg_dest for next segment
687 674
 
688 675
           cx += dx_seg;
689 676
           cy += dy_seg;
690 677
 
691
-          if ( !WITHIN(cx,0,MESH_X_DIST) || !WITHIN(cy,0,MESH_Y_DIST)) {  // done within this cell, break to next
678
+          if (!WITHIN(cx, 0, MESH_X_DIST) || !WITHIN(cy, 0, MESH_Y_DIST)) {  // done within this cell, break to next
692 679
             rx = RAW_X_POSITION(seg_dest[X_AXIS]);
693 680
             ry = RAW_Y_POSITION(seg_dest[Y_AXIS]);
694 681
             break;  

+ 6
- 10
Marlin/ultralcd.cpp View File

@@ -1430,17 +1430,13 @@ void kill_screen(const char* lcd_msg) {
1430 1430
     #endif
1431 1431
 
1432 1432
     // LCD probed points are from defaults
1433
-    constexpr uint8_t total_probe_points =
1434
-      #if ABL_GRID
1435
-        (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
1436
-      #elif ENABLED(AUTO_BED_LEVELING_3POINT)
1437
-        int(3)
1438
-      #elif ENABLED(AUTO_BED_LEVELING_UBL)
1439
-        (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
1440
-      #elif ENABLED(MESH_BED_LEVELING)
1441
-        (GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y)
1433
+    constexpr uint8_t total_probe_points = (
1434
+      #if ENABLED(AUTO_BED_LEVELING_3POINT)
1435
+        3
1436
+      #elif ABL_GRID || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING)
1437
+        GRID_MAX_POINTS
1442 1438
       #endif
1443
-    ;
1439
+    );
1444 1440
 
1445 1441
     #if ENABLED(MESH_BED_LEVELING)
1446 1442
 

+ 0
- 12
buildroot/share/git/mfdoc View File

@@ -16,12 +16,6 @@ if [[ $ORG != "MarlinFirmware" || $REPO != "MarlinDocumentation" ]]; then
16 16
   exit
17 17
 fi
18 18
 
19
-if [[ $BRANCH != "master" ]]; then
20
-  echo "Stashing changes and changing to master."
21
-  git stash
22
-  git checkout master
23
-fi
24
-
25 19
 opensite() {
26 20
   TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
27 21
   URL="http://127.0.0.1:4000/"
@@ -40,9 +34,3 @@ echo "Previewing MarlinDocumentation..."
40 34
 ( sleep 45; opensite ) &
41 35
 
42 36
 bundle exec jekyll serve --watch --incremental
43
-
44
-if [[ $BRANCH != "master" ]]; then
45
-  echo "Restoring branch '$BRANCH'"
46
-  git checkout $BRANCH
47
-  git stash pop
48
-fi

+ 8
- 7
buildroot/share/git/mfpub View File

@@ -30,26 +30,25 @@ if [[ $BRANCH == "gh-pages" ]]; then
30 30
   exit
31 31
 fi
32 32
 
33
-if [[ $BRANCH != "master" ]]; then
34
-  echo "Stashing any changes to files..."
35
-  echo "Don't forget to update and push 'master'!"
36
-  # GOJF Card
37
-  git stash
38
-fi
33
+echo "Stashing any changes to files..."
34
+echo "Don't forget to update and push 'master'!"
35
+# GOJF Card
36
+git stash
39 37
 
40 38
 COMMIT=$( git log --format="%H" -n 1 )
41 39
 
42 40
 # Clean out changes and other junk in the branch
43
-git reset --hard
44 41
 git clean -d -f
45 42
 
46 43
 # Push 'master' to the fork and make a proper PR...
47 44
 if [[ $BRANCH == "master" ]]; then
48 45
 
49 46
   # Allow working directly with the main fork
47
+  echo
50 48
   echo -n "Pushing to origin/master... "
51 49
   git push -f origin
52 50
 
51
+  echo
53 52
   echo -n "Pushing to upstream/master... "
54 53
   git push -f upstream
55 54
 
@@ -58,6 +57,7 @@ else
58 57
   if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then
59 58
     firstpush
60 59
   else
60
+    echo
61 61
     echo -n "Pushing to origin/$BRANCH... "
62 62
     git push -f origin
63 63
   fi
@@ -79,6 +79,7 @@ fi
79 79
 # mv ./_plugins/jekyll-press.rb-disabled ./_plugins/jekyll-press.rb
80 80
 # bundle install
81 81
 
82
+echo
82 83
 echo "Generating MarlinDocumentation..."
83 84
 
84 85
 # build the site statically and proof it

Loading…
Cancel
Save