Browse Source

Skew Correction for UBL

Also remove unused grid slicing function when using UBL segmented.
Scott Lahteine 7 years ago
parent
commit
3255712343

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl.h View File

321
       return i < GRID_MAX_POINTS_Y ? pgm_read_float(&_mesh_index_to_ypos[i]) : MESH_MIN_Y + i * (MESH_Y_DIST);
321
       return i < GRID_MAX_POINTS_Y ? pgm_read_float(&_mesh_index_to_ypos[i]) : MESH_MIN_Y + i * (MESH_Y_DIST);
322
     }
322
     }
323
 
323
 
324
-    static bool prepare_segmented_line_to(const float rtarget[XYZE], const float &feedrate);
325
     static void line_to_destination_cartesian(const float &fr, const uint8_t e);
324
     static void line_to_destination_cartesian(const float &fr, const uint8_t e);
325
+    static bool prepare_segmented_line_to(const float (&rtarget)[XYZE], const float &feedrate);
326
 
326
 
327
     #define _CMPZ(a,b) (z_values[a][b] == z_values[a][b+1])
327
     #define _CMPZ(a,b) (z_values[a][b] == z_values[a][b+1])
328
     #define CMPZ(a) (_CMPZ(a, 0) && _CMPZ(a, 1))
328
     #define CMPZ(a) (_CMPZ(a, 0) && _CMPZ(a, 1))

+ 26
- 21
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp View File

47
      * as possible to determine if this is the case. If this move is within the same cell, we will
47
      * as possible to determine if this is the case. If this move is within the same cell, we will
48
      * just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
48
      * just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
49
      */
49
      */
50
-    const float start[XYZE] = {
51
-                  current_position[X_AXIS],
52
-                  current_position[Y_AXIS],
53
-                  current_position[Z_AXIS],
54
-                  current_position[E_AXIS]
55
-                },
56
-                end[XYZE] = {
57
-                  destination[X_AXIS],
58
-                  destination[Y_AXIS],
59
-                  destination[Z_AXIS],
60
-                  destination[E_AXIS]
61
-                };
50
+    #if ENABLED(SKEW_CORRECTION)
51
+      // For skew correction just adjust the destination point and we're done
52
+      float start[XYZE] = { current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS] },
53
+            end[XYZE] = { destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS] };
54
+      planner.skew(start[X_AXIS], start[Y_AXIS], start[Z_AXIS]);
55
+      planner.skew(end[X_AXIS], end[Y_AXIS], end[Z_AXIS]);
56
+    #else
57
+      const float (&start)[XYZE] = current_position,
58
+                    (&end)[XYZE] = destination;
59
+    #endif
62
 
60
 
63
     const int cell_start_xi = get_cell_index_x(start[X_AXIS]),
61
     const int cell_start_xi = get_cell_index_x(start[X_AXIS]),
64
               cell_start_yi = get_cell_index_y(start[Y_AXIS]),
62
               cell_start_yi = get_cell_index_y(start[Y_AXIS]),
66
               cell_dest_yi  = get_cell_index_y(end[Y_AXIS]);
64
               cell_dest_yi  = get_cell_index_y(end[Y_AXIS]);
67
 
65
 
68
     if (g26_debug_flag) {
66
     if (g26_debug_flag) {
69
-      SERIAL_ECHOPAIR(" ubl.line_to_destination(xe=", end[X_AXIS]);
70
-      SERIAL_ECHOPAIR(", ye=", end[Y_AXIS]);
71
-      SERIAL_ECHOPAIR(", ze=", end[Z_AXIS]);
72
-      SERIAL_ECHOPAIR(", ee=", end[E_AXIS]);
67
+      SERIAL_ECHOPAIR(" ubl.line_to_destination_cartesian(xe=", destination[X_AXIS]);
68
+      SERIAL_ECHOPAIR(", ye=", destination[Y_AXIS]);
69
+      SERIAL_ECHOPAIR(", ze=", destination[Z_AXIS]);
70
+      SERIAL_ECHOPAIR(", ee=", destination[E_AXIS]);
73
       SERIAL_CHAR(')');
71
       SERIAL_CHAR(')');
74
       SERIAL_EOL();
72
       SERIAL_EOL();
75
       debug_current_and_destination(PSTR("Start of ubl.line_to_destination_cartesian()"));
73
       debug_current_and_destination(PSTR("Start of ubl.line_to_destination_cartesian()"));
416
     // We don't want additional apply_leveling() performed by regular buffer_line or buffer_line_kinematic,
414
     // We don't want additional apply_leveling() performed by regular buffer_line or buffer_line_kinematic,
417
     // so we call buffer_segment directly here.  Per-segmented leveling and kinematics performed first.
415
     // so we call buffer_segment directly here.  Per-segmented leveling and kinematics performed first.
418
 
416
 
419
-    inline void _O2 ubl_buffer_segment_raw(const float (&raw)[XYZE], const float &fr) {
417
+    inline void _O2 ubl_buffer_segment_raw(const float (&in_raw)[XYZE], const float &fr) {
418
+
419
+      #if ENABLED(SKEW_CORRECTION)
420
+        float raw[XYZE] = { in_raw[X_AXIS], in_raw[Y_AXIS], in_raw[Z_AXIS] };
421
+        planner.skew(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]);
422
+      #else
423
+        const float (&raw)[XYZE] = in_raw;
424
+      #endif
420
 
425
 
421
       #if ENABLED(DELTA)  // apply delta inverse_kinematics
426
       #if ENABLED(DELTA)  // apply delta inverse_kinematics
422
 
427
 
423
         DELTA_RAW_IK();
428
         DELTA_RAW_IK();
424
-        planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], fr, active_extruder);
429
+        planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], in_raw[E_AXIS], fr, active_extruder);
425
 
430
 
426
       #elif IS_SCARA  // apply scara inverse_kinematics (should be changed to save raw->logical->raw)
431
       #elif IS_SCARA  // apply scara inverse_kinematics (should be changed to save raw->logical->raw)
427
 
432
 
434
         scara_oldB = delta[B_AXIS];
439
         scara_oldB = delta[B_AXIS];
435
         float s_feedrate = max(adiff, bdiff) * scara_feed_factor;
440
         float s_feedrate = max(adiff, bdiff) * scara_feed_factor;
436
 
441
 
437
-        planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], s_feedrate, active_extruder);
442
+        planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], in_raw[E_AXIS], s_feedrate, active_extruder);
438
 
443
 
439
       #else // CARTESIAN
444
       #else // CARTESIAN
440
 
445
 
441
-        planner.buffer_segment(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], raw[E_AXIS], fr, active_extruder);
446
+        planner.buffer_segment(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], in_raw[E_AXIS], fr, active_extruder);
442
 
447
 
443
       #endif
448
       #endif
444
     }
449
     }
461
      * Returns true if did NOT move, false if moved (requires current_position update).
466
      * Returns true if did NOT move, false if moved (requires current_position update).
462
      */
467
      */
463
 
468
 
464
-    bool _O2 unified_bed_leveling::prepare_segmented_line_to(const float rtarget[XYZE], const float &feedrate) {
469
+    bool _O2 unified_bed_leveling::prepare_segmented_line_to(const float (&rtarget)[XYZE], const float &feedrate) {
465
 
470
 
466
       if (!position_is_reachable(rtarget[X_AXIS], rtarget[Y_AXIS]))  // fail if moving outside reachable boundary
471
       if (!position_is_reachable(rtarget[X_AXIS], rtarget[Y_AXIS]))  // fail if moving outside reachable boundary
467
         return true; // did not move, so current_position still accurate
472
         return true; // did not move, so current_position still accurate

+ 2
- 16
Marlin/src/module/planner.cpp View File

580
   void Planner::apply_leveling(float &rx, float &ry, float &rz) {
580
   void Planner::apply_leveling(float &rx, float &ry, float &rz) {
581
 
581
 
582
     #if ENABLED(SKEW_CORRECTION)
582
     #if ENABLED(SKEW_CORRECTION)
583
-      if (WITHIN(rx, X_MIN_POS + 1, X_MAX_POS) && WITHIN(ry, Y_MIN_POS + 1, Y_MAX_POS)) {
584
-        const float tempry = ry - (rz * planner.yz_skew_factor),
585
-                    temprx = rx - (ry * planner.xy_skew_factor) - (rz * (planner.xz_skew_factor - (planner.xy_skew_factor * planner.yz_skew_factor)));
586
-        if (WITHIN(temprx, X_MIN_POS, X_MAX_POS) && WITHIN(tempry, Y_MIN_POS, Y_MAX_POS)) {
587
-          rx = temprx;
588
-          ry = tempry;
589
-        }
590
-      }
583
+      skew(rx, ry, rz);
591
     #endif
584
     #endif
592
 
585
 
593
     if (!leveling_active) return;
586
     if (!leveling_active) return;
678
     }
671
     }
679
 
672
 
680
     #if ENABLED(SKEW_CORRECTION)
673
     #if ENABLED(SKEW_CORRECTION)
681
-      if (WITHIN(raw[X_AXIS], X_MIN_POS, X_MAX_POS) && WITHIN(raw[Y_AXIS], Y_MIN_POS, Y_MAX_POS)) {
682
-        const float temprx = raw[X_AXIS] + raw[Y_AXIS] * planner.xy_skew_factor + raw[Z_AXIS] * planner.xz_skew_factor,
683
-                    tempry = raw[Y_AXIS] + raw[Z_AXIS] * planner.yz_skew_factor;
684
-        if (WITHIN(temprx, X_MIN_POS, X_MAX_POS) && WITHIN(tempry, Y_MIN_POS, Y_MAX_POS)) {
685
-          raw[X_AXIS] = temprx;
686
-          raw[Y_AXIS] = tempry;
687
-        }
688
-      }
674
+      unskew(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]);
689
     #endif
675
     #endif
690
   }
676
   }
691
 
677
 

+ 24
- 0
Marlin/src/module/planner.h View File

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

Loading…
Cancel
Save