Browse Source

Merge pull request #4719 from thinkyhead/rc_delta_homing_patch

Marlin patches for homing, esp. Delta
Scott Lahteine 8 years ago
parent
commit
2cb63f0bf7
1 changed files with 47 additions and 45 deletions
  1. 47
    45
      Marlin/Marlin_main.cpp

+ 47
- 45
Marlin/Marlin_main.cpp View File

1615
       SERIAL_ECHOLNPGM(")");
1615
       SERIAL_ECHOLNPGM(")");
1616
     }
1616
     }
1617
   #endif
1617
   #endif
1618
+
1619
+  axis_known_position[axis] = axis_homed[axis] = true;
1618
 }
1620
 }
1619
 
1621
 
1620
 /**
1622
 /**
2118
     #endif
2120
     #endif
2119
 
2121
 
2120
     do_blocking_move_to(oldXpos, oldYpos, current_position[Z_AXIS]); // return to position before deploy
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
     return false;
2124
     return false;
2123
   }
2125
   }
2124
 
2126
 
2416
  */
2418
  */
2417
 
2419
 
2418
 static void do_homing_move(AxisEnum axis, float where, float fr_mm_s = 0.0) {
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
   current_position[axis] = where;
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
   stepper.synchronize();
2425
   stepper.synchronize();
2424
-  feedrate_mm_s = old_feedrate_mm_s;
2426
+  endstops.hit_on_purpose();
2425
 }
2427
 }
2426
 
2428
 
2427
 #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
2429
 #define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
2430
   #define HOMEAXIS_DO(LETTER) \
2432
   #define HOMEAXIS_DO(LETTER) \
2431
     ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
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
   #if ENABLED(DEBUG_LEVELING_FEATURE)
2437
   #if ENABLED(DEBUG_LEVELING_FEATURE)
2436
     if (DEBUGGING(LEVELING)) {
2438
     if (DEBUGGING(LEVELING)) {
2455
     }
2457
     }
2456
   #endif
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
   // Set a flag for Z motor locking
2460
   // Set a flag for Z motor locking
2463
   #if ENABLED(Z_DUAL_ENDSTOPS)
2461
   #if ENABLED(Z_DUAL_ENDSTOPS)
2464
     if (axis == Z_AXIS) stepper.set_homing_flag(true);
2462
     if (axis == Z_AXIS) stepper.set_homing_flag(true);
2467
   // Move towards the endstop until an endstop is triggered
2465
   // Move towards the endstop until an endstop is triggered
2468
   do_homing_move(axis, 1.5 * max_length(axis) * axis_home_dir);
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
   // Move away from the endstop by the axis HOME_BUMP_MM
2472
   // Move away from the endstop by the axis HOME_BUMP_MM
2475
   do_homing_move(axis, -home_bump_mm(axis) * axis_home_dir);
2473
   do_homing_move(axis, -home_bump_mm(axis) * axis_home_dir);
2477
   // Move slowly towards the endstop until triggered
2475
   // Move slowly towards the endstop until triggered
2478
   do_homing_move(axis, 2 * home_bump_mm(axis) * axis_home_dir, get_homing_bump_feedrate(axis));
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
   #if ENABLED(DEBUG_LEVELING_FEATURE)
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
   #endif
2480
   #endif
2487
 
2481
 
2488
   #if ENABLED(Z_DUAL_ENDSTOPS)
2482
   #if ENABLED(Z_DUAL_ENDSTOPS)
2506
     } // Z_AXIS
2500
     } // Z_AXIS
2507
   #endif
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
   #if ENABLED(DELTA)
2506
   #if ENABLED(DELTA)
2507
+
2510
     // retrace by the amount specified in endstop_adj
2508
     // retrace by the amount specified in endstop_adj
2511
     if (endstop_adj[axis] * Z_HOME_DIR < 0) {
2509
     if (endstop_adj[axis] * Z_HOME_DIR < 0) {
2512
       #if ENABLED(DEBUG_LEVELING_FEATURE)
2510
       #if ENABLED(DEBUG_LEVELING_FEATURE)
2513
         if (DEBUGGING(LEVELING)) {
2511
         if (DEBUGGING(LEVELING)) {
2514
-          SERIAL_ECHOPAIR("> endstop_adj = ", endstop_adj[axis]);
2512
+          SERIAL_ECHOPAIR("> endstop_adj = ", endstop_adj[axis] * Z_HOME_DIR);
2515
           DEBUG_POS("", current_position);
2513
           DEBUG_POS("", current_position);
2516
         }
2514
         }
2517
       #endif
2515
       #endif
2518
       do_homing_move(axis, endstop_adj[axis]);
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
   // Put away the Z probe
2533
   // Put away the Z probe
2537
   #if HAS_BED_PROBE && Z_HOME_DIR < 0 && DISABLED(Z_MIN_PROBE_ENDSTOP)
2534
   #if HAS_BED_PROBE && Z_HOME_DIR < 0 && DISABLED(Z_MIN_PROBE_ENDSTOP)
2979
   #if ENABLED(DELTA)
2976
   #if ENABLED(DELTA)
2980
     /**
2977
     /**
2981
      * A delta can only safely home all axes at the same time
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
     sync_plan_position();
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
     line_to_current_position();
2989
     line_to_current_position();
2993
     stepper.synchronize();
2990
     stepper.synchronize();
2994
     endstops.hit_on_purpose(); // clear endstop hit flags
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
     SYNC_PLAN_POSITION_KINEMATIC();
3008
     SYNC_PLAN_POSITION_KINEMATIC();
3003
 
3009
 
3177
 
3183
 
3178
   #endif // !DELTA (gcode_G28)
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
   endstops.not_homing();
3186
   endstops.not_homing();
3184
-  endstops.hit_on_purpose(); // clear endstop hit flags
3185
 
3187
 
3186
   // Enable mesh leveling again
3188
   // Enable mesh leveling again
3187
   #if ENABLED(MESH_BED_LEVELING)
3189
   #if ENABLED(MESH_BED_LEVELING)

Loading…
Cancel
Save