Bläddra i källkod

Merge pull request #4719 from thinkyhead/rc_delta_homing_patch

Marlin patches for homing, esp. Delta
Scott Lahteine 7 år sedan
förälder
incheckning
2cb63f0bf7
1 ändrade filer med 47 tillägg och 45 borttagningar
  1. 47
    45
      Marlin/Marlin_main.cpp

+ 47
- 45
Marlin/Marlin_main.cpp Visa fil

@@ -1615,6 +1615,8 @@ static void set_axis_is_at_home(AxisEnum axis) {
1615 1615
       SERIAL_ECHOLNPGM(")");
1616 1616
     }
1617 1617
   #endif
1618
+
1619
+  axis_known_position[axis] = axis_homed[axis] = true;
1618 1620
 }
1619 1621
 
1620 1622
 /**
@@ -2118,7 +2120,7 @@ static void clean_up_after_endstop_or_probe_move() {
2118 2120
     #endif
2119 2121
 
2120 2122
     do_blocking_move_to(oldXpos, oldYpos, current_position[Z_AXIS]); // return to position before deploy
2121
-    endstops.enable_z_probe( deploy );
2123
+    endstops.enable_z_probe(deploy);
2122 2124
     return false;
2123 2125
   }
2124 2126
 
@@ -2416,12 +2418,12 @@ static void clean_up_after_endstop_or_probe_move() {
2416 2418
  */
2417 2419
 
2418 2420
 static void do_homing_move(AxisEnum axis, float where, float fr_mm_s = 0.0) {
2419
-  float old_feedrate_mm_s = feedrate_mm_s;
2421
+  current_position[axis] = 0;
2422
+  sync_plan_position();
2420 2423
   current_position[axis] = where;
2421
-  feedrate_mm_s = (fr_mm_s != 0.0) ? fr_mm_s : homing_feedrate_mm_s[axis];
2422
-  planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate_mm_s, active_extruder);
2424
+  planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], (fr_mm_s != 0.0) ? fr_mm_s : homing_feedrate_mm_s[axis], active_extruder);
2423 2425
   stepper.synchronize();
2424
-  feedrate_mm_s = old_feedrate_mm_s;
2426
+  endstops.hit_on_purpose();
2425 2427
 }
2426 2428
 
2427 2429
 #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
@@ -2430,7 +2432,7 @@ static void homeaxis(AxisEnum axis) {
2430 2432
   #define HOMEAXIS_DO(LETTER) \
2431 2433
     ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
2432 2434
 
2433
-  if (!(axis == X_AXIS ? HOMEAXIS_DO(X) : axis == Y_AXIS ? HOMEAXIS_DO(Y) : axis == Z_AXIS ? HOMEAXIS_DO(Z) : 0)) return;
2435
+  if (!(axis == X_AXIS ? HOMEAXIS_DO(X) : axis == Y_AXIS ? HOMEAXIS_DO(Y) : axis == Z_AXIS ? HOMEAXIS_DO(Z) : false)) return;
2434 2436
 
2435 2437
   #if ENABLED(DEBUG_LEVELING_FEATURE)
2436 2438
     if (DEBUGGING(LEVELING)) {
@@ -2455,10 +2457,6 @@ static void homeaxis(AxisEnum axis) {
2455 2457
     }
2456 2458
   #endif
2457 2459
 
2458
-  // Set the axis position as setup for the move
2459
-  current_position[axis] = 0;
2460
-  sync_plan_position();
2461
-
2462 2460
   // Set a flag for Z motor locking
2463 2461
   #if ENABLED(Z_DUAL_ENDSTOPS)
2464 2462
     if (axis == Z_AXIS) stepper.set_homing_flag(true);
@@ -2467,9 +2465,9 @@ static void homeaxis(AxisEnum axis) {
2467 2465
   // Move towards the endstop until an endstop is triggered
2468 2466
   do_homing_move(axis, 1.5 * max_length(axis) * axis_home_dir);
2469 2467
 
2470
-  // Set the axis position as setup for the move
2471
-  current_position[axis] = 0;
2472
-  sync_plan_position();
2468
+  #if ENABLED(DEBUG_LEVELING_FEATURE)
2469
+    if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR("> 1st Home", current_position[axis]);
2470
+  #endif
2473 2471
 
2474 2472
   // Move away from the endstop by the axis HOME_BUMP_MM
2475 2473
   do_homing_move(axis, -home_bump_mm(axis) * axis_home_dir);
@@ -2477,12 +2475,8 @@ static void homeaxis(AxisEnum axis) {
2477 2475
   // Move slowly towards the endstop until triggered
2478 2476
   do_homing_move(axis, 2 * home_bump_mm(axis) * axis_home_dir, get_homing_bump_feedrate(axis));
2479 2477
 
2480
-  // reset current_position to 0 to reflect hitting endpoint
2481
-  current_position[axis] = 0;
2482
-  sync_plan_position();
2483
-
2484 2478
   #if ENABLED(DEBUG_LEVELING_FEATURE)
2485
-    if (DEBUGGING(LEVELING)) DEBUG_POS("> TRIGGER ENDSTOP", current_position);
2479
+    if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR("> 2nd Home", current_position[axis]);
2486 2480
   #endif
2487 2481
 
2488 2482
   #if ENABLED(Z_DUAL_ENDSTOPS)
@@ -2506,32 +2500,35 @@ static void homeaxis(AxisEnum axis) {
2506 2500
     } // Z_AXIS
2507 2501
   #endif
2508 2502
 
2503
+  // Delta has already moved all three towers up in G28
2504
+  // so here it re-homes each tower in turn.
2505
+  // Delta homing treats the axes as normal linear axes.
2509 2506
   #if ENABLED(DELTA)
2507
+
2510 2508
     // retrace by the amount specified in endstop_adj
2511 2509
     if (endstop_adj[axis] * Z_HOME_DIR < 0) {
2512 2510
       #if ENABLED(DEBUG_LEVELING_FEATURE)
2513 2511
         if (DEBUGGING(LEVELING)) {
2514
-          SERIAL_ECHOPAIR("> endstop_adj = ", endstop_adj[axis]);
2512
+          SERIAL_ECHOPAIR("> endstop_adj = ", endstop_adj[axis] * Z_HOME_DIR);
2515 2513
           DEBUG_POS("", current_position);
2516 2514
         }
2517 2515
       #endif
2518 2516
       do_homing_move(axis, endstop_adj[axis]);
2519 2517
     }
2520
-  #endif
2521 2518
 
2522
-  // Set the axis position to its home position (plus home offsets)
2523
-  set_axis_is_at_home(axis);
2519
+  #else
2524 2520
 
2525
-  SYNC_PLAN_POSITION_KINEMATIC();
2521
+    // Set the axis position to its home position (plus home offsets)
2522
+    set_axis_is_at_home(axis);
2523
+    sync_plan_position();
2526 2524
 
2527
-  #if ENABLED(DEBUG_LEVELING_FEATURE)
2528
-    if (DEBUGGING(LEVELING)) DEBUG_POS("> AFTER set_axis_is_at_home", current_position);
2529
-  #endif
2525
+    destination[axis] = current_position[axis];
2526
+
2527
+    #if ENABLED(DEBUG_LEVELING_FEATURE)
2528
+      if (DEBUGGING(LEVELING)) DEBUG_POS("> AFTER set_axis_is_at_home", current_position);
2529
+    #endif
2530 2530
 
2531
-  destination[axis] = current_position[axis];
2532
-  endstops.hit_on_purpose(); // clear endstop hit flags
2533
-  axis_known_position[axis] = true;
2534
-  axis_homed[axis] = true;
2531
+  #endif
2535 2532
 
2536 2533
   // Put away the Z probe
2537 2534
   #if HAS_BED_PROBE && Z_HOME_DIR < 0 && DISABLED(Z_MIN_PROBE_ENDSTOP)
@@ -2979,25 +2976,34 @@ inline void gcode_G28() {
2979 2976
   #if ENABLED(DELTA)
2980 2977
     /**
2981 2978
      * A delta can only safely home all axes at the same time
2979
+     * This is like quick_home_xy() but for 3 towers.
2982 2980
      */
2983 2981
 
2984
-    // Pretend the current position is 0,0,0
2985
-    // This is like quick_home_xy() but for 3 towers.
2986
-    current_position[X_AXIS] = current_position[Y_AXIS] = current_position[Z_AXIS] = 0.0;
2982
+    // Init the current position of all carriages to 0,0,0
2983
+    memset(current_position, 0, sizeof(current_position));
2987 2984
     sync_plan_position();
2988 2985
 
2989
-    // Move all carriages up together until the first endstop is hit.
2990
-    current_position[X_AXIS] = current_position[Y_AXIS] = current_position[Z_AXIS] = 3.0 * (Z_MAX_LENGTH);
2991
-    feedrate_mm_s = 1.732 * homing_feedrate_mm_s[X_AXIS];
2986
+    // Move all carriages together linearly until an endstop is hit.
2987
+    current_position[X_AXIS] = current_position[Y_AXIS] = current_position[Z_AXIS] = (Z_MAX_LENGTH + 10);
2988
+    feedrate_mm_s = homing_feedrate_mm_s[X_AXIS];
2992 2989
     line_to_current_position();
2993 2990
     stepper.synchronize();
2994 2991
     endstops.hit_on_purpose(); // clear endstop hit flags
2995
-    current_position[X_AXIS] = current_position[Y_AXIS] = current_position[Z_AXIS] = 0.0;
2996 2992
 
2997
-    // take care of back off and rehome. Now one carriage is at the top.
2998
-    HOMEAXIS(X);
2999
-    HOMEAXIS(Y);
3000
-    HOMEAXIS(Z);
2993
+    // Probably not needed. Double-check this line:
2994
+    memset(current_position, 0, sizeof(current_position));
2995
+
2996
+    // At least one carriage has reached the top.
2997
+    // Now back off and re-home each carriage separately.
2998
+    HOMEAXIS(A);
2999
+    HOMEAXIS(B);
3000
+    HOMEAXIS(C);
3001
+
3002
+    // Set all carriages to their home positions
3003
+    // Do this here all at once for Delta, because
3004
+    // XYZ isn't ABC. Applying this per-tower would
3005
+    // give the impression that they are the same.
3006
+    LOOP_XYZ(i) set_axis_is_at_home((AxisEnum)i);
3001 3007
 
3002 3008
     SYNC_PLAN_POSITION_KINEMATIC();
3003 3009
 
@@ -3177,11 +3183,7 @@ inline void gcode_G28() {
3177 3183
 
3178 3184
   #endif // !DELTA (gcode_G28)
3179 3185
 
3180
-  #if ENABLED(DEBUG_LEVELING_FEATURE)
3181
-    if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("> endstops.not_homing()");
3182
-  #endif
3183 3186
   endstops.not_homing();
3184
-  endstops.hit_on_purpose(); // clear endstop hit flags
3185 3187
 
3186 3188
   // Enable mesh leveling again
3187 3189
   #if ENABLED(MESH_BED_LEVELING)

Laddar…
Avbryt
Spara