Browse Source

Merge pull request #3227 from thinkyhead/rc_home_offsets_and_limits

Relating current_position, min_pos, max_pos, and home_offset
Scott Lahteine 9 years ago
parent
commit
88367a37f7
1 changed files with 58 additions and 23 deletions
  1. 58
    23
      Marlin/Marlin_main.cpp

+ 58
- 23
Marlin/Marlin_main.cpp View File

283
 bool volumetric_enabled = false;
283
 bool volumetric_enabled = false;
284
 float filament_size[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_NOMINAL_FILAMENT_DIA);
284
 float filament_size[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_NOMINAL_FILAMENT_DIA);
285
 float volumetric_multiplier[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(1.0);
285
 float volumetric_multiplier[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(1.0);
286
+
287
+float position_shift[3] = { 0 };
286
 float home_offset[3] = { 0 };
288
 float home_offset[3] = { 0 };
287
 float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
289
 float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
288
 float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
290
 float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
1190
 
1192
 
1191
 #endif //DUAL_X_CARRIAGE
1193
 #endif //DUAL_X_CARRIAGE
1192
 
1194
 
1195
+/**
1196
+ * Software endstops can be used to monitor the open end of
1197
+ * an axis that has a hardware endstop on the other end. Or
1198
+ * they can prevent axes from moving past endstops and grinding.
1199
+ *
1200
+ * To keep doing their job as the coordinate system changes,
1201
+ * the software endstop positions must be refreshed to remain
1202
+ * at the same positions relative to the machine.
1203
+ */
1204
+static void update_software_endstops(AxisEnum axis) {
1205
+  float offs = home_offset[axis] + position_shift[axis];
1206
+  #if ENABLED(DUAL_X_CARRIAGE)
1207
+    if (axis == X_AXIS) {
1208
+      float dual_max_x = max(extruder_offset[X_AXIS][1], X2_MAX_POS);
1209
+      if (active_extruder != 0) {
1210
+        min_pos[X_AXIS] = X2_MIN_POS + offs;
1211
+        max_pos[X_AXIS] = dual_max_x + offs;
1212
+        return;
1213
+      }
1214
+      else if (dual_x_carriage_mode == DXC_DUPLICATION_MODE) {
1215
+        min_pos[X_AXIS] = base_min_pos(X_AXIS) + offs;
1216
+        max_pos[X_AXIS] = min(base_max_pos(X_AXIS), dual_max_x - duplicate_extruder_x_offset) + offs;
1217
+        return;
1218
+      }
1219
+    }
1220
+    else
1221
+  #endif
1222
+  {
1223
+    min_pos[axis] = base_min_pos(axis) + offs;
1224
+    max_pos[axis] = base_max_pos(axis) + offs;
1225
+  }
1226
+}
1227
+
1228
+static void set_home_offset(AxisEnum axis, float v) {
1229
+  current_position[axis] += v - home_offset[axis];
1230
+  home_offset[axis] = v;
1231
+  update_software_endstops(axis);
1232
+}
1233
+
1193
 static void set_axis_is_at_home(AxisEnum axis) {
1234
 static void set_axis_is_at_home(AxisEnum axis) {
1194
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1235
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1195
     if (DEBUGGING(LEVELING)) {
1236
     if (DEBUGGING(LEVELING)) {
1198
     }
1239
     }
1199
   #endif
1240
   #endif
1200
 
1241
 
1242
+  position_shift[axis] = 0;
1243
+
1201
   #if ENABLED(DUAL_X_CARRIAGE)
1244
   #if ENABLED(DUAL_X_CARRIAGE)
1202
-    if (axis == X_AXIS) {
1203
-      if (active_extruder != 0) {
1245
+    if (axis == X_AXIS && (active_extruder != 0 || dual_x_carriage_mode == DXC_DUPLICATION_MODE)) {
1246
+      if (active_extruder != 0)
1204
         current_position[X_AXIS] = x_home_pos(active_extruder);
1247
         current_position[X_AXIS] = x_home_pos(active_extruder);
1205
-                 min_pos[X_AXIS] = X2_MIN_POS;
1206
-                 max_pos[X_AXIS] = max(extruder_offset[X_AXIS][1], X2_MAX_POS);
1207
-        return;
1208
-      }
1209
-      else if (dual_x_carriage_mode == DXC_DUPLICATION_MODE) {
1210
-        float xoff = home_offset[X_AXIS];
1211
-        current_position[X_AXIS] = base_home_pos(X_AXIS) + xoff;
1212
-                 min_pos[X_AXIS] = base_min_pos(X_AXIS) + xoff;
1213
-                 max_pos[X_AXIS] = min(base_max_pos(X_AXIS) + xoff, max(extruder_offset[X_AXIS][1], X2_MAX_POS) - duplicate_extruder_x_offset);
1214
-        return;
1215
-      }
1248
+      else
1249
+        current_position[X_AXIS] = base_home_pos(X_AXIS) + home_offset[X_AXIS];
1250
+      update_software_endstops(X_AXIS);
1251
+      return;
1216
     }
1252
     }
1217
   #endif
1253
   #endif
1218
 
1254
 
1260
   #endif
1296
   #endif
1261
   {
1297
   {
1262
     current_position[axis] = base_home_pos(axis) + home_offset[axis];
1298
     current_position[axis] = base_home_pos(axis) + home_offset[axis];
1263
-    min_pos[axis] = base_min_pos(axis) + home_offset[axis];
1264
-    max_pos[axis] = base_max_pos(axis) + home_offset[axis];
1299
+    update_software_endstops(axis);
1265
 
1300
 
1266
     #if ENABLED(AUTO_BED_LEVELING_FEATURE) && Z_HOME_DIR < 0
1301
     #if ENABLED(AUTO_BED_LEVELING_FEATURE) && Z_HOME_DIR < 0
1267
       if (axis == Z_AXIS) {
1302
       if (axis == Z_AXIS) {
3548
   bool didXYZ = false;
3583
   bool didXYZ = false;
3549
   for (int i = 0; i < NUM_AXIS; i++) {
3584
   for (int i = 0; i < NUM_AXIS; i++) {
3550
     if (code_seen(axis_codes[i])) {
3585
     if (code_seen(axis_codes[i])) {
3551
-      float v = current_position[i] = code_value();
3586
+      float p = current_position[i],
3587
+            v = code_value();
3588
+
3589
+      current_position[i] = v;
3590
+
3591
+      position_shift[i] += v - p; // Offset the coordinate space
3592
+      update_software_endstops((AxisEnum)i);
3593
+
3552
       if (i == E_AXIS)
3594
       if (i == E_AXIS)
3553
         plan_set_e_position(v);
3595
         plan_set_e_position(v);
3554
       else
3596
       else
5037
   if (code_seen('E')) max_e_jerk = code_value();
5079
   if (code_seen('E')) max_e_jerk = code_value();
5038
 }
5080
 }
5039
 
5081
 
5040
-static void set_home_offset(AxisEnum axis, float v) {
5041
-  min_pos[axis] = base_min_pos(axis) + v;
5042
-  max_pos[axis] = base_max_pos(axis) + v;
5043
-  current_position[axis] += v - home_offset[axis];
5044
-  home_offset[axis] = v;
5045
-}
5046
-
5047
 /**
5082
 /**
5048
  * M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
5083
  * M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
5049
  */
5084
  */

Loading…
Cancel
Save