Przeglądaj źródła

Bed leveling that accounts for home XYZ

Scott Lahteine 8 lat temu
rodzic
commit
9248cfb0ad
4 zmienionych plików z 210 dodań i 207 usunięć
  1. 5
    0
      Marlin/Conditionals_post.h
  2. 140
    144
      Marlin/Marlin_main.cpp
  3. 61
    58
      Marlin/planner.cpp
  4. 4
    5
      Marlin/planner.h

+ 5
- 0
Marlin/Conditionals_post.h Wyświetl plik

@@ -165,6 +165,11 @@
165 165
     #ifndef Z_SAFE_HOMING_Y_POINT
166 166
       #define Z_SAFE_HOMING_Y_POINT ((Y_MIN_POS + Y_MAX_POS) / 2)
167 167
     #endif
168
+    #define X_TILT_FULCRUM Z_SAFE_HOMING_X_POINT
169
+    #define Y_TILT_FULCRUM Z_SAFE_HOMING_Y_POINT
170
+  #else
171
+    #define X_TILT_FULCRUM X_HOME_POS
172
+    #define Y_TILT_FULCRUM Y_HOME_POS
168 173
   #endif
169 174
 
170 175
   /**

+ 140
- 144
Marlin/Marlin_main.cpp Wyświetl plik

@@ -458,45 +458,51 @@ static uint8_t target_extruder;
458 458
 
459 459
 #if ENABLED(DELTA)
460 460
 
461
-  #define TOWER_1 X_AXIS
462
-  #define TOWER_2 Y_AXIS
463
-  #define TOWER_3 Z_AXIS
464
-
465
-  float delta[ABC];
466
-  float cartesian_position[XYZ] = { 0 };
467 461
   #define SIN_60 0.8660254037844386
468 462
   #define COS_60 0.5
469
-  float endstop_adj[ABC] = { 0 };
463
+
464
+  float delta[ABC],
465
+        cartesian_position[XYZ] = { 0 },
466
+        endstop_adj[ABC] = { 0 };
467
+
470 468
   // these are the default values, can be overriden with M665
471
-  float delta_radius = DELTA_RADIUS;
472
-  float delta_tower1_x = -SIN_60 * (delta_radius + DELTA_RADIUS_TRIM_TOWER_1); // front left tower
473
-  float delta_tower1_y = -COS_60 * (delta_radius + DELTA_RADIUS_TRIM_TOWER_1);
474
-  float delta_tower2_x =  SIN_60 * (delta_radius + DELTA_RADIUS_TRIM_TOWER_2); // front right tower
475
-  float delta_tower2_y = -COS_60 * (delta_radius + DELTA_RADIUS_TRIM_TOWER_2);
476
-  float delta_tower3_x = 0;                                                    // back middle tower
477
-  float delta_tower3_y = (delta_radius + DELTA_RADIUS_TRIM_TOWER_3);
478
-  float delta_diagonal_rod = DELTA_DIAGONAL_ROD;
479
-  float delta_diagonal_rod_trim_tower_1 = DELTA_DIAGONAL_ROD_TRIM_TOWER_1;
480
-  float delta_diagonal_rod_trim_tower_2 = DELTA_DIAGONAL_ROD_TRIM_TOWER_2;
481
-  float delta_diagonal_rod_trim_tower_3 = DELTA_DIAGONAL_ROD_TRIM_TOWER_3;
482
-  float delta_diagonal_rod_2_tower_1 = sq(delta_diagonal_rod + delta_diagonal_rod_trim_tower_1);
483
-  float delta_diagonal_rod_2_tower_2 = sq(delta_diagonal_rod + delta_diagonal_rod_trim_tower_2);
484
-  float delta_diagonal_rod_2_tower_3 = sq(delta_diagonal_rod + delta_diagonal_rod_trim_tower_3);
485
-  float delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND;
486
-  float delta_clip_start_height = Z_MAX_POS;
469
+  float delta_radius = DELTA_RADIUS,
470
+        delta_tower1_x = -SIN_60 * (delta_radius + DELTA_RADIUS_TRIM_TOWER_1), // front left tower
471
+        delta_tower1_y = -COS_60 * (delta_radius + DELTA_RADIUS_TRIM_TOWER_1),
472
+        delta_tower2_x =  SIN_60 * (delta_radius + DELTA_RADIUS_TRIM_TOWER_2), // front right tower
473
+        delta_tower2_y = -COS_60 * (delta_radius + DELTA_RADIUS_TRIM_TOWER_2),
474
+        delta_tower3_x = 0,                                                    // back middle tower
475
+        delta_tower3_y = (delta_radius + DELTA_RADIUS_TRIM_TOWER_3),
476
+        delta_diagonal_rod = DELTA_DIAGONAL_ROD,
477
+        delta_diagonal_rod_trim_tower_1 = DELTA_DIAGONAL_ROD_TRIM_TOWER_1,
478
+        delta_diagonal_rod_trim_tower_2 = DELTA_DIAGONAL_ROD_TRIM_TOWER_2,
479
+        delta_diagonal_rod_trim_tower_3 = DELTA_DIAGONAL_ROD_TRIM_TOWER_3,
480
+        delta_diagonal_rod_2_tower_1 = sq(delta_diagonal_rod + delta_diagonal_rod_trim_tower_1),
481
+        delta_diagonal_rod_2_tower_2 = sq(delta_diagonal_rod + delta_diagonal_rod_trim_tower_2),
482
+        delta_diagonal_rod_2_tower_3 = sq(delta_diagonal_rod + delta_diagonal_rod_trim_tower_3),
483
+        delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND,
484
+        delta_clip_start_height = Z_MAX_POS;
485
+
487 486
   #if ENABLED(AUTO_BED_LEVELING_FEATURE)
488 487
     int delta_grid_spacing[2] = { 0, 0 };
489 488
     float bed_level[AUTO_BED_LEVELING_GRID_POINTS][AUTO_BED_LEVELING_GRID_POINTS];
490 489
   #endif
490
+
491 491
   float delta_safe_distance_from_top();
492
+  void set_cartesian_from_steppers();
493
+
492 494
 #else
495
+
493 496
   static bool home_all_axis = true;
497
+
494 498
 #endif
495 499
 
496 500
 #if ENABLED(SCARA)
497
-  float delta_segments_per_second = SCARA_SEGMENTS_PER_SECOND;
498
-  float delta[ABC];
499
-  float axis_scaling[ABC] = { 1, 1, 1 };    // Build size scaling, default to 1
501
+  float delta_segments_per_second = SCARA_SEGMENTS_PER_SECOND,
502
+        delta[ABC],
503
+        axis_scaling[ABC] = { 1, 1, 1 },    // Build size scaling, default to 1
504
+        cartesian_position[XYZ] = { 0 };
505
+  void set_cartesian_from_steppers() { }    // to be written later
500 506
 #endif
501 507
 
502 508
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
@@ -2266,79 +2272,37 @@ static void clean_up_after_endstop_or_probe_move() {
2266 2272
 
2267 2273
 #if ENABLED(AUTO_BED_LEVELING_FEATURE)
2268 2274
 
2269
-  #if ENABLED(AUTO_BED_LEVELING_GRID)
2270
-
2271
-    #if DISABLED(DELTA)
2272
-
2273
-      static void set_bed_level_equation_lsq(double* plane_equation_coefficients) {
2274
-
2275
-        //planner.bed_level_matrix.debug("bed level before");
2276
-
2277
-        #if ENABLED(DEBUG_LEVELING_FEATURE)
2278
-          planner.bed_level_matrix.set_to_identity();
2279
-          if (DEBUGGING(LEVELING)) {
2280
-            vector_3 uncorrected_position = planner.adjusted_position();
2281
-            DEBUG_POS(">>> set_bed_level_equation_lsq", uncorrected_position);
2282
-            DEBUG_POS(">>> set_bed_level_equation_lsq", current_position);
2283
-          }
2284
-        #endif
2285
-
2286
-        vector_3 planeNormal = vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1);
2287
-        planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
2288
-
2289
-        vector_3 corrected_position = planner.adjusted_position();
2290
-        current_position[X_AXIS] = corrected_position.x;
2291
-        current_position[Y_AXIS] = corrected_position.y;
2292
-        current_position[Z_AXIS] = corrected_position.z;
2275
+  #if DISABLED(DELTA)
2293 2276
 
2294
-        #if ENABLED(DEBUG_LEVELING_FEATURE)
2295
-          if (DEBUGGING(LEVELING)) DEBUG_POS("<<< set_bed_level_equation_lsq", corrected_position);
2296
-        #endif
2297
-
2298
-        SYNC_PLAN_POSITION_KINEMATIC();
2299
-      }
2300
-
2301
-    #endif // !DELTA
2302
-
2303
-  #else // !AUTO_BED_LEVELING_GRID
2304
-
2305
-    static void set_bed_level_equation_3pts(float z_at_pt_1, float z_at_pt_2, float z_at_pt_3) {
2306
-
2307
-      planner.bed_level_matrix.set_to_identity();
2277
+    /**
2278
+     * Get the stepper positions, apply the rotation matrix
2279
+     * using the home XY and Z0 position as the fulcrum.
2280
+     */
2281
+    vector_3 untilted_stepper_position() {
2282
+      vector_3 pos = vector_3(
2283
+        RAW_X_POSITION(stepper.get_axis_position_mm(X_AXIS)) - X_TILT_FULCRUM,
2284
+        RAW_Y_POSITION(stepper.get_axis_position_mm(Y_AXIS)) - Y_TILT_FULCRUM,
2285
+        RAW_Z_POSITION(stepper.get_axis_position_mm(Z_AXIS))
2286
+      );
2308 2287
 
2309
-      #if ENABLED(DEBUG_LEVELING_FEATURE)
2310
-        if (DEBUGGING(LEVELING)) {
2311
-          vector_3 uncorrected_position = planner.adjusted_position();
2312
-          DEBUG_POS("set_bed_level_equation_3pts", uncorrected_position);
2313
-        }
2314
-      #endif
2288
+      matrix_3x3 inverse = matrix_3x3::transpose(planner.bed_level_matrix);
2315 2289
 
2316
-      vector_3 pt1 = vector_3(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, z_at_pt_1);
2317
-      vector_3 pt2 = vector_3(ABL_PROBE_PT_2_X, ABL_PROBE_PT_2_Y, z_at_pt_2);
2318
-      vector_3 pt3 = vector_3(ABL_PROBE_PT_3_X, ABL_PROBE_PT_3_Y, z_at_pt_3);
2319
-      vector_3 planeNormal = vector_3::cross(pt1 - pt2, pt3 - pt2).get_normal();
2290
+      //pos.debug("untilted_stepper_position offset");
2291
+      //bed_level_matrix.debug("untilted_stepper_position");
2292
+      //inverse.debug("in untilted_stepper_position");
2320 2293
 
2321
-      if (planeNormal.z < 0) {
2322
-        planeNormal.x = -planeNormal.x;
2323
-        planeNormal.y = -planeNormal.y;
2324
-        planeNormal.z = -planeNormal.z;
2325
-      }
2294
+      pos.apply_rotation(inverse);
2326 2295
 
2327
-      planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
2328
-      vector_3 corrected_position = planner.adjusted_position();
2296
+      pos.x = LOGICAL_X_POSITION(pos.x + X_TILT_FULCRUM);
2297
+      pos.y = LOGICAL_Y_POSITION(pos.y + Y_TILT_FULCRUM);
2298
+      pos.z = LOGICAL_Z_POSITION(pos.z);
2329 2299
 
2330
-      current_position[X_AXIS] = corrected_position.x;
2331
-      current_position[Y_AXIS] = corrected_position.y;
2332
-      current_position[Z_AXIS] = corrected_position.z;
2300
+      //pos.debug("after rotation and reorientation");
2333 2301
 
2334
-      #if ENABLED(DEBUG_LEVELING_FEATURE)
2335
-        if (DEBUGGING(LEVELING)) DEBUG_POS("set_bed_level_equation_3pts", corrected_position);
2336
-      #endif
2337
-
2338
-      SYNC_PLAN_POSITION_KINEMATIC();
2302
+      return pos;
2339 2303
     }
2340 2304
 
2341
-  #endif // !AUTO_BED_LEVELING_GRID
2305
+  #endif // !DELTA
2342 2306
 
2343 2307
   #if ENABLED(DELTA)
2344 2308
 
@@ -3626,41 +3590,41 @@ inline void gcode_G28() {
3626 3590
 
3627 3591
     #endif // AUTO_BED_LEVELING_GRID
3628 3592
 
3629
-    if (!dryrun) {
3593
+    stepper.synchronize();
3630 3594
 
3631
-      #if ENABLED(DEBUG_LEVELING_FEATURE) && DISABLED(DELTA)
3632
-        if (DEBUGGING(LEVELING)) {
3633
-          vector_3 corrected_position = planner.adjusted_position();
3634
-          DEBUG_POS("BEFORE matrix.set_to_identity", corrected_position);
3635
-          DEBUG_POS("BEFORE matrix.set_to_identity", current_position);
3636
-        }
3637
-      #endif
3595
+    if (!dryrun) {
3638 3596
 
3639
-      // make sure the bed_level_rotation_matrix is identity or the planner will get it wrong
3597
+      // Reset the bed_level_matrix because leveling
3598
+      // needs to be done without leveling enabled.
3640 3599
       planner.bed_level_matrix.set_to_identity();
3641 3600
 
3642
-      #if ENABLED(DELTA)
3643
-        reset_bed_level();
3644
-      #else //!DELTA
3645
-
3646
-        //vector_3 corrected_position = planner.adjusted_position();
3647
-        //corrected_position.debug("position before G29");
3648
-        vector_3 uncorrected_position = planner.adjusted_position();
3649
-        //uncorrected_position.debug("position during G29");
3650
-        current_position[X_AXIS] = uncorrected_position.x;
3651
-        current_position[Y_AXIS] = uncorrected_position.y;
3652
-        current_position[Z_AXIS] = uncorrected_position.z;
3601
+      //
3602
+      // Re-orient the current position without leveling
3603
+      // based on where the steppers are positioned.
3604
+      //
3605
+      #if ENABLED(DELTA) || ENABLED(SCARA)
3653 3606
 
3654
-        #if ENABLED(DEBUG_LEVELING_FEATURE)
3655
-          if (DEBUGGING(LEVELING)) DEBUG_POS("AFTER matrix.set_to_identity", uncorrected_position);
3607
+        #if ENABLED(DELTA)
3608
+          reset_bed_level();
3656 3609
         #endif
3657 3610
 
3658
-        SYNC_PLAN_POSITION_KINEMATIC();
3611
+        // For DELTA/SCARA we need to apply forward kinematics.
3612
+        // This returns raw positions and we remap to the space.
3613
+        set_cartesian_from_steppers();
3614
+        LOOP_XYZ(i) current_position[i] = LOGICAL_POSITION(cartesian_position[i], i);
3615
+
3616
+      #else
3617
+
3618
+        // For cartesian/core the steppers are already mapped to
3619
+        // the coordinate space by design.
3620
+        LOOP_XYZ(i) current_position[i] = stepper.get_axis_position_mm((AxisEnum)i);
3659 3621
 
3660 3622
       #endif // !DELTA
3661
-    }
3662 3623
 
3663
-    stepper.synchronize();
3624
+      // Inform the planner about the new coordinates
3625
+      // (This is probably not needed here)
3626
+      SYNC_PLAN_POSITION_KINEMATIC();
3627
+    }
3664 3628
 
3665 3629
     setup_for_endstop_or_probe_move();
3666 3630
 
@@ -3766,7 +3730,20 @@ inline void gcode_G28() {
3766 3730
                                   LOGICAL_Y_POSITION(ABL_PROBE_PT_3_Y),
3767 3731
                                   stow_probe_after_each, verbose_level);
3768 3732
 
3769
-      if (!dryrun) set_bed_level_equation_3pts(z_at_pt_1, z_at_pt_2, z_at_pt_3);
3733
+      if (!dryrun) {
3734
+        vector_3 pt1 = vector_3(ABL_PROBE_PT_1_X, ABL_PROBE_PT_1_Y, z_at_pt_1),
3735
+                 pt2 = vector_3(ABL_PROBE_PT_2_X, ABL_PROBE_PT_2_Y, z_at_pt_2),
3736
+                 pt3 = vector_3(ABL_PROBE_PT_3_X, ABL_PROBE_PT_3_Y, z_at_pt_3);
3737
+
3738
+        vector_3 planeNormal = vector_3::cross(pt1 - pt2, pt3 - pt2).get_normal();
3739
+
3740
+        if (planeNormal.z < 0) {
3741
+          planeNormal.x *= -1;
3742
+          planeNormal.y *= -1;
3743
+          planeNormal.z *= -1;
3744
+        }
3745
+        planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
3746
+      }
3770 3747
 
3771 3748
     #endif // !AUTO_BED_LEVELING_GRID
3772 3749
 
@@ -3810,7 +3787,12 @@ inline void gcode_G28() {
3810 3787
           }
3811 3788
         }
3812 3789
 
3813
-        if (!dryrun) set_bed_level_equation_lsq(plane_equation_coefficients);
3790
+        // Create the matrix but don't correct the position yet
3791
+        if (!dryrun) {
3792
+          planner.bed_level_matrix = matrix_3x3::create_look_at(
3793
+            vector_3(-plane_equation_coefficients[0], -plane_equation_coefficients[1], 1)
3794
+          );
3795
+        }
3814 3796
 
3815 3797
         // Show the Topography map if enabled
3816 3798
         if (do_topography_map) {
@@ -3851,6 +3833,7 @@ inline void gcode_G28() {
3851 3833
             SERIAL_EOL;
3852 3834
           } // yy
3853 3835
           SERIAL_EOL;
3836
+
3854 3837
           if (verbose_level > 3) {
3855 3838
             SERIAL_PROTOCOLLNPGM("\nCorrected Bed Height vs. Bed Topology:");
3856 3839
 
@@ -3876,47 +3859,60 @@ inline void gcode_G28() {
3876 3859
             SERIAL_EOL;
3877 3860
           }
3878 3861
         } //do_topography_map
3862
+
3879 3863
       #endif //!DELTA
3864
+
3880 3865
     #endif // AUTO_BED_LEVELING_GRID
3881 3866
 
3882 3867
     #if DISABLED(DELTA)
3868
+
3883 3869
       if (verbose_level > 0)
3884 3870
         planner.bed_level_matrix.debug("\n\nBed Level Correction Matrix:");
3885 3871
 
3886 3872
       if (!dryrun) {
3887
-        /**
3888
-         * Correct the Z height difference from Z probe position and nozzle tip position.
3889
-         * The Z height on homing is measured by Z probe, but the Z probe is quite far
3890
-         * from the nozzle. When the bed is uneven, this height must be corrected.
3891
-         */
3892
-        float x_tmp = current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER,
3893
-              y_tmp = current_position[Y_AXIS] + Y_PROBE_OFFSET_FROM_EXTRUDER,
3894
-              z_tmp = current_position[Z_AXIS],
3895
-              stepper_z = stepper.get_axis_position_mm(Z_AXIS);  //get the real Z (since planner.adjusted_position is now correcting the plane)
3873
+        //
3874
+        // Correct the current XYZ position based on the tilted plane.
3875
+        //
3876
+
3877
+        // Get the distance from the reference point to the current position
3878
+        // The current XY is in sync with the planner/steppers at this point
3879
+        // but the current Z is only known to the steppers.
3880
+        float x_dist = RAW_CURRENT_POSITION(X_AXIS) - X_TILT_FULCRUM,
3881
+              y_dist = RAW_CURRENT_POSITION(Y_AXIS) - Y_TILT_FULCRUM,
3882
+              z_real = RAW_Z_POSITION(stepper.get_axis_position_mm(Z_AXIS));
3896 3883
 
3897 3884
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3898 3885
           if (DEBUGGING(LEVELING)) {
3899
-            SERIAL_ECHOPAIR("> BEFORE apply_rotation_xyz > stepper_z = ", stepper_z);
3900
-            SERIAL_ECHOLNPAIR(" ... z_tmp  = ", z_tmp);
3886
+            SERIAL_ECHOPAIR("BEFORE ROTATION ... x_dist:", x_dist);
3887
+            SERIAL_ECHOPAIR("y_dist:", y_dist);
3888
+            SERIAL_ECHOPAIR("z_real:", z_real);
3901 3889
           }
3902 3890
         #endif
3903 3891
 
3904
-        // Apply the correction sending the Z probe offset
3905
-        apply_rotation_xyz(planner.bed_level_matrix, x_tmp, y_tmp, z_tmp);
3892
+        // Apply the matrix to the distance from the reference point to XY,
3893
+        // and from the homed Z to the current Z.
3894
+        apply_rotation_xyz(planner.bed_level_matrix, x_dist, y_dist, z_real);
3906 3895
 
3907 3896
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3908
-          if (DEBUGGING(LEVELING))
3909
-            SERIAL_ECHOLNPAIR("> AFTER apply_rotation_xyz > z_tmp  = ", z_tmp);
3897
+          if (DEBUGGING(LEVELING)) {
3898
+            SERIAL_ECHOPAIR("AFTER ROTATION ... x_dist:", x_dist);
3899
+            SERIAL_ECHOPAIR("y_dist:", y_dist);
3900
+            SERIAL_ECHOPAIR("z_real:", z_real);
3901
+          }
3910 3902
         #endif
3911 3903
 
3912
-        // Adjust the current Z and send it to the planner.
3913
-        current_position[Z_AXIS] += z_tmp - stepper_z;
3904
+        // Apply the rotated distance and Z to the current position
3905
+        current_position[X_AXIS] = LOGICAL_X_POSITION(X_TILT_FULCRUM + x_dist);
3906
+        current_position[Y_AXIS] = LOGICAL_Y_POSITION(Y_TILT_FULCRUM + y_dist);
3907
+        current_position[Z_AXIS] = LOGICAL_Z_POSITION(z_real);
3908
+
3914 3909
         SYNC_PLAN_POSITION_KINEMATIC();
3915 3910
 
3916 3911
         #if ENABLED(DEBUG_LEVELING_FEATURE)
3917
-          if (DEBUGGING(LEVELING)) DEBUG_POS("> corrected Z in G29", current_position);
3912
+          if (DEBUGGING(LEVELING)) DEBUG_POS("> corrected XYZ in G29", current_position);
3918 3913
         #endif
3919 3914
       }
3915
+
3920 3916
     #endif // !DELTA
3921 3917
 
3922 3918
     #ifdef Z_PROBE_END_SCRIPT
@@ -7850,15 +7846,15 @@ void ok_to_send() {
7850 7846
       RAW_Z_POSITION(in_cartesian[Z_AXIS])
7851 7847
     };
7852 7848
 
7853
-    delta[TOWER_1] = sqrt(delta_diagonal_rod_2_tower_1
7849
+    delta[A_AXIS] = sqrt(delta_diagonal_rod_2_tower_1
7854 7850
                           - sq(delta_tower1_x - cartesian[X_AXIS])
7855 7851
                           - sq(delta_tower1_y - cartesian[Y_AXIS])
7856 7852
                          ) + cartesian[Z_AXIS];
7857
-    delta[TOWER_2] = sqrt(delta_diagonal_rod_2_tower_2
7853
+    delta[B_AXIS] = sqrt(delta_diagonal_rod_2_tower_2
7858 7854
                           - sq(delta_tower2_x - cartesian[X_AXIS])
7859 7855
                           - sq(delta_tower2_y - cartesian[Y_AXIS])
7860 7856
                          ) + cartesian[Z_AXIS];
7861
-    delta[TOWER_3] = sqrt(delta_diagonal_rod_2_tower_3
7857
+    delta[C_AXIS] = sqrt(delta_diagonal_rod_2_tower_3
7862 7858
                           - sq(delta_tower3_x - cartesian[X_AXIS])
7863 7859
                           - sq(delta_tower3_y - cartesian[Y_AXIS])
7864 7860
                          ) + cartesian[Z_AXIS];
@@ -7867,9 +7863,9 @@ void ok_to_send() {
7867 7863
     SERIAL_ECHOPGM(" y="); SERIAL_ECHO(cartesian[Y_AXIS]);
7868 7864
     SERIAL_ECHOPGM(" z="); SERIAL_ECHOLN(cartesian[Z_AXIS]);
7869 7865
 
7870
-    SERIAL_ECHOPGM("delta a="); SERIAL_ECHO(delta[TOWER_1]);
7871
-    SERIAL_ECHOPGM(" b="); SERIAL_ECHO(delta[TOWER_2]);
7872
-    SERIAL_ECHOPGM(" c="); SERIAL_ECHOLN(delta[TOWER_3]);
7866
+    SERIAL_ECHOPGM("delta a="); SERIAL_ECHO(delta[A_AXIS]);
7867
+    SERIAL_ECHOPGM(" b="); SERIAL_ECHO(delta[B_AXIS]);
7868
+    SERIAL_ECHOPGM(" c="); SERIAL_ECHOLN(delta[C_AXIS]);
7873 7869
     */
7874 7870
   }
7875 7871
 
@@ -7880,10 +7876,10 @@ void ok_to_send() {
7880 7876
       LOGICAL_Z_POSITION(0)
7881 7877
     };
7882 7878
     inverse_kinematics(cartesian);
7883
-    float distance = delta[TOWER_3];
7879
+    float distance = delta[A_AXIS];
7884 7880
     cartesian[Y_AXIS] = LOGICAL_Y_POSITION(DELTA_PRINTABLE_RADIUS);
7885 7881
     inverse_kinematics(cartesian);
7886
-    return abs(distance - delta[TOWER_3]);
7882
+    return abs(distance - delta[A_AXIS]);
7887 7883
   }
7888 7884
 
7889 7885
   void forward_kinematics_DELTA(float z1, float z2, float z3) {
@@ -8014,7 +8010,7 @@ void set_current_from_steppers_for_axis(AxisEnum axis) {
8014 8010
     set_cartesian_from_steppers();
8015 8011
     current_position[axis] = LOGICAL_POSITION(cartesian_position[axis], axis);
8016 8012
   #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
8017
-    vector_3 pos = planner.adjusted_position();
8013
+    vector_3 pos = untilted_stepper_position();
8018 8014
     current_position[axis] = axis == X_AXIS ? pos.x : axis == Y_AXIS ? pos.y : pos.z;
8019 8015
   #else
8020 8016
     current_position[axis] = stepper.get_axis_position_mm(axis); // CORE handled transparently

+ 61
- 58
Marlin/planner.cpp Wyświetl plik

@@ -521,6 +521,38 @@ void Planner::check_axes_activity() {
521 521
   #endif
522 522
 }
523 523
 
524
+#if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
525
+
526
+  void Planner::apply_leveling(
527
+    #if ENABLED(MESH_BED_LEVELING)
528
+      const float &x, const float &y
529
+    #else
530
+      float &x, float &y
531
+    #endif
532
+    , float &z
533
+  ) {
534
+    #if ENABLED(MESH_BED_LEVELING)
535
+
536
+      if (mbl.active())
537
+        z += mbl.get_z(RAW_X_POSITION(x), RAW_Y_POSITION(y));
538
+
539
+    #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
540
+
541
+      float tx = RAW_X_POSITION(x) - (X_TILT_FULCRUM),
542
+            ty = RAW_Y_POSITION(y) - (Y_TILT_FULCRUM),
543
+            tz = RAW_Z_POSITION(z);
544
+
545
+      apply_rotation_xyz(bed_level_matrix, tx, ty, tz);
546
+
547
+      x = LOGICAL_X_POSITION(tx + X_TILT_FULCRUM);
548
+      y = LOGICAL_Y_POSITION(ty + Y_TILT_FULCRUM);
549
+      z = LOGICAL_Z_POSITION(tz);
550
+
551
+    #endif
552
+  }
553
+
554
+#endif
555
+
524 556
 /**
525 557
  * Planner::buffer_line
526 558
  *
@@ -531,12 +563,14 @@ void Planner::check_axes_activity() {
531 563
  *  extruder  - target extruder
532 564
  */
533 565
 
534
-#if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
535
-  void Planner::buffer_line(float x, float y, float z, const float& e, float fr_mm_s, const uint8_t extruder)
536
-#else
537
-  void Planner::buffer_line(const float& x, const float& y, const float& z, const float& e, float fr_mm_s, const uint8_t extruder)
538
-#endif  // AUTO_BED_LEVELING_FEATURE
539
-{
566
+void Planner::buffer_line(
567
+  #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
568
+    float x, float y, float z
569
+  #else
570
+    const float& x, const float& y, const float& z
571
+  #endif
572
+  , const float& e, float fr_mm_s, const uint8_t extruder
573
+) {
540 574
   // Calculate the buffer head after we push this byte
541 575
   int next_buffer_head = next_block_index(block_buffer_head);
542 576
 
@@ -544,11 +578,8 @@ void Planner::check_axes_activity() {
544 578
   // Rest here until there is room in the buffer.
545 579
   while (block_buffer_tail == next_buffer_head) idle();
546 580
 
547
-  #if ENABLED(MESH_BED_LEVELING)
548
-    if (mbl.active())
549
-      z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
550
-  #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
551
-    apply_rotation_xyz(bed_level_matrix, x, y, z);
581
+  #if ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_FEATURE)
582
+    apply_leveling(x, y, z);
552 583
   #endif
553 584
 
554 585
   // The target position of the tool in absolute steps
@@ -1116,61 +1147,33 @@ void Planner::check_axes_activity() {
1116 1147
 
1117 1148
 } // buffer_line()
1118 1149
 
1119
-#if ENABLED(AUTO_BED_LEVELING_FEATURE) && DISABLED(DELTA)
1120
-
1121
-  /**
1122
-   * Get the XYZ position of the steppers as a vector_3.
1123
-   *
1124
-   * On CORE machines XYZ is derived from ABC.
1125
-   */
1126
-  vector_3 Planner::adjusted_position() {
1127
-    vector_3 pos = vector_3(stepper.get_axis_position_mm(X_AXIS), stepper.get_axis_position_mm(Y_AXIS), stepper.get_axis_position_mm(Z_AXIS));
1128
-
1129
-    //pos.debug("in Planner::adjusted_position");
1130
-    //bed_level_matrix.debug("in Planner::adjusted_position");
1131
-
1132
-    matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix);
1133
-    //inverse.debug("in Planner::inverse");
1134
-
1135
-    pos.apply_rotation(inverse);
1136
-    //pos.debug("after rotation");
1137
-
1138
-    return pos;
1139
-  }
1140
-
1141
-#endif // AUTO_BED_LEVELING_FEATURE && !DELTA
1142
-
1143 1150
 /**
1144 1151
  * Directly set the planner XYZ position (hence the stepper positions).
1145 1152
  *
1146 1153
  * On CORE machines stepper ABC will be translated from the given XYZ.
1147 1154
  */
1148
-#if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
1149
-  void Planner::set_position_mm(float x, float y, float z, const float& e)
1150
-#else
1151
-  void Planner::set_position_mm(const float& x, const float& y, const float& z, const float& e)
1152
-#endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
1153
-  {
1154
-    #if ENABLED(MESH_BED_LEVELING)
1155
-
1156
-      if (mbl.active())
1157
-        z += mbl.get_z(RAW_X_POSITION(x), RAW_Y_POSITION(y));
1158
-
1159
-    #elif ENABLED(AUTO_BED_LEVELING_FEATURE)
1160
-
1161
-      apply_rotation_xyz(bed_level_matrix, x, y, z);
1155
+void Planner::set_position_mm(
1156
+  #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
1157
+    float x, float y, float z
1158
+  #else
1159
+    const float& x, const float& y, const float& z
1160
+  #endif
1161
+  , const float& e
1162
+) {
1162 1163
 
1163
-    #endif
1164
+  #if ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_FEATURE)
1165
+    apply_leveling(x, y, z);
1166
+  #endif
1164 1167
 
1165
-    long nx = position[X_AXIS] = lround(x * axis_steps_per_mm[X_AXIS]),
1166
-         ny = position[Y_AXIS] = lround(y * axis_steps_per_mm[Y_AXIS]),
1167
-         nz = position[Z_AXIS] = lround(z * axis_steps_per_mm[Z_AXIS]),
1168
-         ne = position[E_AXIS] = lround(e * axis_steps_per_mm[E_AXIS]);
1169
-    stepper.set_position(nx, ny, nz, ne);
1170
-    previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1168
+  long nx = position[X_AXIS] = lround(x * axis_steps_per_mm[X_AXIS]),
1169
+       ny = position[Y_AXIS] = lround(y * axis_steps_per_mm[Y_AXIS]),
1170
+       nz = position[Z_AXIS] = lround(z * axis_steps_per_mm[Z_AXIS]),
1171
+       ne = position[E_AXIS] = lround(e * axis_steps_per_mm[E_AXIS]);
1172
+  stepper.set_position(nx, ny, nz, ne);
1173
+  previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
1171 1174
 
1172
-    LOOP_XYZE(i) previous_speed[i] = 0.0;
1173
-  }
1175
+  LOOP_XYZE(i) previous_speed[i] = 0.0;
1176
+}
1174 1177
 
1175 1178
 /**
1176 1179
  * Directly set the planner E position (hence the stepper E position).

+ 4
- 5
Marlin/planner.h Wyświetl plik

@@ -203,11 +203,10 @@ class Planner {
203 203
 
204 204
     #if ENABLED(AUTO_BED_LEVELING_FEATURE) || ENABLED(MESH_BED_LEVELING)
205 205
 
206
-      #if ENABLED(AUTO_BED_LEVELING_FEATURE)
207
-        /**
208
-         * The corrected position, applying the bed level matrix
209
-         */
210
-        static vector_3 adjusted_position();
206
+      #if ENABLED(MESH_BED_LEVELING)
207
+        static void apply_leveling(const float &x, const float &y, float &z);
208
+      #else
209
+        static void apply_leveling(float &x, float &y, float &z);
211 210
       #endif
212 211
 
213 212
       /**

Ładowanie…
Anuluj
Zapisz