ソースを参照

Merge pull request #6181 from thinkyhead/rc_ubl_further_fixes

Further adjustments to UBL code
Scott Lahteine 7年前
コミット
541165e878

+ 1
- 1
.travis.yml ファイルの表示

@@ -120,7 +120,7 @@ script:
120 120
   # Test a simple build of AUTO_BED_LEVELING_UBL
121 121
   #
122 122
   - restore_configs
123
-  - opt_enable AUTO_BED_LEVELING_UBL UBL_G26_MESH_EDITING FIX_MOUNTED_PROBE EEPROM_SETTINGS G3D_PANEL
123
+  - opt_enable AUTO_BED_LEVELING_UBL UBL_G26_MESH_EDITING ENABLE_LEVELING_FADE_HEIGHT FIX_MOUNTED_PROBE EEPROM_SETTINGS G3D_PANEL
124 124
   - build_marlin
125 125
   #
126 126
   # Test a Sled Z Probe

+ 46
- 71
Marlin/G26_Mesh_Validation_Tool.cpp ファイルの表示

@@ -47,8 +47,8 @@
47 47
   #define OOZE_AMOUNT 0.3
48 48
 
49 49
   #define SIZE_OF_INTERSECTION_CIRCLES 5
50
-  #define SIZE_OF_CROSS_HAIRS 3 // cross hairs inside the circle.  This number should be
51
-                                // less than SIZE_OR_INTERSECTION_CIRCLES
50
+  #define SIZE_OF_CROSSHAIRS 3 // crosshairs inside the circle.  This number should be
51
+                               // less than SIZE_OR_INTERSECTION_CIRCLES
52 52
 
53 53
   /**
54 54
    *   Roxy's G26 Mesh Validation Tool
@@ -132,12 +132,12 @@
132 132
   void line_to_destination(float );
133 133
   void gcode_G28();
134 134
   void sync_plan_position_e();
135
-  void un_retract_filament();
136
-  void retract_filament();
135
+  void un_retract_filament(float where[XYZE]);
136
+  void retract_filament(float where[XYZE]);
137 137
   void look_for_lines_to_connect();
138 138
   bool parse_G26_parameters();
139 139
   void move_to(const float&, const float&, const float&, const float&) ;
140
-  void print_line_from_here_to_there(float sx, float sy, float sz, float ex, float ey, float ez);
140
+  void print_line_from_here_to_there(const float&, const float&, const float&, const float&, const float&, const float&);
141 141
   bool turn_on_heaters();
142 142
   bool prime_nozzle();
143 143
   void chirp_at_user();
@@ -154,8 +154,6 @@
154 154
 
155 155
   float valid_trig_angle(float);
156 156
   mesh_index_pair find_closest_circle_to_print(float, float);
157
-  void ubl_line_to_destination(const float&, const float&, const float&, const float&, const float&, uint8_t);
158
-  //uint16_t x_splits = 0xFFFF, uint16_t y_splits = 0xFFFF);  /* needed for the old mesh_buffer_line() routine */
159 157
 
160 158
   static float extrusion_multiplier = EXTRUSION_MULTIPLIER,
161 159
                retraction_multiplier = RETRACTION_MULTIPLIER,
@@ -269,7 +267,7 @@
269 267
         #endif
270 268
 
271 269
         // TODO: Change this to use `position_is_reachable`
272
-        if (circle_x < (X_MIN_POS) || circle_x > (X_MAX_POS) || circle_y < (Y_MIN_POS) || circle_y > (Y_MAX_POS)) {
270
+        if (!WITHIN(circle_x, X_MIN_POS, X_MAX_POS) || !WITHIN(circle_y, Y_MIN_POS, Y_MAX_POS)) {
273 271
           SERIAL_ERROR_START;
274 272
           SERIAL_ERRORLNPGM("Attempt to print off the bed.");
275 273
           goto LEAVE;
@@ -359,7 +357,7 @@
359 357
     lcd_reset_alert_level();
360 358
     lcd_setstatuspgm(PSTR("Leaving G26"));
361 359
 
362
-    retract_filament();
360
+    retract_filament(destination);
363 361
     destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES;
364 362
 
365 363
     //debug_current_and_destination((char*)"ready to do Z-Raise.");
@@ -445,18 +443,12 @@
445 443
               // We found two circles that need a horizontal line to connect them
446 444
               // Print it!
447 445
               //
448
-              sx = ubl.mesh_index_to_xpos[i];
449
-              sx = sx + SIZE_OF_INTERSECTION_CIRCLES - SIZE_OF_CROSS_HAIRS; // get the right edge of the circle
450
-              sy = ubl.mesh_index_to_ypos[j];
446
+              sx = ubl.mesh_index_to_xpos[  i  ] + (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // right edge
447
+              ex = ubl.mesh_index_to_xpos[i + 1] - (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // left edge
451 448
 
452
-              ex = ubl.mesh_index_to_xpos[i + 1];
453
-              ex = ex - SIZE_OF_INTERSECTION_CIRCLES + SIZE_OF_CROSS_HAIRS; // get the left edge of the circle
454
-              ey = sy;
455
-
456
-              sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1);             // This keeps us from bumping the endstops
457
-              sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1);
449
+              sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1);
450
+              sy = ey = constrain(ubl.mesh_index_to_ypos[j], Y_MIN_POS + 1, Y_MAX_POS - 1);
458 451
               ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
459
-              ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
460 452
 
461 453
               if (ubl.g26_debug_flag) {
462 454
                 SERIAL_ECHOPAIR(" Connecting with horizontal line (sx=", sx);
@@ -468,7 +460,7 @@
468 460
                 //debug_current_and_destination((char*)"Connecting horizontal line.");
469 461
               }
470 462
 
471
-              print_line_from_here_to_there(sx, sy, layer_height, ex, ey, layer_height);
463
+              print_line_from_here_to_there(LOGICAL_X_POSITION(sx), LOGICAL_Y_POSITION(sy), layer_height, LOGICAL_X_POSITION(ex), LOGICAL_Y_POSITION(ey), layer_height);
472 464
               bit_set(horizontal_mesh_line_flags, i, j);   // Mark it as done so we don't do it again
473 465
             }
474 466
           }
@@ -482,17 +474,11 @@
482 474
                 // We found two circles that need a vertical line to connect them
483 475
                 // Print it!
484 476
                 //
485
-                sx = ubl.mesh_index_to_xpos[i];
486
-                sy = ubl.mesh_index_to_ypos[j];
487
-                sy = sy + SIZE_OF_INTERSECTION_CIRCLES - SIZE_OF_CROSS_HAIRS; // get the top edge of the circle
488
-
489
-                ex = sx;
490
-                ey = ubl.mesh_index_to_ypos[j + 1];
491
-                ey = ey - SIZE_OF_INTERSECTION_CIRCLES + SIZE_OF_CROSS_HAIRS; // get the bottom edge of the circle
477
+                sy = ubl.mesh_index_to_ypos[  j  ] + (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // top edge
478
+                ey = ubl.mesh_index_to_ypos[j + 1] - (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // bottom edge
492 479
 
493
-                sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1);             // This keeps us from bumping the endstops
480
+                sx = ex = constrain(ubl.mesh_index_to_xpos[i], X_MIN_POS + 1, X_MAX_POS - 1);
494 481
                 sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1);
495
-                ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
496 482
                 ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
497 483
 
498 484
                 if (ubl.g26_debug_flag) {
@@ -504,8 +490,8 @@
504 490
                   SERIAL_EOL;
505 491
                   debug_current_and_destination((char*)"Connecting vertical line.");
506 492
                 }
507
-                print_line_from_here_to_there(sx, sy, layer_height, ex, ey, layer_height);
508
-                bit_set( vertical_mesh_line_flags, i, j);   // Mark it as done so we don't do it again
493
+                print_line_from_here_to_there(LOGICAL_X_POSITION(sx), LOGICAL_Y_POSITION(sy), layer_height, LOGICAL_X_POSITION(ex), LOGICAL_Y_POSITION(ey), layer_height);
494
+                bit_set(vertical_mesh_line_flags, i, j);   // Mark it as done so we don't do it again
509 495
               }
510 496
             }
511 497
           }
@@ -533,7 +519,7 @@
533 519
       destination[Z_AXIS] = z;                          // We know the last_z==z or we wouldn't be in this block of code.
534 520
       destination[E_AXIS] = current_position[E_AXIS];
535 521
 
536
-      ubl_line_to_destination(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feed_value, 0);
522
+      ubl_line_to_destination(feed_value, 0);
537 523
 
538 524
       stepper.synchronize();
539 525
       set_destination_to_current();
@@ -553,7 +539,7 @@
553 539
 
554 540
     //if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() doing last move");
555 541
 
556
-    ubl_line_to_destination(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feed_value, 0);
542
+    ubl_line_to_destination(feed_value, 0);
557 543
 
558 544
     //if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() after last move");
559 545
 
@@ -562,18 +548,18 @@
562 548
 
563 549
   }
564 550
 
565
-  void retract_filament() {
551
+  void retract_filament(float where[XYZE]) {
566 552
     if (!g26_retracted) { // Only retract if we are not already retracted!
567 553
       g26_retracted = true;
568 554
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Decided to do retract.");
569
-      move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], -1.0 * retraction_multiplier);
555
+      move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], -1.0 * retraction_multiplier);
570 556
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Retraction done.");
571 557
     }
572 558
   }
573 559
 
574
-  void un_retract_filament() {
560
+  void un_retract_filament(float where[XYZE]) {
575 561
     if (g26_retracted) { // Only un-retract if we are retracted.
576
-      move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 1.2 * retraction_multiplier);
562
+      move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], 1.2 * retraction_multiplier);
577 563
       g26_retracted = false;
578 564
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" unretract done.");
579 565
     }
@@ -594,7 +580,7 @@
594 580
    * segment of a 'circle'.   The time this requires is very short and is easily saved by the other
595 581
    * cases where the optimization comes into play.
596 582
    */
597
-  void print_line_from_here_to_there( float sx, float sy, float sz, float ex, float ey, float ez) {
583
+  void print_line_from_here_to_there(const float &sx, const float &sy, const float &sz, const float &ex, const float &ey, const float &ez) {
598 584
     const float dx_s = current_position[X_AXIS] - sx,   // find our distance from the start of the actual line segment
599 585
                 dy_s = current_position[Y_AXIS] - sy,
600 586
                 dist_start = HYPOT2(dx_s, dy_s),        // We don't need to do a sqrt(), we can compare the distance^2
@@ -603,31 +589,26 @@
603 589
                 dy_e = current_position[Y_AXIS] - ey,
604 590
                 dist_end = HYPOT2(dx_e, dy_e),
605 591
 
606
-                dx = ex - sx,
607
-                dy = ey - sy,
608
-                line_length = HYPOT(dx, dy);
592
+                line_length = HYPOT(ex - sx, ey - sy);
609 593
 
610
-    // If the end point of the line is closer to the nozzle, we are going to
611
-    // flip the direction of this line.   We will print it from the end to the start.
612
-    // On very small lines we don't do the optimization because it just isn't worth it.
613
-    //
594
+    // If the end point of the line is closer to the nozzle, flip the direction,
595
+    // moving from the end to the start. On very small lines the optimization isn't worth it.
614 596
     if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < abs(line_length)) {
615 597
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  Reversing start and end of print_line_from_here_to_there()");
616
-      print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
617
-      return;
598
+      return print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
618 599
     }
619 600
 
620
-    // Now decide if we should retract.
601
+    // Decide whether to retract.
621 602
 
622 603
     if (dist_start > 2.0) {
623
-      retract_filament();
604
+      retract_filament(destination);
624 605
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  filament retracted.");
625 606
     }
626 607
     move_to(sx, sy, sz, 0.0); // Get to the starting point with no extrusion
627 608
 
628 609
     const float e_pos_delta = line_length * g26_e_axis_feedrate * extrusion_multiplier;
629 610
 
630
-    un_retract_filament();
611
+    un_retract_filament(destination);
631 612
 
632 613
     //if (ubl.g26_debug_flag) {
633 614
     //  SERIAL_ECHOLNPGM("  doing printing move.");
@@ -657,7 +638,7 @@
657 638
 
658 639
     if (code_seen('B')) {
659 640
       bed_temp = code_value_float();
660
-      if (bed_temp < 15.0 || bed_temp > 140.0) {
641
+      if (!WITHIN(bed_temp, 15.0, 140.0)) {
661 642
         SERIAL_PROTOCOLLNPGM("?Specified bed temperature not plausible.");
662 643
         return UBL_ERR;
663 644
       }
@@ -667,7 +648,7 @@
667 648
 
668 649
     if (code_seen('L')) {
669 650
       layer_height = code_value_float();
670
-      if (layer_height < 0.0 || layer_height > 2.0) {
651
+      if (!WITHIN(layer_height, 0.0, 2.0)) {
671 652
         SERIAL_PROTOCOLLNPGM("?Specified layer height not plausible.");
672 653
         return UBL_ERR;
673 654
       }
@@ -676,7 +657,7 @@
676 657
     if (code_seen('Q')) {
677 658
       if (code_has_value()) {
678 659
         retraction_multiplier = code_value_float();
679
-        if (retraction_multiplier < 0.05 || retraction_multiplier > 15.0) {
660
+        if (!WITHIN(retraction_multiplier, 0.05, 15.0)) {
680 661
           SERIAL_PROTOCOLLNPGM("?Specified Retraction Multiplier not plausible.");
681 662
           return UBL_ERR;
682 663
         }
@@ -689,7 +670,7 @@
689 670
 
690 671
     if (code_seen('N')) {
691 672
       nozzle = code_value_float();
692
-      if (nozzle < 0.1 || nozzle > 1.0) {
673
+      if (!WITHIN(nozzle, 0.1, 1.0)) {
693 674
         SERIAL_PROTOCOLLNPGM("?Specified nozzle size not plausible.");
694 675
         return UBL_ERR;
695 676
       }
@@ -706,7 +687,7 @@
706 687
       else {
707 688
         prime_flag++;
708 689
         prime_length = code_value_float();
709
-        if (prime_length < 0.0 || prime_length > 25.0) {
690
+        if (!WITHIN(prime_length, 0.0, 25.0)) {
710 691
           SERIAL_PROTOCOLLNPGM("?Specified prime length not plausible.");
711 692
           return UBL_ERR;
712 693
         }
@@ -715,7 +696,7 @@
715 696
 
716 697
     if (code_seen('F')) {
717 698
       filament_diameter = code_value_float();
718
-      if (filament_diameter < 1.0 || filament_diameter > 4.0) {
699
+      if (!WITHIN(filament_diameter, 1.0, 4.0)) {
719 700
         SERIAL_PROTOCOLLNPGM("?Specified filament size not plausible.");
720 701
         return UBL_ERR;
721 702
       }
@@ -728,7 +709,7 @@
728 709
 
729 710
     if (code_seen('H')) {
730 711
       hotend_temp = code_value_float();
731
-      if (hotend_temp < 165.0 || hotend_temp > 280.0) {
712
+      if (!WITHIN(hotend_temp, 165.0, 280.0)) {
732 713
         SERIAL_PROTOCOLLNPGM("?Specified nozzle temperature not plausible.");
733 714
         return UBL_ERR;
734 715
       }
@@ -744,7 +725,7 @@
744 725
 
745 726
     if (code_seen('X')) {
746 727
       x_pos = code_value_float();
747
-      if (x_pos < X_MIN_POS || x_pos > X_MAX_POS) {
728
+      if (!WITHIN(x_pos, X_MIN_POS, X_MAX_POS)) {
748 729
         SERIAL_PROTOCOLLNPGM("?Specified X coordinate not plausible.");
749 730
         return UBL_ERR;
750 731
       }
@@ -753,7 +734,7 @@
753 734
 
754 735
     if (code_seen('Y')) {
755 736
       y_pos = code_value_float();
756
-      if (y_pos < Y_MIN_POS || y_pos > Y_MAX_POS) {
737
+      if (!WITHIN(y_pos, Y_MIN_POS, Y_MAX_POS)) {
757 738
         SERIAL_PROTOCOLLNPGM("?Specified Y coordinate not plausible.");
758 739
         return UBL_ERR;
759 740
       }
@@ -814,6 +795,7 @@
814 795
       lcd_setstatuspgm(PSTR(""));
815 796
       lcd_quick_feedback();
816 797
     #endif
798
+
817 799
     return UBL_OK;
818 800
   }
819 801
 
@@ -832,9 +814,8 @@
832 814
 
833 815
       set_destination_to_current();
834 816
 
835
-      un_retract_filament();    // Lets make sure the G26 command doesn't think the filament is
836
-                                // retracted().  We are here because we want to prime the nozzle.
837
-                                // So let's just unretract just to be sure.
817
+      un_retract_filament(destination); // Make sure G26 doesn't think the filament is retracted().
818
+
838 819
       while (!ubl_lcd_clicked()) {
839 820
         chirp_at_user();
840 821
         destination[E_AXIS] += 0.25;
@@ -842,10 +823,7 @@
842 823
           Total_Prime += 0.25;
843 824
           if (Total_Prime >= EXTRUDE_MAXLENGTH) return UBL_ERR;
844 825
         #endif
845
-        ubl_line_to_destination(
846
-          destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS],
847
-          planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0
848
-        );
826
+        ubl_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0);
849 827
 
850 828
         stepper.synchronize();    // Without this synchronize, the purge is more consistent,
851 829
                                   // but because the planner has a buffer, we won't be able
@@ -874,13 +852,10 @@
874 852
       #endif
875 853
       set_destination_to_current();
876 854
       destination[E_AXIS] += prime_length;
877
-      ubl_line_to_destination(
878
-        destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS],
879
-        planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0
880
-      );
855
+      ubl_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0);
881 856
       stepper.synchronize();
882 857
       set_destination_to_current();
883
-      retract_filament();
858
+      retract_filament(destination);
884 859
     }
885 860
 
886 861
     return UBL_OK;

+ 0
- 1
Marlin/Marlin.h ファイルの表示

@@ -244,7 +244,6 @@ inline bool IsRunning() { return  Running; }
244 244
 inline bool IsStopped() { return !Running; }
245 245
 
246 246
 bool enqueue_and_echo_command(const char* cmd, bool say_ok=false); //put a single ASCII command at the end of the current buffer or return false when it is full
247
-void enqueue_and_echo_command_now(const char* cmd); // enqueue now, only return when the command has been enqueued
248 247
 void enqueue_and_echo_commands_P(const char* cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
249 248
 void clear_command_queue();
250 249
 

+ 36
- 44
Marlin/Marlin_main.cpp ファイルの表示

@@ -896,10 +896,6 @@ bool enqueue_and_echo_command(const char* cmd, bool say_ok/*=false*/) {
896 896
   return false;
897 897
 }
898 898
 
899
-void enqueue_and_echo_command_now(const char* cmd) {
900
-  while (!enqueue_and_echo_command(cmd)) idle();
901
-}
902
-
903 899
 void setup_killpin() {
904 900
   #if HAS_KILL
905 901
     SET_INPUT_PULLUP(KILL_PIN);
@@ -2237,7 +2233,7 @@ static void clean_up_after_endstop_or_probe_move() {
2237 2233
         SERIAL_ECHOLNPAIR(" Discrepancy:", first_probe_z - current_position[Z_AXIS]);
2238 2234
       }
2239 2235
     #endif
2240
-    return current_position[Z_AXIS];
2236
+    return current_position[Z_AXIS] + zprobe_zoffset;
2241 2237
   }
2242 2238
 
2243 2239
   //
@@ -2291,7 +2287,7 @@ static void clean_up_after_endstop_or_probe_move() {
2291 2287
       SERIAL_PROTOCOLPGM(" Y: ");
2292 2288
       SERIAL_PROTOCOL_F(y, 3);
2293 2289
       SERIAL_PROTOCOLPGM(" Z: ");
2294
-      SERIAL_PROTOCOL_F(measured_z - -zprobe_zoffset + 0.0001, 3);
2290
+      SERIAL_PROTOCOL_F(FIXFLOAT(measured_z), 3);
2295 2291
       SERIAL_EOL;
2296 2292
     }
2297 2293
 
@@ -2569,7 +2565,7 @@ static void clean_up_after_endstop_or_probe_move() {
2569 2565
           ep = ABL_GRID_MAX_POINTS_X - 1;
2570 2566
           ip = ABL_GRID_MAX_POINTS_X - 2;
2571 2567
         }
2572
-        if (y > 0 && y < ABL_TEMP_POINTS_Y - 1)
2568
+        if (WITHIN(y, 1, ABL_TEMP_POINTS_Y - 2))
2573 2569
           return LINEAR_EXTRAPOLATION(
2574 2570
             bed_level_grid[ep][y - 1],
2575 2571
             bed_level_grid[ip][y - 1]
@@ -2585,7 +2581,7 @@ static void clean_up_after_endstop_or_probe_move() {
2585 2581
           ep = ABL_GRID_MAX_POINTS_Y - 1;
2586 2582
           ip = ABL_GRID_MAX_POINTS_Y - 2;
2587 2583
         }
2588
-        if (x > 0 && x < ABL_TEMP_POINTS_X - 1)
2584
+        if (WITHIN(x, 1, ABL_TEMP_POINTS_X - 2))
2589 2585
           return LINEAR_EXTRAPOLATION(
2590 2586
             bed_level_grid[x - 1][ep],
2591 2587
             bed_level_grid[x - 1][ip]
@@ -3028,9 +3024,9 @@ bool position_is_reachable(float target[XYZ]
3028 3024
     return HYPOT2(dx, dy) <= sq((float)(DELTA_PRINTABLE_RADIUS));
3029 3025
   #else
3030 3026
     const float dz = RAW_Z_POSITION(target[Z_AXIS]);
3031
-    return dx >= X_MIN_POS - 0.0001 && dx <= X_MAX_POS + 0.0001
3032
-        && dy >= Y_MIN_POS - 0.0001 && dy <= Y_MAX_POS + 0.0001
3033
-        && dz >= Z_MIN_POS - 0.0001 && dz <= Z_MAX_POS + 0.0001;
3027
+    return WITHIN(dx, X_MIN_POS - 0.0001, X_MAX_POS + 0.0001)
3028
+        && WITHIN(dy, Y_MIN_POS - 0.0001, Y_MAX_POS + 0.0001)
3029
+        && WITHIN(dz, Z_MIN_POS - 0.0001, Z_MAX_POS + 0.0001);
3034 3030
   #endif
3035 3031
 }
3036 3032
 
@@ -3788,13 +3784,13 @@ inline void gcode_G28() {
3788 3784
    */
3789 3785
   inline void gcode_G29() {
3790 3786
 
3791
-    static int probe_index = -1;
3787
+    static int mbl_probe_index = -1;
3792 3788
     #if HAS_SOFTWARE_ENDSTOPS
3793 3789
       static bool enable_soft_endstops;
3794 3790
     #endif
3795 3791
 
3796 3792
     const MeshLevelingState state = code_seen('S') ? (MeshLevelingState)code_value_byte() : MeshReport;
3797
-    if (state < 0 || state > 5) {
3793
+    if (!WITHIN(state, 0, 5)) {
3798 3794
       SERIAL_PROTOCOLLNPGM("S out of range (0-5).");
3799 3795
       return;
3800 3796
     }
@@ -3813,17 +3809,17 @@ inline void gcode_G28() {
3813 3809
 
3814 3810
       case MeshStart:
3815 3811
         mbl.reset();
3816
-        probe_index = 0;
3812
+        mbl_probe_index = 0;
3817 3813
         enqueue_and_echo_commands_P(PSTR("G28\nG29 S2"));
3818 3814
         break;
3819 3815
 
3820 3816
       case MeshNext:
3821
-        if (probe_index < 0) {
3817
+        if (mbl_probe_index < 0) {
3822 3818
           SERIAL_PROTOCOLLNPGM("Start mesh probing with \"G29 S1\" first.");
3823 3819
           return;
3824 3820
         }
3825 3821
         // For each G29 S2...
3826
-        if (probe_index == 0) {
3822
+        if (mbl_probe_index == 0) {
3827 3823
           #if HAS_SOFTWARE_ENDSTOPS
3828 3824
             // For the initial G29 S2 save software endstop state
3829 3825
             enable_soft_endstops = soft_endstops_enabled;
@@ -3831,14 +3827,14 @@ inline void gcode_G28() {
3831 3827
         }
3832 3828
         else {
3833 3829
           // For G29 S2 after adjusting Z.
3834
-          mbl.set_zigzag_z(probe_index - 1, current_position[Z_AXIS]);
3830
+          mbl.set_zigzag_z(mbl_probe_index - 1, current_position[Z_AXIS]);
3835 3831
           #if HAS_SOFTWARE_ENDSTOPS
3836 3832
             soft_endstops_enabled = enable_soft_endstops;
3837 3833
           #endif
3838 3834
         }
3839 3835
         // If there's another point to sample, move there with optional lift.
3840
-        if (probe_index < (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
3841
-          mbl.zigzag(probe_index, px, py);
3836
+        if (mbl_probe_index < (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
3837
+          mbl.zigzag(mbl_probe_index, px, py);
3842 3838
           _mbl_goto_xy(mbl.index_to_xpos[px], mbl.index_to_ypos[py]);
3843 3839
 
3844 3840
           #if HAS_SOFTWARE_ENDSTOPS
@@ -3847,7 +3843,7 @@ inline void gcode_G28() {
3847 3843
             soft_endstops_enabled = false;
3848 3844
           #endif
3849 3845
 
3850
-          probe_index++;
3846
+          mbl_probe_index++;
3851 3847
         }
3852 3848
         else {
3853 3849
           // One last "return to the bed" (as originally coded) at completion
@@ -3857,7 +3853,7 @@ inline void gcode_G28() {
3857 3853
 
3858 3854
           // After recording the last point, activate the mbl and home
3859 3855
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
3860
-          probe_index = -1;
3856
+          mbl_probe_index = -1;
3861 3857
           mbl.set_has_mesh(true);
3862 3858
           mbl.set_reactivate(true);
3863 3859
           enqueue_and_echo_commands_P(PSTR("G28"));
@@ -3869,7 +3865,7 @@ inline void gcode_G28() {
3869 3865
       case MeshSet:
3870 3866
         if (code_seen('X')) {
3871 3867
           px = code_value_int() - 1;
3872
-          if (px < 0 || px >= MESH_NUM_X_POINTS) {
3868
+          if (!WITHIN(px, 0, MESH_NUM_X_POINTS - 1)) {
3873 3869
             SERIAL_PROTOCOLLNPGM("X out of range (1-" STRINGIFY(MESH_NUM_X_POINTS) ").");
3874 3870
             return;
3875 3871
           }
@@ -3881,7 +3877,7 @@ inline void gcode_G28() {
3881 3877
 
3882 3878
         if (code_seen('Y')) {
3883 3879
           py = code_value_int() - 1;
3884
-          if (py < 0 || py >= MESH_NUM_Y_POINTS) {
3880
+          if (!WITHIN(py, 0, MESH_NUM_Y_POINTS - 1)) {
3885 3881
             SERIAL_PROTOCOLLNPGM("Y out of range (1-" STRINGIFY(MESH_NUM_Y_POINTS) ").");
3886 3882
             return;
3887 3883
           }
@@ -4412,7 +4408,7 @@ inline void gcode_G28() {
4412 4408
         if ( NEAR(current_position[X_AXIS], xProbe - (X_PROBE_OFFSET_FROM_EXTRUDER))
4413 4409
           && NEAR(current_position[Y_AXIS], yProbe - (Y_PROBE_OFFSET_FROM_EXTRUDER))
4414 4410
         ) {
4415
-          float simple_z = current_position[Z_AXIS] - (measured_z - (-zprobe_zoffset));
4411
+          float simple_z = current_position[Z_AXIS] - measured_z;
4416 4412
           #if ENABLED(DEBUG_LEVELING_FEATURE)
4417 4413
             if (DEBUGGING(LEVELING)) {
4418 4414
               SERIAL_ECHOPAIR("Z from Probe:", simple_z);
@@ -4503,11 +4499,11 @@ inline void gcode_G28() {
4503 4499
     float measured_z = probe_pt(X_probe_location, Y_probe_location, stow, 1);
4504 4500
 
4505 4501
     SERIAL_PROTOCOLPGM("Bed X: ");
4506
-    SERIAL_PROTOCOL(X_probe_location + 0.0001);
4502
+    SERIAL_PROTOCOL(FIXFLOAT(X_probe_location));
4507 4503
     SERIAL_PROTOCOLPGM(" Y: ");
4508
-    SERIAL_PROTOCOL(Y_probe_location + 0.0001);
4504
+    SERIAL_PROTOCOL(FIXFLOAT(Y_probe_location));
4509 4505
     SERIAL_PROTOCOLPGM(" Z: ");
4510
-    SERIAL_PROTOCOLLN(measured_z - -zprobe_zoffset + 0.0001);
4506
+    SERIAL_PROTOCOLLN(FIXFLOAT(measured_z));
4511 4507
 
4512 4508
     clean_up_after_endstop_or_probe_move();
4513 4509
 
@@ -4971,7 +4967,7 @@ inline void gcode_M42() {
4971 4967
   if (!code_seen('S')) return;
4972 4968
 
4973 4969
   int pin_status = code_value_int();
4974
-  if (pin_status < 0 || pin_status > 255) return;
4970
+  if (!WITHIN(pin_status, 0, 255)) return;
4975 4971
 
4976 4972
   int pin_number = code_seen('P') ? code_value_int() : LED_PIN;
4977 4973
   if (pin_number < 0) return;
@@ -5115,7 +5111,7 @@ inline void gcode_M42() {
5115 5111
     if (axis_unhomed_error(true, true, true)) return;
5116 5112
 
5117 5113
     int8_t verbose_level = code_seen('V') ? code_value_byte() : 1;
5118
-    if (verbose_level < 0 || verbose_level > 4) {
5114
+    if (!WITHIN(verbose_level, 0, 4)) {
5119 5115
       SERIAL_PROTOCOLLNPGM("?Verbose Level not plausible (0-4).");
5120 5116
       return;
5121 5117
     }
@@ -5124,7 +5120,7 @@ inline void gcode_M42() {
5124 5120
       SERIAL_PROTOCOLLNPGM("M48 Z-Probe Repeatability Test");
5125 5121
 
5126 5122
     int8_t n_samples = code_seen('P') ? code_value_byte() : 10;
5127
-    if (n_samples < 4 || n_samples > 50) {
5123
+    if (!WITHIN(n_samples, 4, 50)) {
5128 5124
       SERIAL_PROTOCOLLNPGM("?Sample size not plausible (4-50).");
5129 5125
       return;
5130 5126
     }
@@ -5136,7 +5132,7 @@ inline void gcode_M42() {
5136 5132
 
5137 5133
     float X_probe_location = code_seen('X') ? code_value_axis_units(X_AXIS) : X_current + X_PROBE_OFFSET_FROM_EXTRUDER;
5138 5134
     #if DISABLED(DELTA)
5139
-      if (X_probe_location < LOGICAL_X_POSITION(MIN_PROBE_X) || X_probe_location > LOGICAL_X_POSITION(MAX_PROBE_X)) {
5135
+      if (!WITHIN(X_probe_location, LOGICAL_X_POSITION(MIN_PROBE_X), LOGICAL_X_POSITION(MAX_PROBE_X))) {
5140 5136
         out_of_range_error(PSTR("X"));
5141 5137
         return;
5142 5138
       }
@@ -5144,7 +5140,7 @@ inline void gcode_M42() {
5144 5140
 
5145 5141
     float Y_probe_location = code_seen('Y') ? code_value_axis_units(Y_AXIS) : Y_current + Y_PROBE_OFFSET_FROM_EXTRUDER;
5146 5142
     #if DISABLED(DELTA)
5147
-      if (Y_probe_location < LOGICAL_Y_POSITION(MIN_PROBE_Y) || Y_probe_location > LOGICAL_Y_POSITION(MAX_PROBE_Y)) {
5143
+      if (!WITHIN(Y_probe_location, LOGICAL_Y_POSITION(MIN_PROBE_Y), LOGICAL_Y_POSITION(MAX_PROBE_Y))) {
5148 5144
         out_of_range_error(PSTR("Y"));
5149 5145
         return;
5150 5146
       }
@@ -6795,7 +6791,7 @@ inline void gcode_M226() {
6795 6791
   inline void gcode_M280() {
6796 6792
     if (!code_seen('P')) return;
6797 6793
     int servo_index = code_value_int();
6798
-    if (servo_index >= 0 && servo_index < NUM_SERVOS) {
6794
+    if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
6799 6795
       if (code_seen('S'))
6800 6796
         MOVE_SERVO(servo_index, code_value_int());
6801 6797
       else {
@@ -7002,7 +6998,7 @@ inline void gcode_M303() {
7002 6998
 
7003 6999
     float temp = code_seen('S') ? code_value_temp_abs() : (e < 0 ? 70.0 : 150.0);
7004 7000
 
7005
-    if (e >= 0 && e < HOTENDS)
7001
+    if (WITHIN(e, 0, HOTENDS - 1))
7006 7002
       target_extruder = e;
7007 7003
 
7008 7004
     KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
@@ -7223,7 +7219,7 @@ void quickstop_stepper() {
7223 7219
       if (code_seen('L')) {
7224 7220
         const int8_t storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot;
7225 7221
         const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
7226
-        if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
7222
+        if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
7227 7223
           SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
7228 7224
           return;
7229 7225
         }
@@ -7316,7 +7312,7 @@ void quickstop_stepper() {
7316 7312
       }
7317 7313
     }
7318 7314
     else if (hasI && hasJ && hasZ) {
7319
-      if (px >= 0 && px < MESH_NUM_X_POINTS && py >= 0 && py < MESH_NUM_Y_POINTS)
7315
+      if (WITHIN(px, 0, MESH_NUM_X_POINTS - 1) && WITHIN(py, 0, MESH_NUM_Y_POINTS - 1))
7320 7316
         mbl.set_z(px, py, z);
7321 7317
       else {
7322 7318
         SERIAL_ERROR_START;
@@ -7345,7 +7341,7 @@ void quickstop_stepper() {
7345 7341
     if ((hasZ = code_seen('Z'))) z = code_value_axis_units(Z_AXIS);
7346 7342
 
7347 7343
     if (hasI && hasJ && hasZ) {
7348
-      if (px >= 0 && px < ABL_GRID_MAX_POINTS_X && py >= 0 && py < ABL_GRID_MAX_POINTS_X) {
7344
+      if (WITHIN(px, 0, ABL_GRID_MAX_POINTS_X - 1) && WITHIN(py, 0, ABL_GRID_MAX_POINTS_X - 1)) {
7349 7345
         bed_level_grid[px][py] = z;
7350 7346
         #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7351 7347
           bed_level_virt_interpolate();
@@ -7383,7 +7379,7 @@ void quickstop_stepper() {
7383 7379
       if (axis_homed[i]) {
7384 7380
         float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos((AxisEnum)i) : 0,
7385 7381
               diff = current_position[i] - LOGICAL_POSITION(base, i);
7386
-        if (diff > -20 && diff < 20) {
7382
+        if (WITHIN(diff, -20, 20)) {
7387 7383
           set_home_offset((AxisEnum)i, home_offset[i] - diff);
7388 7384
         }
7389 7385
         else {
@@ -7457,7 +7453,7 @@ inline void gcode_M503() {
7457 7453
 
7458 7454
     if (code_seen('Z')) {
7459 7455
       float value = code_value_axis_units(Z_AXIS);
7460
-      if (Z_PROBE_OFFSET_RANGE_MIN <= value && value <= Z_PROBE_OFFSET_RANGE_MAX) {
7456
+      if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
7461 7457
 
7462 7458
         #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
7463 7459
           // Correct bilinear grid for new probe offset
@@ -9905,11 +9901,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9905 9901
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
9906 9902
         if (ubl.state.active) {
9907 9903
 
9908
-//        ubl_line_to_destination(MMS_SCALED(feedrate_mm_s));
9909
-
9910
-          ubl_line_to_destination(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS],
9911
-//                      (feedrate*(1.0/60.0))*(feedrate_percentage*(1.0/100.0) ), active_extruder);
9912
-                      MMS_SCALED(feedrate_mm_s), active_extruder);
9904
+          ubl_line_to_destination(MMS_SCALED(feedrate_mm_s), active_extruder);
9913 9905
 
9914 9906
           return false;
9915 9907
         }

+ 18
- 18
Marlin/SanityCheck.h ファイルの表示

@@ -540,13 +540,13 @@ static_assert(1 >= 0
540 540
  * Make sure Z_SAFE_HOMING point is reachable
541 541
  */
542 542
 #if ENABLED(Z_SAFE_HOMING)
543
-  #if Z_SAFE_HOMING_X_POINT < MIN_PROBE_X || Z_SAFE_HOMING_X_POINT > MAX_PROBE_X
543
+  #if !WITHIN(Z_SAFE_HOMING_X_POINT, MIN_PROBE_X, MAX_PROBE_X)
544 544
     #if HAS_BED_PROBE
545 545
       #error "Z_SAFE_HOMING_X_POINT can't be reached by the Z probe."
546 546
     #else
547 547
       #error "Z_SAFE_HOMING_X_POINT can't be reached by the nozzle."
548 548
     #endif
549
-  #elif Z_SAFE_HOMING_Y_POINT < MIN_PROBE_Y || Z_SAFE_HOMING_Y_POINT > MAX_PROBE_Y
549
+  #elif !WITHIN(Z_SAFE_HOMING_Y_POINT, MIN_PROBE_Y, MAX_PROBE_Y)
550 550
     #if HAS_BED_PROBE
551 551
       #error "Z_SAFE_HOMING_Y_POINT can't be reached by the Z probe."
552 552
     #else
@@ -598,33 +598,33 @@ static_assert(1 >= 0
598 598
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
599 599
     #if DISABLED(EEPROM_SETTINGS)
600 600
       #error "AUTO_BED_LEVELING_UBL requires EEPROM_SETTINGS. Please update your configuration."
601
-    #elif UBL_MESH_NUM_X_POINTS < 3 || UBL_MESH_NUM_X_POINTS > 15 || UBL_MESH_NUM_Y_POINTS < 3 || UBL_MESH_NUM_Y_POINTS > 15
601
+    #elif !WITHIN(UBL_MESH_NUM_X_POINTS, 3, 15) || !WITHIN(UBL_MESH_NUM_Y_POINTS, 3, 15)
602 602
       #error "UBL_MESH_NUM_[XY]_POINTS must be a whole number between 3 and 15."
603
-    #elif UBL_PROBE_PT_1_X < MIN_PROBE_X || UBL_PROBE_PT_1_X > MAX_PROBE_X
603
+    #elif !WITHIN(UBL_PROBE_PT_1_X, MIN_PROBE_X, MAX_PROBE_X)
604 604
       #error "The given UBL_PROBE_PT_1_X can't be reached by the Z probe."
605
-    #elif UBL_PROBE_PT_2_X < MIN_PROBE_X || UBL_PROBE_PT_2_X > MAX_PROBE_X
605
+    #elif !WITHIN(UBL_PROBE_PT_2_X, MIN_PROBE_X, MAX_PROBE_X)
606 606
       #error "The given UBL_PROBE_PT_2_X can't be reached by the Z probe."
607
-    #elif UBL_PROBE_PT_3_X < MIN_PROBE_X || UBL_PROBE_PT_3_X > MAX_PROBE_X
607
+    #elif !WITHIN(UBL_PROBE_PT_3_X, MIN_PROBE_X, MAX_PROBE_X)
608 608
       #error "The given UBL_PROBE_PT_3_X can't be reached by the Z probe."
609
-    #elif UBL_PROBE_PT_1_Y < MIN_PROBE_Y || UBL_PROBE_PT_1_Y > MAX_PROBE_Y
609
+    #elif !WITHIN(UBL_PROBE_PT_1_Y, MIN_PROBE_Y, MAX_PROBE_Y)
610 610
       #error "The given UBL_PROBE_PT_1_Y can't be reached by the Z probe."
611
-    #elif UBL_PROBE_PT_2_Y < MIN_PROBE_Y || UBL_PROBE_PT_2_Y > MAX_PROBE_Y
611
+    #elif !WITHIN(UBL_PROBE_PT_2_Y, MIN_PROBE_Y, MAX_PROBE_Y)
612 612
       #error "The given UBL_PROBE_PT_2_Y can't be reached by the Z probe."
613
-    #elif UBL_PROBE_PT_3_Y < MIN_PROBE_Y || UBL_PROBE_PT_3_Y > MAX_PROBE_Y
613
+    #elif !WITHIN(UBL_PROBE_PT_3_Y, MIN_PROBE_Y, MAX_PROBE_Y)
614 614
       #error "The given UBL_PROBE_PT_3_Y can't be reached by the Z probe."
615 615
     #endif
616 616
   #else // AUTO_BED_LEVELING_3POINT
617
-    #if ABL_PROBE_PT_1_X < MIN_PROBE_X || ABL_PROBE_PT_1_X > MAX_PROBE_X
617
+    #if !WITHIN(ABL_PROBE_PT_1_X, MIN_PROBE_X, MAX_PROBE_X)
618 618
       #error "The given ABL_PROBE_PT_1_X can't be reached by the Z probe."
619
-    #elif ABL_PROBE_PT_2_X < MIN_PROBE_X || ABL_PROBE_PT_2_X > MAX_PROBE_X
619
+    #elif !WITHIN(ABL_PROBE_PT_2_X, MIN_PROBE_X, MAX_PROBE_X)
620 620
       #error "The given ABL_PROBE_PT_2_X can't be reached by the Z probe."
621
-    #elif ABL_PROBE_PT_3_X < MIN_PROBE_X || ABL_PROBE_PT_3_X > MAX_PROBE_X
621
+    #elif !WITHIN(ABL_PROBE_PT_3_X, MIN_PROBE_X, MAX_PROBE_X)
622 622
       #error "The given ABL_PROBE_PT_3_X can't be reached by the Z probe."
623
-    #elif ABL_PROBE_PT_1_Y < MIN_PROBE_Y || ABL_PROBE_PT_1_Y > MAX_PROBE_Y
623
+    #elif !WITHIN(ABL_PROBE_PT_1_Y, MIN_PROBE_Y, MAX_PROBE_Y)
624 624
       #error "The given ABL_PROBE_PT_1_Y can't be reached by the Z probe."
625
-    #elif ABL_PROBE_PT_2_Y < MIN_PROBE_Y || ABL_PROBE_PT_2_Y > MAX_PROBE_Y
625
+    #elif !WITHIN(ABL_PROBE_PT_2_Y, MIN_PROBE_Y, MAX_PROBE_Y)
626 626
       #error "The given ABL_PROBE_PT_2_Y can't be reached by the Z probe."
627
-    #elif ABL_PROBE_PT_3_Y < MIN_PROBE_Y || ABL_PROBE_PT_3_Y > MAX_PROBE_Y
627
+    #elif !WITHIN(ABL_PROBE_PT_3_Y, MIN_PROBE_Y, MAX_PROBE_Y)
628 628
       #error "The given ABL_PROBE_PT_3_Y can't be reached by the Z probe."
629 629
     #endif
630 630
   #endif // AUTO_BED_LEVELING_3POINT
@@ -862,11 +862,11 @@ static_assert(1 >= 0
862 862
 /**
863 863
  * Endstops
864 864
  */
865
-#if DISABLED(USE_XMIN_PLUG) && DISABLED(USE_XMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && Z2_USE_ENDSTOP >= _XMAX_ && Z2_USE_ENDSTOP <= _XMIN_)
865
+#if DISABLED(USE_XMIN_PLUG) && DISABLED(USE_XMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && WITHIN(Z2_USE_ENDSTOP, _XMAX_, _XMIN_))
866 866
  #error "You must enable USE_XMIN_PLUG or USE_XMAX_PLUG."
867
-#elif DISABLED(USE_YMIN_PLUG) && DISABLED(USE_YMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && Z2_USE_ENDSTOP >= _YMAX_ && Z2_USE_ENDSTOP <= _YMIN_)
867
+#elif DISABLED(USE_YMIN_PLUG) && DISABLED(USE_YMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && WITHIN(Z2_USE_ENDSTOP, _YMAX_, _YMIN_))
868 868
  #error "You must enable USE_YMIN_PLUG or USE_YMAX_PLUG."
869
-#elif DISABLED(USE_ZMIN_PLUG) && DISABLED(USE_ZMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && Z2_USE_ENDSTOP >= _ZMAX_ && Z2_USE_ENDSTOP <= _ZMIN_)
869
+#elif DISABLED(USE_ZMIN_PLUG) && DISABLED(USE_ZMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && WITHIN(Z2_USE_ENDSTOP, _ZMAX_, _ZMIN_))
870 870
  #error "You must enable USE_ZMIN_PLUG or USE_ZMAX_PLUG."
871 871
 #elif ENABLED(Z_DUAL_ENDSTOPS)
872 872
   #if !Z2_USE_ENDSTOP

+ 33
- 43
Marlin/UBL.h ファイルの表示

@@ -43,7 +43,7 @@
43 43
     bool ubl_lcd_clicked();
44 44
     void probe_entire_mesh(const float&, const float&, const bool, const bool, const bool);
45 45
     void debug_current_and_destination(char *title);
46
-    void ubl_line_to_destination(const float&, const float&, const float&, const float&, const float&, uint8_t);
46
+    void ubl_line_to_destination(const float&, uint8_t);
47 47
     void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
48 48
     vector_3 tilt_mesh_based_on_3pts(const float&, const float&, const float&);
49 49
     float measure_business_card_thickness(const float&);
@@ -169,12 +169,12 @@
169 169
 
170 170
         static int8_t find_closest_x_index(const float &x) {
171 171
           const int8_t px = (x - (UBL_MESH_MIN_X) + (MESH_X_DIST) * 0.5) * (1.0 / (MESH_X_DIST));
172
-          return (px >= 0 && px < (UBL_MESH_NUM_X_POINTS)) ? px : -1;
172
+          return WITHIN(px, 0, UBL_MESH_NUM_X_POINTS - 1) ? px : -1;
173 173
         }
174 174
 
175 175
         static int8_t find_closest_y_index(const float &y) {
176 176
           const int8_t py = (y - (UBL_MESH_MIN_Y) + (MESH_Y_DIST) * 0.5) * (1.0 / (MESH_Y_DIST));
177
-          return (py >= 0 && py < (UBL_MESH_NUM_Y_POINTS)) ? py : -1;
177
+          return WITHIN(py, 0, UBL_MESH_NUM_Y_POINTS - 1) ? py : -1;
178 178
         }
179 179
 
180 180
         /**
@@ -193,22 +193,16 @@
193 193
          *  multiplications.
194 194
          */
195 195
         static FORCE_INLINE float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) {
196
-          const float delta_z = (z2 - z1),
197
-                      delta_a = (a0 - a1) / (a2 - a1);
198
-          return z1 + delta_a * delta_z;
196
+          return z1 + (z2 - z1) * (a0 - a1) / (a2 - a1);
199 197
         }
200 198
 
201 199
         /**
202
-         * get_z_correction_at_Y_intercept(float x0, int x1_i, int yi) only takes
203
-         * three parameters. It assumes the x0 point is on a Mesh line denoted by yi. In theory
204
-         * we could use get_cell_index_x(float x) to obtain the 2nd parameter x1_i but any code calling
205
-         * the get_z_correction_along_vertical_mesh_line_at_specific_X routine  will already have
206
-         * the X index of the x0 intersection available and we don't want to perform any extra floating
207
-         * point operations.
200
+         * z_correction_for_x_on_horizontal_mesh_line is an optimization for
201
+         * the rare occasion when a point lies exactly on a Mesh line (denoted by index yi).
208 202
          */
209
-        static inline float get_z_correction_along_horizontal_mesh_line_at_specific_X(const float &x0, const int x1_i, const int yi) {
210
-          if (x1_i < 0 || yi < 0 || x1_i >= UBL_MESH_NUM_X_POINTS || yi >= UBL_MESH_NUM_Y_POINTS) {
211
-            SERIAL_ECHOPAIR("? in get_z_correction_along_horizontal_mesh_line_at_specific_X(x0=", x0);
203
+        static inline float z_correction_for_x_on_horizontal_mesh_line(const float &lx0, const int x1_i, const int yi) {
204
+          if (!WITHIN(x1_i, 0, UBL_MESH_NUM_X_POINTS - 1) || !WITHIN(yi, 0, UBL_MESH_NUM_Y_POINTS - 1)) {
205
+            SERIAL_ECHOPAIR("? in z_correction_for_x_on_horizontal_mesh_line(lx0=", lx0);
212 206
             SERIAL_ECHOPAIR(",x1_i=", x1_i);
213 207
             SERIAL_ECHOPAIR(",yi=", yi);
214 208
             SERIAL_CHAR(')');
@@ -216,20 +210,18 @@
216 210
             return NAN;
217 211
           }
218 212
 
219
-          const float xratio = (RAW_X_POSITION(x0) - mesh_index_to_xpos[x1_i]) * (1.0 / (MESH_X_DIST)),
220
-                      z1 = z_values[x1_i][yi],
221
-                      z2 = z_values[x1_i + 1][yi],
222
-                      dz = (z2 - z1);
213
+          const float xratio = (RAW_X_POSITION(lx0) - mesh_index_to_xpos[x1_i]) * (1.0 / (MESH_X_DIST)),
214
+                      z1 = z_values[x1_i][yi];
223 215
 
224
-          return z1 + xratio * dz;
216
+          return z1 + xratio * (z_values[x1_i + 1][yi] - z1);
225 217
         }
226 218
 
227 219
         //
228
-        // See comments above for get_z_correction_along_horizontal_mesh_line_at_specific_X
220
+        // See comments above for z_correction_for_x_on_horizontal_mesh_line
229 221
         //
230
-        static inline float get_z_correction_along_vertical_mesh_line_at_specific_Y(const float &y0, const int xi, const int y1_i) {
231
-          if (xi < 0 || y1_i < 0 || xi >= UBL_MESH_NUM_X_POINTS || y1_i >= UBL_MESH_NUM_Y_POINTS) {
232
-            SERIAL_ECHOPAIR("? in get_z_correction_along_vertical_mesh_line_at_specific_X(y0=", y0);
222
+        static inline float z_correction_for_y_on_vertical_mesh_line(const float &ly0, const int xi, const int y1_i) {
223
+          if (!WITHIN(xi, 0, UBL_MESH_NUM_X_POINTS - 1) || !WITHIN(y1_i, 0, UBL_MESH_NUM_Y_POINTS - 1)) {
224
+            SERIAL_ECHOPAIR("? in get_z_correction_along_vertical_mesh_line_at_specific_x(ly0=", ly0);
233 225
             SERIAL_ECHOPAIR(", x1_i=", xi);
234 226
             SERIAL_ECHOPAIR(", yi=", y1_i);
235 227
             SERIAL_CHAR(')');
@@ -237,12 +229,10 @@
237 229
             return NAN;
238 230
           }
239 231
 
240
-          const float yratio = (RAW_Y_POSITION(y0) - mesh_index_to_ypos[y1_i]) * (1.0 / (MESH_Y_DIST)),
241
-                      z1 = z_values[xi][y1_i],
242
-                      z2 = z_values[xi][y1_i + 1],
243
-                      dz = (z2 - z1);
232
+          const float yratio = (RAW_Y_POSITION(ly0) - mesh_index_to_ypos[y1_i]) * (1.0 / (MESH_Y_DIST)),
233
+                      z1 = z_values[xi][y1_i];
244 234
 
245
-          return z1 + yratio * dz;
235
+          return z1 + yratio * (z_values[xi][y1_i + 1] - z1);
246 236
         }
247 237
 
248 238
         /**
@@ -251,14 +241,14 @@
251 241
          * Z-Height at both ends. Then it does a linear interpolation of these heights based
252 242
          * on the Y position within the cell.
253 243
          */
254
-        static float get_z_correction(const float &x0, const float &y0) {
255
-          const int8_t cx = get_cell_index_x(RAW_X_POSITION(x0)),
256
-                       cy = get_cell_index_y(RAW_Y_POSITION(y0));
244
+        static float get_z_correction(const float &lx0, const float &ly0) {
245
+          const int8_t cx = get_cell_index_x(RAW_X_POSITION(lx0)),
246
+                       cy = get_cell_index_y(RAW_Y_POSITION(ly0));
257 247
 
258
-          if (cx < 0 || cy < 0 || cx >= UBL_MESH_NUM_X_POINTS || cy >= UBL_MESH_NUM_Y_POINTS) {
248
+          if (!WITHIN(cx, 0, UBL_MESH_NUM_X_POINTS - 1) || !WITHIN(cy, 0, UBL_MESH_NUM_Y_POINTS - 1)) {
259 249
 
260
-            SERIAL_ECHOPAIR("? in get_z_correction(x0=", x0);
261
-            SERIAL_ECHOPAIR(", y0=", y0);
250
+            SERIAL_ECHOPAIR("? in get_z_correction(lx0=", lx0);
251
+            SERIAL_ECHOPAIR(", ly0=", ly0);
262 252
             SERIAL_CHAR(')');
263 253
             SERIAL_EOL;
264 254
 
@@ -269,21 +259,21 @@
269 259
             return 0.0; // this used to return state.z_offset
270 260
           }
271 261
 
272
-          const float z1 = calc_z0(RAW_X_POSITION(x0),
262
+          const float z1 = calc_z0(RAW_X_POSITION(lx0),
273 263
                         mesh_index_to_xpos[cx], z_values[cx][cy],
274 264
                         mesh_index_to_xpos[cx + 1], z_values[cx + 1][cy]),
275
-                      z2 = calc_z0(RAW_X_POSITION(x0),
265
+                      z2 = calc_z0(RAW_X_POSITION(lx0),
276 266
                         mesh_index_to_xpos[cx], z_values[cx][cy + 1],
277 267
                         mesh_index_to_xpos[cx + 1], z_values[cx + 1][cy + 1]);
278
-                float z0 = calc_z0(RAW_Y_POSITION(y0),
268
+                float z0 = calc_z0(RAW_Y_POSITION(ly0),
279 269
                     mesh_index_to_ypos[cy], z1,
280 270
                     mesh_index_to_ypos[cy + 1], z2);
281 271
 
282 272
           #if ENABLED(DEBUG_LEVELING_FEATURE)
283 273
             if (DEBUGGING(MESH_ADJUST)) {
284
-              SERIAL_ECHOPAIR(" raw get_z_correction(", x0);
274
+              SERIAL_ECHOPAIR(" raw get_z_correction(", lx0);
285 275
               SERIAL_CHAR(',')
286
-              SERIAL_ECHO(y0);
276
+              SERIAL_ECHO(ly0);
287 277
               SERIAL_ECHOPGM(") = ");
288 278
               SERIAL_ECHO_F(z0, 6);
289 279
             }
@@ -305,9 +295,9 @@
305 295
 
306 296
             #if ENABLED(DEBUG_LEVELING_FEATURE)
307 297
               if (DEBUGGING(MESH_ADJUST)) {
308
-                SERIAL_ECHOPAIR("??? Yikes!  NAN in get_z_correction(", x0);
298
+                SERIAL_ECHOPAIR("??? Yikes!  NAN in get_z_correction(", lx0);
309 299
                 SERIAL_CHAR(',');
310
-                SERIAL_ECHO(y0);
300
+                SERIAL_ECHO(ly0);
311 301
                 SERIAL_CHAR(')');
312 302
                 SERIAL_EOL;
313 303
               }
@@ -327,7 +317,7 @@
327 317
          */
328 318
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
329 319
 
330
-          FORCE_INLINE float fade_scaling_factor_for_z(const float &lz) {
320
+          static FORCE_INLINE float fade_scaling_factor_for_z(const float &lz) {
331 321
             const float rz = RAW_Z_POSITION(lz);
332 322
             if (last_specified_z != rz) {
333 323
               last_specified_z = rz;

+ 3
- 3
Marlin/UBL_Bed_Leveling.cpp ファイルの表示

@@ -118,7 +118,7 @@
118 118
       return;
119 119
     }
120 120
 
121
-    if (m < 0 || m >= j || eeprom_start <= 0) {
121
+    if (!WITHIN(m, 0, j - 1) || eeprom_start <= 0) {
122 122
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
123 123
       return;
124 124
     }
@@ -133,7 +133,7 @@
133 133
   void unified_bed_leveling::store_mesh(const int16_t m) {
134 134
     int16_t j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
135 135
 
136
-    if (m < 0 || m >= j || eeprom_start <= 0) {
136
+    if (!WITHIN(m, 0, j - 1) || eeprom_start <= 0) {
137 137
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
138 138
       SERIAL_PROTOCOL(m);
139 139
       SERIAL_PROTOCOLLNPGM(" mesh slots available.\n");
@@ -203,7 +203,7 @@
203 203
 
204 204
         const float f = z_values[i][j];
205 205
         if (isnan(f)) {
206
-          serialprintPGM(map0 ? PSTR("    .    ") : PSTR("NAN"));
206
+          serialprintPGM(map0 ? PSTR("   .  ") : PSTR("NAN"));
207 207
         }
208 208
         else {
209 209
           // if we don't do this, the columns won't line up nicely

+ 39
- 32
Marlin/UBL_G29.cpp ファイルの表示

@@ -49,7 +49,6 @@
49 49
   extern bool code_value_bool();
50 50
   extern bool code_has_value();
51 51
   extern float probe_pt(float x, float y, bool, int);
52
-  extern float zprobe_zoffset;
53 52
   extern bool set_probe_deployed(bool);
54 53
   #define DEPLOY_PROBE() set_probe_deployed(true)
55 54
   #define STOW_PROBE() set_probe_deployed(false)
@@ -342,7 +341,7 @@
342 341
     if (code_seen('Q')) {
343 342
 
344 343
       const int test_pattern = code_has_value() ? code_value_int() : -1;
345
-      if (test_pattern < 0 || test_pattern > 2) {
344
+      if (!WITHIN(test_pattern, 0, 2)) {
346 345
         SERIAL_PROTOCOLLNPGM("Invalid test_pattern value. (0-2)\n");
347 346
         return;
348 347
       }
@@ -375,7 +374,7 @@
375 374
     /*
376 375
     if (code_seen('U')) {
377 376
       unlevel_value = code_value_int();
378
-      //if (unlevel_value < 0 || unlevel_value > 7) {
377
+      //if (!WITHIN(unlevel_value, 0, 7)) {
379 378
       //  SERIAL_PROTOCOLLNPGM("Invalid Unlevel value. (0-4)\n");
380 379
       //  return;
381 380
       //}
@@ -384,7 +383,7 @@
384 383
 
385 384
     if (code_seen('P')) {
386 385
       phase_value = code_value_int();
387
-      if (phase_value < 0 || phase_value > 7) {
386
+      if (!WITHIN(phase_value, 0, 7)) {
388 387
         SERIAL_PROTOCOLLNPGM("Invalid Phase value. (0-4)\n");
389 388
         return;
390 389
       }
@@ -516,16 +515,23 @@
516 515
     }
517 516
 
518 517
     if (code_seen('T')) {
519
-      float z1 = probe_pt(ubl_3_point_1_X, ubl_3_point_1_Y, false /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset,
520
-            z2 = probe_pt(ubl_3_point_2_X, ubl_3_point_2_Y, false /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset,
521
-            z3 = probe_pt(ubl_3_point_3_X, ubl_3_point_3_Y, true  /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset;
518
+      const float lx1 = LOGICAL_X_POSITION(ubl_3_point_1_X),
519
+                  lx2 = LOGICAL_X_POSITION(ubl_3_point_2_X),
520
+                  lx3 = LOGICAL_X_POSITION(ubl_3_point_3_X),
521
+                  ly1 = LOGICAL_Y_POSITION(ubl_3_point_1_Y),
522
+                  ly2 = LOGICAL_Y_POSITION(ubl_3_point_2_Y),
523
+                  ly3 = LOGICAL_Y_POSITION(ubl_3_point_3_Y);
524
+
525
+      float z1 = probe_pt(lx1, ly1, false /*Stow Flag*/, g29_verbose_level),
526
+            z2 = probe_pt(lx2, ly2, false /*Stow Flag*/, g29_verbose_level),
527
+            z3 = probe_pt(lx3, ly3, true  /*Stow Flag*/, g29_verbose_level);
522 528
 
523 529
       //  We need to adjust z1, z2, z3 by the Mesh Height at these points. Just because they are non-zero doesn't mean
524 530
       //  the Mesh is tilted!  (We need to compensate each probe point by what the Mesh says that location's height is)
525 531
 
526
-      z1 -= ubl.get_z_correction(ubl_3_point_1_X, ubl_3_point_1_Y);
527
-      z2 -= ubl.get_z_correction(ubl_3_point_2_X, ubl_3_point_2_Y);
528
-      z3 -= ubl.get_z_correction(ubl_3_point_3_X, ubl_3_point_3_Y);
532
+      z1 -= ubl.get_z_correction(lx1, ly1);
533
+      z2 -= ubl.get_z_correction(lx2, ly2);
534
+      z3 -= ubl.get_z_correction(lx3, ly3);
529 535
 
530 536
       do_blocking_move_to_xy((X_MAX_POS - (X_MIN_POS)) / 2.0, (Y_MAX_POS - (Y_MIN_POS)) / 2.0);
531 537
       tilt_mesh_based_on_3pts(z1, z2, z3);
@@ -560,7 +566,7 @@
560 566
 
561 567
       const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
562 568
 
563
-      if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
569
+      if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
564 570
         SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
565 571
         return;
566 572
       }
@@ -594,7 +600,7 @@
594 600
 
595 601
       const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
596 602
 
597
-      if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
603
+      if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
598 604
         SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
599 605
         SERIAL_PROTOCOLLNPAIR("?Use 0 to ", j - 1);
600 606
         goto LEAVE;
@@ -754,14 +760,14 @@
754 760
                     rawy = ubl.mesh_index_to_ypos[location.y_index];
755 761
 
756 762
         // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
757
-        if (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y)) {
763
+        if (!WITHIN(rawx, MIN_PROBE_X, MAX_PROBE_X) || !WITHIN(rawy, MIN_PROBE_Y, MAX_PROBE_Y)) {
758 764
           SERIAL_ERROR_START;
759 765
           SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
760 766
           ubl.has_control_of_lcd_panel = false;
761 767
           goto LEAVE;
762 768
         }
763 769
         const float measured_z = probe_pt(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy), stow_probe, g29_verbose_level);
764
-        ubl.z_values[location.x_index][location.y_index] = measured_z + zprobe_zoffset;
770
+        ubl.z_values[location.x_index][location.y_index] = measured_z;
765 771
       }
766 772
 
767 773
       if (do_ubl_mesh_map) ubl.display_map(map_type);
@@ -779,17 +785,17 @@
779 785
     );
780 786
   }
781 787
 
782
-  vector_3 tilt_mesh_based_on_3pts(const float &pt1, const float &pt2, const float &pt3) {
788
+  vector_3 tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3) {
783 789
     float c, d, t;
784 790
     int i, j;
785 791
 
786 792
     vector_3 v1 = vector_3( (ubl_3_point_1_X - ubl_3_point_2_X),
787 793
                             (ubl_3_point_1_Y - ubl_3_point_2_Y),
788
-                            (pt1 - pt2) ),
794
+                            (z1 - z2) ),
789 795
 
790 796
              v2 = vector_3( (ubl_3_point_3_X - ubl_3_point_2_X),
791 797
                             (ubl_3_point_3_Y - ubl_3_point_2_Y),
792
-                            (pt3 - pt2) ),
798
+                            (z3 - z2) ),
793 799
 
794 800
              normal = vector_3::cross(v1, v2);
795 801
 
@@ -811,7 +817,7 @@
811 817
     // All of 3 of these points should give us the same d constant
812 818
     //
813 819
     t = normal.x * ubl_3_point_1_X + normal.y * ubl_3_point_1_Y;
814
-    d = t + normal.z * pt1;
820
+    d = t + normal.z * z1;
815 821
     c = d - t;
816 822
     SERIAL_ECHOPGM("d from 1st point: ");
817 823
     SERIAL_ECHO_F(d, 6);
@@ -819,7 +825,7 @@
819 825
     SERIAL_ECHO_F(c, 6);
820 826
     SERIAL_EOL;
821 827
     t = normal.x * ubl_3_point_2_X + normal.y * ubl_3_point_2_Y;
822
-    d = t + normal.z * pt2;
828
+    d = t + normal.z * z2;
823 829
     c = d - t;
824 830
     SERIAL_ECHOPGM("d from 2nd point: ");
825 831
     SERIAL_ECHO_F(d, 6);
@@ -827,7 +833,7 @@
827 833
     SERIAL_ECHO_F(c, 6);
828 834
     SERIAL_EOL;
829 835
     t = normal.x * ubl_3_point_3_X + normal.y * ubl_3_point_3_Y;
830
-    d = t + normal.z * pt3;
836
+    d = t + normal.z * z3;
831 837
     c = d - t;
832 838
     SERIAL_ECHOPGM("d from 3rd point: ");
833 839
     SERIAL_ECHO_F(d, 6);
@@ -904,7 +910,7 @@
904 910
                   rawy = ubl.mesh_index_to_ypos[location.y_index];
905 911
 
906 912
       // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
907
-      if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) {
913
+      if (!WITHIN(rawx, X_MIN_POS, X_MAX_POS) || !WITHIN(rawy, Y_MIN_POS, Y_MAX_POS)) {
908 914
         SERIAL_ERROR_START;
909 915
         SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
910 916
         ubl.has_control_of_lcd_panel = false;
@@ -976,21 +982,21 @@
976 982
     #endif
977 983
 
978 984
     g29_verbose_level = code_seen('V') ? code_value_int() : 0;
979
-    if (g29_verbose_level < 0 || g29_verbose_level > 4) {
985
+    if (!WITHIN(g29_verbose_level, 0, 4)) {
980 986
       SERIAL_PROTOCOLLNPGM("Invalid Verbose Level specified. (0-4)\n");
981 987
       return UBL_ERR;
982 988
     }
983 989
 
984 990
     x_flag = code_seen('X') && code_has_value();
985 991
     x_pos = x_flag ? code_value_float() : current_position[X_AXIS];
986
-    if (x_pos < LOGICAL_X_POSITION(X_MIN_POS) || x_pos > LOGICAL_X_POSITION(X_MAX_POS)) {
992
+    if (!WITHIN(RAW_X_POSITION(x_pos), X_MIN_POS, X_MAX_POS)) {
987 993
       SERIAL_PROTOCOLLNPGM("Invalid X location specified.\n");
988 994
       return UBL_ERR;
989 995
     }
990 996
 
991 997
     y_flag = code_seen('Y') && code_has_value();
992 998
     y_pos = y_flag ? code_value_float() : current_position[Y_AXIS];
993
-    if (y_pos < LOGICAL_Y_POSITION(Y_MIN_POS) || y_pos > LOGICAL_Y_POSITION(Y_MAX_POS)) {
999
+    if (!WITHIN(RAW_Y_POSITION(y_pos), Y_MIN_POS, Y_MAX_POS)) {
994 1000
       SERIAL_PROTOCOLLNPGM("Invalid Y location specified.\n");
995 1001
       return UBL_ERR;
996 1002
     }
@@ -1018,7 +1024,7 @@
1018 1024
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1019 1025
       if (code_seen('F') && code_has_value()) {
1020 1026
         const float fh = code_value_float();
1021
-        if (fh < 0.0 || fh > 100.0) {
1027
+        if (!WITHIN(fh, 0.0, 100.0)) {
1022 1028
           SERIAL_PROTOCOLLNPGM("?Bed Level Correction Fade Height Not Plausible.\n");
1023 1029
           return UBL_ERR;
1024 1030
         }
@@ -1035,7 +1041,7 @@
1035 1041
     }
1036 1042
 
1037 1043
     map_type = code_seen('O') && code_has_value() ? code_value_int() : 0;
1038
-    if (map_type < 0 || map_type > 1) {
1044
+    if (!WITHIN(map_type, 0, 1)) {
1039 1045
       SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1040 1046
       return UBL_ERR;
1041 1047
     }
@@ -1043,7 +1049,7 @@
1043 1049
     /*
1044 1050
     if (code_seen('M')) {     // Check if a map type was specified
1045 1051
       map_type = code_has_value() ? code_value_int() : 0; 
1046
-      if (map_type < 0 || map_type > 1) {
1052
+      if (!WITHIN(map_type, 0, 1)) {
1047 1053
         SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1048 1054
         return UBL_ERR;
1049 1055
       }
@@ -1109,7 +1115,7 @@
1109 1115
     const uint16_t k = E2END - ubl.eeprom_start;
1110 1116
 
1111 1117
     SERIAL_PROTOCOLPGM("Unified Bed Leveling System Version 1.00 ");
1112
-    if (ubl.state.active)  
1118
+    if (ubl.state.active)
1113 1119
       SERIAL_PROTOCOLCHAR('A');
1114 1120
     else
1115 1121
       SERIAL_PROTOCOLPGM("In");
@@ -1243,7 +1249,7 @@
1243 1249
 
1244 1250
     int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(tmp_z_values);
1245 1251
 
1246
-    if (storage_slot < 0 || storage_slot > j || ubl.eeprom_start <= 0) {
1252
+    if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
1247 1253
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
1248 1254
       return;
1249 1255
     }
@@ -1290,7 +1296,7 @@
1290 1296
           // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
1291 1297
 
1292 1298
           if (probe_as_reference &&
1293
-            (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y))
1299
+            (!WITHIN(rawx, MIN_PROBE_X, MAX_PROBE_X) || !WITHIN(rawy, MIN_PROBE_Y, MAX_PROBE_Y))
1294 1300
           ) continue;
1295 1301
 
1296 1302
           // Unreachable. Check if it's the closest location to the nozzle.
@@ -1354,7 +1360,7 @@
1354 1360
                   rawy = ubl.mesh_index_to_ypos[location.y_index];
1355 1361
 
1356 1362
       // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
1357
-      if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) { // In theory, we don't need this check.
1363
+      if (!WITHIN(rawx, X_MIN_POS, X_MAX_POS) || !WITHIN(rawy, Y_MIN_POS, Y_MAX_POS)) { // In theory, we don't need this check.
1358 1364
         SERIAL_ERROR_START;
1359 1365
         SERIAL_ERRORLNPGM("Attempt to edit off the bed."); // This really can't happen, but do the check for now
1360 1366
         ubl.has_control_of_lcd_panel = false;
@@ -1363,6 +1369,7 @@
1363 1369
 
1364 1370
       do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);    // Move the nozzle to where we are going to edit
1365 1371
       do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy));
1372
+
1366 1373
       float new_z = ubl.z_values[location.x_index][location.y_index];
1367 1374
       
1368 1375
       round_off = (int32_t)(new_z * 1000.0);    // we chop off the last digits just to be clean. We are rounding to the
@@ -1425,4 +1432,4 @@
1425 1432
     SERIAL_ECHOLNPGM("Done Editing Mesh.");
1426 1433
   }
1427 1434
 
1428
-#endif // AUTO_BED_LEVELING_UBL
1435
+#endif // AUTO_BED_LEVELING_UBL

+ 88
- 95
Marlin/UBL_line_to_destination.cpp ファイルの表示

@@ -31,7 +31,14 @@
31 31
 
32 32
   extern float destination[XYZE];
33 33
   extern void set_current_to_destination();
34
-  extern float destination[];
34
+
35
+  static void debug_echo_axis(const AxisEnum axis) {
36
+    if (current_position[axis] == destination[axis])
37
+      SERIAL_ECHOPGM("-------------");
38
+    else
39
+      SERIAL_ECHO_F(destination[X_AXIS], 6);
40
+  }
41
+
35 42
   void debug_current_and_destination(char *title) {
36 43
 
37 44
     // if the title message starts with a '!' it is so important, we are going to
@@ -67,32 +74,13 @@
67 74
     SERIAL_ECHOPGM(", ");
68 75
     SERIAL_ECHO_F(current_position[E_AXIS], 6);
69 76
     SERIAL_ECHOPGM(" )   destination=( ");
70
-    if (current_position[X_AXIS] == destination[X_AXIS])
71
-      SERIAL_ECHOPGM("-------------");
72
-    else
73
-      SERIAL_ECHO_F(destination[X_AXIS], 6);
74
-
77
+    debug_echo_axis(X_AXIS);
75 78
     SERIAL_ECHOPGM(", ");
76
-
77
-    if (current_position[Y_AXIS] == destination[Y_AXIS])
78
-      SERIAL_ECHOPGM("-------------");
79
-    else
80
-      SERIAL_ECHO_F(destination[Y_AXIS], 6);
81
-
79
+    debug_echo_axis(Y_AXIS);
82 80
     SERIAL_ECHOPGM(", ");
83
-
84
-    if (current_position[Z_AXIS] == destination[Z_AXIS])
85
-      SERIAL_ECHOPGM("-------------");
86
-    else
87
-      SERIAL_ECHO_F(destination[Z_AXIS], 6);
88
-
81
+    debug_echo_axis(Z_AXIS);
89 82
     SERIAL_ECHOPGM(", ");
90
-
91
-    if (current_position[E_AXIS] == destination[E_AXIS])
92
-      SERIAL_ECHOPGM("-------------");
93
-    else
94
-      SERIAL_ECHO_F(destination[E_AXIS], 6);
95
-
83
+    debug_echo_axis(E_AXIS);
96 84
     SERIAL_ECHOPGM(" )   ");
97 85
     SERIAL_ECHO(title);
98 86
     SERIAL_EOL;
@@ -105,32 +93,37 @@
105 93
     //}
106 94
   }
107 95
 
108
-  void ubl_line_to_destination(const float &x_end, const float &y_end, const float &z_end, const float &e_end, const float &feed_rate, uint8_t extruder) {
96
+  void ubl_line_to_destination(const float &feed_rate, uint8_t extruder) {
109 97
     /**
110 98
      * Much of the nozzle movement will be within the same cell. So we will do as little computation
111 99
      * as possible to determine if this is the case. If this move is within the same cell, we will
112 100
      * just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
113 101
      */
114
-    const float x_start = current_position[X_AXIS],
115
-                y_start = current_position[Y_AXIS],
116
-                z_start = current_position[Z_AXIS],
117
-                e_start = current_position[E_AXIS];
118
-
119
-    const int cell_start_xi = ubl.get_cell_index_x(RAW_X_POSITION(x_start)),
120
-              cell_start_yi = ubl.get_cell_index_y(RAW_Y_POSITION(y_start)),
121
-              cell_dest_xi  = ubl.get_cell_index_x(RAW_X_POSITION(x_end)),
122
-              cell_dest_yi  = ubl.get_cell_index_y(RAW_Y_POSITION(y_end));
102
+    const float start[XYZE] = {
103
+                  current_position[X_AXIS],
104
+                  current_position[Y_AXIS],
105
+                  current_position[Z_AXIS],
106
+                  current_position[E_AXIS]
107
+                },
108
+                end[XYZE] = {
109
+                  destination[X_AXIS],
110
+                  destination[Y_AXIS],
111
+                  destination[Z_AXIS],
112
+                  destination[E_AXIS]
113
+                };
114
+
115
+    const int cell_start_xi = ubl.get_cell_index_x(RAW_X_POSITION(start[X_AXIS])),
116
+              cell_start_yi = ubl.get_cell_index_y(RAW_Y_POSITION(start[Y_AXIS])),
117
+              cell_dest_xi  = ubl.get_cell_index_x(RAW_X_POSITION(end[X_AXIS])),
118
+              cell_dest_yi  = ubl.get_cell_index_y(RAW_Y_POSITION(end[Y_AXIS]));
123 119
 
124 120
     if (ubl.g26_debug_flag) {
125
-      SERIAL_ECHOPGM(" ubl_line_to_destination(xe=");
126
-      SERIAL_ECHO(x_end);
127
-      SERIAL_ECHOPGM(", ye=");
128
-      SERIAL_ECHO(y_end);
129
-      SERIAL_ECHOPGM(", ze=");
130
-      SERIAL_ECHO(z_end);
131
-      SERIAL_ECHOPGM(", ee=");
132
-      SERIAL_ECHO(e_end);
133
-      SERIAL_ECHOLNPGM(")");
121
+      SERIAL_ECHOPAIR(" ubl_line_to_destination(xe=", end[X_AXIS]);
122
+      SERIAL_ECHOPAIR(", ye=", end[Y_AXIS]);
123
+      SERIAL_ECHOPAIR(", ze=", end[Z_AXIS]);
124
+      SERIAL_ECHOPAIR(", ee=", end[E_AXIS]);
125
+      SERIAL_CHAR(')');
126
+      SERIAL_EOL;
134 127
       debug_current_and_destination((char*)"Start of ubl_line_to_destination()");
135 128
     }
136 129
 
@@ -142,12 +135,12 @@
142 135
        * But we detect it and isolate it. For now, we just pass along the request.
143 136
        */
144 137
 
145
-      if (cell_dest_xi < 0 || cell_dest_yi < 0 || cell_dest_xi >= UBL_MESH_NUM_X_POINTS || cell_dest_yi >= UBL_MESH_NUM_Y_POINTS) {
138
+      if (!WITHIN(cell_dest_xi, 0, UBL_MESH_NUM_X_POINTS - 1) || !WITHIN(cell_dest_yi, 0, UBL_MESH_NUM_Y_POINTS - 1)) {
146 139
 
147 140
         // Note: There is no Z Correction in this case. We are off the grid and don't know what
148 141
         // a reasonable correction would be.
149 142
 
150
-        planner.buffer_line(x_end, y_end, z_end + ubl.state.z_offset, e_end, feed_rate, extruder);
143
+        planner.buffer_line(end[X_AXIS], end[Y_AXIS], end[Z_AXIS] + ubl.state.z_offset, end[E_AXIS], feed_rate, extruder);
151 144
         set_current_to_destination();
152 145
 
153 146
         if (ubl.g26_debug_flag)
@@ -167,7 +160,7 @@
167 160
        * to create a 1-over number for us. That will allow us to do a floating point multiply instead of a floating point divide.
168 161
        */
169 162
 
170
-      const float xratio = (RAW_X_POSITION(x_end) - ubl.mesh_index_to_xpos[cell_dest_xi]) * (1.0 / (MESH_X_DIST)),
163
+      const float xratio = (RAW_X_POSITION(end[X_AXIS]) - ubl.mesh_index_to_xpos[cell_dest_xi]) * (1.0 / (MESH_X_DIST)),
171 164
                   z1 = ubl.z_values[cell_dest_xi    ][cell_dest_yi    ] + xratio *
172 165
                       (ubl.z_values[cell_dest_xi + 1][cell_dest_yi    ] - ubl.z_values[cell_dest_xi][cell_dest_yi    ]),
173 166
                   z2 = ubl.z_values[cell_dest_xi    ][cell_dest_yi + 1] + xratio *
@@ -176,7 +169,7 @@
176 169
       // we are done with the fractional X distance into the cell. Now with the two Z-Heights we have calculated, we
177 170
       // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
178 171
 
179
-      const float yratio = (RAW_Y_POSITION(y_end) - ubl.mesh_index_to_ypos[cell_dest_yi]) * (1.0 / (MESH_Y_DIST));
172
+      const float yratio = (RAW_Y_POSITION(end[Y_AXIS]) - ubl.mesh_index_to_ypos[cell_dest_yi]) * (1.0 / (MESH_Y_DIST));
180 173
 
181 174
       float z0 = z1 + (z2 - z1) * yratio;
182 175
 
@@ -186,20 +179,20 @@
186 179
        */
187 180
       /*
188 181
         z_optimized = z0;
189
-        z0 = ubl.get_z_correction(x_end, y_end);
182
+        z0 = ubl.get_z_correction(end[X_AXIS], end[Y_AXIS]);
190 183
         if (fabs(z_optimized - z0) > .01 || isnan(z0) || isnan(z_optimized)) {
191 184
         debug_current_and_destination((char*)"FINAL_MOVE: z_correction()");
192 185
         if (isnan(z0)) SERIAL_ECHO(" z0==NAN  ");
193 186
         if (isnan(z_optimized)) SERIAL_ECHO(" z_optimized==NAN  ");
194
-        SERIAL_ECHOPAIR("  x_end=", x_end);
195
-        SERIAL_ECHOPAIR("  y_end=", y_end);
187
+        SERIAL_ECHOPAIR("  end[X_AXIS]=", end[X_AXIS]);
188
+        SERIAL_ECHOPAIR("  end[Y_AXIS]=", end[Y_AXIS]);
196 189
         SERIAL_ECHOPAIR("  z0=", z0);
197 190
         SERIAL_ECHOPAIR("  z_optimized=", z_optimized);
198 191
         SERIAL_ECHOPAIR("  err=",fabs(z_optimized - z0));
199 192
         SERIAL_EOL;
200 193
         }
201 194
       //*/
202
-      z0 *= ubl.fade_scaling_factor_for_z(z_end);
195
+      z0 *= ubl.fade_scaling_factor_for_z(end[Z_AXIS]);
203 196
 
204 197
       /**
205 198
        * If part of the Mesh is undefined, it will show up as NAN
@@ -210,7 +203,7 @@
210 203
        */
211 204
       if (isnan(z0)) z0 = 0.0;
212 205
 
213
-      planner.buffer_line(x_end, y_end, z_end + z0 + ubl.state.z_offset, e_end, feed_rate, extruder);
206
+      planner.buffer_line(end[X_AXIS], end[Y_AXIS], end[Z_AXIS] + z0 + ubl.state.z_offset, end[E_AXIS], feed_rate, extruder);
214 207
 
215 208
       if (ubl.g26_debug_flag)
216 209
         debug_current_and_destination((char*)"FINAL_MOVE in ubl_line_to_destination()");
@@ -227,8 +220,8 @@
227 220
      * blocks of code:
228 221
      */
229 222
 
230
-    const float dx = x_end - x_start,
231
-                dy = y_end - y_start;
223
+    const float dx = end[X_AXIS] - start[X_AXIS],
224
+                dy = end[Y_AXIS] - start[Y_AXIS];
232 225
 
233 226
     const int left_flag = dx < 0.0 ? 1 : 0,
234 227
               down_flag = dy < 0.0 ? 1 : 0;
@@ -251,8 +244,8 @@
251 244
     const bool use_x_dist = adx > ady;
252 245
 
253 246
     float on_axis_distance = use_x_dist ? dx : dy,
254
-          e_position = e_end - e_start,
255
-          z_position = z_end - z_start;
247
+          e_position = end[E_AXIS] - start[E_AXIS],
248
+          z_position = end[Z_AXIS] - start[Z_AXIS];
256 249
 
257 250
     const float e_normalized_dist = e_position / on_axis_distance,
258 251
                 z_normalized_dist = z_position / on_axis_distance;
@@ -260,7 +253,7 @@
260 253
     int current_xi = cell_start_xi, current_yi = cell_start_yi;
261 254
 
262 255
     const float m = dy / dx,
263
-                c = y_start - m * x_start;
256
+                c = start[Y_AXIS] - m * start[X_AXIS];
264 257
 
265 258
     const bool inf_normalized_flag = NEAR_ZERO(on_axis_distance),
266 259
                inf_m_flag = NEAR_ZERO(dx);
@@ -281,9 +274,9 @@
281 274
          * else, we know the next X is the same so we can recover and continue!
282 275
          * Calculate X at the next Y mesh line
283 276
          */
284
-        const float x = inf_m_flag ? x_start : (next_mesh_line_y - c) / m;
277
+        const float x = inf_m_flag ? start[X_AXIS] : (next_mesh_line_y - c) / m;
285 278
 
286
-        float z0 = ubl.get_z_correction_along_horizontal_mesh_line_at_specific_X(x, current_xi, current_yi);
279
+        float z0 = ubl.z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi);
287 280
 
288 281
         /**
289 282
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
@@ -305,7 +298,7 @@
305 298
           }
306 299
         //*/
307 300
 
308
-        z0 *= ubl.fade_scaling_factor_for_z(z_end);
301
+        z0 *= ubl.fade_scaling_factor_for_z(end[Z_AXIS]);
309 302
 
310 303
         /**
311 304
          * If part of the Mesh is undefined, it will show up as NAN
@@ -324,15 +317,15 @@
324 317
          * happens, it might be best to remove the check and always 'schedule' the move because
325 318
          * the planner.buffer_line() routine will filter it if that happens.
326 319
          */
327
-        if (y != y_start) {
320
+        if (y != start[Y_AXIS]) {
328 321
           if (!inf_normalized_flag) {
329
-            on_axis_distance = y - y_start;                               // we don't need to check if the extruder position
330
-            e_position = e_start + on_axis_distance * e_normalized_dist;  // is based on X or Y because this is a vertical move
331
-            z_position = z_start + on_axis_distance * z_normalized_dist;
322
+            on_axis_distance = y - start[Y_AXIS];                               // we don't need to check if the extruder position
323
+            e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;  // is based on X or Y because this is a vertical move
324
+            z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
332 325
           }
333 326
           else {
334
-            e_position = e_start;
335
-            z_position = z_start;
327
+            e_position = start[E_AXIS];
328
+            z_position = start[Z_AXIS];
336 329
           }
337 330
 
338 331
           planner.buffer_line(x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
@@ -345,7 +338,7 @@
345 338
       //
346 339
       // Check if we are at the final destination. Usually, we won't be, but if it is on a Y Mesh Line, we are done.
347 340
       //
348
-      if (current_position[X_AXIS] != x_end || current_position[Y_AXIS] != y_end)
341
+      if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
349 342
         goto FINAL_MOVE;
350 343
 
351 344
       set_current_to_destination();
@@ -368,7 +361,7 @@
368 361
         const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi]),
369 362
                     y = m * next_mesh_line_x + c;   // Calculate X at the next Y mesh line
370 363
 
371
-        float z0 = ubl.get_z_correction_along_vertical_mesh_line_at_specific_Y(y, current_xi, current_yi);
364
+        float z0 = ubl.z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi);
372 365
 
373 366
         /**
374 367
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
@@ -390,7 +383,7 @@
390 383
           }
391 384
         //*/
392 385
 
393
-        z0 = z0 * ubl.fade_scaling_factor_for_z(z_end);
386
+        z0 *= ubl.fade_scaling_factor_for_z(end[Z_AXIS]);
394 387
 
395 388
         /**
396 389
          * If part of the Mesh is undefined, it will show up as NAN
@@ -409,15 +402,15 @@
409 402
          * that happens, it might be best to remove the check and always 'schedule' the move because
410 403
          * the planner.buffer_line() routine will filter it if that happens.
411 404
          */
412
-        if (x != x_start) {
405
+        if (x != start[X_AXIS]) {
413 406
           if (!inf_normalized_flag) {
414
-            on_axis_distance = x - x_start;                               // we don't need to check if the extruder position
415
-            e_position = e_start + on_axis_distance * e_normalized_dist;  // is based on X or Y because this is a horizontal move
416
-            z_position = z_start + on_axis_distance * z_normalized_dist;
407
+            on_axis_distance = x - start[X_AXIS];                               // we don't need to check if the extruder position
408
+            e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;  // is based on X or Y because this is a horizontal move
409
+            z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
417 410
           }
418 411
           else {
419
-            e_position = e_start;
420
-            z_position = z_start;
412
+            e_position = start[E_AXIS];
413
+            z_position = start[Z_AXIS];
421 414
           }
422 415
 
423 416
           planner.buffer_line(x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
@@ -427,7 +420,7 @@
427 420
       if (ubl.g26_debug_flag)
428 421
         debug_current_and_destination((char*)"horizontal move done in ubl_line_to_destination()");
429 422
 
430
-      if (current_position[X_AXIS] != x_end || current_position[Y_AXIS] != y_end)
423
+      if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
431 424
         goto FINAL_MOVE;
432 425
 
433 426
       set_current_to_destination();
@@ -454,16 +447,16 @@
454 447
       const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi + dxi]),
455 448
                   next_mesh_line_y = LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos[current_yi + dyi]),
456 449
                   y = m * next_mesh_line_x + c,   // Calculate Y at the next X mesh line
457
-                  x = (next_mesh_line_y - c) / m; // Calculate X at the next Y mesh line    (we don't have to worry
458
-                                                  // about m being equal to 0.0  If this was the case, we would have
459
-                                                  // detected this as a vertical line move up above and we wouldn't
460
-                                                  // be down here doing a generic type of move.
450
+                  x = (next_mesh_line_y - c) / m; // Calculate X at the next Y mesh line
451
+                                                  // (No need to worry about m being zero.
452
+                                                  //  If that was the case, it was already detected
453
+                                                  //  as a vertical line move above.)
461 454
 
462 455
       if (left_flag == (x > next_mesh_line_x)) { // Check if we hit the Y line first
463 456
         //
464 457
         // Yes!  Crossing a Y Mesh Line next
465 458
         //
466
-        float z0 = ubl.get_z_correction_along_horizontal_mesh_line_at_specific_X(x, current_xi - left_flag, current_yi + dyi);
459
+        float z0 = ubl.z_correction_for_x_on_horizontal_mesh_line(x, current_xi - left_flag, current_yi + dyi);
467 460
 
468 461
         /**
469 462
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
@@ -486,7 +479,7 @@
486 479
           }
487 480
         //*/
488 481
 
489
-        z0 *= ubl.fade_scaling_factor_for_z(z_end);
482
+        z0 *= ubl.fade_scaling_factor_for_z(end[Z_AXIS]);
490 483
 
491 484
         /**
492 485
          * If part of the Mesh is undefined, it will show up as NAN
@@ -498,13 +491,13 @@
498 491
         if (isnan(z0)) z0 = 0.0;
499 492
 
500 493
         if (!inf_normalized_flag) {
501
-          on_axis_distance = use_x_dist ? x - x_start : next_mesh_line_y - y_start;
502
-          e_position = e_start + on_axis_distance * e_normalized_dist;
503
-          z_position = z_start + on_axis_distance * z_normalized_dist;
494
+          on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS];
495
+          e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;
496
+          z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
504 497
         }
505 498
         else {
506
-          e_position = e_start;
507
-          z_position = z_start;
499
+          e_position = start[E_AXIS];
500
+          z_position = start[Z_AXIS];
508 501
         }
509 502
         planner.buffer_line(x, next_mesh_line_y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
510 503
         current_yi += dyi;
@@ -514,7 +507,7 @@
514 507
         //
515 508
         // Yes!  Crossing a X Mesh Line next
516 509
         //
517
-        float z0 = ubl.get_z_correction_along_vertical_mesh_line_at_specific_Y(y, current_xi + dxi, current_yi - down_flag);
510
+        float z0 = ubl.z_correction_for_y_on_vertical_mesh_line(y, current_xi + dxi, current_yi - down_flag);
518 511
 
519 512
         /**
520 513
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
@@ -536,7 +529,7 @@
536 529
           }
537 530
         //*/
538 531
 
539
-        z0 *= ubl.fade_scaling_factor_for_z(z_end);
532
+        z0 *= ubl.fade_scaling_factor_for_z(end[Z_AXIS]);
540 533
 
541 534
         /**
542 535
          * If part of the Mesh is undefined, it will show up as NAN
@@ -548,13 +541,13 @@
548 541
         if (isnan(z0)) z0 = 0.0;
549 542
 
550 543
         if (!inf_normalized_flag) {
551
-          on_axis_distance = use_x_dist ? next_mesh_line_x - x_start : y - y_start;
552
-          e_position = e_start + on_axis_distance * e_normalized_dist;
553
-          z_position = z_start + on_axis_distance * z_normalized_dist;
544
+          on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS];
545
+          e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;
546
+          z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
554 547
         }
555 548
         else {
556
-          e_position = e_start;
557
-          z_position = z_start;
549
+          e_position = start[E_AXIS];
550
+          z_position = start[Z_AXIS];
558 551
         }
559 552
 
560 553
         planner.buffer_line(next_mesh_line_x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
@@ -566,7 +559,7 @@
566 559
     if (ubl.g26_debug_flag)
567 560
       debug_current_and_destination((char*)"generic move done in ubl_line_to_destination()");
568 561
 
569
-    if (current_position[0] != x_end || current_position[1] != y_end)
562
+    if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
570 563
       goto FINAL_MOVE;
571 564
 
572 565
     set_current_to_destination();

+ 27
- 27
Marlin/endstop_interrupts.h ファイルの表示

@@ -35,8 +35,10 @@
35 35
  * (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
36 36
  */
37 37
 
38
- #ifndef _ENDSTOP_INTERRUPTS_H_
39
- #define _ENDSTOP_INTERRUPTS_H_
38
+#ifndef _ENDSTOP_INTERRUPTS_H_
39
+#define _ENDSTOP_INTERRUPTS_H_
40
+
41
+#include "macros.h"
40 42
 
41 43
 /**
42 44
  * Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
@@ -47,39 +49,37 @@
47 49
  */
48 50
 #if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
49 51
   #undef  digitalPinToPCICR
50
-  #define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 15)) || \
51
-                                  (((p) >= 50) && ((p) <= 53)) || \
52
-                                  (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
52
+  #define digitalPinToPCICR(p)    ( WITHIN(p, 10, 15) || \
53
+                                    WITHIN(p, 50, 53) || \
54
+                                    WITHIN(p, 62, 69) ? &PCICR : (uint8_t*)0 )
53 55
   #undef  digitalPinToPCICRbit
54
-  #define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
55
-                                  ( (((p) >= 14) && ((p) <= 15)) ? 1 : \
56
-                                  ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
57
-                                  0 ) ) )
56
+  #define digitalPinToPCICRbit(p) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? 0 : \
57
+                                    WITHIN(p, 14, 15) ? 1 : \
58
+                                    WITHIN(p, 62, 69) ? 2 : \
59
+                                    0 )
58 60
   #undef  digitalPinToPCMSK
59
-  #define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
60
-                                  ( (((p) >= 14) && ((p) <= 15)) ? (&PCMSK1) : \
61
-                                  ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
62
-                                  ((uint8_t *)0) ) ) )
61
+  #define digitalPinToPCMSK(p)    ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? &PCMSK0 : \
62
+                                    WITHIN(p, 14, 15) ? &PCMSK1 : \
63
+                                    WITHIN(p, 62, 69) ? &PCMSK2 : \
64
+                                    (uint8_t *)0 )
63 65
   #undef  digitalPinToPCMSKbit
64
-  #define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
65
-                                  ( ((p) == 14) ? 2 : \
66
-                                  ( ((p) == 15) ? 1 : \
67
-                                  ( ((p) == 50) ? 3 : \
68
-                                  ( ((p) == 51) ? 2 : \
69
-                                  ( ((p) == 52) ? 1 : \
70
-                                  ( ((p) == 53) ? 0 : \
71
-                                  ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
72
-                                  0 ) ) ) ) ) ) ) )
66
+  #define digitalPinToPCMSKbit(p) ( WITHIN(p, 10, 13) ? ((p) - 6) : \
67
+                                    (p) == 14 || (p) == 51 ? 2 : \
68
+                                    (p) == 15 || (p) == 52 ? 1 : \
69
+                                    (p) == 50 ? 3 : \
70
+                                    (p) == 53 ? 0 : \
71
+                                    WITHIN(p, 62, 69) ? ((p) - 62) : \
72
+                                    0 )
73 73
 #endif
74 74
 
75
-volatile uint8_t e_hit = 0; // Different from 0 when the endstops shall be tested in detail.
76
-                            // Must be reset to 0 by the test function when the tests are finished.
75
+volatile uint8_t e_hit = 0; // Different from 0 when the endstops should be tested in detail.
76
+                            // Must be reset to 0 by the test function when finished.
77 77
 
78 78
 // Install Pin change interrupt for a pin. Can be called multiple times.
79 79
 void pciSetup(byte pin) {
80
-  *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
81
-  PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
82
-  PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
80
+  SBI(*digitalPinToPCMSK(pin), digitalPinToPCMSKbit(pin));  // enable pin
81
+  SBI(PCIFR, digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
82
+  SBI(PCICR, digitalPinToPCICRbit(pin)); // enable interrupt for the group
83 83
 }
84 84
 
85 85
 // This is what is really done inside the interrupts.

+ 4
- 2
Marlin/macros.h ファイルの表示

@@ -75,7 +75,8 @@
75 75
 #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
76 76
 #define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
77 77
 
78
-#define NUMERIC(a) ((a) >= '0' && '9' >= (a))
78
+#define WITHIN(V,L,H) ((V) >= (L) && (V) <= (H))
79
+#define NUMERIC(a) WITHIN(a, '0', '9')
79 80
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
80 81
 #define COUNT(a) (sizeof(a)/sizeof(*a))
81 82
 #define ZERO(a) memset(a,0,sizeof(a))
@@ -133,9 +134,10 @@
133 134
 #define MAX4(a, b, c, d) max(max(a, b), max(c, d))
134 135
 
135 136
 #define UNEAR_ZERO(x) ((x) < 0.000001)
136
-#define NEAR_ZERO(x) ((x) > -0.000001 && (x) < 0.000001)
137
+#define NEAR_ZERO(x) WITHIN(x, -0.000001, 0.000001)
137 138
 #define NEAR(x,y) NEAR_ZERO((x)-(y))
138 139
 
139 140
 #define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0 : 1.0 / (x))
141
+#define FIXFLOAT(f) (f + 0.00001)
140 142
 
141 143
 #endif //__MACROS_H

+ 2
- 2
Marlin/mesh_bed_leveling.h ファイルの表示

@@ -88,12 +88,12 @@
88 88
 
89 89
     static int8_t probe_index_x(const float &x) {
90 90
       int8_t px = (x - (MESH_MIN_X) + 0.5 * (MESH_X_DIST)) * (1.0 / (MESH_X_DIST));
91
-      return (px >= 0 && px < (MESH_NUM_X_POINTS)) ? px : -1;
91
+      return WITHIN(px, 0, MESH_NUM_X_POINTS - 1) ? px : -1;
92 92
     }
93 93
 
94 94
     static int8_t probe_index_y(const float &y) {
95 95
       int8_t py = (y - (MESH_MIN_Y) + 0.5 * (MESH_Y_DIST)) * (1.0 / (MESH_Y_DIST));
96
-      return (py >= 0 && py < (MESH_NUM_Y_POINTS)) ? py : -1;
96
+      return WITHIN(py, 0, MESH_NUM_Y_POINTS - 1) ? py : -1;
97 97
     }
98 98
 
99 99
     static float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) {

+ 3
- 1
Marlin/pinsDebug.h ファイルの表示

@@ -20,6 +20,8 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "macros.h"
24
+
23 25
 bool endstop_monitor_flag = false;
24 26
 
25 27
 #if !defined(TIMER1B)    // working with Teensyduino extension so need to re-define some things
@@ -35,7 +37,7 @@ bool endstop_monitor_flag = false;
35 37
 #define _ANALOG_PIN_SAY(NAME) { sprintf(buffer, NAME_FORMAT, NAME); SERIAL_ECHO(buffer); pin_is_analog = true; return true; }
36 38
 #define ANALOG_PIN_SAY(NAME) if (pin == analogInputToDigitalPin(NAME)) _ANALOG_PIN_SAY(#NAME);
37 39
 
38
-#define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && ((P) <= analogInputToDigitalPin(15) || (P) <= analogInputToDigitalPin(5)))
40
+#define IS_ANALOG(P) ( WITHIN(P, analogInputToDigitalPin(0), analogInputToDigitalPin(15)) || (P) <= analogInputToDigitalPin(5) )
39 41
 
40 42
 int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
41 43
   uint8_t port = digitalPinToPort(pin);

+ 1
- 1
Marlin/planner.cpp ファイルの表示

@@ -999,7 +999,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
999 999
     unsigned long segment_time = lround(1000000.0 / inverse_mm_s);
1000 1000
   #endif
1001 1001
   #if ENABLED(SLOWDOWN)
1002
-    if (moves_queued > 1 && moves_queued < (BLOCK_BUFFER_SIZE) / 2) {
1002
+    if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
1003 1003
       if (segment_time < min_segment_time) {
1004 1004
         // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
1005 1005
         inverse_mm_s = 1000000.0 / (segment_time + lround(2 * (min_segment_time - segment_time) / moves_queued));

+ 3
- 3
Marlin/temperature.cpp ファイルの表示

@@ -786,11 +786,11 @@ void Temperature::manage_heater() {
786 786
     #if ENABLED(PIDTEMPBED)
787 787
       float pid_output = get_pid_output_bed();
788 788
 
789
-      soft_pwm_bed = current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP ? (int)pid_output >> 1 : 0;
789
+      soft_pwm_bed = WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP) ? (int)pid_output >> 1 : 0;
790 790
 
791 791
     #elif ENABLED(BED_LIMIT_SWITCHING)
792 792
       // Check if temperature is within the correct band
793
-      if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
793
+      if (WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP)) {
794 794
         if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS)
795 795
           soft_pwm_bed = 0;
796 796
         else if (current_temperature_bed <= target_temperature_bed - (BED_HYSTERESIS))
@@ -802,7 +802,7 @@ void Temperature::manage_heater() {
802 802
       }
803 803
     #else // !PIDTEMPBED && !BED_LIMIT_SWITCHING
804 804
       // Check if temperature is within the correct range
805
-      if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
805
+      if (WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP)) {
806 806
         soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0;
807 807
       }
808 808
       else {

+ 1
- 1
Marlin/twibus.cpp ファイルの表示

@@ -42,7 +42,7 @@ void TWIBus::reset() {
42 42
 }
43 43
 
44 44
 void TWIBus::address(const uint8_t adr) {
45
-  if (adr < 8 || adr > 127) {
45
+  if (!WITHIN(adr, 8, 127)) {
46 46
     SERIAL_ECHO_START;
47 47
     SERIAL_ECHOLNPGM("Bad I2C address (8-127)");
48 48
   }

+ 0
- 2
Marlin/ultralcd.cpp ファイルの表示

@@ -30,8 +30,6 @@
30 30
 #include "configuration_store.h"
31 31
 #include "utility.h"
32 32
 
33
-extern float zprobe_zoffset;
34
-
35 33
 #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
36 34
   #include "buzzer.h"
37 35
 #endif

+ 3
- 3
Marlin/ultralcd_impl_DOGM.h ファイルの表示

@@ -213,7 +213,7 @@ static void lcd_setFont(const char font_nr) {
213 213
 }
214 214
 
215 215
 void lcd_print(const char c) {
216
-  if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
216
+  if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
217 217
     u8g.setFont(FONT_SPECIAL_NAME);
218 218
     u8g.print(c);
219 219
     lcd_setFont(currentfont);
@@ -222,7 +222,7 @@ void lcd_print(const char c) {
222 222
 }
223 223
 
224 224
 char lcd_print_and_count(const char c) {
225
-  if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
225
+  if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
226 226
     u8g.setFont(FONT_SPECIAL_NAME);
227 227
     u8g.print(c);
228 228
     lcd_setFont(currentfont);
@@ -543,7 +543,7 @@ static void lcd_implementation_status_screen() {
543 543
   if (page.page == 0) {
544 544
     strcpy(xstring, ftostr4sign(current_position[X_AXIS]));
545 545
     strcpy(ystring, ftostr4sign(current_position[Y_AXIS]));
546
-    strcpy(zstring, ftostr52sp(current_position[Z_AXIS] + 0.00001));
546
+    strcpy(zstring, ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
547 547
     #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
548 548
       strcpy(wstring, ftostr12ns(filament_width_meas));
549 549
       strcpy(mstring, itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));

+ 1
- 1
Marlin/ultralcd_impl_HD44780.h ファイルの表示

@@ -729,7 +729,7 @@ static void lcd_implementation_status_screen() {
729 729
 
730 730
     lcd.setCursor(LCD_WIDTH - 8, 1);
731 731
     _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
732
-    lcd.print(ftostr52sp(current_position[Z_AXIS] + 0.00001));
732
+    lcd.print(ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
733 733
 
734 734
   #endif // LCD_HEIGHT > 2
735 735
 

+ 1
- 1
Marlin/utility.cpp ファイルの表示

@@ -134,7 +134,7 @@ void safe_delay(millis_t ms) {
134 134
     // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
135 135
     char *ftostr4sign(const float& fx) {
136 136
       int x = fx * 10;
137
-      if (x <= -100 || x >= 1000) return itostr4sign((int)fx);
137
+      if (WITHIN(x, -99, 999)) return itostr4sign((int)fx);
138 138
       int xx = abs(x);
139 139
       conv[0] = x < 0 ? '-' : (xx >= 100 ? DIGIMOD(xx, 100) : ' ');
140 140
       conv[1] = DIGIMOD(xx, 10);

読み込み中…
キャンセル
保存