Bläddra i källkod

Add M428 to set home_offset logically

Scott Lahteine 9 år sedan
förälder
incheckning
d065d37822
4 ändrade filer med 37 tillägg och 11 borttagningar
  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 Visa fil

@@ -189,6 +189,7 @@
189 189
  * M410 - Quickstop. Abort all the planned moves
190 190
  * M420 - Enable/Disable Mesh Leveling (with current values) S1=enable S0=disable
191 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 193
  * M500 - Store parameters in EEPROM
193 194
  * M501 - Read parameters from EEPROM (if you need reset them after you changed them temporarily).
194 195
  * M502 - Revert to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
@@ -4505,6 +4506,31 @@ inline void gcode_M410() { quickStop(); }
4505 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 4534
  * M500: Store settings in EEPROM
4509 4535
  */
4510 4536
 inline void gcode_M500() {
@@ -5353,6 +5379,10 @@ void process_commands() {
5353 5379
           break;
5354 5380
       #endif
5355 5381
 
5382
+      case 428: // M428 Apply current_position to home_offset
5383
+        gcode_M428();
5384
+        break;
5385
+
5356 5386
       case 500: // M500 Store settings in EEPROM
5357 5387
         gcode_M500();
5358 5388
         break;

+ 1
- 1
Marlin/configuration_store.cpp Visa fil

@@ -676,7 +676,7 @@ void Config_PrintSettings(bool forReplay) {
676 676
       SERIAL_ECHOLNPGM("Mesh bed leveling:");
677 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 680
     SERIAL_ECHOPAIR(" X", MESH_NUM_X_POINTS);
681 681
     SERIAL_ECHOPAIR(" Y", MESH_NUM_Y_POINTS);
682 682
     SERIAL_EOL;

+ 1
- 0
Marlin/language.h Visa fil

@@ -162,6 +162,7 @@
162 162
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
163 163
 #define MSG_ERR_M421_REQUIRES_XYZ           "M421 requires XYZ parameters"
164 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 166
 #define MSG_M119_REPORT                     "Reporting endstop status"
166 167
 #define MSG_ENDSTOP_HIT                     "TRIGGERED"
167 168
 #define MSG_ENDSTOP_OPEN                    "open"

+ 5
- 10
Marlin/ultralcd.cpp Visa fil

@@ -438,17 +438,12 @@ static void lcd_main_menu() {
438 438
   }
439 439
 #endif
440 440
 
441
+/**
442
+ * Set the home offset based on the current_position
443
+ */
441 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 447
   lcd_return_to_status();
453 448
 }
454 449
 

Laddar…
Avbryt
Spara