Browse Source

Add M428 to set home_offset logically

Scott Lahteine 10 years ago
parent
commit
d065d37822
4 changed files with 37 additions and 11 deletions
  1. 30
    0
      Marlin/Marlin_main.cpp
  2. 1
    1
      Marlin/configuration_store.cpp
  3. 1
    0
      Marlin/language.h
  4. 5
    10
      Marlin/ultralcd.cpp

+ 30
- 0
Marlin/Marlin_main.cpp View File

189
  * M410 - Quickstop. Abort all the planned moves
189
  * M410 - Quickstop. Abort all the planned moves
190
  * M420 - Enable/Disable Mesh Leveling (with current values) S1=enable S0=disable
190
  * M420 - Enable/Disable Mesh Leveling (with current values) S1=enable S0=disable
191
  * M421 - Set a single Z coordinate in the Mesh Leveling grid. X<mm> Y<mm> Z<mm>
191
  * M421 - Set a single Z coordinate in the Mesh Leveling grid. X<mm> Y<mm> Z<mm>
192
+ * M428 - Set the home_offset logically based on the current_position
192
  * M500 - Store parameters in EEPROM
193
  * M500 - Store parameters in EEPROM
193
  * M501 - Read parameters from EEPROM (if you need reset them after you changed them temporarily).
194
  * M501 - Read parameters from EEPROM (if you need reset them after you changed them temporarily).
194
  * M502 - Revert to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
195
  * M502 - Revert to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
4505
 #endif
4506
 #endif
4506
 
4507
 
4507
 /**
4508
 /**
4509
+ * M428: Set home_offset based on the distance between the
4510
+ *       current_position and the nearest "reference position."
4511
+ *       If an axis is past center the endstop position
4512
+ *       is the reference-point. Otherwise it uses 0. This allows
4513
+ *       the Z offset to be set near the bed when using a max endstop.
4514
+ *
4515
+ *       Use M206 to set these values directly.
4516
+ */
4517
+inline void gcode_M428() {
4518
+  for (int8_t i = X_AXIS; i <= Z_AXIS; i++) {
4519
+    float base = (current_position[i] > (min_pos[i] + max_pos[i]) / 2) ? base_home_pos(i) : 0,
4520
+          diff = current_position[i] - base;
4521
+    if (diff > -20 && diff < 20) {
4522
+      home_offset[i] -= diff;
4523
+      current_position[i] = base;
4524
+    }
4525
+    else {
4526
+      SERIAL_ERROR_START;
4527
+      SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
4528
+    }
4529
+  }
4530
+  sync_plan_position();
4531
+}
4532
+
4533
+/**
4508
  * M500: Store settings in EEPROM
4534
  * M500: Store settings in EEPROM
4509
  */
4535
  */
4510
 inline void gcode_M500() {
4536
 inline void gcode_M500() {
5353
           break;
5379
           break;
5354
       #endif
5380
       #endif
5355
 
5381
 
5382
+      case 428: // M428 Apply current_position to home_offset
5383
+        gcode_M428();
5384
+        break;
5385
+
5356
       case 500: // M500 Store settings in EEPROM
5386
       case 500: // M500 Store settings in EEPROM
5357
         gcode_M500();
5387
         gcode_M500();
5358
         break;
5388
         break;

+ 1
- 1
Marlin/configuration_store.cpp View File

676
       SERIAL_ECHOLNPGM("Mesh bed leveling:");
676
       SERIAL_ECHOLNPGM("Mesh bed leveling:");
677
       CONFIG_ECHO_START;
677
       CONFIG_ECHO_START;
678
     }
678
     }
679
-    SERIAL_ECHOPAIR("  M420 S", (int32_t)mbl.active);
679
+    SERIAL_ECHOPAIR("  M420 S", (unsigned long)mbl.active);
680
     SERIAL_ECHOPAIR(" X", MESH_NUM_X_POINTS);
680
     SERIAL_ECHOPAIR(" X", MESH_NUM_X_POINTS);
681
     SERIAL_ECHOPAIR(" Y", MESH_NUM_Y_POINTS);
681
     SERIAL_ECHOPAIR(" Y", MESH_NUM_Y_POINTS);
682
     SERIAL_EOL;
682
     SERIAL_EOL;

+ 1
- 0
Marlin/language.h View File

162
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
162
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
163
 #define MSG_ERR_M421_REQUIRES_XYZ           "M421 requires XYZ parameters"
163
 #define MSG_ERR_M421_REQUIRES_XYZ           "M421 requires XYZ parameters"
164
 #define MSG_ERR_MESH_INDEX_OOB              "Mesh XY index is out of bounds"
164
 #define MSG_ERR_MESH_INDEX_OOB              "Mesh XY index is out of bounds"
165
+#define MSG_ERR_M428_TOO_FAR                "Too far from home or origin position"
165
 #define MSG_M119_REPORT                     "Reporting endstop status"
166
 #define MSG_M119_REPORT                     "Reporting endstop status"
166
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
167
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
167
 #define MSG_ENDSTOP_OPEN                    "open"
168
 #define MSG_ENDSTOP_OPEN                    "open"

+ 5
- 10
Marlin/ultralcd.cpp View File

438
   }
438
   }
439
 #endif
439
 #endif
440
 
440
 
441
+/**
442
+ * Set the home offset based on the current_position
443
+ */
441
 void lcd_set_home_offsets() {
444
 void lcd_set_home_offsets() {
442
-  for (int8_t i=0; i < NUM_AXIS; i++) {
443
-    if (i != E_AXIS) {
444
-      home_offset[i] -= current_position[i];
445
-      current_position[i] = 0.0;
446
-    }
447
-  }
448
-  plan_set_position(0.0, 0.0, 0.0, current_position[E_AXIS]);
449
-
450
-  // Audio feedback
451
-  enqueuecommands_P(PSTR("M300 S659 P200\nM300 S698 P200"));
445
+  // Command with Audio feedback
446
+  enqueuecommands_P(PSTR("M428\nM300 S659 P200\nM300 S698 P200"));
452
   lcd_return_to_status();
447
   lcd_return_to_status();
453
 }
448
 }
454
 
449
 

Loading…
Cancel
Save