Browse Source

Extend Skew Correction to UBL

Scott Lahteine 7 years ago
parent
commit
bdf69db0a8
4 changed files with 59 additions and 42 deletions
  1. 0
    3
      Marlin/SanityCheck.h
  2. 2
    16
      Marlin/planner.cpp
  3. 24
    0
      Marlin/planner.h
  4. 33
    23
      Marlin/ubl_motion.cpp

+ 0
- 3
Marlin/SanityCheck.h View File

1539
 #endif
1539
 #endif
1540
 
1540
 
1541
 #if ENABLED(SKEW_CORRECTION)
1541
 #if ENABLED(SKEW_CORRECTION)
1542
-  #if ENABLED(AUTO_BED_LEVELING_UBL) && !ENABLED(SEGMENT_LEVELED_MOVES)
1543
-    #error "SKEW_CORRECTION with AUTO_BED_LEVELING_UBL requires SEGMENT_LEVELED_MOVES."
1544
-  #endif
1545
   #if !defined(XY_SKEW_FACTOR) && !(defined(XY_DIAG_AC) && defined(XY_DIAG_BD) && defined(XY_SIDE_AD))
1542
   #if !defined(XY_SKEW_FACTOR) && !(defined(XY_DIAG_AC) && defined(XY_DIAG_BD) && defined(XY_SIDE_AD))
1546
     #error "SKEW_CORRECTION requires XY_SKEW_FACTOR or XY_DIAG_AC, XY_DIAG_BD, XY_SIDE_AD."
1543
     #error "SKEW_CORRECTION requires XY_SKEW_FACTOR or XY_DIAG_AC, XY_DIAG_BD, XY_SIDE_AD."
1547
   #endif
1544
   #endif

+ 2
- 16
Marlin/planner.cpp View File

569
   void Planner::apply_leveling(float &rx, float &ry, float &rz) {
569
   void Planner::apply_leveling(float &rx, float &ry, float &rz) {
570
 
570
 
571
     #if ENABLED(SKEW_CORRECTION)
571
     #if ENABLED(SKEW_CORRECTION)
572
-      if (WITHIN(rx, X_MIN_POS + 1, X_MAX_POS) && WITHIN(ry, Y_MIN_POS + 1, Y_MAX_POS)) {
573
-        const float tempry = ry - (rz * planner.yz_skew_factor),
574
-                    temprx = rx - (ry * planner.xy_skew_factor) - (rz * (planner.xz_skew_factor - (planner.xy_skew_factor * planner.yz_skew_factor)));
575
-        if (WITHIN(temprx, X_MIN_POS, X_MAX_POS) && WITHIN(tempry, Y_MIN_POS, Y_MAX_POS)) {
576
-          rx = temprx;
577
-          ry = tempry;
578
-        }
579
-      }
572
+      skew(rx, ry, rz);
580
     #endif
573
     #endif
581
 
574
 
582
     if (!leveling_active) return;
575
     if (!leveling_active) return;
667
     }
660
     }
668
 
661
 
669
     #if ENABLED(SKEW_CORRECTION)
662
     #if ENABLED(SKEW_CORRECTION)
670
-      if (WITHIN(raw[X_AXIS], X_MIN_POS, X_MAX_POS) && WITHIN(raw[Y_AXIS], Y_MIN_POS, Y_MAX_POS)) {
671
-        const float temprx = raw[X_AXIS] + raw[Y_AXIS] * planner.xy_skew_factor + raw[Z_AXIS] * planner.xz_skew_factor,
672
-                    tempry = raw[Y_AXIS] + raw[Z_AXIS] * planner.yz_skew_factor;
673
-        if (WITHIN(temprx, X_MIN_POS, X_MAX_POS) && WITHIN(tempry, Y_MIN_POS, Y_MAX_POS)) {
674
-          raw[X_AXIS] = temprx;
675
-          raw[Y_AXIS] = tempry;
676
-        }
677
-      }
663
+      unskew(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]);
678
     #endif
664
     #endif
679
   }
665
   }
680
 
666
 

+ 24
- 0
Marlin/planner.h View File

341
 
341
 
342
     #endif
342
     #endif
343
 
343
 
344
+    #if ENABLED(SKEW_CORRECTION)
345
+
346
+      FORCE_INLINE static void skew(float &cx, float &cy, const float &cz) {
347
+        if (WITHIN(cx, X_MIN_POS + 1, X_MAX_POS) && WITHIN(cy, Y_MIN_POS + 1, Y_MAX_POS)) {
348
+          const float sx = cx - (cy * xy_skew_factor) - (cz * (xz_skew_factor - (xy_skew_factor * yz_skew_factor))),
349
+                      sy = cy - (cz * yz_skew_factor);
350
+          if (WITHIN(sx, X_MIN_POS, X_MAX_POS) && WITHIN(sy, Y_MIN_POS, Y_MAX_POS)) {
351
+            cx = sx; cy = sy;
352
+          }
353
+        }
354
+      }
355
+
356
+      FORCE_INLINE static void unskew(float &cx, float &cy, const float &cz) {
357
+        if (WITHIN(cx, X_MIN_POS, X_MAX_POS) && WITHIN(cy, Y_MIN_POS, Y_MAX_POS)) {
358
+          const float sx = cx + cy * xy_skew_factor + cz * xz_skew_factor,
359
+                      sy = cy + cz * yz_skew_factor;
360
+          if (WITHIN(sx, X_MIN_POS, X_MAX_POS) && WITHIN(sy, Y_MIN_POS, Y_MAX_POS)) {
361
+            cx = sx; cy = sy;
362
+          }
363
+        }
364
+      }
365
+
366
+    #endif // SKEW_CORRECTION
367
+
344
     #if PLANNER_LEVELING
368
     #if PLANNER_LEVELING
345
 
369
 
346
       #define ARG_X float rx
370
       #define ARG_X float rx

+ 33
- 23
Marlin/ubl_motion.cpp View File

44
        * as possible to determine if this is the case. If this move is within the same cell, we will
44
        * as possible to determine if this is the case. If this move is within the same cell, we will
45
        * just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
45
        * just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
46
        */
46
        */
47
-      const float start[XYZE] = {
48
-                    current_position[X_AXIS],
49
-                    current_position[Y_AXIS],
50
-                    current_position[Z_AXIS],
51
-                    current_position[E_AXIS]
52
-                  },
53
-                  end[XYZE] = {
54
-                    destination[X_AXIS],
55
-                    destination[Y_AXIS],
56
-                    destination[Z_AXIS],
57
-                    destination[E_AXIS]
58
-                  };
47
+      #if ENABLED(SKEW_CORRECTION)
48
+        // For skew correction just adjust the destination point and we're done
49
+        float start[XYZE] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS] },
50
+              end[XYZE] = { destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS] };
51
+        planner.skew(start[X_AXIS], start[Y_AXIS], start[Z_AXIS]);
52
+        planner.skew(end[X_AXIS], end[Y_AXIS], end[Z_AXIS]);
53
+      #else
54
+        const float (&start)[XYZE] = current_position,
55
+                      (&end)[XYZE] = destination;
56
+      #endif
59
 
57
 
60
       const int cell_start_xi = get_cell_index_x(start[X_AXIS]),
58
       const int cell_start_xi = get_cell_index_x(start[X_AXIS]),
61
                 cell_start_yi = get_cell_index_y(start[Y_AXIS]),
59
                 cell_start_yi = get_cell_index_y(start[Y_AXIS]),
63
                 cell_dest_yi  = get_cell_index_y(end[Y_AXIS]);
61
                 cell_dest_yi  = get_cell_index_y(end[Y_AXIS]);
64
 
62
 
65
       if (g26_debug_flag) {
63
       if (g26_debug_flag) {
66
-        SERIAL_ECHOPAIR(" ubl.line_to_destination(xe=", end[X_AXIS]);
67
-        SERIAL_ECHOPAIR(", ye=", end[Y_AXIS]);
68
-        SERIAL_ECHOPAIR(", ze=", end[Z_AXIS]);
69
-        SERIAL_ECHOPAIR(", ee=", end[E_AXIS]);
64
+        SERIAL_ECHOPAIR(" ubl.line_to_destination_cartesian(xe=", destination[X_AXIS]);
65
+        SERIAL_ECHOPAIR(", ye=", destination[Y_AXIS]);
66
+        SERIAL_ECHOPAIR(", ze=", destination[Z_AXIS]);
67
+        SERIAL_ECHOPAIR(", ee=", destination[E_AXIS]);
70
         SERIAL_CHAR(')');
68
         SERIAL_CHAR(')');
71
         SERIAL_EOL();
69
         SERIAL_EOL();
72
-        debug_current_and_destination(PSTR("Start of ubl.line_to_destination()"));
70
+        debug_current_and_destination(PSTR("Start of ubl.line_to_destination_cartesian()"));
73
       }
71
       }
74
 
72
 
75
       if (cell_start_xi == cell_dest_xi && cell_start_yi == cell_dest_yi) { // if the whole move is within the same cell,
73
       if (cell_start_xi == cell_dest_xi && cell_start_yi == cell_dest_yi) { // if the whole move is within the same cell,
89
           set_current_from_destination();
87
           set_current_from_destination();
90
 
88
 
91
           if (g26_debug_flag)
89
           if (g26_debug_flag)
92
-            debug_current_and_destination(PSTR("out of bounds in ubl.line_to_destination()"));
90
+            debug_current_and_destination(PSTR("out of bounds in ubl.line_to_destination_cartesian()"));
93
 
91
 
94
           return;
92
           return;
95
         }
93
         }
132
         planner.buffer_segment(end[X_AXIS], end[Y_AXIS], end[Z_AXIS] + z0, end[E_AXIS], feed_rate, extruder);
130
         planner.buffer_segment(end[X_AXIS], end[Y_AXIS], end[Z_AXIS] + z0, end[E_AXIS], feed_rate, extruder);
133
 
131
 
134
         if (g26_debug_flag)
132
         if (g26_debug_flag)
135
-          debug_current_and_destination(PSTR("FINAL_MOVE in ubl.line_to_destination()"));
133
+          debug_current_and_destination(PSTR("FINAL_MOVE in ubl.line_to_destination_cartesian()"));
136
 
134
 
137
         set_current_from_destination();
135
         set_current_from_destination();
138
         return;
136
         return;
238
         }
236
         }
239
 
237
 
240
         if (g26_debug_flag)
238
         if (g26_debug_flag)
241
-          debug_current_and_destination(PSTR("vertical move done in ubl.line_to_destination()"));
239
+          debug_current_and_destination(PSTR("vertical move done in ubl.line_to_destination_cartesian()"));
242
 
240
 
243
         //
241
         //
244
         // 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.
242
         // 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.
302
         }
300
         }
303
 
301
 
304
         if (g26_debug_flag)
302
         if (g26_debug_flag)
305
-          debug_current_and_destination(PSTR("horizontal move done in ubl.line_to_destination()"));
303
+          debug_current_and_destination(PSTR("horizontal move done in ubl.line_to_destination_cartesian()"));
306
 
304
 
307
         if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
305
         if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
308
           goto FINAL_MOVE;
306
           goto FINAL_MOVE;
396
       }
394
       }
397
 
395
 
398
       if (g26_debug_flag)
396
       if (g26_debug_flag)
399
-        debug_current_and_destination(PSTR("generic move done in ubl.line_to_destination()"));
397
+        debug_current_and_destination(PSTR("generic move done in ubl.line_to_destination_cartesian()"));
400
 
398
 
401
       if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
399
       if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
402
         goto FINAL_MOVE;
400
         goto FINAL_MOVE;
460
 
458
 
461
     bool _O2 unified_bed_leveling::prepare_segmented_line_to(const float (&in_target)[XYZE], const float &feedrate) {
459
     bool _O2 unified_bed_leveling::prepare_segmented_line_to(const float (&in_target)[XYZE], const float &feedrate) {
462
 
460
 
463
-      if (!position_is_reachable(rtarget[X_AXIS], rtarget[Y_AXIS]))  // fail if moving outside reachable boundary
461
+      if (!position_is_reachable(in_target[X_AXIS], in_target[Y_AXIS]))  // fail if moving outside reachable boundary
464
         return true; // did not move, so current_position still accurate
462
         return true; // did not move, so current_position still accurate
465
 
463
 
464
+      #if ENABLED(SKEW_CORRECTION)
465
+        // For skew correction just adjust the destination point and we're done
466
+        float rtarget[XYZE] = { in_target[X_AXIS], in_target[Y_AXIS], in_target[Z_AXIS], in_target[E_AXIS] };
467
+        planner.skew(rtarget[X_AXIS], rtarget[Y_AXIS], rtarget[Z_AXIS]);
468
+      #else
469
+        const float (&rtarget)[XYZE] = in_target;
470
+      #endif
471
+
466
       const float total[XYZE] = {
472
       const float total[XYZE] = {
467
         rtarget[X_AXIS] - current_position[X_AXIS],
473
         rtarget[X_AXIS] - current_position[X_AXIS],
468
         rtarget[Y_AXIS] - current_position[Y_AXIS],
474
         rtarget[Y_AXIS] - current_position[Y_AXIS],
507
         current_position[E_AXIS]
513
         current_position[E_AXIS]
508
       };
514
       };
509
 
515
 
516
+      #if ENABLED(SKEW_CORRECTION)
517
+        planner.skew(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]);
518
+      #endif
519
+
510
       // Only compute leveling per segment if ubl active and target below z_fade_height.
520
       // Only compute leveling per segment if ubl active and target below z_fade_height.
511
       if (!planner.leveling_active || !planner.leveling_active_at_z(rtarget[Z_AXIS])) {   // no mesh leveling
521
       if (!planner.leveling_active || !planner.leveling_active_at_z(rtarget[Z_AXIS])) {   // no mesh leveling
512
         while (--segments) {
522
         while (--segments) {

Loading…
Cancel
Save