Browse Source

Merge pull request #3620 from Blue-Marlin/feedrate_atfer_toolchange

Scott Lahteine 8 years ago
parent
commit
ad0f70f2f3
1 changed files with 112 additions and 109 deletions
  1. 112
    109
      Marlin/Marlin_main.cpp

+ 112
- 109
Marlin/Marlin_main.cpp View File

@@ -6304,131 +6304,134 @@ inline void gcode_T(uint8_t tmp_extruder) {
6304 6304
     SERIAL_CHAR('T');
6305 6305
     SERIAL_PROTOCOL_F(tmp_extruder, DEC);
6306 6306
     SERIAL_ECHOLN(MSG_INVALID_EXTRUDER);
6307
+    return;
6307 6308
   }
6308
-  else {
6309
-    target_extruder = tmp_extruder;
6310 6309
 
6311
-    #if EXTRUDERS > 1
6312
-      bool make_move = false;
6310
+  float stored_feedrate = feedrate;
6311
+
6312
+  if (code_seen('F')) {
6313
+    float next_feedrate = code_value();
6314
+    if (next_feedrate > 0.0) stored_feedrate = feedrate = next_feedrate;
6315
+  }
6316
+  else {
6317
+    #ifdef XY_TRAVEL_SPEED
6318
+      feedrate = XY_TRAVEL_SPEED;
6319
+    #else
6320
+      feedrate = min(max_feedrate[X_AXIS], max_feedrate[Y_AXIS]);
6313 6321
     #endif
6322
+  }
6314 6323
 
6315
-    if (code_seen('F')) {
6324
+  #if EXTRUDERS > 1
6325
+    if (tmp_extruder != active_extruder) {
6326
+      // Save current position to return to after applying extruder offset
6327
+      set_destination_to_current();
6328
+      #if ENABLED(DUAL_X_CARRIAGE)
6329
+        if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE && IsRunning() &&
6330
+            (delayed_move_time || current_position[X_AXIS] != x_home_pos(active_extruder))) {
6331
+          // Park old head: 1) raise 2) move to park position 3) lower
6332
+          plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT,
6333
+                           current_position[E_AXIS], max_feedrate[Z_AXIS], active_extruder);
6334
+          plan_buffer_line(x_home_pos(active_extruder), current_position[Y_AXIS], current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT,
6335
+                           current_position[E_AXIS], max_feedrate[X_AXIS], active_extruder);
6336
+          plan_buffer_line(x_home_pos(active_extruder), current_position[Y_AXIS], current_position[Z_AXIS],
6337
+                           current_position[E_AXIS], max_feedrate[Z_AXIS], active_extruder);
6338
+          st_synchronize();
6339
+        }
6316 6340
 
6317
-      #if EXTRUDERS > 1
6318
-        make_move = true;
6319
-      #endif
6341
+        // apply Y & Z extruder offset (x offset is already used in determining home pos)
6342
+        current_position[Y_AXIS] -= extruder_offset[Y_AXIS][active_extruder] - extruder_offset[Y_AXIS][tmp_extruder];
6343
+        current_position[Z_AXIS] -= extruder_offset[Z_AXIS][active_extruder] - extruder_offset[Z_AXIS][tmp_extruder];
6344
+        active_extruder = tmp_extruder;
6320 6345
 
6321
-      float next_feedrate = code_value();
6322
-      if (next_feedrate > 0.0) feedrate = next_feedrate;
6323
-    }
6324
-    #if EXTRUDERS > 1
6325
-      if (tmp_extruder != active_extruder) {
6326
-        // Save current position to return to after applying extruder offset
6327
-        set_destination_to_current();
6328
-        #if ENABLED(DUAL_X_CARRIAGE)
6329
-          if (dual_x_carriage_mode == DXC_AUTO_PARK_MODE && IsRunning() &&
6330
-              (delayed_move_time || current_position[X_AXIS] != x_home_pos(active_extruder))) {
6331
-            // Park old head: 1) raise 2) move to park position 3) lower
6332
-            plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT,
6333
-                             current_position[E_AXIS], max_feedrate[Z_AXIS], active_extruder);
6334
-            plan_buffer_line(x_home_pos(active_extruder), current_position[Y_AXIS], current_position[Z_AXIS] + TOOLCHANGE_PARK_ZLIFT,
6335
-                             current_position[E_AXIS], max_feedrate[X_AXIS], active_extruder);
6336
-            plan_buffer_line(x_home_pos(active_extruder), current_position[Y_AXIS], current_position[Z_AXIS],
6337
-                             current_position[E_AXIS], max_feedrate[Z_AXIS], active_extruder);
6338
-            st_synchronize();
6339
-          }
6346
+        // This function resets the max/min values - the current position may be overwritten below.
6347
+        set_axis_is_at_home(X_AXIS);
6340 6348
 
6341
-          // apply Y & Z extruder offset (x offset is already used in determining home pos)
6342
-          current_position[Y_AXIS] -= extruder_offset[Y_AXIS][active_extruder] - extruder_offset[Y_AXIS][tmp_extruder];
6343
-          current_position[Z_AXIS] -= extruder_offset[Z_AXIS][active_extruder] - extruder_offset[Z_AXIS][tmp_extruder];
6344
-          active_extruder = tmp_extruder;
6349
+        if (dual_x_carriage_mode == DXC_FULL_CONTROL_MODE) {
6350
+          current_position[X_AXIS] = inactive_extruder_x_pos;
6351
+          inactive_extruder_x_pos = destination[X_AXIS];
6352
+        }
6353
+        else if (dual_x_carriage_mode == DXC_DUPLICATION_MODE) {
6354
+          active_extruder_parked = (active_extruder == 0); // this triggers the second extruder to move into the duplication position
6355
+          if (active_extruder_parked)
6356
+            current_position[X_AXIS] = inactive_extruder_x_pos;
6357
+          else
6358
+            current_position[X_AXIS] = destination[X_AXIS] + duplicate_extruder_x_offset;
6359
+          inactive_extruder_x_pos = destination[X_AXIS];
6360
+          extruder_duplication_enabled = false;
6361
+        }
6362
+        else {
6363
+          // record raised toolhead position for use by unpark
6364
+          memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
6365
+          raised_parked_position[Z_AXIS] += TOOLCHANGE_UNPARK_ZLIFT;
6366
+          active_extruder_parked = true;
6367
+          delayed_move_time = 0;
6368
+        }
6369
+        // No extra case for AUTO_BED_LEVELING_FEATURE in DUAL_X_CARRIAGE. Does that mean they don't work together?
6370
+      #else // !DUAL_X_CARRIAGE
6371
+        #if ENABLED(AUTO_BED_LEVELING_FEATURE)
6372
+          // Offset extruder, make sure to apply the bed level rotation matrix
6373
+          vector_3 tmp_offset_vec = vector_3(extruder_offset[X_AXIS][tmp_extruder],
6374
+                                             extruder_offset[Y_AXIS][tmp_extruder],
6375
+                                             0),
6376
+                   act_offset_vec = vector_3(extruder_offset[X_AXIS][active_extruder],
6377
+                                             extruder_offset[Y_AXIS][active_extruder],
6378
+                                             0),
6379
+                   offset_vec = tmp_offset_vec - act_offset_vec;
6345 6380
 
6346
-          // This function resets the max/min values - the current position may be overwritten below.
6347
-          set_axis_is_at_home(X_AXIS);
6381
+          #if ENABLED(DEBUG_LEVELING_FEATURE)
6382
+            if (DEBUGGING(LEVELING)) {
6383
+              SERIAL_ECHOLNPGM(">>> gcode_T");
6384
+              tmp_offset_vec.debug("tmp_offset_vec");
6385
+              act_offset_vec.debug("act_offset_vec");
6386
+              offset_vec.debug("offset_vec (BEFORE)");
6387
+              DEBUG_POS("BEFORE rotation", current_position);
6388
+            }
6389
+          #endif
6348 6390
 
6349
-          if (dual_x_carriage_mode == DXC_FULL_CONTROL_MODE) {
6350
-            current_position[X_AXIS] = inactive_extruder_x_pos;
6351
-            inactive_extruder_x_pos = destination[X_AXIS];
6352
-          }
6353
-          else if (dual_x_carriage_mode == DXC_DUPLICATION_MODE) {
6354
-            active_extruder_parked = (active_extruder == 0); // this triggers the second extruder to move into the duplication position
6355
-            if (active_extruder == 0 || active_extruder_parked)
6356
-              current_position[X_AXIS] = inactive_extruder_x_pos;
6357
-            else
6358
-              current_position[X_AXIS] = destination[X_AXIS] + duplicate_extruder_x_offset;
6359
-            inactive_extruder_x_pos = destination[X_AXIS];
6360
-            extruder_duplication_enabled = false;
6361
-          }
6362
-          else {
6363
-            // record raised toolhead position for use by unpark
6364
-            memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
6365
-            raised_parked_position[Z_AXIS] += TOOLCHANGE_UNPARK_ZLIFT;
6366
-            active_extruder_parked = true;
6367
-            delayed_move_time = 0;
6368
-          }
6369
-        #else // !DUAL_X_CARRIAGE
6370
-          #if ENABLED(AUTO_BED_LEVELING_FEATURE)
6371
-            // Offset extruder, make sure to apply the bed level rotation matrix
6372
-            vector_3 tmp_offset_vec = vector_3(extruder_offset[X_AXIS][tmp_extruder],
6373
-                                               extruder_offset[Y_AXIS][tmp_extruder],
6374
-                                               0),
6375
-                     act_offset_vec = vector_3(extruder_offset[X_AXIS][active_extruder],
6376
-                                               extruder_offset[Y_AXIS][active_extruder],
6377
-                                               0),
6378
-                     offset_vec = tmp_offset_vec - act_offset_vec;
6391
+          offset_vec.apply_rotation(plan_bed_level_matrix.transpose(plan_bed_level_matrix));
6379 6392
 
6380
-            #if ENABLED(DEBUG_LEVELING_FEATURE)
6381
-              if (DEBUGGING(LEVELING)) {
6382
-                SERIAL_ECHOLNPGM(">>> gcode_T");
6383
-                tmp_offset_vec.debug("tmp_offset_vec");
6384
-                act_offset_vec.debug("act_offset_vec");
6385
-                offset_vec.debug("offset_vec (BEFORE)");
6386
-                DEBUG_POS("BEFORE rotation", current_position);
6387
-              }
6388
-            #endif
6393
+          current_position[X_AXIS] += offset_vec.x;
6394
+          current_position[Y_AXIS] += offset_vec.y;
6395
+          current_position[Z_AXIS] += offset_vec.z;
6389 6396
 
6390
-            offset_vec.apply_rotation(plan_bed_level_matrix.transpose(plan_bed_level_matrix));
6397
+          #if ENABLED(DEBUG_LEVELING_FEATURE)
6398
+            if (DEBUGGING(LEVELING)) {
6399
+              offset_vec.debug("offset_vec (AFTER)");
6400
+              DEBUG_POS("AFTER rotation", current_position);
6401
+              SERIAL_ECHOLNPGM("<<< gcode_T");
6402
+            }
6403
+          #endif
6391 6404
 
6392
-            current_position[X_AXIS] += offset_vec.x;
6393
-            current_position[Y_AXIS] += offset_vec.y;
6394
-            current_position[Z_AXIS] += offset_vec.z;
6405
+        #else // !AUTO_BED_LEVELING_FEATURE
6406
+          // Offset extruder (only by XY)
6407
+          for (int i=X_AXIS; i<=Y_AXIS; i++)
6408
+            current_position[i] += extruder_offset[i][tmp_extruder] - extruder_offset[i][active_extruder];
6409
+        #endif // !AUTO_BED_LEVELING_FEATURE
6410
+        // Set the new active extruder and position
6411
+        active_extruder = tmp_extruder;
6412
+      #endif // !DUAL_X_CARRIAGE
6413
+      #if ENABLED(DELTA)
6414
+        sync_plan_position_delta();
6415
+      #else
6416
+        sync_plan_position();
6417
+      #endif
6418
+      // Move to the old position
6419
+      if (IsRunning()) prepare_move();
6420
+    } // (tmp_extruder != active_extruder)
6395 6421
 
6396
-            #if ENABLED(DEBUG_LEVELING_FEATURE)
6397
-              if (DEBUGGING(LEVELING)) {
6398
-                offset_vec.debug("offset_vec (AFTER)");
6399
-                DEBUG_POS("AFTER rotation", current_position);
6400
-                SERIAL_ECHOLNPGM("<<< gcode_T");
6401
-              }
6402
-            #endif
6422
+    #if ENABLED(EXT_SOLENOID)
6423
+      st_synchronize();
6424
+      disable_all_solenoids();
6425
+      enable_solenoid_on_active_extruder();
6426
+    #endif // EXT_SOLENOID
6403 6427
 
6404
-          #else // !AUTO_BED_LEVELING_FEATURE
6405
-            // Offset extruder (only by XY)
6406
-            for (int i=X_AXIS; i<=Y_AXIS; i++)
6407
-              current_position[i] += extruder_offset[i][tmp_extruder] - extruder_offset[i][active_extruder];
6408
-          #endif // !AUTO_BED_LEVELING_FEATURE
6409
-          // Set the new active extruder and position
6410
-          active_extruder = tmp_extruder;
6411
-        #endif // !DUAL_X_CARRIAGE
6412
-        #if ENABLED(DELTA)
6413
-          sync_plan_position_delta();
6414
-        #else
6415
-          sync_plan_position();
6416
-        #endif
6417
-        // Move to the old position if 'F' was in the parameters
6418
-        if (make_move && IsRunning()) prepare_move();
6419
-      }
6428
+  #endif // EXTRUDERS > 1
6420 6429
 
6421
-      #if ENABLED(EXT_SOLENOID)
6422
-        st_synchronize();
6423
-        disable_all_solenoids();
6424
-        enable_solenoid_on_active_extruder();
6425
-      #endif // EXT_SOLENOID
6430
+  feedrate = stored_feedrate;
6426 6431
 
6427
-    #endif // EXTRUDERS > 1
6428
-    SERIAL_ECHO_START;
6429
-    SERIAL_ECHO(MSG_ACTIVE_EXTRUDER);
6430
-    SERIAL_PROTOCOLLN((int)active_extruder);
6431
-  }
6432
+  SERIAL_ECHO_START;
6433
+  SERIAL_ECHO(MSG_ACTIVE_EXTRUDER);
6434
+  SERIAL_PROTOCOLLN((int)active_extruder);
6432 6435
 }
6433 6436
 
6434 6437
 /**

Loading…
Cancel
Save