Browse Source

Add a proper flag for ABL enabled

Scott Lahteine 7 years ago
parent
commit
cbc158eb62
3 changed files with 63 additions and 14 deletions
  1. 47
    12
      Marlin/Marlin_main.cpp
  2. 15
    2
      Marlin/planner.cpp
  3. 1
    0
      Marlin/planner.h

+ 47
- 12
Marlin/Marlin_main.cpp View File

@@ -2119,8 +2119,13 @@ static void clean_up_after_endstop_or_probe_move() {
2119 2119
 
2120 2120
   /**
2121 2121
    * Reset calibration results to zero.
2122
+   *
2123
+   * TODO: Proper functions to disable / enable
2124
+   *       bed leveling via a flag, correcting the
2125
+   *       current position in each case.
2122 2126
    */
2123 2127
   void reset_bed_level() {
2128
+    planner.abl_enabled = false;
2124 2129
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2125 2130
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("reset_bed_level");
2126 2131
     #endif
@@ -2128,7 +2133,6 @@ static void clean_up_after_endstop_or_probe_move() {
2128 2133
       planner.bed_level_matrix.set_to_identity();
2129 2134
     #elif ENABLED(AUTO_BED_LEVELING_NONLINEAR)
2130 2135
       memset(bed_level_grid, 0, sizeof(bed_level_grid));
2131
-      nonlinear_grid_spacing[X_AXIS] = nonlinear_grid_spacing[Y_AXIS] = 0;
2132 2136
     #endif
2133 2137
   }
2134 2138
 
@@ -3505,16 +3509,15 @@ inline void gcode_G28() {
3505 3509
 
3506 3510
     stepper.synchronize();
3507 3511
 
3508
-    if (!dryrun) {
3512
+    // Disable auto bed leveling during G29
3513
+    bool auto_bed_leveling_was_enabled = planner.abl_enabled,
3514
+         abl_should_reenable = auto_bed_leveling_was_enabled;
3509 3515
 
3510
-      // Reset the bed_level_matrix because leveling
3511
-      // needs to be done without leveling enabled.
3512
-      reset_bed_level();
3516
+    planner.abl_enabled = false;
3513 3517
 
3514
-      //
3518
+    if (!dryrun) {
3515 3519
       // Re-orient the current position without leveling
3516 3520
       // based on where the steppers are positioned.
3517
-      //
3518 3521
       get_cartesian_from_steppers();
3519 3522
       memcpy(current_position, cartes, sizeof(cartes));
3520 3523
 
@@ -3525,7 +3528,10 @@ inline void gcode_G28() {
3525 3528
     setup_for_endstop_or_probe_move();
3526 3529
 
3527 3530
     // Deploy the probe. Probe will raise if needed.
3528
-    if (DEPLOY_PROBE()) return;
3531
+    if (DEPLOY_PROBE()) {
3532
+      planner.abl_enabled = abl_should_reenable;
3533
+      return;
3534
+    }
3529 3535
 
3530 3536
     float xProbe = 0, yProbe = 0, measured_z = 0;
3531 3537
 
@@ -3537,11 +3543,16 @@ inline void gcode_G28() {
3537 3543
 
3538 3544
       #if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
3539 3545
 
3540
-        nonlinear_grid_spacing[X_AXIS] = xGridSpacing;
3541
-        nonlinear_grid_spacing[Y_AXIS] = yGridSpacing;
3542 3546
         float zoffset = zprobe_zoffset;
3543 3547
         if (code_seen('Z')) zoffset += code_value_axis_units(Z_AXIS);
3544 3548
 
3549
+        if (xGridSpacing != nonlinear_grid_spacing[X_AXIS] || yGridSpacing != nonlinear_grid_spacing[Y_AXIS]) {
3550
+          nonlinear_grid_spacing[X_AXIS] = xGridSpacing;
3551
+          nonlinear_grid_spacing[Y_AXIS] = yGridSpacing;
3552
+          // Can't re-enable (on error) until the new grid is written
3553
+          abl_should_reenable = false;
3554
+        }
3555
+
3545 3556
       #elif ENABLED(AUTO_BED_LEVELING_LINEAR_GRID)
3546 3557
 
3547 3558
         /**
@@ -3600,6 +3611,11 @@ inline void gcode_G28() {
3600 3611
 
3601 3612
           measured_z = probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
3602 3613
 
3614
+          if (measured_z == NAN) {
3615
+            planner.abl_enabled = abl_should_reenable;
3616
+            return;
3617
+          }
3618
+
3603 3619
           #if ENABLED(AUTO_BED_LEVELING_LINEAR_GRID)
3604 3620
 
3605 3621
             mean += measured_z;
@@ -3639,6 +3655,11 @@ inline void gcode_G28() {
3639 3655
         measured_z = points[i].z = probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
3640 3656
       }
3641 3657
 
3658
+      if (measured_z == NAN) {
3659
+        planner.abl_enabled = abl_should_reenable;
3660
+        return;
3661
+      }
3662
+
3642 3663
       if (!dryrun) {
3643 3664
         vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal();
3644 3665
         if (planeNormal.z < 0) {
@@ -3647,12 +3668,23 @@ inline void gcode_G28() {
3647 3668
           planeNormal.z *= -1;
3648 3669
         }
3649 3670
         planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
3671
+
3672
+        // Can't re-enable (on error) until the new grid is written
3673
+        abl_should_reenable = false;
3650 3674
       }
3651 3675
 
3652 3676
     #endif // AUTO_BED_LEVELING_3POINT
3653 3677
 
3654 3678
     // Raise to _Z_CLEARANCE_DEPLOY_PROBE. Stow the probe.
3655
-    if (STOW_PROBE()) return;
3679
+    if (STOW_PROBE()) {
3680
+      planner.abl_enabled = abl_should_reenable;
3681
+      return;
3682
+    }
3683
+
3684
+    //
3685
+    // Unless this is a dry run, auto bed leveling will
3686
+    // definitely be enabled after this point
3687
+    //
3656 3688
 
3657 3689
     // Restore state after probing
3658 3690
     clean_up_after_endstop_or_probe_move();
@@ -3842,6 +3874,9 @@ inline void gcode_G28() {
3842 3874
     report_current_position();
3843 3875
 
3844 3876
     KEEPALIVE_STATE(IN_HANDLER);
3877
+
3878
+    // Auto Bed Leveling is complete! Enable if possible.
3879
+    planner.abl_enabled = dryrun ? abl_should_reenable : true;
3845 3880
   }
3846 3881
 
3847 3882
 #endif // AUTO_BED_LEVELING_FEATURE
@@ -7738,7 +7773,7 @@ void ok_to_send() {
7738 7773
 
7739 7774
   // Get the Z adjustment for non-linear bed leveling
7740 7775
   float nonlinear_z_offset(float cartesian[XYZ]) {
7741
-    if (nonlinear_grid_spacing[X_AXIS] == 0 || nonlinear_grid_spacing[Y_AXIS] == 0) return 0; // G29 not done!
7776
+    if (planner.abl_enabled) return;
7742 7777
 
7743 7778
     int half_x = (ABL_GRID_POINTS_X - 1) / 2,
7744 7779
         half_y = (ABL_GRID_POINTS_Y - 1) / 2;

+ 15
- 2
Marlin/planner.cpp View File

@@ -98,6 +98,10 @@ float Planner::min_feedrate_mm_s,
98 98
       Planner::max_e_jerk,
99 99
       Planner::min_travel_feedrate_mm_s;
100 100
 
101
+#if ENABLED(AUTO_BED_LEVELING_FEATURE)
102
+  bool Planner::abl_enabled = false; // Flag that auto bed leveling is enabled
103
+#endif
104
+
101 105
 #if ENABLED(AUTO_BED_LEVELING_LINEAR)
102 106
   matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
103 107
 #endif
@@ -524,6 +528,11 @@ void Planner::check_axes_activity() {
524 528
 #if PLANNER_LEVELING
525 529
 
526 530
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
531
+
532
+    #if ENABLED(AUTO_BED_LEVELING_FEATURE)
533
+      if (!abl_enabled) return;
534
+    #endif
535
+
527 536
     #if ENABLED(MESH_BED_LEVELING)
528 537
 
529 538
       if (mbl.active())
@@ -562,6 +571,11 @@ void Planner::check_axes_activity() {
562 571
   }
563 572
 
564 573
   void Planner::unapply_leveling(float &lx, float &ly, float &lz) {
574
+
575
+    #if ENABLED(AUTO_BED_LEVELING_FEATURE)
576
+      if (!abl_enabled) return;
577
+    #endif
578
+
565 579
     #if ENABLED(MESH_BED_LEVELING)
566 580
 
567 581
       if (mbl.active())
@@ -627,8 +641,7 @@ void Planner::buffer_line(ARG_X, ARG_Y, ARG_Z, const float &e, float fr_mm_s, co
627 641
        dz = target[Z_AXIS] - position[Z_AXIS];
628 642
 
629 643
   /*
630
-  SERIAL_ECHOPGM("  Planner ");
631
-  SERIAL_ECHOPAIR("FR:", fr_mm_s);
644
+  SERIAL_ECHOPAIR("  Planner FR:", fr_mm_s);
632 645
   SERIAL_CHAR(' ');
633 646
   #if IS_KINEMATIC
634 647
     SERIAL_ECHOPAIR("A:", lx);

+ 1
- 0
Marlin/planner.h View File

@@ -137,6 +137,7 @@ class Planner {
137 137
     static float min_travel_feedrate_mm_s;
138 138
 
139 139
     #if ENABLED(AUTO_BED_LEVELING_FEATURE)
140
+      static bool abl_enabled;            // Flag that bed leveling is enabled
140 141
       static matrix_3x3 bed_level_matrix; // Transform to compensate for bed level
141 142
     #endif
142 143
 

Loading…
Cancel
Save