Browse Source

Additional UBL fixes, optimizations

Scott Lahteine 8 years ago
parent
commit
342ee458ae

+ 1
- 1
.travis.yml View File

120
   # Test a simple build of AUTO_BED_LEVELING_UBL
120
   # Test a simple build of AUTO_BED_LEVELING_UBL
121
   #
121
   #
122
   - restore_configs
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
   - build_marlin
124
   - build_marlin
125
   #
125
   #
126
   # Test a Sled Z Probe
126
   # Test a Sled Z Probe

+ 36
- 61
Marlin/G26_Mesh_Validation_Tool.cpp View File

47
   #define OOZE_AMOUNT 0.3
47
   #define OOZE_AMOUNT 0.3
48
 
48
 
49
   #define SIZE_OF_INTERSECTION_CIRCLES 5
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
    *   Roxy's G26 Mesh Validation Tool
54
    *   Roxy's G26 Mesh Validation Tool
132
   void line_to_destination(float );
132
   void line_to_destination(float );
133
   void gcode_G28();
133
   void gcode_G28();
134
   void sync_plan_position_e();
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
   void look_for_lines_to_connect();
137
   void look_for_lines_to_connect();
138
   bool parse_G26_parameters();
138
   bool parse_G26_parameters();
139
   void move_to(const float&, const float&, const float&, const float&) ;
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
   bool turn_on_heaters();
141
   bool turn_on_heaters();
142
   bool prime_nozzle();
142
   bool prime_nozzle();
143
   void chirp_at_user();
143
   void chirp_at_user();
154
 
154
 
155
   float valid_trig_angle(float);
155
   float valid_trig_angle(float);
156
   mesh_index_pair find_closest_circle_to_print(float, float);
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
   static float extrusion_multiplier = EXTRUSION_MULTIPLIER,
158
   static float extrusion_multiplier = EXTRUSION_MULTIPLIER,
161
                retraction_multiplier = RETRACTION_MULTIPLIER,
159
                retraction_multiplier = RETRACTION_MULTIPLIER,
359
     lcd_reset_alert_level();
357
     lcd_reset_alert_level();
360
     lcd_setstatuspgm(PSTR("Leaving G26"));
358
     lcd_setstatuspgm(PSTR("Leaving G26"));
361
 
359
 
362
-    retract_filament();
360
+    retract_filament(destination);
363
     destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES;
361
     destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES;
364
 
362
 
365
     //debug_current_and_destination((char*)"ready to do Z-Raise.");
363
     //debug_current_and_destination((char*)"ready to do Z-Raise.");
445
               // We found two circles that need a horizontal line to connect them
443
               // We found two circles that need a horizontal line to connect them
446
               // Print it!
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
               ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
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
               if (ubl.g26_debug_flag) {
453
               if (ubl.g26_debug_flag) {
462
                 SERIAL_ECHOPAIR(" Connecting with horizontal line (sx=", sx);
454
                 SERIAL_ECHOPAIR(" Connecting with horizontal line (sx=", sx);
468
                 //debug_current_and_destination((char*)"Connecting horizontal line.");
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
               bit_set(horizontal_mesh_line_flags, i, j);   // Mark it as done so we don't do it again
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
                 // We found two circles that need a vertical line to connect them
474
                 // We found two circles that need a vertical line to connect them
483
                 // Print it!
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
                 sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1);
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
                 ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
482
                 ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
497
 
483
 
498
                 if (ubl.g26_debug_flag) {
484
                 if (ubl.g26_debug_flag) {
504
                   SERIAL_EOL;
490
                   SERIAL_EOL;
505
                   debug_current_and_destination((char*)"Connecting vertical line.");
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
       destination[Z_AXIS] = z;                          // We know the last_z==z or we wouldn't be in this block of code.
519
       destination[Z_AXIS] = z;                          // We know the last_z==z or we wouldn't be in this block of code.
534
       destination[E_AXIS] = current_position[E_AXIS];
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
       stepper.synchronize();
524
       stepper.synchronize();
539
       set_destination_to_current();
525
       set_destination_to_current();
553
 
539
 
554
     //if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() doing last move");
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
     //if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() after last move");
544
     //if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() after last move");
559
 
545
 
562
 
548
 
563
   }
549
   }
564
 
550
 
565
-  void retract_filament() {
551
+  void retract_filament(float where[XYZE]) {
566
     if (!g26_retracted) { // Only retract if we are not already retracted!
552
     if (!g26_retracted) { // Only retract if we are not already retracted!
567
       g26_retracted = true;
553
       g26_retracted = true;
568
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Decided to do retract.");
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
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Retraction done.");
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
     if (g26_retracted) { // Only un-retract if we are retracted.
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
       g26_retracted = false;
563
       g26_retracted = false;
578
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" unretract done.");
564
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" unretract done.");
579
     }
565
     }
594
    * segment of a 'circle'.   The time this requires is very short and is easily saved by the other
580
    * segment of a 'circle'.   The time this requires is very short and is easily saved by the other
595
    * cases where the optimization comes into play.
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
     const float dx_s = current_position[X_AXIS] - sx,   // find our distance from the start of the actual line segment
584
     const float dx_s = current_position[X_AXIS] - sx,   // find our distance from the start of the actual line segment
599
                 dy_s = current_position[Y_AXIS] - sy,
585
                 dy_s = current_position[Y_AXIS] - sy,
600
                 dist_start = HYPOT2(dx_s, dy_s),        // We don't need to do a sqrt(), we can compare the distance^2
586
                 dist_start = HYPOT2(dx_s, dy_s),        // We don't need to do a sqrt(), we can compare the distance^2
603
                 dy_e = current_position[Y_AXIS] - ey,
589
                 dy_e = current_position[Y_AXIS] - ey,
604
                 dist_end = HYPOT2(dx_e, dy_e),
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
     if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < abs(line_length)) {
596
     if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < abs(line_length)) {
615
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  Reversing start and end of print_line_from_here_to_there()");
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
     if (dist_start > 2.0) {
603
     if (dist_start > 2.0) {
623
-      retract_filament();
604
+      retract_filament(destination);
624
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  filament retracted.");
605
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  filament retracted.");
625
     }
606
     }
626
     move_to(sx, sy, sz, 0.0); // Get to the starting point with no extrusion
607
     move_to(sx, sy, sz, 0.0); // Get to the starting point with no extrusion
627
 
608
 
628
     const float e_pos_delta = line_length * g26_e_axis_feedrate * extrusion_multiplier;
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
     //if (ubl.g26_debug_flag) {
613
     //if (ubl.g26_debug_flag) {
633
     //  SERIAL_ECHOLNPGM("  doing printing move.");
614
     //  SERIAL_ECHOLNPGM("  doing printing move.");
814
       lcd_setstatuspgm(PSTR(""));
795
       lcd_setstatuspgm(PSTR(""));
815
       lcd_quick_feedback();
796
       lcd_quick_feedback();
816
     #endif
797
     #endif
798
+
817
     return UBL_OK;
799
     return UBL_OK;
818
   }
800
   }
819
 
801
 
832
 
814
 
833
       set_destination_to_current();
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
       while (!ubl_lcd_clicked()) {
819
       while (!ubl_lcd_clicked()) {
839
         chirp_at_user();
820
         chirp_at_user();
840
         destination[E_AXIS] += 0.25;
821
         destination[E_AXIS] += 0.25;
842
           Total_Prime += 0.25;
823
           Total_Prime += 0.25;
843
           if (Total_Prime >= EXTRUDE_MAXLENGTH) return UBL_ERR;
824
           if (Total_Prime >= EXTRUDE_MAXLENGTH) return UBL_ERR;
844
         #endif
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
         stepper.synchronize();    // Without this synchronize, the purge is more consistent,
828
         stepper.synchronize();    // Without this synchronize, the purge is more consistent,
851
                                   // but because the planner has a buffer, we won't be able
829
                                   // but because the planner has a buffer, we won't be able
874
       #endif
852
       #endif
875
       set_destination_to_current();
853
       set_destination_to_current();
876
       destination[E_AXIS] += prime_length;
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
       stepper.synchronize();
856
       stepper.synchronize();
882
       set_destination_to_current();
857
       set_destination_to_current();
883
-      retract_filament();
858
+      retract_filament(destination);
884
     }
859
     }
885
 
860
 
886
     return UBL_OK;
861
     return UBL_OK;

+ 1
- 5
Marlin/Marlin_main.cpp View File

9901
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
9901
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
9902
         if (ubl.state.active) {
9902
         if (ubl.state.active) {
9903
 
9903
 
9904
-//        ubl_line_to_destination(MMS_SCALED(feedrate_mm_s));
9905
-
9906
-          ubl_line_to_destination(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS],
9907
-//                      (feedrate*(1.0/60.0))*(feedrate_percentage*(1.0/100.0) ), active_extruder);
9908
-                      MMS_SCALED(feedrate_mm_s), active_extruder);
9904
+          ubl_line_to_destination(MMS_SCALED(feedrate_mm_s), active_extruder);
9909
 
9905
 
9910
           return false;
9906
           return false;
9911
         }
9907
         }

+ 31
- 41
Marlin/UBL.h View File

43
     bool ubl_lcd_clicked();
43
     bool ubl_lcd_clicked();
44
     void probe_entire_mesh(const float&, const float&, const bool, const bool, const bool);
44
     void probe_entire_mesh(const float&, const float&, const bool, const bool, const bool);
45
     void debug_current_and_destination(char *title);
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
     void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
47
     void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
48
     vector_3 tilt_mesh_based_on_3pts(const float&, const float&, const float&);
48
     vector_3 tilt_mesh_based_on_3pts(const float&, const float&, const float&);
49
     float measure_business_card_thickness(const float&);
49
     float measure_business_card_thickness(const float&);
193
          *  multiplications.
193
          *  multiplications.
194
          */
194
          */
195
         static FORCE_INLINE float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) {
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
             SERIAL_ECHOPAIR(",x1_i=", x1_i);
206
             SERIAL_ECHOPAIR(",x1_i=", x1_i);
213
             SERIAL_ECHOPAIR(",yi=", yi);
207
             SERIAL_ECHOPAIR(",yi=", yi);
214
             SERIAL_CHAR(')');
208
             SERIAL_CHAR(')');
216
             return NAN;
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
             SERIAL_ECHOPAIR(", x1_i=", xi);
225
             SERIAL_ECHOPAIR(", x1_i=", xi);
234
             SERIAL_ECHOPAIR(", yi=", y1_i);
226
             SERIAL_ECHOPAIR(", yi=", y1_i);
235
             SERIAL_CHAR(')');
227
             SERIAL_CHAR(')');
237
             return NAN;
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
          * Z-Height at both ends. Then it does a linear interpolation of these heights based
241
          * Z-Height at both ends. Then it does a linear interpolation of these heights based
252
          * on the Y position within the cell.
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
             SERIAL_CHAR(')');
252
             SERIAL_CHAR(')');
263
             SERIAL_EOL;
253
             SERIAL_EOL;
264
 
254
 
269
             return 0.0; // this used to return state.z_offset
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
                         mesh_index_to_xpos[cx], z_values[cx][cy],
263
                         mesh_index_to_xpos[cx], z_values[cx][cy],
274
                         mesh_index_to_xpos[cx + 1], z_values[cx + 1][cy]),
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
                         mesh_index_to_xpos[cx], z_values[cx][cy + 1],
266
                         mesh_index_to_xpos[cx], z_values[cx][cy + 1],
277
                         mesh_index_to_xpos[cx + 1], z_values[cx + 1][cy + 1]);
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
                     mesh_index_to_ypos[cy], z1,
269
                     mesh_index_to_ypos[cy], z1,
280
                     mesh_index_to_ypos[cy + 1], z2);
270
                     mesh_index_to_ypos[cy + 1], z2);
281
 
271
 
282
           #if ENABLED(DEBUG_LEVELING_FEATURE)
272
           #if ENABLED(DEBUG_LEVELING_FEATURE)
283
             if (DEBUGGING(MESH_ADJUST)) {
273
             if (DEBUGGING(MESH_ADJUST)) {
284
-              SERIAL_ECHOPAIR(" raw get_z_correction(", x0);
274
+              SERIAL_ECHOPAIR(" raw get_z_correction(", lx0);
285
               SERIAL_CHAR(',')
275
               SERIAL_CHAR(',')
286
-              SERIAL_ECHO(y0);
276
+              SERIAL_ECHO(ly0);
287
               SERIAL_ECHOPGM(") = ");
277
               SERIAL_ECHOPGM(") = ");
288
               SERIAL_ECHO_F(z0, 6);
278
               SERIAL_ECHO_F(z0, 6);
289
             }
279
             }
305
 
295
 
306
             #if ENABLED(DEBUG_LEVELING_FEATURE)
296
             #if ENABLED(DEBUG_LEVELING_FEATURE)
307
               if (DEBUGGING(MESH_ADJUST)) {
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
                 SERIAL_CHAR(',');
299
                 SERIAL_CHAR(',');
310
-                SERIAL_ECHO(y0);
300
+                SERIAL_ECHO(ly0);
311
                 SERIAL_CHAR(')');
301
                 SERIAL_CHAR(')');
312
                 SERIAL_EOL;
302
                 SERIAL_EOL;
313
               }
303
               }
327
          */
317
          */
328
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
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
             const float rz = RAW_Z_POSITION(lz);
321
             const float rz = RAW_Z_POSITION(lz);
332
             if (last_specified_z != rz) {
322
             if (last_specified_z != rz) {
333
               last_specified_z = rz;
323
               last_specified_z = rz;

+ 1
- 1
Marlin/UBL_Bed_Leveling.cpp View File

203
 
203
 
204
         const float f = z_values[i][j];
204
         const float f = z_values[i][j];
205
         if (isnan(f)) {
205
         if (isnan(f)) {
206
-          serialprintPGM(map0 ? PSTR("    .    ") : PSTR("NAN"));
206
+          serialprintPGM(map0 ? PSTR("   .  ") : PSTR("NAN"));
207
         }
207
         }
208
         else {
208
         else {
209
           // if we don't do this, the columns won't line up nicely
209
           // if we don't do this, the columns won't line up nicely

+ 20
- 13
Marlin/UBL_G29.cpp View File

515
     }
515
     }
516
 
516
 
517
     if (code_seen('T')) {
517
     if (code_seen('T')) {
518
-      float z1 = probe_pt(ubl_3_point_1_X, ubl_3_point_1_Y, false /*Stow Flag*/, g29_verbose_level),
519
-            z2 = probe_pt(ubl_3_point_2_X, ubl_3_point_2_Y, false /*Stow Flag*/, g29_verbose_level),
520
-            z3 = probe_pt(ubl_3_point_3_X, ubl_3_point_3_Y, true  /*Stow Flag*/, g29_verbose_level);
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);
521
 
528
 
522
       //  We need to adjust z1, z2, z3 by the Mesh Height at these points. Just because they are non-zero doesn't mean
529
       //  We need to adjust z1, z2, z3 by the Mesh Height at these points. Just because they are non-zero doesn't mean
523
       //  the Mesh is tilted!  (We need to compensate each probe point by what the Mesh says that location's height is)
530
       //  the Mesh is tilted!  (We need to compensate each probe point by what the Mesh says that location's height is)
524
 
531
 
525
-      z1 -= ubl.get_z_correction(ubl_3_point_1_X, ubl_3_point_1_Y);
526
-      z2 -= ubl.get_z_correction(ubl_3_point_2_X, ubl_3_point_2_Y);
527
-      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);
528
 
535
 
529
       do_blocking_move_to_xy((X_MAX_POS - (X_MIN_POS)) / 2.0, (Y_MAX_POS - (Y_MIN_POS)) / 2.0);
536
       do_blocking_move_to_xy((X_MAX_POS - (X_MIN_POS)) / 2.0, (Y_MAX_POS - (Y_MIN_POS)) / 2.0);
530
       tilt_mesh_based_on_3pts(z1, z2, z3);
537
       tilt_mesh_based_on_3pts(z1, z2, z3);
778
     );
785
     );
779
   }
786
   }
780
 
787
 
781
-  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) {
782
     float c, d, t;
789
     float c, d, t;
783
     int i, j;
790
     int i, j;
784
 
791
 
785
     vector_3 v1 = vector_3( (ubl_3_point_1_X - ubl_3_point_2_X),
792
     vector_3 v1 = vector_3( (ubl_3_point_1_X - ubl_3_point_2_X),
786
                             (ubl_3_point_1_Y - ubl_3_point_2_Y),
793
                             (ubl_3_point_1_Y - ubl_3_point_2_Y),
787
-                            (pt1 - pt2) ),
794
+                            (z1 - z2) ),
788
 
795
 
789
              v2 = vector_3( (ubl_3_point_3_X - ubl_3_point_2_X),
796
              v2 = vector_3( (ubl_3_point_3_X - ubl_3_point_2_X),
790
                             (ubl_3_point_3_Y - ubl_3_point_2_Y),
797
                             (ubl_3_point_3_Y - ubl_3_point_2_Y),
791
-                            (pt3 - pt2) ),
798
+                            (z3 - z2) ),
792
 
799
 
793
              normal = vector_3::cross(v1, v2);
800
              normal = vector_3::cross(v1, v2);
794
 
801
 
810
     // All of 3 of these points should give us the same d constant
817
     // All of 3 of these points should give us the same d constant
811
     //
818
     //
812
     t = normal.x * ubl_3_point_1_X + normal.y * ubl_3_point_1_Y;
819
     t = normal.x * ubl_3_point_1_X + normal.y * ubl_3_point_1_Y;
813
-    d = t + normal.z * pt1;
820
+    d = t + normal.z * z1;
814
     c = d - t;
821
     c = d - t;
815
     SERIAL_ECHOPGM("d from 1st point: ");
822
     SERIAL_ECHOPGM("d from 1st point: ");
816
     SERIAL_ECHO_F(d, 6);
823
     SERIAL_ECHO_F(d, 6);
818
     SERIAL_ECHO_F(c, 6);
825
     SERIAL_ECHO_F(c, 6);
819
     SERIAL_EOL;
826
     SERIAL_EOL;
820
     t = normal.x * ubl_3_point_2_X + normal.y * ubl_3_point_2_Y;
827
     t = normal.x * ubl_3_point_2_X + normal.y * ubl_3_point_2_Y;
821
-    d = t + normal.z * pt2;
828
+    d = t + normal.z * z2;
822
     c = d - t;
829
     c = d - t;
823
     SERIAL_ECHOPGM("d from 2nd point: ");
830
     SERIAL_ECHOPGM("d from 2nd point: ");
824
     SERIAL_ECHO_F(d, 6);
831
     SERIAL_ECHO_F(d, 6);
826
     SERIAL_ECHO_F(c, 6);
833
     SERIAL_ECHO_F(c, 6);
827
     SERIAL_EOL;
834
     SERIAL_EOL;
828
     t = normal.x * ubl_3_point_3_X + normal.y * ubl_3_point_3_Y;
835
     t = normal.x * ubl_3_point_3_X + normal.y * ubl_3_point_3_Y;
829
-    d = t + normal.z * pt3;
836
+    d = t + normal.z * z3;
830
     c = d - t;
837
     c = d - t;
831
     SERIAL_ECHOPGM("d from 3rd point: ");
838
     SERIAL_ECHOPGM("d from 3rd point: ");
832
     SERIAL_ECHO_F(d, 6);
839
     SERIAL_ECHO_F(d, 6);
1425
     SERIAL_ECHOLNPGM("Done Editing Mesh.");
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 View File

31
 
31
 
32
   extern float destination[XYZE];
32
   extern float destination[XYZE];
33
   extern void set_current_to_destination();
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
   void debug_current_and_destination(char *title) {
42
   void debug_current_and_destination(char *title) {
36
 
43
 
37
     // if the title message starts with a '!' it is so important, we are going to
44
     // if the title message starts with a '!' it is so important, we are going to
67
     SERIAL_ECHOPGM(", ");
74
     SERIAL_ECHOPGM(", ");
68
     SERIAL_ECHO_F(current_position[E_AXIS], 6);
75
     SERIAL_ECHO_F(current_position[E_AXIS], 6);
69
     SERIAL_ECHOPGM(" )   destination=( ");
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
     SERIAL_ECHOPGM(", ");
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
     SERIAL_ECHOPGM(", ");
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
     SERIAL_ECHOPGM(", ");
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
     SERIAL_ECHOPGM(" )   ");
84
     SERIAL_ECHOPGM(" )   ");
97
     SERIAL_ECHO(title);
85
     SERIAL_ECHO(title);
98
     SERIAL_EOL;
86
     SERIAL_EOL;
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
      * Much of the nozzle movement will be within the same cell. So we will do as little computation
98
      * Much of the nozzle movement will be within the same cell. So we will do as little computation
111
      * as possible to determine if this is the case. If this move is within the same cell, we will
99
      * as possible to determine if this is the case. If this move is within the same cell, we will
112
      * just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
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
     if (ubl.g26_debug_flag) {
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
       debug_current_and_destination((char*)"Start of ubl_line_to_destination()");
127
       debug_current_and_destination((char*)"Start of ubl_line_to_destination()");
135
     }
128
     }
136
 
129
 
142
        * But we detect it and isolate it. For now, we just pass along the request.
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
         // Note: There is no Z Correction in this case. We are off the grid and don't know what
140
         // Note: There is no Z Correction in this case. We are off the grid and don't know what
148
         // a reasonable correction would be.
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
         set_current_to_destination();
144
         set_current_to_destination();
152
 
145
 
153
         if (ubl.g26_debug_flag)
146
         if (ubl.g26_debug_flag)
167
        * to create a 1-over number for us. That will allow us to do a floating point multiply instead of a floating point divide.
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
                   z1 = ubl.z_values[cell_dest_xi    ][cell_dest_yi    ] + xratio *
164
                   z1 = ubl.z_values[cell_dest_xi    ][cell_dest_yi    ] + xratio *
172
                       (ubl.z_values[cell_dest_xi + 1][cell_dest_yi    ] - ubl.z_values[cell_dest_xi][cell_dest_yi    ]),
165
                       (ubl.z_values[cell_dest_xi + 1][cell_dest_yi    ] - ubl.z_values[cell_dest_xi][cell_dest_yi    ]),
173
                   z2 = ubl.z_values[cell_dest_xi    ][cell_dest_yi + 1] + xratio *
166
                   z2 = ubl.z_values[cell_dest_xi    ][cell_dest_yi + 1] + xratio *
176
       // we are done with the fractional X distance into the cell. Now with the two Z-Heights we have calculated, we
169
       // we are done with the fractional X distance into the cell. Now with the two Z-Heights we have calculated, we
177
       // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
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
       float z0 = z1 + (z2 - z1) * yratio;
174
       float z0 = z1 + (z2 - z1) * yratio;
182
 
175
 
186
        */
179
        */
187
       /*
180
       /*
188
         z_optimized = z0;
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
         if (fabs(z_optimized - z0) > .01 || isnan(z0) || isnan(z_optimized)) {
183
         if (fabs(z_optimized - z0) > .01 || isnan(z0) || isnan(z_optimized)) {
191
         debug_current_and_destination((char*)"FINAL_MOVE: z_correction()");
184
         debug_current_and_destination((char*)"FINAL_MOVE: z_correction()");
192
         if (isnan(z0)) SERIAL_ECHO(" z0==NAN  ");
185
         if (isnan(z0)) SERIAL_ECHO(" z0==NAN  ");
193
         if (isnan(z_optimized)) SERIAL_ECHO(" z_optimized==NAN  ");
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
         SERIAL_ECHOPAIR("  z0=", z0);
189
         SERIAL_ECHOPAIR("  z0=", z0);
197
         SERIAL_ECHOPAIR("  z_optimized=", z_optimized);
190
         SERIAL_ECHOPAIR("  z_optimized=", z_optimized);
198
         SERIAL_ECHOPAIR("  err=",fabs(z_optimized - z0));
191
         SERIAL_ECHOPAIR("  err=",fabs(z_optimized - z0));
199
         SERIAL_EOL;
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
        * If part of the Mesh is undefined, it will show up as NAN
198
        * If part of the Mesh is undefined, it will show up as NAN
210
        */
203
        */
211
       if (isnan(z0)) z0 = 0.0;
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
       if (ubl.g26_debug_flag)
208
       if (ubl.g26_debug_flag)
216
         debug_current_and_destination((char*)"FINAL_MOVE in ubl_line_to_destination()");
209
         debug_current_and_destination((char*)"FINAL_MOVE in ubl_line_to_destination()");
227
      * blocks of code:
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
     const int left_flag = dx < 0.0 ? 1 : 0,
226
     const int left_flag = dx < 0.0 ? 1 : 0,
234
               down_flag = dy < 0.0 ? 1 : 0;
227
               down_flag = dy < 0.0 ? 1 : 0;
251
     const bool use_x_dist = adx > ady;
244
     const bool use_x_dist = adx > ady;
252
 
245
 
253
     float on_axis_distance = use_x_dist ? dx : dy,
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
     const float e_normalized_dist = e_position / on_axis_distance,
250
     const float e_normalized_dist = e_position / on_axis_distance,
258
                 z_normalized_dist = z_position / on_axis_distance;
251
                 z_normalized_dist = z_position / on_axis_distance;
260
     int current_xi = cell_start_xi, current_yi = cell_start_yi;
253
     int current_xi = cell_start_xi, current_yi = cell_start_yi;
261
 
254
 
262
     const float m = dy / dx,
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
     const bool inf_normalized_flag = NEAR_ZERO(on_axis_distance),
258
     const bool inf_normalized_flag = NEAR_ZERO(on_axis_distance),
266
                inf_m_flag = NEAR_ZERO(dx);
259
                inf_m_flag = NEAR_ZERO(dx);
281
          * else, we know the next X is the same so we can recover and continue!
274
          * else, we know the next X is the same so we can recover and continue!
282
          * Calculate X at the next Y mesh line
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
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
282
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
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
          * If part of the Mesh is undefined, it will show up as NAN
304
          * If part of the Mesh is undefined, it will show up as NAN
324
          * happens, it might be best to remove the check and always 'schedule' the move because
317
          * happens, it might be best to remove the check and always 'schedule' the move because
325
          * the planner.buffer_line() routine will filter it if that happens.
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
           if (!inf_normalized_flag) {
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
           else {
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
           planner.buffer_line(x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
331
           planner.buffer_line(x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
345
       //
338
       //
346
       // 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.
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
         goto FINAL_MOVE;
342
         goto FINAL_MOVE;
350
 
343
 
351
       set_current_to_destination();
344
       set_current_to_destination();
368
         const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi]),
361
         const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi]),
369
                     y = m * next_mesh_line_x + c;   // Calculate X at the next Y mesh line
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
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
367
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
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
          * If part of the Mesh is undefined, it will show up as NAN
389
          * If part of the Mesh is undefined, it will show up as NAN
409
          * that happens, it might be best to remove the check and always 'schedule' the move because
402
          * that happens, it might be best to remove the check and always 'schedule' the move because
410
          * the planner.buffer_line() routine will filter it if that happens.
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
           if (!inf_normalized_flag) {
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
           else {
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
           planner.buffer_line(x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
416
           planner.buffer_line(x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
427
       if (ubl.g26_debug_flag)
420
       if (ubl.g26_debug_flag)
428
         debug_current_and_destination((char*)"horizontal move done in ubl_line_to_destination()");
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
         goto FINAL_MOVE;
424
         goto FINAL_MOVE;
432
 
425
 
433
       set_current_to_destination();
426
       set_current_to_destination();
454
       const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi + dxi]),
447
       const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi + dxi]),
455
                   next_mesh_line_y = LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos[current_yi + dyi]),
448
                   next_mesh_line_y = LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos[current_yi + dyi]),
456
                   y = m * next_mesh_line_x + c,   // Calculate Y at the next X mesh line
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
       if (left_flag == (x > next_mesh_line_x)) { // Check if we hit the Y line first
455
       if (left_flag == (x > next_mesh_line_x)) { // Check if we hit the Y line first
463
         //
456
         //
464
         // Yes!  Crossing a Y Mesh Line next
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
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
462
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
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
          * If part of the Mesh is undefined, it will show up as NAN
485
          * If part of the Mesh is undefined, it will show up as NAN
498
         if (isnan(z0)) z0 = 0.0;
491
         if (isnan(z0)) z0 = 0.0;
499
 
492
 
500
         if (!inf_normalized_flag) {
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
         else {
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
         planner.buffer_line(x, next_mesh_line_y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
502
         planner.buffer_line(x, next_mesh_line_y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
510
         current_yi += dyi;
503
         current_yi += dyi;
514
         //
507
         //
515
         // Yes!  Crossing a X Mesh Line next
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
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
513
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
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
          * If part of the Mesh is undefined, it will show up as NAN
535
          * If part of the Mesh is undefined, it will show up as NAN
548
         if (isnan(z0)) z0 = 0.0;
541
         if (isnan(z0)) z0 = 0.0;
549
 
542
 
550
         if (!inf_normalized_flag) {
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
         else {
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
         planner.buffer_line(next_mesh_line_x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
553
         planner.buffer_line(next_mesh_line_x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
566
     if (ubl.g26_debug_flag)
559
     if (ubl.g26_debug_flag)
567
       debug_current_and_destination((char*)"generic move done in ubl_line_to_destination()");
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
       goto FINAL_MOVE;
563
       goto FINAL_MOVE;
571
 
564
 
572
     set_current_to_destination();
565
     set_current_to_destination();

Loading…
Cancel
Save