Browse Source

Adjust park code in tool_change

Scott Lahteine 8 years ago
parent
commit
4217e9653e
1 changed files with 50 additions and 26 deletions
  1. 50
    26
      Marlin/Marlin_main.cpp

+ 50
- 26
Marlin/Marlin_main.cpp View File

1416
  * current_position to home, because neither X nor Y is at home until
1416
  * current_position to home, because neither X nor Y is at home until
1417
  * both are at home. Z can however be homed individually.
1417
  * both are at home. Z can however be homed individually.
1418
  *
1418
  *
1419
+ * Callers must sync the planner position after calling this!
1419
  */
1420
  */
1420
 static void set_axis_is_at_home(AxisEnum axis) {
1421
 static void set_axis_is_at_home(AxisEnum axis) {
1421
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1422
   #if ENABLED(DEBUG_LEVELING_FEATURE)
3246
           #endif
3247
           #endif
3247
         )
3248
         )
3248
     ) {
3249
     ) {
3250
+
3249
       #if HOMING_Z_WITH_PROBE
3251
       #if HOMING_Z_WITH_PROBE
3250
         destination[X_AXIS] -= X_PROBE_OFFSET_FROM_EXTRUDER;
3252
         destination[X_AXIS] -= X_PROBE_OFFSET_FROM_EXTRUDER;
3251
         destination[Y_AXIS] -= Y_PROBE_OFFSET_FROM_EXTRUDER;
3253
         destination[Y_AXIS] -= Y_PROBE_OFFSET_FROM_EXTRUDER;
3252
       #endif
3254
       #endif
3255
+
3253
       #if ENABLED(DEBUG_LEVELING_FEATURE)
3256
       #if ENABLED(DEBUG_LEVELING_FEATURE)
3254
         if (DEBUGGING(LEVELING)) DEBUG_POS("Z_SAFE_HOMING", destination);
3257
         if (DEBUGGING(LEVELING)) DEBUG_POS("Z_SAFE_HOMING", destination);
3255
       #endif
3258
       #endif
3407
 
3410
 
3408
     // Home X
3411
     // Home X
3409
     if (home_all_axis || homeX) {
3412
     if (home_all_axis || homeX) {
3413
+
3410
       #if ENABLED(DUAL_X_CARRIAGE)
3414
       #if ENABLED(DUAL_X_CARRIAGE)
3411
-        int tmp_extruder = active_extruder;
3412
-        active_extruder = !active_extruder;
3415
+
3416
+        // Always home the 2nd (right) extruder first
3417
+        active_extruder = 1;
3413
         HOMEAXIS(X);
3418
         HOMEAXIS(X);
3419
+
3420
+        // Remember this extruder's position for later tool change
3414
         inactive_extruder_x_pos = RAW_X_POSITION(current_position[X_AXIS]);
3421
         inactive_extruder_x_pos = RAW_X_POSITION(current_position[X_AXIS]);
3415
-        active_extruder = tmp_extruder;
3422
+
3423
+        // Home the 1st (left) extruder
3424
+        active_extruder = 0;
3416
         HOMEAXIS(X);
3425
         HOMEAXIS(X);
3417
-        // reset state used by the different modes
3426
+
3427
+        // Consider the active extruder to be parked
3418
         memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
3428
         memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
3419
         delayed_move_time = 0;
3429
         delayed_move_time = 0;
3420
         active_extruder_parked = true;
3430
         active_extruder_parked = true;
3431
+
3421
       #else
3432
       #else
3433
+
3422
         HOMEAXIS(X);
3434
         HOMEAXIS(X);
3435
+
3423
       #endif
3436
       #endif
3437
+
3424
       #if ENABLED(DEBUG_LEVELING_FEATURE)
3438
       #if ENABLED(DEBUG_LEVELING_FEATURE)
3425
         if (DEBUGGING(LEVELING)) DEBUG_POS("> homeX", current_position);
3439
         if (DEBUGGING(LEVELING)) DEBUG_POS("> homeX", current_position);
3426
       #endif
3440
       #endif
7446
 void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) {
7460
 void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool no_move/*=false*/) {
7447
   #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
7461
   #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
7448
 
7462
 
7449
-    if (tmp_extruder >= MIXING_VIRTUAL_TOOLS) {
7450
-      invalid_extruder_error(tmp_extruder);
7451
-      return;
7452
-    }
7463
+    if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
7464
+      return invalid_extruder_error(tmp_extruder);
7453
 
7465
 
7454
     // T0-Tnnn: Switch virtual tool by changing the mix
7466
     // T0-Tnnn: Switch virtual tool by changing the mix
7455
     for (uint8_t j = 0; j < MIXING_STEPPERS; j++)
7467
     for (uint8_t j = 0; j < MIXING_STEPPERS; j++)
7459
 
7471
 
7460
     #if HOTENDS > 1
7472
     #if HOTENDS > 1
7461
 
7473
 
7462
-      if (tmp_extruder >= EXTRUDERS) {
7463
-        invalid_extruder_error(tmp_extruder);
7464
-        return;
7465
-      }
7474
+      if (tmp_extruder >= EXTRUDERS)
7475
+        return invalid_extruder_error(tmp_extruder);
7466
 
7476
 
7467
       float old_feedrate_mm_s = feedrate_mm_s;
7477
       float old_feedrate_mm_s = feedrate_mm_s;
7468
 
7478
 
7490
             }
7500
             }
7491
           #endif
7501
           #endif
7492
 
7502
 
7493
-          if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE && IsRunning() &&
7494
-              (delayed_move_time || current_position[X_AXIS] != x_home_pos(active_extruder))
7503
+          const float xhome = x_home_pos(active_extruder);
7504
+          if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE
7505
+              && IsRunning()
7506
+              && (delayed_move_time || current_position[X_AXIS] != xhome)
7495
           ) {
7507
           ) {
7508
+            float raised_z = current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT;
7509
+            #if ENABLED(max_software_endstops)
7510
+              NOMORE(raised_z, soft_endstop_max[Z_AXIS]);
7511
+            #endif
7496
             #if ENABLED(DEBUG_LEVELING_FEATURE)
7512
             #if ENABLED(DEBUG_LEVELING_FEATURE)
7497
               if (DEBUGGING(LEVELING)) {
7513
               if (DEBUGGING(LEVELING)) {
7498
-                SERIAL_ECHOPAIR("Raise to ", current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT); SERIAL_EOL;
7499
-                SERIAL_ECHOPAIR("MoveX to ", x_home_pos(active_extruder)); SERIAL_EOL;
7500
-                SERIAL_ECHOPAIR("Lower to ", current_position[Z_AXIS]); SERIAL_EOL;
7514
+                SERIAL_ECHOLNPAIR("Raise to ", raised_z);
7515
+                SERIAL_ECHOLNPAIR("MoveX to ", xhome);
7516
+                SERIAL_ECHOLNPAIR("Lower to ", current_position[Z_AXIS]);
7501
               }
7517
               }
7502
             #endif
7518
             #endif
7503
             // Park old head: 1) raise 2) move to park position 3) lower
7519
             // Park old head: 1) raise 2) move to park position 3) lower
7504
             for (uint8_t i = 0; i < 3; i++)
7520
             for (uint8_t i = 0; i < 3; i++)
7505
               planner.buffer_line(
7521
               planner.buffer_line(
7506
-                i == 0 ? current_position[X_AXIS] : x_home_pos(active_extruder),
7522
+                i == 0 ? current_position[X_AXIS] : xhome,
7507
                 current_position[Y_AXIS],
7523
                 current_position[Y_AXIS],
7508
-                current_position[Z_AXIS] + (i == 2 ? 0 : TOOLCHANGE_PARK_ZLIFT),
7524
+                i == 2 ? current_position[Z_AXIS] : raised_z,
7509
                 current_position[E_AXIS],
7525
                 current_position[E_AXIS],
7510
                 planner.max_feedrate_mm_s[i == 1 ? X_AXIS : Z_AXIS],
7526
                 planner.max_feedrate_mm_s[i == 1 ? X_AXIS : Z_AXIS],
7511
                 active_extruder
7527
                 active_extruder
7513
             stepper.synchronize();
7529
             stepper.synchronize();
7514
           }
7530
           }
7515
 
7531
 
7516
-          // apply Y & Z extruder offset (x offset is already used in determining home pos)
7532
+          // Apply Y & Z extruder offset (X offset is used as home pos with Dual X)
7517
           current_position[Y_AXIS] -= hotend_offset[Y_AXIS][active_extruder] - hotend_offset[Y_AXIS][tmp_extruder];
7533
           current_position[Y_AXIS] -= hotend_offset[Y_AXIS][active_extruder] - hotend_offset[Y_AXIS][tmp_extruder];
7518
           current_position[Z_AXIS] -= hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
7534
           current_position[Z_AXIS] -= hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder];
7535
+
7536
+          // Activate the new extruder
7519
           active_extruder = tmp_extruder;
7537
           active_extruder = tmp_extruder;
7520
 
7538
 
7521
           // This function resets the max/min values - the current position may be overwritten below.
7539
           // This function resets the max/min values - the current position may be overwritten below.
7530
 
7548
 
7531
           switch (dual_x_carriage_mode) {
7549
           switch (dual_x_carriage_mode) {
7532
             case DXC_FULL_CONTROL_MODE:
7550
             case DXC_FULL_CONTROL_MODE:
7551
+              // New current position is the position of the activated extruder
7533
               current_position[X_AXIS] = LOGICAL_X_POSITION(inactive_extruder_x_pos);
7552
               current_position[X_AXIS] = LOGICAL_X_POSITION(inactive_extruder_x_pos);
7553
+              // Save the inactive extruder's position (from the old current_position)
7534
               inactive_extruder_x_pos = RAW_X_POSITION(destination[X_AXIS]);
7554
               inactive_extruder_x_pos = RAW_X_POSITION(destination[X_AXIS]);
7535
               break;
7555
               break;
7536
             case DXC_AUTO_PARK_MODE:
7556
             case DXC_AUTO_PARK_MODE:
7544
               delayed_move_time = 0;
7564
               delayed_move_time = 0;
7545
               break;
7565
               break;
7546
             case DXC_DUPLICATION_MODE:
7566
             case DXC_DUPLICATION_MODE:
7547
-              active_extruder_parked = (active_extruder == 0); // this triggers the second extruder to move into the duplication position
7567
+              // If the new extruder is the left one, set it "parked"
7568
+              // This triggers the second extruder to move into the duplication position
7569
+              active_extruder_parked = (active_extruder == 0);
7570
+
7548
               if (active_extruder_parked)
7571
               if (active_extruder_parked)
7549
                 current_position[X_AXIS] = LOGICAL_X_POSITION(inactive_extruder_x_pos);
7572
                 current_position[X_AXIS] = LOGICAL_X_POSITION(inactive_extruder_x_pos);
7550
               else
7573
               else
7569
             float z_diff = hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder],
7592
             float z_diff = hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder],
7570
                   z_raise = 0.3 + (z_diff > 0.0 ? z_diff : 0.0);
7593
                   z_raise = 0.3 + (z_diff > 0.0 ? z_diff : 0.0);
7571
 
7594
 
7572
-            set_destination_to_current();
7573
-
7574
-            // Always raise by some amount
7595
+            // Always raise by some amount (destination copied from current_position earlier)
7575
             destination[Z_AXIS] += z_raise;
7596
             destination[Z_AXIS] += z_raise;
7576
             planner.buffer_line_kinematic(destination, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
7597
             planner.buffer_line_kinematic(destination, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
7577
             stepper.synchronize();
7598
             stepper.synchronize();
9260
               current_position[Z_AXIS],
9281
               current_position[Z_AXIS],
9261
               current_position[E_AXIS]
9282
               current_position[E_AXIS]
9262
             );
9283
             );
9263
-            planner.buffer_line(current_position[X_AXIS] + duplicate_extruder_x_offset,
9264
-                             current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], planner.max_feedrate_mm_s[X_AXIS], 1);
9284
+            planner.buffer_line(
9285
+              current_position[X_AXIS] + duplicate_extruder_x_offset,
9286
+              current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS],
9287
+              planner.max_feedrate_mm_s[X_AXIS], 1
9288
+            );
9265
             SYNC_PLAN_POSITION_KINEMATIC();
9289
             SYNC_PLAN_POSITION_KINEMATIC();
9266
             stepper.synchronize();
9290
             stepper.synchronize();
9267
             extruder_duplication_enabled = true;
9291
             extruder_duplication_enabled = true;

Loading…
Cancel
Save