Browse Source

Merge pull request #4837 from thinkyhead/rc_nonlinear_in_planner

Handle nonlinear bed-leveling in Planner
Scott Lahteine 8 years ago
parent
commit
127d796420
6 changed files with 117 additions and 111 deletions
  1. 1
    1
      Marlin/Conditionals_post.h
  2. 3
    4
      Marlin/Marlin.h
  3. 87
    99
      Marlin/Marlin_main.cpp
  4. 23
    1
      Marlin/planner.cpp
  5. 1
    4
      Marlin/planner_bezier.cpp
  6. 2
    2
      Marlin/ultralcd.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

+ 3
- 4
Marlin/Marlin.h View File

303
 
303
 
304
 #if IS_KINEMATIC
304
 #if IS_KINEMATIC
305
   extern float delta[ABC];
305
   extern float delta[ABC];
306
-  void inverse_kinematics(const float cartesian[XYZ]);
306
+  void inverse_kinematics(const float logical[XYZ]);
307
 #endif
307
 #endif
308
 
308
 
309
 #if ENABLED(DELTA)
309
 #if ENABLED(DELTA)
310
-  extern float delta[ABC],
311
-               endstop_adj[ABC],
310
+  extern float endstop_adj[ABC],
312
                delta_radius,
311
                delta_radius,
313
                delta_diagonal_rod,
312
                delta_diagonal_rod,
314
                delta_segments_per_second,
313
                delta_segments_per_second,
322
 
321
 
323
 #if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
322
 #if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
324
   extern int nonlinear_grid_spacing[2];
323
   extern int nonlinear_grid_spacing[2];
325
-  void adjust_delta(float cartesian[XYZ]);
324
+  float nonlinear_z_offset(float logical[XYZ]);
326
 #endif
325
 #endif
327
 
326
 
328
 #if ENABLED(Z_DUAL_ENDSTOPS)
327
 #if ENABLED(Z_DUAL_ENDSTOPS)

+ 87
- 99
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)
658
 inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
657
 inline void sync_plan_position_e() { planner.set_e_position_mm(current_position[E_AXIS]); }
659
 
658
 
660
 #if IS_KINEMATIC
659
 #if IS_KINEMATIC
660
+
661
   inline void sync_plan_position_kinematic() {
661
   inline void sync_plan_position_kinematic() {
662
     #if ENABLED(DEBUG_LEVELING_FEATURE)
662
     #if ENABLED(DEBUG_LEVELING_FEATURE)
663
       if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position_kinematic", current_position);
663
       if (DEBUGGING(LEVELING)) DEBUG_POS("sync_plan_position_kinematic", current_position);
664
     #endif
664
     #endif
665
     inverse_kinematics(current_position);
665
     inverse_kinematics(current_position);
666
-    planner.set_position_mm(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
666
+    planner.set_position_mm(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], current_position[E_AXIS]);
667
   }
667
   }
668
   #define SYNC_PLAN_POSITION_KINEMATIC() sync_plan_position_kinematic()
668
   #define SYNC_PLAN_POSITION_KINEMATIC() sync_plan_position_kinematic()
669
+
669
 #else
670
 #else
671
+
670
   #define SYNC_PLAN_POSITION_KINEMATIC() sync_plan_position()
672
   #define SYNC_PLAN_POSITION_KINEMATIC() sync_plan_position()
673
+
671
 #endif
674
 #endif
672
 
675
 
673
 #if ENABLED(SDSUPPORT)
676
 #if ENABLED(SDSUPPORT)
795
   #endif
798
   #endif
796
 }
799
 }
797
 
800
 
798
-
799
 void setup_photpin() {
801
 void setup_photpin() {
800
   #if HAS_PHOTOGRAPH
802
   #if HAS_PHOTOGRAPH
801
     OUT_WRITE(PHOTOGRAPH_PIN, LOW);
803
     OUT_WRITE(PHOTOGRAPH_PIN, LOW);
1479
     #endif
1481
     #endif
1480
     refresh_cmd_timeout();
1482
     refresh_cmd_timeout();
1481
     inverse_kinematics(destination);
1483
     inverse_kinematics(destination);
1482
-    planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], MMS_SCALED(feedrate_mm_s), active_extruder);
1484
+    planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], destination[E_AXIS], MMS_SCALED(feedrate_mm_s), active_extruder);
1483
     set_current_to_destination();
1485
     set_current_to_destination();
1484
   }
1486
   }
1485
 #endif
1487
 #endif
3431
     // Deploy the probe. Probe will raise if needed.
3433
     // Deploy the probe. Probe will raise if needed.
3432
     if (DEPLOY_PROBE()) return;
3434
     if (DEPLOY_PROBE()) return;
3433
 
3435
 
3434
-    bed_leveling_in_progress = true;
3435
-
3436
     float xProbe, yProbe, measured_z = 0;
3436
     float xProbe, yProbe, measured_z = 0;
3437
 
3437
 
3438
     #if ENABLED(AUTO_BED_LEVELING_GRID)
3438
     #if ENABLED(AUTO_BED_LEVELING_GRID)
3573
 
3573
 
3574
     #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
3574
     #elif ENABLED(AUTO_BED_LEVELING_LINEAR)
3575
 
3575
 
3576
+      // For LINEAR leveling calculate matrix, print reports, correct the position
3577
+
3576
       // solve lsq problem
3578
       // solve lsq problem
3577
       double plane_equation_coefficients[3];
3579
       double plane_equation_coefficients[3];
3578
       qr_solve(plane_equation_coefficients, abl2, 3, eqnAMatrix, eqnBVector);
3580
       qr_solve(plane_equation_coefficients, abl2, 3, eqnAMatrix, eqnBVector);
3666
         }
3668
         }
3667
       } //do_topography_map
3669
       } //do_topography_map
3668
 
3670
 
3671
+      // For LINEAR and 3POINT leveling correct the current position
3672
+
3669
       if (verbose_level > 0)
3673
       if (verbose_level > 0)
3670
         planner.bed_level_matrix.debug("\n\nBed Level Correction Matrix:");
3674
         planner.bed_level_matrix.debug("\n\nBed Level Correction Matrix:");
3671
 
3675
 
3735
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G29");
3739
       if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G29");
3736
     #endif
3740
     #endif
3737
 
3741
 
3738
-    bed_leveling_in_progress = false;
3739
-
3740
     report_current_position();
3742
     report_current_position();
3741
 
3743
 
3742
     KEEPALIVE_STATE(IN_HANDLER);
3744
     KEEPALIVE_STATE(IN_HANDLER);
5075
 
5077
 
5076
   #if IS_SCARA
5078
   #if IS_SCARA
5077
     SERIAL_PROTOCOLPGM("SCARA Theta:");
5079
     SERIAL_PROTOCOLPGM("SCARA Theta:");
5078
-    SERIAL_PROTOCOL(delta[X_AXIS]);
5080
+    SERIAL_PROTOCOL(delta[A_AXIS]);
5079
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
5081
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
5080
-    SERIAL_PROTOCOL(delta[Y_AXIS]);
5081
-    SERIAL_EOL;
5082
+    SERIAL_PROTOCOLLN(delta[B_AXIS]);
5082
 
5083
 
5083
     SERIAL_PROTOCOLPGM("SCARA Cal - Theta:");
5084
     SERIAL_PROTOCOLPGM("SCARA Cal - Theta:");
5084
-    SERIAL_PROTOCOL(delta[X_AXIS]);
5085
+    SERIAL_PROTOCOL(delta[A_AXIS]);
5085
     SERIAL_PROTOCOLPGM("   Psi+Theta (90):");
5086
     SERIAL_PROTOCOLPGM("   Psi+Theta (90):");
5086
-    SERIAL_PROTOCOL(delta[Y_AXIS] - delta[X_AXIS] - 90);
5087
-    SERIAL_EOL;
5087
+    SERIAL_PROTOCOLLN(delta[B_AXIS] - delta[A_AXIS] - 90);
5088
 
5088
 
5089
     SERIAL_PROTOCOLPGM("SCARA step Cal - Theta:");
5089
     SERIAL_PROTOCOLPGM("SCARA step Cal - Theta:");
5090
-    SERIAL_PROTOCOL(delta[X_AXIS] / 90 * planner.axis_steps_per_mm[X_AXIS]);
5090
+    SERIAL_PROTOCOL(delta[A_AXIS] / 90 * planner.axis_steps_per_mm[A_AXIS]);
5091
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
5091
     SERIAL_PROTOCOLPGM("   Psi+Theta:");
5092
-    SERIAL_PROTOCOL((delta[Y_AXIS] - delta[X_AXIS]) / 90 * planner.axis_steps_per_mm[Y_AXIS]);
5093
-    SERIAL_EOL; SERIAL_EOL;
5092
+    SERIAL_PROTOCOLLN((delta[B_AXIS] - delta[A_AXIS]) / 90 * planner.axis_steps_per_mm[A_AXIS]);
5093
+    SERIAL_EOL;
5094
   #endif
5094
   #endif
5095
 }
5095
 }
5096
 
5096
 
6160
     // Define runplan for move axes
6160
     // Define runplan for move axes
6161
     #if IS_KINEMATIC
6161
     #if IS_KINEMATIC
6162
       #define RUNPLAN(RATE_MM_S) inverse_kinematics(destination); \
6162
       #define RUNPLAN(RATE_MM_S) inverse_kinematics(destination); \
6163
-                                 planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], RATE_MM_S, active_extruder);
6163
+                                 planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], destination[E_AXIS], RATE_MM_S, active_extruder);
6164
     #else
6164
     #else
6165
       #define RUNPLAN(RATE_MM_S) line_to_destination(RATE_MM_S);
6165
       #define RUNPLAN(RATE_MM_S) line_to_destination(RATE_MM_S);
6166
     #endif
6166
     #endif
6282
     #if IS_KINEMATIC
6282
     #if IS_KINEMATIC
6283
       // Move XYZ to starting position, then E
6283
       // Move XYZ to starting position, then E
6284
       inverse_kinematics(lastpos);
6284
       inverse_kinematics(lastpos);
6285
-      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], FILAMENT_CHANGE_XY_FEEDRATE, active_extruder);
6286
-      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], lastpos[E_AXIS], FILAMENT_CHANGE_XY_FEEDRATE, active_extruder);
6285
+      planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], destination[E_AXIS], FILAMENT_CHANGE_XY_FEEDRATE, active_extruder);
6286
+      planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], lastpos[E_AXIS], FILAMENT_CHANGE_XY_FEEDRATE, active_extruder);
6287
     #else
6287
     #else
6288
       // Move XY to starting position, then Z, then E
6288
       // Move XY to starting position, then Z, then E
6289
       destination[X_AXIS] = lastpos[X_AXIS];
6289
       destination[X_AXIS] = lastpos[X_AXIS];
7637
 
7637
 
7638
 #endif
7638
 #endif
7639
 
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
+
7640
 #if ENABLED(DELTA)
7682
 #if ENABLED(DELTA)
7641
 
7683
 
7642
   /**
7684
   /**
7827
     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]);
7828
   }
7870
   }
7829
 
7871
 
7830
-  #if ENABLED(AUTO_BED_LEVELING_NONLINEAR)
7831
-
7832
-    // Adjust print surface height by linear interpolation over the bed_level array.
7833
-    void adjust_delta(float cartesian[XYZ]) {
7834
-      if (nonlinear_grid_spacing[X_AXIS] == 0 || nonlinear_grid_spacing[Y_AXIS] == 0) return; // G29 not done!
7835
-
7836
-      int half_x = (ABL_GRID_POINTS_X - 1) / 2,
7837
-          half_y = (ABL_GRID_POINTS_Y - 1) / 2;
7838
-      float hx2 = half_x - 0.001, hx1 = -hx2,
7839
-            hy2 = half_y - 0.001, hy1 = -hy2,
7840
-            grid_x = max(hx1, min(hx2, RAW_X_POSITION(cartesian[X_AXIS]) / nonlinear_grid_spacing[X_AXIS])),
7841
-            grid_y = max(hy1, min(hy2, RAW_Y_POSITION(cartesian[Y_AXIS]) / nonlinear_grid_spacing[Y_AXIS]));
7842
-      int   floor_x = floor(grid_x), floor_y = floor(grid_y);
7843
-      float ratio_x = grid_x - floor_x, ratio_y = grid_y - floor_y,
7844
-            z1 = bed_level_grid[floor_x + half_x][floor_y + half_y],
7845
-            z2 = bed_level_grid[floor_x + half_x][floor_y + half_y + 1],
7846
-            z3 = bed_level_grid[floor_x + half_x + 1][floor_y + half_y],
7847
-            z4 = bed_level_grid[floor_x + half_x + 1][floor_y + half_y + 1],
7848
-            left = (1 - ratio_y) * z1 + ratio_y * z2,
7849
-            right = (1 - ratio_y) * z3 + ratio_y * z4,
7850
-            offset = (1 - ratio_x) * left + ratio_x * right;
7851
-
7852
-      delta[X_AXIS] += offset;
7853
-      delta[Y_AXIS] += offset;
7854
-      delta[Z_AXIS] += offset;
7855
-
7856
-      /**
7857
-      SERIAL_ECHOPAIR("grid_x=", grid_x);
7858
-      SERIAL_ECHOPAIR(" grid_y=", grid_y);
7859
-      SERIAL_ECHOPAIR(" floor_x=", floor_x);
7860
-      SERIAL_ECHOPAIR(" floor_y=", floor_y);
7861
-      SERIAL_ECHOPAIR(" ratio_x=", ratio_x);
7862
-      SERIAL_ECHOPAIR(" ratio_y=", ratio_y);
7863
-      SERIAL_ECHOPAIR(" z1=", z1);
7864
-      SERIAL_ECHOPAIR(" z2=", z2);
7865
-      SERIAL_ECHOPAIR(" z3=", z3);
7866
-      SERIAL_ECHOPAIR(" z4=", z4);
7867
-      SERIAL_ECHOPAIR(" left=", left);
7868
-      SERIAL_ECHOPAIR(" right=", right);
7869
-      SERIAL_ECHOLNPAIR(" offset=", offset);
7870
-      */
7871
-    }
7872
-  #endif // AUTO_BED_LEVELING_NONLINEAR
7873
-
7874
 #endif // DELTA
7872
 #endif // DELTA
7875
 
7873
 
7876
 /**
7874
 /**
7992
    * This calls planner.buffer_line several times, adding
7990
    * This calls planner.buffer_line several times, adding
7993
    * small incremental moves for DELTA or SCARA.
7991
    * small incremental moves for DELTA or SCARA.
7994
    */
7992
    */
7995
-  inline bool prepare_kinematic_move_to(float target[NUM_AXIS]) {
7993
+  inline bool prepare_kinematic_move_to(float logical[NUM_AXIS]) {
7996
     float difference[NUM_AXIS];
7994
     float difference[NUM_AXIS];
7997
-    LOOP_XYZE(i) difference[i] = target[i] - current_position[i];
7995
+    LOOP_XYZE(i) difference[i] = logical[i] - current_position[i];
7998
 
7996
 
7999
     float cartesian_mm = sqrt(sq(difference[X_AXIS]) + sq(difference[Y_AXIS]) + sq(difference[Z_AXIS]));
7997
     float cartesian_mm = sqrt(sq(difference[X_AXIS]) + sq(difference[Y_AXIS]) + sq(difference[Z_AXIS]));
8000
     if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = abs(difference[E_AXIS]);
7998
     if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = abs(difference[E_AXIS]);
8013
       float fraction = float(s) * inv_steps;
8011
       float fraction = float(s) * inv_steps;
8014
 
8012
 
8015
       LOOP_XYZE(i)
8013
       LOOP_XYZE(i)
8016
-        target[i] = current_position[i] + difference[i] * fraction;
8014
+        logical[i] = current_position[i] + difference[i] * fraction;
8017
 
8015
 
8018
-      inverse_kinematics(target);
8016
+      inverse_kinematics(logical);
8019
 
8017
 
8020
-      #if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_NONLINEAR)
8021
-        if (!bed_leveling_in_progress) adjust_delta(target);
8022
-      #endif
8023
-
8024
-      //DEBUG_POS("prepare_kinematic_move_to", target);
8018
+      //DEBUG_POS("prepare_kinematic_move_to", logical);
8025
       //DEBUG_POS("prepare_kinematic_move_to", delta);
8019
       //DEBUG_POS("prepare_kinematic_move_to", delta);
8026
 
8020
 
8027
-      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], target[E_AXIS], _feedrate_mm_s, active_extruder);
8021
+      planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], _feedrate_mm_s, active_extruder);
8028
     }
8022
     }
8029
     return true;
8023
     return true;
8030
   }
8024
   }
8156
    * options for G2/G3 arc generation. In future these options may be GCode tunable.
8150
    * options for G2/G3 arc generation. In future these options may be GCode tunable.
8157
    */
8151
    */
8158
   void plan_arc(
8152
   void plan_arc(
8159
-    float target[NUM_AXIS], // Destination position
8160
-    float* offset,          // Center of rotation relative to current_position
8161
-    uint8_t clockwise       // Clockwise?
8153
+    float logical[NUM_AXIS], // Destination position
8154
+    float* offset,           // Center of rotation relative to current_position
8155
+    uint8_t clockwise        // Clockwise?
8162
   ) {
8156
   ) {
8163
 
8157
 
8164
     float radius = HYPOT(offset[X_AXIS], offset[Y_AXIS]),
8158
     float radius = HYPOT(offset[X_AXIS], offset[Y_AXIS]),
8165
           center_X = current_position[X_AXIS] + offset[X_AXIS],
8159
           center_X = current_position[X_AXIS] + offset[X_AXIS],
8166
           center_Y = current_position[Y_AXIS] + offset[Y_AXIS],
8160
           center_Y = current_position[Y_AXIS] + offset[Y_AXIS],
8167
-          linear_travel = target[Z_AXIS] - current_position[Z_AXIS],
8168
-          extruder_travel = target[E_AXIS] - current_position[E_AXIS],
8161
+          linear_travel = logical[Z_AXIS] - current_position[Z_AXIS],
8162
+          extruder_travel = logical[E_AXIS] - current_position[E_AXIS],
8169
           r_X = -offset[X_AXIS],  // Radius vector from center to current location
8163
           r_X = -offset[X_AXIS],  // Radius vector from center to current location
8170
           r_Y = -offset[Y_AXIS],
8164
           r_Y = -offset[Y_AXIS],
8171
-          rt_X = target[X_AXIS] - center_X,
8172
-          rt_Y = target[Y_AXIS] - center_Y;
8165
+          rt_X = logical[X_AXIS] - center_X,
8166
+          rt_Y = logical[Y_AXIS] - center_Y;
8173
 
8167
 
8174
     // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
8168
     // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
8175
     float angular_travel = atan2(r_X * rt_Y - r_Y * rt_X, r_X * rt_X + r_Y * rt_Y);
8169
     float angular_travel = atan2(r_X * rt_Y - r_Y * rt_X, r_X * rt_X + r_Y * rt_Y);
8177
     if (clockwise) angular_travel -= RADIANS(360);
8171
     if (clockwise) angular_travel -= RADIANS(360);
8178
 
8172
 
8179
     // Make a circle if the angular rotation is 0
8173
     // Make a circle if the angular rotation is 0
8180
-    if (angular_travel == 0 && current_position[X_AXIS] == target[X_AXIS] && current_position[Y_AXIS] == target[Y_AXIS])
8174
+    if (angular_travel == 0 && current_position[X_AXIS] == logical[X_AXIS] && current_position[Y_AXIS] == logical[Y_AXIS])
8181
       angular_travel += RADIANS(360);
8175
       angular_travel += RADIANS(360);
8182
 
8176
 
8183
     float mm_of_travel = HYPOT(angular_travel * radius, fabs(linear_travel));
8177
     float mm_of_travel = HYPOT(angular_travel * radius, fabs(linear_travel));
8271
 
8265
 
8272
       #if IS_KINEMATIC
8266
       #if IS_KINEMATIC
8273
         inverse_kinematics(arc_target);
8267
         inverse_kinematics(arc_target);
8274
-        #if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_NONLINEAR)
8275
-          adjust_delta(arc_target);
8276
-        #endif
8277
-        planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_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);
8278
       #else
8269
       #else
8279
         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);
8280
       #endif
8271
       #endif
8282
 
8273
 
8283
     // Ensure last segment arrives at target location.
8274
     // Ensure last segment arrives at target location.
8284
     #if IS_KINEMATIC
8275
     #if IS_KINEMATIC
8285
-      inverse_kinematics(target);
8286
-      #if ENABLED(DELTA) && ENABLED(AUTO_BED_LEVELING_NONLINEAR)
8287
-        adjust_delta(target);
8288
-      #endif
8289
-      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], target[E_AXIS], fr_mm_s, active_extruder);
8276
+      inverse_kinematics(logical);
8277
+      planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], logical[E_AXIS], fr_mm_s, active_extruder);
8290
     #else
8278
     #else
8291
-      planner.buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[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);
8292
     #endif
8280
     #endif
8293
 
8281
 
8294
     // As far as the parser is concerned, the position is now == target. In reality the
8282
     // As far as the parser is concerned, the position is now == target. In reality the
8303
   void plan_cubic_move(const float offset[4]) {
8291
   void plan_cubic_move(const float offset[4]) {
8304
     cubic_b_spline(current_position, destination, offset, MMS_SCALED(feedrate_mm_s), active_extruder);
8292
     cubic_b_spline(current_position, destination, offset, MMS_SCALED(feedrate_mm_s), active_extruder);
8305
 
8293
 
8306
-    // As far as the parser is concerned, the position is now == target. In reality the
8294
+    // As far as the parser is concerned, the position is now == destination. In reality the
8307
     // motion control system might still be processing the action and the real tool position
8295
     // motion control system might still be processing the action and the real tool position
8308
     // in any intermediate location.
8296
     // in any intermediate location.
8309
     set_current_to_destination();
8297
     set_current_to_destination();
8376
     //*/
8364
     //*/
8377
   }
8365
   }
8378
 
8366
 
8379
-  void inverse_kinematics(const float cartesian[XYZ]) {
8367
+  void inverse_kinematics(const float logical[XYZ]) {
8380
     // Inverse kinematics.
8368
     // Inverse kinematics.
8381
     // Perform SCARA IK and place results in delta[].
8369
     // Perform SCARA IK and place results in delta[].
8382
     // The maths and first version were done by QHARLEY.
8370
     // The maths and first version were done by QHARLEY.
8384
 
8372
 
8385
     static float C2, S2, SK1, SK2, THETA, PSI;
8373
     static float C2, S2, SK1, SK2, THETA, PSI;
8386
 
8374
 
8387
-    float sx = RAW_X_POSITION(cartesian[X_AXIS]) - SCARA_OFFSET_X,  //Translate SCARA to standard X Y
8388
-          sy = RAW_Y_POSITION(cartesian[Y_AXIS]) - SCARA_OFFSET_Y;  // With scaling factor.
8375
+    float sx = RAW_X_POSITION(logical[X_AXIS]) - SCARA_OFFSET_X,  // Translate SCARA to standard X Y
8376
+          sy = RAW_Y_POSITION(logical[Y_AXIS]) - SCARA_OFFSET_Y;  // With scaling factor.
8389
 
8377
 
8390
     #if (L1 == L2)
8378
     #if (L1 == L2)
8391
       C2 = HYPOT2(sx, sy) / (2 * L1_2) - 1;
8379
       C2 = HYPOT2(sx, sy) / (2 * L1_2) - 1;
8403
 
8391
 
8404
     delta[A_AXIS] = DEGREES(THETA);        // theta is support arm angle
8392
     delta[A_AXIS] = DEGREES(THETA);        // theta is support arm angle
8405
     delta[B_AXIS] = DEGREES(THETA + PSI);  // equal to sub arm angle (inverted motor)
8393
     delta[B_AXIS] = DEGREES(THETA + PSI);  // equal to sub arm angle (inverted motor)
8406
-    delta[Z_AXIS] = cartesian[Z_AXIS];
8394
+    delta[C_AXIS] = logical[Z_AXIS];
8407
 
8395
 
8408
-    /**
8409
-      DEBUG_POS("SCARA IK", cartesian);
8396
+    /*
8397
+      DEBUG_POS("SCARA IK", logical);
8410
       DEBUG_POS("SCARA IK", delta);
8398
       DEBUG_POS("SCARA IK", delta);
8411
       SERIAL_ECHOPAIR("  SCARA (x,y) ", sx);
8399
       SERIAL_ECHOPAIR("  SCARA (x,y) ", sx);
8412
       SERIAL_ECHOPAIR(",", sy);
8400
       SERIAL_ECHOPAIR(",", sy);

+ 23
- 1
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
 
1205
   LOOP_XYZE(i) steps_to_mm[i] = 1.0 / axis_steps_per_mm[i];
1227
   LOOP_XYZE(i) steps_to_mm[i] = 1.0 / axis_steps_per_mm[i];
1206
   #if IS_KINEMATIC
1228
   #if IS_KINEMATIC
1207
     inverse_kinematics(current_position);
1229
     inverse_kinematics(current_position);
1208
-    set_position_mm(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
1230
+    set_position_mm(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], current_position[E_AXIS]);
1209
   #else
1231
   #else
1210
     set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1232
     set_position_mm(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1211
   #endif
1233
   #endif

+ 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

+ 2
- 2
Marlin/ultralcd.cpp View File

547
   inline void line_to_current(AxisEnum axis) {
547
   inline void line_to_current(AxisEnum axis) {
548
     #if ENABLED(DELTA)
548
     #if ENABLED(DELTA)
549
       inverse_kinematics(current_position);
549
       inverse_kinematics(current_position);
550
-      planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], MMM_TO_MMS(manual_feedrate_mm_m[axis]), active_extruder);
550
+      planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], current_position[E_AXIS], MMM_TO_MMS(manual_feedrate_mm_m[axis]), active_extruder);
551
     #else // !DELTA
551
     #else // !DELTA
552
       planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], MMM_TO_MMS(manual_feedrate_mm_m[axis]), active_extruder);
552
       planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], MMM_TO_MMS(manual_feedrate_mm_m[axis]), active_extruder);
553
     #endif // !DELTA
553
     #endif // !DELTA
1297
     if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
1297
     if (manual_move_axis != (int8_t)NO_AXIS && ELAPSED(millis(), manual_move_start_time) && !planner.is_full()) {
1298
       #if ENABLED(DELTA)
1298
       #if ENABLED(DELTA)
1299
         inverse_kinematics(current_position);
1299
         inverse_kinematics(current_position);
1300
-        planner.buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
1300
+        planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], current_position[E_AXIS], MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
1301
       #else
1301
       #else
1302
         planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
1302
         planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], MMM_TO_MMS(manual_feedrate_mm_m[manual_move_axis]), manual_move_e_index);
1303
       #endif
1303
       #endif

Loading…
Cancel
Save