Browse Source

Update software endstop positions with M206, M428, G92, etc.

Scott Lahteine 9 years ago
parent
commit
8e5099fa0c
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,6 +283,8 @@ int extruder_multiplier[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100);
283 283
 bool volumetric_enabled = false;
284 284
 float filament_size[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_NOMINAL_FILAMENT_DIA);
285 285
 float volumetric_multiplier[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(1.0);
286
+
287
+float position_shift[3] = { 0 };
286 288
 float home_offset[3] = { 0 };
287 289
 float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
288 290
 float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
@@ -1190,6 +1192,45 @@ XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR);
1190 1192
 
1191 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 1234
 static void set_axis_is_at_home(AxisEnum axis) {
1194 1235
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1195 1236
     if (DEBUGGING(LEVELING)) {
@@ -1198,21 +1239,16 @@ static void set_axis_is_at_home(AxisEnum axis) {
1198 1239
     }
1199 1240
   #endif
1200 1241
 
1242
+  position_shift[axis] = 0;
1243
+
1201 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 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 1253
   #endif
1218 1254
 
@@ -1260,8 +1296,7 @@ static void set_axis_is_at_home(AxisEnum axis) {
1260 1296
   #endif
1261 1297
   {
1262 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 1301
     #if ENABLED(AUTO_BED_LEVELING_FEATURE) && Z_HOME_DIR < 0
1267 1302
       if (axis == Z_AXIS) {
@@ -3531,7 +3566,14 @@ inline void gcode_G92() {
3531 3566
   bool didXYZ = false;
3532 3567
   for (int i = 0; i < NUM_AXIS; i++) {
3533 3568
     if (code_seen(axis_codes[i])) {
3534
-      float v = current_position[i] = code_value();
3569
+      float p = current_position[i],
3570
+            v = code_value();
3571
+
3572
+      current_position[i] = v;
3573
+
3574
+      position_shift[i] += v - p; // Offset the coordinate space
3575
+      update_software_endstops((AxisEnum)i);
3576
+
3535 3577
       if (i == E_AXIS)
3536 3578
         plan_set_e_position(v);
3537 3579
       else
@@ -5020,13 +5062,6 @@ inline void gcode_M205() {
5020 5062
   if (code_seen('E')) max_e_jerk = code_value();
5021 5063
 }
5022 5064
 
5023
-static void set_home_offset(AxisEnum axis, float v) {
5024
-  min_pos[axis] = base_min_pos(axis) + v;
5025
-  max_pos[axis] = base_max_pos(axis) + v;
5026
-  current_position[axis] += v - home_offset[axis];
5027
-  home_offset[axis] = v;
5028
-}
5029
-
5030 5065
 /**
5031 5066
  * M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
5032 5067
  */

Loading…
Cancel
Save