Просмотр исходного кода

Add a proper flag for ABL enabled

Scott Lahteine 8 лет назад
Родитель
Сommit
cbc158eb62
3 измененных файлов: 63 добавлений и 14 удалений
  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 Просмотреть файл

2119
 
2119
 
2120
   /**
2120
   /**
2121
    * Reset calibration results to zero.
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
   void reset_bed_level() {
2127
   void reset_bed_level() {
2128
+    planner.abl_enabled = false;
2124
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2129
     #if ENABLED(DEBUG_LEVELING_FEATURE)
2125
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("reset_bed_level");
2130
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("reset_bed_level");
2126
     #endif
2131
     #endif
2128
       planner.bed_level_matrix.set_to_identity();
2133
       planner.bed_level_matrix.set_to_identity();
2129
     #elif ENABLED(AUTO_BED_LEVELING_NONLINEAR)
2134
     #elif ENABLED(AUTO_BED_LEVELING_NONLINEAR)
2130
       memset(bed_level_grid, 0, sizeof(bed_level_grid));
2135
       memset(bed_level_grid, 0, sizeof(bed_level_grid));
2131
-      nonlinear_grid_spacing[X_AXIS] = nonlinear_grid_spacing[Y_AXIS] = 0;
2132
     #endif
2136
     #endif
2133
   }
2137
   }
2134
 
2138
 
3505
 
3509
 
3506
     stepper.synchronize();
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
       // Re-orient the current position without leveling
3519
       // Re-orient the current position without leveling
3516
       // based on where the steppers are positioned.
3520
       // based on where the steppers are positioned.
3517
-      //
3518
       get_cartesian_from_steppers();
3521
       get_cartesian_from_steppers();
3519
       memcpy(current_position, cartes, sizeof(cartes));
3522
       memcpy(current_position, cartes, sizeof(cartes));
3520
 
3523
 
3525
     setup_for_endstop_or_probe_move();
3528
     setup_for_endstop_or_probe_move();
3526
 
3529
 
3527
     // Deploy the probe. Probe will raise if needed.
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
     float xProbe = 0, yProbe = 0, measured_z = 0;
3536
     float xProbe = 0, yProbe = 0, measured_z = 0;
3531
 
3537
 
3537
 
3543
 
3538
       #if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
3544
       #if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
3539
 
3545
 
3540
-        nonlinear_grid_spacing[X_AXIS] = xGridSpacing;
3541
-        nonlinear_grid_spacing[Y_AXIS] = yGridSpacing;
3542
         float zoffset = zprobe_zoffset;
3546
         float zoffset = zprobe_zoffset;
3543
         if (code_seen('Z')) zoffset += code_value_axis_units(Z_AXIS);
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
       #elif ENABLED(AUTO_BED_LEVELING_LINEAR_GRID)
3556
       #elif ENABLED(AUTO_BED_LEVELING_LINEAR_GRID)
3546
 
3557
 
3547
         /**
3558
         /**
3600
 
3611
 
3601
           measured_z = probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
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
           #if ENABLED(AUTO_BED_LEVELING_LINEAR_GRID)
3619
           #if ENABLED(AUTO_BED_LEVELING_LINEAR_GRID)
3604
 
3620
 
3605
             mean += measured_z;
3621
             mean += measured_z;
3639
         measured_z = points[i].z = probe_pt(xProbe, yProbe, stow_probe_after_each, verbose_level);
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
       if (!dryrun) {
3663
       if (!dryrun) {
3643
         vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal();
3664
         vector_3 planeNormal = vector_3::cross(points[0] - points[1], points[2] - points[1]).get_normal();
3644
         if (planeNormal.z < 0) {
3665
         if (planeNormal.z < 0) {
3647
           planeNormal.z *= -1;
3668
           planeNormal.z *= -1;
3648
         }
3669
         }
3649
         planner.bed_level_matrix = matrix_3x3::create_look_at(planeNormal);
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
     #endif // AUTO_BED_LEVELING_3POINT
3676
     #endif // AUTO_BED_LEVELING_3POINT
3653
 
3677
 
3654
     // Raise to _Z_CLEARANCE_DEPLOY_PROBE. Stow the probe.
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
     // Restore state after probing
3689
     // Restore state after probing
3658
     clean_up_after_endstop_or_probe_move();
3690
     clean_up_after_endstop_or_probe_move();
3842
     report_current_position();
3874
     report_current_position();
3843
 
3875
 
3844
     KEEPALIVE_STATE(IN_HANDLER);
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
 #endif // AUTO_BED_LEVELING_FEATURE
3882
 #endif // AUTO_BED_LEVELING_FEATURE
7738
 
7773
 
7739
   // Get the Z adjustment for non-linear bed leveling
7774
   // Get the Z adjustment for non-linear bed leveling
7740
   float nonlinear_z_offset(float cartesian[XYZ]) {
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
     int half_x = (ABL_GRID_POINTS_X - 1) / 2,
7778
     int half_x = (ABL_GRID_POINTS_X - 1) / 2,
7744
         half_y = (ABL_GRID_POINTS_Y - 1) / 2;
7779
         half_y = (ABL_GRID_POINTS_Y - 1) / 2;

+ 15
- 2
Marlin/planner.cpp Просмотреть файл

98
       Planner::max_e_jerk,
98
       Planner::max_e_jerk,
99
       Planner::min_travel_feedrate_mm_s;
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
 #if ENABLED(AUTO_BED_LEVELING_LINEAR)
105
 #if ENABLED(AUTO_BED_LEVELING_LINEAR)
102
   matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
106
   matrix_3x3 Planner::bed_level_matrix; // Transform to compensate for bed level
103
 #endif
107
 #endif
524
 #if PLANNER_LEVELING
528
 #if PLANNER_LEVELING
525
 
529
 
526
   void Planner::apply_leveling(float &lx, float &ly, float &lz) {
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
     #if ENABLED(MESH_BED_LEVELING)
536
     #if ENABLED(MESH_BED_LEVELING)
528
 
537
 
529
       if (mbl.active())
538
       if (mbl.active())
562
   }
571
   }
563
 
572
 
564
   void Planner::unapply_leveling(float &lx, float &ly, float &lz) {
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
     #if ENABLED(MESH_BED_LEVELING)
579
     #if ENABLED(MESH_BED_LEVELING)
566
 
580
 
567
       if (mbl.active())
581
       if (mbl.active())
627
        dz = target[Z_AXIS] - position[Z_AXIS];
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
   SERIAL_CHAR(' ');
645
   SERIAL_CHAR(' ');
633
   #if IS_KINEMATIC
646
   #if IS_KINEMATIC
634
     SERIAL_ECHOPAIR("A:", lx);
647
     SERIAL_ECHOPAIR("A:", lx);

+ 1
- 0
Marlin/planner.h Просмотреть файл

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

Загрузка…
Отмена
Сохранить