Browse Source

Move NONLINEAR bed leveling to planner

This is in advance of moving non-linear bed leveling to the planner
class.
Scott Lahteine 8 years ago
parent
commit
77639672d7
5 changed files with 71 additions and 65 deletions
  1. 1
    1
      Marlin/Conditionals_post.h
  2. 1
    1
      Marlin/Marlin.h
  3. 46
    59
      Marlin/Marlin_main.cpp
  4. 22
    0
      Marlin/planner.cpp
  5. 1
    4
      Marlin/planner_bezier.cpp

+ 1
- 1
Marlin/Conditionals_post.h View File

675
     #endif
675
     #endif
676
   #endif
676
   #endif
677
 
677
 
678
-  #define PLANNER_LEVELING (ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_LINEAR))
678
+  #define PLANNER_LEVELING (ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_FEATURE))
679
 
679
 
680
   /**
680
   /**
681
    * Buzzer/Speaker
681
    * Buzzer/Speaker

+ 1
- 1
Marlin/Marlin.h View File

321
 
321
 
322
 #if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
322
 #if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
323
   extern int nonlinear_grid_spacing[2];
323
   extern int nonlinear_grid_spacing[2];
324
-  void adjust_delta(float cartesian[XYZ]);
324
+  float nonlinear_z_offset(float logical[XYZ]);
325
 #endif
325
 #endif
326
 
326
 
327
 #if ENABLED(Z_DUAL_ENDSTOPS)
327
 #if ENABLED(Z_DUAL_ENDSTOPS)

+ 46
- 59
Marlin/Marlin_main.cpp View File

400
 
400
 
401
 #if ENABLED(AUTO_BED_LEVELING_FEATURE)
401
 #if ENABLED(AUTO_BED_LEVELING_FEATURE)
402
   float xy_probe_feedrate_mm_s = MMM_TO_MMS(XY_PROBE_SPEED);
402
   float xy_probe_feedrate_mm_s = MMM_TO_MMS(XY_PROBE_SPEED);
403
-  bool bed_leveling_in_progress = false;
404
   #define XY_PROBE_FEEDRATE_MM_S xy_probe_feedrate_mm_s
403
   #define XY_PROBE_FEEDRATE_MM_S xy_probe_feedrate_mm_s
405
 #elif defined(XY_PROBE_SPEED)
404
 #elif defined(XY_PROBE_SPEED)
406
   #define XY_PROBE_FEEDRATE_MM_S MMM_TO_MMS(XY_PROBE_SPEED)
405
   #define XY_PROBE_FEEDRATE_MM_S MMM_TO_MMS(XY_PROBE_SPEED)
3434
     // Deploy the probe. Probe will raise if needed.
3433
     // Deploy the probe. Probe will raise if needed.
3435
     if (DEPLOY_PROBE()) return;
3434
     if (DEPLOY_PROBE()) return;
3436
 
3435
 
3437
-    bed_leveling_in_progress = true;
3438
-
3439
     float xProbe, yProbe, measured_z = 0;
3436
     float xProbe, yProbe, measured_z = 0;
3440
 
3437
 
3441
     #if ENABLED(AUTO_BED_LEVELING_GRID)
3438
     #if ENABLED(AUTO_BED_LEVELING_GRID)
3576
 
3573
 
3577
     #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
3574
     #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
3578
 
3575
 
3576
+      // For LINEAR leveling calculate matrix, print reports, correct the position
3577
+
3579
       // solve lsq problem
3578
       // solve lsq problem
3580
       double plane_equation_coefficients[3];
3579
       double plane_equation_coefficients[3];
3581
       qr_solve(plane_equation_coefficients, abl2, 3, eqnAMatrix, eqnBVector);
3580
       qr_solve(plane_equation_coefficients, abl2, 3, eqnAMatrix, eqnBVector);
3669
         }
3668
         }
3670
       } //do_topography_map
3669
       } //do_topography_map
3671
 
3670
 
3671
+      // For LINEAR and 3POINT leveling correct the current position
3672
+
3672
       if (verbose_level > 0)
3673
       if (verbose_level > 0)
3673
         planner.bed_level_matrix.debug("\n\nBed Level Correction Matrix:");
3674
         planner.bed_level_matrix.debug("\n\nBed Level Correction Matrix:");
3674
 
3675
 
3738
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G29");
3739
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G29");
3739
     #endif
3740
     #endif
3740
 
3741
 
3741
-    bed_leveling_in_progress = false;
3742
-
3743
     report_current_position();
3742
     report_current_position();
3744
 
3743
 
3745
     KEEPALIVE_STATE(IN_HANDLER);
3744
     KEEPALIVE_STATE(IN_HANDLER);
7638
 
7637
 
7639
 #endif
7638
 #endif
7640
 
7639
 
7640
+#if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
7641
+
7642
+  // Get the Z adjustment for non-linear bed leveling
7643
+  float nonlinear_z_offset(float cartesian[XYZ]) {
7644
+    if (nonlinear_grid_spacing[X_AXIS] == 0 || nonlinear_grid_spacing[Y_AXIS] == 0) return 0; // G29 not done!
7645
+
7646
+    int half_x = (ABL_GRID_POINTS_X - 1) / 2,
7647
+        half_y = (ABL_GRID_POINTS_Y - 1) / 2;
7648
+    float hx2 = half_x - 0.001, hx1 = -hx2,
7649
+          hy2 = half_y - 0.001, hy1 = -hy2,
7650
+          grid_x = max(hx1, min(hx2, RAW_X_POSITION(cartesian[X_AXIS]) / nonlinear_grid_spacing[X_AXIS])),
7651
+          grid_y = max(hy1, min(hy2, RAW_Y_POSITION(cartesian[Y_AXIS]) / nonlinear_grid_spacing[Y_AXIS]));
7652
+    int   floor_x = floor(grid_x), floor_y = floor(grid_y);
7653
+    float ratio_x = grid_x - floor_x, ratio_y = grid_y - floor_y,
7654
+          z1 = bed_level_grid[floor_x + half_x][floor_y + half_y],
7655
+          z2 = bed_level_grid[floor_x + half_x][floor_y + half_y + 1],
7656
+          z3 = bed_level_grid[floor_x + half_x + 1][floor_y + half_y],
7657
+          z4 = bed_level_grid[floor_x + half_x + 1][floor_y + half_y + 1],
7658
+          left = (1 - ratio_y) * z1 + ratio_y * z2,
7659
+          right = (1 - ratio_y) * z3 + ratio_y * z4;
7660
+
7661
+    /*
7662
+      SERIAL_ECHOPAIR("grid_x=", grid_x);
7663
+      SERIAL_ECHOPAIR(" grid_y=", grid_y);
7664
+      SERIAL_ECHOPAIR(" floor_x=", floor_x);
7665
+      SERIAL_ECHOPAIR(" floor_y=", floor_y);
7666
+      SERIAL_ECHOPAIR(" ratio_x=", ratio_x);
7667
+      SERIAL_ECHOPAIR(" ratio_y=", ratio_y);
7668
+      SERIAL_ECHOPAIR(" z1=", z1);
7669
+      SERIAL_ECHOPAIR(" z2=", z2);
7670
+      SERIAL_ECHOPAIR(" z3=", z3);
7671
+      SERIAL_ECHOPAIR(" z4=", z4);
7672
+      SERIAL_ECHOPAIR(" left=", left);
7673
+      SERIAL_ECHOPAIR(" right=", right);
7674
+      SERIAL_ECHOPAIR(" offset=", (1 - ratio_x) * left + ratio_x * right);
7675
+    //*/
7676
+
7677
+    return (1 - ratio_x) * left + ratio_x * right;
7678
+  }
7679
+
7680
+#endif // AUTO_BED_LEVELING_NONLINEAR
7681
+
7641
 #if ENABLED(DELTA)
7682
 #if ENABLED(DELTA)
7642
 
7683
 
7643
   /**
7684
   /**
7828
     forward_kinematics_DELTA(point[A_AXIS], point[B_AXIS], point[C_AXIS]);
7869
     forward_kinematics_DELTA(point[A_AXIS], point[B_AXIS], point[C_AXIS]);
7829
   }
7870
   }
7830
 
7871
 
7831
-  #if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
7832
-
7833
-    // Adjust print surface height by linear interpolation over the bed_level array.
7834
-    void adjust_delta(float cartesian[XYZ]) {
7835
-      if (nonlinear_grid_spacing[X_AXIS] == 0 || nonlinear_grid_spacing[Y_AXIS] == 0) return; // G29 not done!
7836
-
7837
-      int half_x = (ABL_GRID_POINTS_X - 1) / 2,
7838
-          half_y = (ABL_GRID_POINTS_Y - 1) / 2;
7839
-      float hx2 = half_x - 0.001, hx1 = -hx2,
7840
-            hy2 = half_y - 0.001, hy1 = -hy2,
7841
-            grid_x = max(hx1, min(hx2, RAW_X_POSITION(cartesian[X_AXIS]) / nonlinear_grid_spacing[X_AXIS])),
7842
-            grid_y = max(hy1, min(hy2, RAW_Y_POSITION(cartesian[Y_AXIS]) / nonlinear_grid_spacing[Y_AXIS]));
7843
-      int   floor_x = floor(grid_x), floor_y = floor(grid_y);
7844
-      float ratio_x = grid_x - floor_x, ratio_y = grid_y - floor_y,
7845
-            z1 = bed_level_grid[floor_x + half_x][floor_y + half_y],
7846
-            z2 = bed_level_grid[floor_x + half_x][floor_y + half_y + 1],
7847
-            z3 = bed_level_grid[floor_x + half_x + 1][floor_y + half_y],
7848
-            z4 = bed_level_grid[floor_x + half_x + 1][floor_y + half_y + 1],
7849
-            left = (1 - ratio_y) * z1 + ratio_y * z2,
7850
-            right = (1 - ratio_y) * z3 + ratio_y * z4,
7851
-            offset = (1 - ratio_x) * left + ratio_x * right;
7852
-
7853
-      delta[X_AXIS] += offset;
7854
-      delta[Y_AXIS] += offset;
7855
-      delta[Z_AXIS] += offset;
7856
-
7857
-      /**
7858
-      SERIAL_ECHOPAIR("grid_x=", grid_x);
7859
-      SERIAL_ECHOPAIR(" grid_y=", grid_y);
7860
-      SERIAL_ECHOPAIR(" floor_x=", floor_x);
7861
-      SERIAL_ECHOPAIR(" floor_y=", floor_y);
7862
-      SERIAL_ECHOPAIR(" ratio_x=", ratio_x);
7863
-      SERIAL_ECHOPAIR(" ratio_y=", ratio_y);
7864
-      SERIAL_ECHOPAIR(" z1=", z1);
7865
-      SERIAL_ECHOPAIR(" z2=", z2);
7866
-      SERIAL_ECHOPAIR(" z3=", z3);
7867
-      SERIAL_ECHOPAIR(" z4=", z4);
7868
-      SERIAL_ECHOPAIR(" left=", left);
7869
-      SERIAL_ECHOPAIR(" right=", right);
7870
-      SERIAL_ECHOLNPAIR(" offset=", offset);
7871
-      */
7872
-    }
7873
-  #endif // AUTO_BED_LEVELING_NONLINEAR
7874
-
7875
 #endif // DELTA
7872
 #endif // DELTA
7876
 
7873
 
7877
 /**
7874
 /**
8018
 
8015
 
8019
       inverse_kinematics(logical);
8016
       inverse_kinematics(logical);
8020
 
8017
 
8021
-      #if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_NONLINEAR)
8022
-        if (!bed_leveling_in_progress) adjust_delta(logical);
8023
-      #endif
8024
-
8025
       //DEBUG_POS("prepare_kinematic_move_to", logical);
8018
       //DEBUG_POS("prepare_kinematic_move_to", logical);
8026
       //DEBUG_POS("prepare_kinematic_move_to", delta);
8019
       //DEBUG_POS("prepare_kinematic_move_to", delta);
8027
 
8020
 
8272
 
8265
 
8273
       #if IS_KINEMATIC
8266
       #if IS_KINEMATIC
8274
         inverse_kinematics(arc_target);
8267
         inverse_kinematics(arc_target);
8275
-        #if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_NONLINEAR)
8276
-          adjust_delta(arc_target);
8277
-        #endif
8278
         planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], arc_target[E_AXIS], fr_mm_s, active_extruder);
8268
         planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], arc_target[E_AXIS], fr_mm_s, active_extruder);
8279
       #else
8269
       #else
8280
         planner.buffer_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], arc_target[E_AXIS], fr_mm_s, active_extruder);
8270
         planner.buffer_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], arc_target[E_AXIS], fr_mm_s, active_extruder);
8284
     // Ensure last segment arrives at target location.
8274
     // Ensure last segment arrives at target location.
8285
     #if IS_KINEMATIC
8275
     #if IS_KINEMATIC
8286
       inverse_kinematics(logical);
8276
       inverse_kinematics(logical);
8287
-      #if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_NONLINEAR)
8288
-        adjust_delta(logical);
8289
-      #endif
8290
       planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], fr_mm_s, active_extruder);
8277
       planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], fr_mm_s, active_extruder);
8291
     #else
8278
     #else
8292
       planner.buffer_line(logical[X_AXIS], logical[Y_AXIS], logical[Z_AXIS], logical[E_AXIS], fr_mm_s, active_extruder);
8279
       planner.buffer_line(logical[X_AXIS], logical[Y_AXIS], logical[Z_AXIS], logical[E_AXIS], fr_mm_s, active_extruder);

+ 22
- 0
Marlin/planner.cpp View File

541
       ly = LOGICAL_Y_POSITION(dy + Y_TILT_FULCRUM);
541
       ly = LOGICAL_Y_POSITION(dy + Y_TILT_FULCRUM);
542
       lz = LOGICAL_Z_POSITION(dz);
542
       lz = LOGICAL_Z_POSITION(dz);
543
 
543
 
544
+    #elif ENABLED(AUTO_BED_LEVELING_NONLINEAR)
545
+
546
+      float tmp[XYZ] = { lx, ly, 0 };
547
+
548
+      #if ENABLED(DELTA)
549
+
550
+        float offset = nonlinear_z_offset(tmp);
551
+        lx += offset;
552
+        ly += offset;
553
+        lz += offset;
554
+
555
+      #else
556
+
557
+        lz += nonlinear_z_offset(tmp);
558
+
559
+      #endif
560
+
544
     #endif
561
     #endif
545
   }
562
   }
546
 
563
 
562
       ly = LOGICAL_Y_POSITION(dy + Y_TILT_FULCRUM);
579
       ly = LOGICAL_Y_POSITION(dy + Y_TILT_FULCRUM);
563
       lz = LOGICAL_Z_POSITION(dz);
580
       lz = LOGICAL_Z_POSITION(dz);
564
 
581
 
582
+    #elif ENABLED(AUTO_BED_LEVELING_NONLINEAR)
583
+
584
+      float tmp[XYZ] = { lx, ly, 0 };
585
+      lz -= nonlinear_z_offset(tmp);
586
+
565
     #endif
587
     #endif
566
   }
588
   }
567
 
589
 

+ 1
- 4
Marlin/planner_bezier.cpp View File

190
 
190
 
191
     #if IS_KINEMATIC
191
     #if IS_KINEMATIC
192
       inverse_kinematics(bez_target);
192
       inverse_kinematics(bez_target);
193
-      #if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_FEATURE)
194
-        adjust_delta(bez_target);
195
-      #endif
196
-      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], bez_target[E_AXIS], fr_mm_s, extruder);
193
+      planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], bez_target[E_AXIS], fr_mm_s, extruder);
197
     #else
194
     #else
198
       planner.buffer_line(bez_target[X_AXIS], bez_target[Y_AXIS], bez_target[Z_AXIS], bez_target[E_AXIS], fr_mm_s, extruder);
195
       planner.buffer_line(bez_target[X_AXIS], bez_target[Y_AXIS], bez_target[Z_AXIS], bez_target[E_AXIS], fr_mm_s, extruder);
199
     #endif
196
     #endif

Loading…
Cancel
Save