Browse Source

M421 Mesh Point Offset and misc. UBL clean up (#6685)

* M421 Mesh Point Offset and misc. UBL clean up

Allow M421 to accept an offset as well as absolute value for a specified
mesh point.
And misc. UBL clean up to reduce redundent code.

* Better error checking for M421

* Fix M421 Y index bug

I just noticed....  We've had a Y index bug for who knows how long?
Roxy-3D 7 years ago
parent
commit
b63e82f309
5 changed files with 62 additions and 83 deletions
  1. 24
    10
      Marlin/Marlin_main.cpp
  2. 1
    26
      Marlin/configuration_store.cpp
  3. 1
    1
      Marlin/language.h
  4. 0
    1
      Marlin/ubl.h
  5. 36
    45
      Marlin/ubl_G29.cpp

+ 24
- 10
Marlin/Marlin_main.cpp View File

8473
    * M421: Set a single Mesh Bed Leveling Z coordinate
8473
    * M421: Set a single Mesh Bed Leveling Z coordinate
8474
    *
8474
    *
8475
    *   M421 I<xindex> J<yindex> Z<linear>
8475
    *   M421 I<xindex> J<yindex> Z<linear>
8476
+   *   or
8477
+   *   M421 I<xindex> J<yindex> Q<offset>
8476
    */
8478
    */
8477
   inline void gcode_M421() {
8479
   inline void gcode_M421() {
8478
     int8_t px = 0, py = 0;
8480
     int8_t px = 0, py = 0;
8479
     float z = 0;
8481
     float z = 0;
8480
-    bool hasI, hasJ, hasZ;
8482
+    bool hasI, hasJ, hasZ, hasQ;
8481
     if ((hasI = code_seen('I'))) px = code_value_linear_units();
8483
     if ((hasI = code_seen('I'))) px = code_value_linear_units();
8482
     if ((hasJ = code_seen('J'))) py = code_value_linear_units();
8484
     if ((hasJ = code_seen('J'))) py = code_value_linear_units();
8483
     if ((hasZ = code_seen('Z'))) z = code_value_linear_units();
8485
     if ((hasZ = code_seen('Z'))) z = code_value_linear_units();
8486
+    if ((hasQ = code_seen('Q'))) z = code_value_linear_units();
8484
 
8487
 
8485
-    if (hasI && hasJ && hasZ) {
8486
-      if (WITHIN(px, 0, GRID_MAX_POINTS_X - 1) && WITHIN(py, 0, GRID_MAX_POINTS_X - 1)) {
8488
+    if (!hasI || !hasJ || (hasQ && hasZ) || (!hasQ && !hasZ)) {
8489
+      SERIAL_ERROR_START;
8490
+      SERIAL_ERRORLNPGM(MSG_ERR_M421_PARAMETERS);
8491
+      return;
8492
+    }
8493
+
8494
+    if (WITHIN(px, 0, GRID_MAX_POINTS_X - 1) && WITHIN(py, 0, GRID_MAX_POINTS_Y - 1)) {
8495
+      if (hasZ) { // doing an absolute mesh value
8487
         #if ENABLED(AUTO_BED_LEVELING_UBL)
8496
         #if ENABLED(AUTO_BED_LEVELING_UBL)
8488
           ubl.z_values[px][py] = z;
8497
           ubl.z_values[px][py] = z;
8489
         #else
8498
         #else
8492
             bed_level_virt_interpolate();
8501
             bed_level_virt_interpolate();
8493
           #endif
8502
           #endif
8494
         #endif
8503
         #endif
8495
-      }
8496
-      else {
8497
-        SERIAL_ERROR_START;
8498
-        SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY);
8504
+      } 
8505
+      else { // doing an offset of a mesh value
8506
+        #if ENABLED(AUTO_BED_LEVELING_UBL)
8507
+          ubl.z_values[px][py] += z;
8508
+        #else
8509
+          z_values[px][py] += z;
8510
+          #if ENABLED(ABL_BILINEAR_SUBDIVISION)
8511
+            bed_level_virt_interpolate();
8512
+          #endif
8513
+        #endif
8499
       }
8514
       }
8500
     }
8515
     }
8501
-    else {
8516
+    else { // bad indexes were specified for the mesh point
8502
       SERIAL_ERROR_START;
8517
       SERIAL_ERROR_START;
8503
-      SERIAL_ERRORLNPGM(MSG_ERR_M421_PARAMETERS);
8518
+      SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY);
8504
     }
8519
     }
8505
   }
8520
   }
8506
-
8507
 #endif
8521
 #endif
8508
 
8522
 
8509
 #if HAS_M206_COMMAND
8523
 #if HAS_M206_COMMAND

+ 1
- 26
Marlin/configuration_store.cpp View File

1459
       SERIAL_EOL;
1459
       SERIAL_EOL;
1460
 
1460
 
1461
       if (!forReplay) {
1461
       if (!forReplay) {
1462
-        SERIAL_ECHOPGM("\nUBL is ");
1463
-        ubl.state.active ? SERIAL_CHAR('A') : SERIAL_ECHOPGM("Ina");
1464
-        SERIAL_ECHOLNPAIR("ctive\n\nActive Mesh Slot: ", ubl.state.eeprom_storage_slot);
1462
+        ubl.g29_what_command();        
1465
 
1463
 
1466
-        SERIAL_ECHOPGM("z_offset: ");
1467
-        SERIAL_ECHO_F(ubl.state.z_offset, 6);
1468
-        SERIAL_EOL;
1469
-
1470
-        SERIAL_ECHOPAIR("EEPROM can hold ", (int)((UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values)));
1471
-        SERIAL_ECHOLNPGM(" meshes.\n");
1472
-
1473
-        SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_X  ", GRID_MAX_POINTS_X);
1474
-        SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_Y  ", GRID_MAX_POINTS_Y);
1475
-
1476
-        SERIAL_ECHOPGM("UBL_MESH_MIN_X  " STRINGIFY(UBL_MESH_MIN_X));
1477
-        SERIAL_ECHOLNPAIR("=", UBL_MESH_MIN_X );
1478
-        SERIAL_ECHOPGM("UBL_MESH_MIN_Y  " STRINGIFY(UBL_MESH_MIN_Y));
1479
-        SERIAL_ECHOLNPAIR("=", UBL_MESH_MIN_Y );
1480
-
1481
-        SERIAL_ECHOPGM("UBL_MESH_MAX_X  " STRINGIFY(UBL_MESH_MAX_X));
1482
-        SERIAL_ECHOLNPAIR("=", UBL_MESH_MAX_X);
1483
-        SERIAL_ECHOPGM("UBL_MESH_MAX_Y  " STRINGIFY(UBL_MESH_MAX_Y));
1484
-        SERIAL_ECHOLNPAIR("=", UBL_MESH_MAX_Y);
1485
-
1486
-        SERIAL_ECHOLNPAIR("MESH_X_DIST  ", MESH_X_DIST);
1487
-        SERIAL_ECHOLNPAIR("MESH_Y_DIST  ", MESH_Y_DIST);
1488
-        SERIAL_EOL;
1489
       }
1464
       }
1490
 
1465
 
1491
     #elif HAS_ABL
1466
     #elif HAS_ABL

+ 1
- 1
Marlin/language.h View File

155
 #define MSG_FILAMENT_RUNOUT_SENSOR          "filament: "
155
 #define MSG_FILAMENT_RUNOUT_SENSOR          "filament: "
156
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
156
 #define MSG_ERR_MATERIAL_INDEX              "M145 S<index> out of range (0-1)"
157
 #define MSG_ERR_M355_NONE                   "No case light"
157
 #define MSG_ERR_M355_NONE                   "No case light"
158
-#define MSG_ERR_M421_PARAMETERS             "M421 required parameters missing"
158
+#define MSG_ERR_M421_PARAMETERS             "M421 incorrect parameter usage"
159
 #define MSG_ERR_MESH_XY                     "Mesh point cannot be resolved"
159
 #define MSG_ERR_MESH_XY                     "Mesh point cannot be resolved"
160
 #define MSG_ERR_ARC_ARGS                    "G2/G3 bad parameters"
160
 #define MSG_ERR_ARC_ARGS                    "G2/G3 bad parameters"
161
 #define MSG_ERR_PROTECTED_PIN               "Protected Pin"
161
 #define MSG_ERR_PROTECTED_PIN               "Protected Pin"

+ 0
- 1
Marlin/ubl.h View File

63
   void shift_mesh_height();
63
   void shift_mesh_height();
64
   void fine_tune_mesh(const float&, const float&, const bool);
64
   void fine_tune_mesh(const float&, const float&, const bool);
65
   bool g29_parameter_parsing();
65
   bool g29_parameter_parsing();
66
-  void g29_what_command();
67
   void g29_eeprom_dump();
66
   void g29_eeprom_dump();
68
   void g29_compare_current_mesh_to_stored_mesh();
67
   void g29_compare_current_mesh_to_stored_mesh();
69
 
68
 

+ 36
- 45
Marlin/ubl_G29.cpp View File

520
     // Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
520
     // Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
521
     // good to have the extra information. Soon... we prune this to just a few items
521
     // good to have the extra information. Soon... we prune this to just a few items
522
     //
522
     //
523
-    if (code_seen('W')) g29_what_command();
524
-
523
+    if (code_seen('W')) ubl.g29_what_command();
524
+ 
525
     //
525
     //
526
     // When we are fully debugged, the EEPROM dump command will get deleted also. But
526
     // When we are fully debugged, the EEPROM dump command will get deleted also. But
527
     // right now, it is good to have the extra information. Soon... we prune this.
527
     // right now, it is good to have the extra information. Soon... we prune this.
1181
    * Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
1181
    * Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
1182
    * good to have the extra information. Soon... we prune this to just a few items
1182
    * good to have the extra information. Soon... we prune this to just a few items
1183
    */
1183
    */
1184
-  void g29_what_command() {
1184
+  void unified_bed_leveling::g29_what_command() {
1185
     const uint16_t k = E2END - ubl.eeprom_start;
1185
     const uint16_t k = E2END - ubl.eeprom_start;
1186
 
1186
 
1187
     say_ubl_name();
1187
     say_ubl_name();
1205
     SERIAL_PROTOCOLLNPAIR("UBL object count: ", (int)ubl_cnt);
1205
     SERIAL_PROTOCOLLNPAIR("UBL object count: ", (int)ubl_cnt);
1206
 
1206
 
1207
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1207
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1208
-      SERIAL_PROTOCOLLNPAIR("planner.z_fade_height : ", planner.z_fade_height);
1208
+      SERIAL_PROTOCOL("planner.z_fade_height : ");
1209
+      SERIAL_PROTOCOL_F(planner.z_fade_height, 4);
1210
+      SERIAL_EOL;
1209
     #endif
1211
     #endif
1210
     SERIAL_PROTOCOLPGM("zprobe_zoffset: ");
1212
     SERIAL_PROTOCOLPGM("zprobe_zoffset: ");
1211
     SERIAL_PROTOCOL_F(zprobe_zoffset, 7);
1213
     SERIAL_PROTOCOL_F(zprobe_zoffset, 7);
1212
     SERIAL_EOL;
1214
     SERIAL_EOL;
1213
 
1215
 
1214
-    SERIAL_PROTOCOLPGM("z_offset: ");
1215
-    SERIAL_PROTOCOL_F(ubl.state.z_offset, 7);
1216
-    SERIAL_EOL;
1216
+    SERIAL_PROTOCOLLNPAIR("ubl.eeprom_start=", hex_address((void*)ubl.eeprom_start));
1217
+
1218
+    SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_X  ", GRID_MAX_POINTS_X);
1219
+    SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_Y  ", GRID_MAX_POINTS_Y);
1217
     safe_delay(25);
1220
     safe_delay(25);
1218
 
1221
 
1219
-    SERIAL_PROTOCOLLNPAIR("ubl.eeprom_start=", hex_address((void*)ubl.eeprom_start));
1222
+    SERIAL_ECHOLNPAIR("MESH_X_DIST  ", MESH_X_DIST);
1223
+    SERIAL_ECHOLNPAIR("MESH_Y_DIST  ", MESH_Y_DIST);
1224
+    safe_delay(25);
1220
 
1225
 
1221
     SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
1226
     SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
1222
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1227
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1223
-      SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(pgm_read_float(&ubl.mesh_index_to_xpos[i])), 1);
1228
+      SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(pgm_read_float(&ubl.mesh_index_to_xpos[i])), 3);
1224
       SERIAL_PROTOCOLPGM("  ");
1229
       SERIAL_PROTOCOLPGM("  ");
1225
-      safe_delay(50);
1230
+      safe_delay(25);
1226
     }
1231
     }
1227
     SERIAL_EOL;
1232
     SERIAL_EOL;
1228
 
1233
 
1229
     SERIAL_PROTOCOLPGM("Y-Axis Mesh Points at: ");
1234
     SERIAL_PROTOCOLPGM("Y-Axis Mesh Points at: ");
1230
     for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; i++) {
1235
     for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; i++) {
1231
-      SERIAL_PROTOCOL_F(LOGICAL_Y_POSITION(pgm_read_float(&ubl.mesh_index_to_ypos[i])), 1);
1236
+      SERIAL_PROTOCOL_F(LOGICAL_Y_POSITION(pgm_read_float(&ubl.mesh_index_to_ypos[i])), 3);
1232
       SERIAL_PROTOCOLPGM("  ");
1237
       SERIAL_PROTOCOLPGM("  ");
1233
-      safe_delay(50);
1238
+      safe_delay(25);
1234
     }
1239
     }
1235
     SERIAL_EOL;
1240
     SERIAL_EOL;
1236
 
1241
 
1237
-    #if HAS_KILL
1238
-      SERIAL_PROTOCOLPAIR("Kill pin on :", KILL_PIN);
1239
-      SERIAL_PROTOCOLLNPAIR("  state:", READ(KILL_PIN));
1240
-    #endif
1241
-    SERIAL_EOL;
1242
-    safe_delay(50);
1243
-
1244
-    SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
1245
-    SERIAL_EOL;
1246
-    SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
1247
-    SERIAL_EOL;
1248
-    safe_delay(50);
1249
     SERIAL_PROTOCOLLNPAIR("Free EEPROM space starts at: ", hex_address((void*)ubl.eeprom_start));
1242
     SERIAL_PROTOCOLLNPAIR("Free EEPROM space starts at: ", hex_address((void*)ubl.eeprom_start));
1243
+    SERIAL_PROTOCOLLNPAIR("end of EEPROM: ", hex_address((void*)E2END));
1244
+    safe_delay(25);
1250
 
1245
 
1251
-    SERIAL_PROTOCOLLNPAIR("end of EEPROM              : ", hex_address((void*)E2END));
1252
-    safe_delay(50);
1253
-
1254
-    SERIAL_PROTOCOLLNPAIR("sizeof(ubl) :  ", (int)sizeof(ubl));
1246
+    SERIAL_PROTOCOLPAIR("sizeof(ubl.state) : ", (int)sizeof(ubl.state));
1255
     SERIAL_EOL;
1247
     SERIAL_EOL;
1256
     SERIAL_PROTOCOLLNPAIR("z_value[][] size: ", (int)sizeof(ubl.z_values));
1248
     SERIAL_PROTOCOLLNPAIR("z_value[][] size: ", (int)sizeof(ubl.z_values));
1257
     SERIAL_EOL;
1249
     SERIAL_EOL;
1258
-    safe_delay(50);
1250
+    safe_delay(25);
1259
 
1251
 
1260
     SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: ", hex_address((void*)k));
1252
     SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: ", hex_address((void*)k));
1261
-    safe_delay(50);
1253
+    safe_delay(25);
1262
 
1254
 
1263
     SERIAL_PROTOCOLPAIR("EEPROM can hold ", k / sizeof(ubl.z_values));
1255
     SERIAL_PROTOCOLPAIR("EEPROM can hold ", k / sizeof(ubl.z_values));
1264
     SERIAL_PROTOCOLLNPGM(" meshes.\n");
1256
     SERIAL_PROTOCOLLNPGM(" meshes.\n");
1265
-    safe_delay(50);
1266
-
1267
-    SERIAL_PROTOCOLPAIR("sizeof(ubl.state) : ", (int)sizeof(ubl.state));
1257
+    safe_delay(25);
1268
 
1258
 
1269
     SERIAL_PROTOCOLPAIR("\nGRID_MAX_POINTS_X  ", GRID_MAX_POINTS_X);
1259
     SERIAL_PROTOCOLPAIR("\nGRID_MAX_POINTS_X  ", GRID_MAX_POINTS_X);
1270
     SERIAL_PROTOCOLPAIR("\nGRID_MAX_POINTS_Y  ", GRID_MAX_POINTS_Y);
1260
     SERIAL_PROTOCOLPAIR("\nGRID_MAX_POINTS_Y  ", GRID_MAX_POINTS_Y);
1271
-    safe_delay(50);
1272
-    SERIAL_PROTOCOLPAIR("\nUBL_MESH_MIN_X         ", UBL_MESH_MIN_X);
1273
-    SERIAL_PROTOCOLPAIR("\nUBL_MESH_MIN_Y         ", UBL_MESH_MIN_Y);
1274
-    safe_delay(50);
1275
-    SERIAL_PROTOCOLPAIR("\nUBL_MESH_MAX_X         ", UBL_MESH_MAX_X);
1276
-    SERIAL_PROTOCOLPAIR("\nUBL_MESH_MAX_Y         ", UBL_MESH_MAX_Y);
1277
-    safe_delay(50);
1278
-    SERIAL_PROTOCOLPGM("\nMESH_X_DIST        ");
1279
-    SERIAL_PROTOCOL_F(MESH_X_DIST, 6);
1280
-    SERIAL_PROTOCOLPGM("\nMESH_Y_DIST        ");
1281
-    SERIAL_PROTOCOL_F(MESH_Y_DIST, 6);
1261
+    safe_delay(25);
1282
     SERIAL_EOL;
1262
     SERIAL_EOL;
1283
-    safe_delay(50);
1263
+
1264
+    SERIAL_ECHOPGM("UBL_MESH_MIN_X  " STRINGIFY(UBL_MESH_MIN_X));
1265
+    SERIAL_ECHOLNPAIR("=", UBL_MESH_MIN_X );
1266
+    SERIAL_ECHOPGM("UBL_MESH_MIN_Y  " STRINGIFY(UBL_MESH_MIN_Y));
1267
+    SERIAL_ECHOLNPAIR("=", UBL_MESH_MIN_Y );
1268
+    safe_delay(25);
1269
+
1270
+    SERIAL_ECHOPGM("UBL_MESH_MAX_X  " STRINGIFY(UBL_MESH_MAX_X));
1271
+    SERIAL_ECHOLNPAIR("=", UBL_MESH_MAX_X);
1272
+    SERIAL_ECHOPGM("UBL_MESH_MAX_Y  " STRINGIFY(UBL_MESH_MAX_Y));
1273
+    SERIAL_ECHOLNPAIR("=", UBL_MESH_MAX_Y);
1274
+    safe_delay(25);
1284
 
1275
 
1285
     if (!ubl.sanity_check()) {
1276
     if (!ubl.sanity_check()) {
1286
       say_ubl_name();
1277
       say_ubl_name();

Loading…
Cancel
Save