Browse Source

UBL no longer flout's the sacred GCode standard (#6745)

Also clean up ubl_motion.cpp debug info and fix declaration of cx & cy
Roxy-3D 7 years ago
parent
commit
1fbcbc05f6
4 changed files with 63 additions and 133 deletions
  1. 12
    14
      Marlin/G26_Mesh_Validation_Tool.cpp
  2. 1
    1
      Marlin/Marlin_main.cpp
  3. 44
    87
      Marlin/ubl_G29.cpp
  4. 6
    31
      Marlin/ubl_motion.cpp

+ 12
- 14
Marlin/G26_Mesh_Validation_Tool.cpp View File

@@ -88,17 +88,6 @@
88 88
    *
89 89
    *   L #  Layer       Layer height.  (Height of nozzle above bed)  If not specified .20mm will be used.
90 90
    *
91
-   *   Q #  Multiplier  Retraction Multiplier.  Normally not needed.  Retraction defaults to 1.0mm and
92
-   *                    un-retraction is at 1.2mm   These numbers will be scaled by the specified amount
93
-   *
94
-   *   M #  Random      Randomize the order that the circles are drawn on the bed.  The search for the closest
95
-   *                    undrawn cicle is still done.  But the distance to the location for each circle has a
96
-   *                    random number of the size specified added to it.  Specifying R50 will give an interesting
97
-   *                    deviation from the normal behaviour on a 10 x 10 Mesh.
98
-
99
-   *   N #  Nozzle      Used to control the size of nozzle diameter.  If not specified, a .4mm nozzle is assumed.
100
-   *                    'n' can be used instead if your host program does not appreciate you using 'N'.
101
-   *
102 91
    *   O #  Ooooze      How much your nozzle will Ooooze filament while getting in position to print.  This
103 92
    *                    is over kill, but using this parameter will let you get the very first 'circle' perfect
104 93
    *                    so you have a trophy to peel off of the bed and hang up to show how perfectly you have your
@@ -111,10 +100,20 @@
111 100
    *                    printing the Mesh.  You can carefully remove the spent filament with a needle nose
112 101
    *                    pliers while holding the LCD Click wheel in a depressed state.
113 102
    *
103
+   *   Q #  Multiplier  Retraction Multiplier.  Normally not needed.  Retraction defaults to 1.0mm and
104
+   *                    un-retraction is at 1.2mm   These numbers will be scaled by the specified amount
105
+   *
114 106
    *   R #  Repeat      Prints the number of patterns given as a parameter, starting at the current location.
115 107
    *                    If a parameter isn't given, every point will be printed unless G26 is interrupted.
116 108
    *                    This works the same way that the UBL G29 P4 R parameter works.
117 109
    *
110
+   *   S #  Nozzle      Used to control the size of nozzle diameter.  If not specified, a .4mm nozzle is assumed.
111
+   *
112
+   *   U #  Random      Randomize the order that the circles are drawn on the bed.  The search for the closest
113
+   *                    undrawn cicle is still done.  But the distance to the location for each circle has a
114
+   *                    random number of the size specified added to it.  Specifying S50 will give an interesting
115
+   *                    deviation from the normal behaviour on a 10 x 10 Mesh.
116
+   *
118 117
    *   X #  X Coord.    Specify the starting location of the drawing activity.
119 118
    *
120 119
    *   Y #  Y Coord.    Specify the starting location of the drawing activity.
@@ -686,7 +685,7 @@
686 685
       }
687 686
     }
688 687
 
689
-    if (code_seen('N') || code_seen('n')) { // Warning! Use of 'N' / lowercase flouts established standards.
688
+    if (code_seen('S')) { 
690 689
       nozzle = code_value_float();
691 690
       if (!WITHIN(nozzle, 0.1, 1.0)) {
692 691
         SERIAL_PROTOCOLLNPGM("?Specified nozzle size not plausible.");
@@ -728,9 +727,8 @@
728 727
       }
729 728
     }
730 729
 
731
-    if (code_seen('M')) { // Warning! Use of 'M' flouts established standards.
730
+    if (code_seen('U')) { 
732 731
       randomSeed(millis());
733
-      // This setting will persist for the next G26
734 732
       random_deviation = code_has_value() ? code_value_float() : 50.0;
735 733
     }
736 734
 

+ 1
- 1
Marlin/Marlin_main.cpp View File

@@ -5761,7 +5761,7 @@ inline void gcode_M31() {
5761 5761
   /**
5762 5762
    * M32: Select file and start SD Print
5763 5763
    */
5764
-  inline void gcode_M32() {
5764
+  inline void gcode_M32() {  // Why is M32 allowed to flout the sacred GCode standard?
5765 5765
     if (card.sdprinting)
5766 5766
       stepper.synchronize();
5767 5767
 

+ 44
- 87
Marlin/ubl_G29.cpp View File

@@ -116,8 +116,7 @@
116 116
    *                    invalidate.
117 117
    *
118 118
    *   J #   Grid   *   Perform a Grid Based Leveling of the current Mesh using a grid with n points on a side.
119
-   *
120
-   *   j  EEPROM Dump   This function probably goes away after debug is complete.
119
+   *                    Not specifying a grid size will invoke the 3-Point leveling function.
121 120
    *
122 121
    *   K #   Kompare    Kompare current Mesh with stored Mesh # replacing current Mesh with the result. This
123 122
    *                    command literally performs a diff between two Meshes.
@@ -264,8 +263,6 @@
264 263
    *                    at a later date. The GCode output can be saved and later replayed by the host software
265 264
    *                    to reconstruct the current mesh on another machine.
266 265
    *
267
-   *   T     3-Point    Perform a 3 Point Bed Leveling on the current Mesh
268
-   *
269 266
    *   U     Unlevel    Perform a probe of the outer perimeter to assist in physically leveling unlevel beds.
270 267
    *                    Only used for G29 P1 O U   It will speed up the probing of the edge of the bed.  This
271 268
    *                    is useful when the entire bed does not need to be probed because it will be adjusted.
@@ -276,12 +273,6 @@
276 273
    *
277 274
    *   Y #   *      *   Y Location for this line of commands
278 275
    *
279
-   *   Z     Zero   *   Probes to set the Z Height of the nozzle. The entire Mesh can be raised or lowered
280
-   *                    by just doing a G29 Z
281
-   *
282
-   *   Z #   Zero   *   The entire Mesh can be raised or lowered to conform with the specified difference.
283
-   *                    zprobe_zoffset is added to the calculation.
284
-   *
285 276
    *
286 277
    *   Release Notes:
287 278
    *   You MUST do M502, M500 to initialize the storage. Failure to do this will cause all
@@ -329,7 +320,7 @@
329 320
     }
330 321
 
331 322
     // Don't allow auto-leveling without homing first
332
-    if (!(code_seen('N') && code_value_bool()) && axis_unhomed_error()) // Warning! Use of 'N' flouts established standards.
323
+    if (axis_unhomed_error()) 
333 324
       home_all_axes();
334 325
 
335 326
     if (g29_parameter_parsing()) return; // abort if parsing the simple parameters causes a problem,
@@ -353,13 +344,16 @@
353 344
     }
354 345
 
355 346
     if (code_seen('Q')) {
356
-      const int test_pattern = code_has_value() ? code_value_int() : -1;
357
-      if (!WITHIN(test_pattern, 0, 2)) {
347
+      const int test_pattern = code_has_value() ? code_value_int() : -99;
348
+      if (!WITHIN(test_pattern, -1, 2)) {
358 349
         SERIAL_PROTOCOLLNPGM("Invalid test_pattern value. (0-2)\n");
359 350
         return;
360 351
       }
361 352
       SERIAL_PROTOCOLLNPGM("Loading test_pattern values.\n");
362 353
       switch (test_pattern) {
354
+        case -1:
355
+          g29_eeprom_dump();
356
+          break;
363 357
         case 0:
364 358
           for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) {   // Create a bowl shape - similar to
365 359
             for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) { // a poorly calibrated Delta.
@@ -385,9 +379,33 @@
385 379
     }
386 380
 
387 381
     if (code_seen('J')) {
388
-      ubl.save_ubl_active_state_and_disable();
389
-      ubl.tilt_mesh_based_on_probed_grid(code_seen('O') || code_seen('M')); // Warning! Use of 'M' flouts established standards.
390
-      ubl.restore_ubl_active_state_and_leave();
382
+      if (grid_size!=0) {  // if not 0 it is a normal n x n grid being probed
383
+        ubl.save_ubl_active_state_and_disable();
384
+        ubl.tilt_mesh_based_on_probed_grid(code_seen('O')); 
385
+        ubl.restore_ubl_active_state_and_leave();
386
+      } else { // grid_size==0 which means a 3-Point leveling has been requested
387
+        float z1 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y), false, g29_verbose_level),
388
+              z2 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_2_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_2_Y), false, g29_verbose_level),
389
+              z3 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_3_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_3_Y), true, g29_verbose_level);
390
+
391
+        if ( isnan(z1) || isnan(z2) || isnan(z3)) {   // probe_pt will return NAN if unreachable
392
+          SERIAL_ERROR_START;
393
+          SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
394
+          goto LEAVE;
395
+        }
396
+
397
+      //  We need to adjust z1, z2, z3 by the Mesh Height at these points. Just because they are non-zero doesn't mean
398
+      //  the Mesh is tilted!  (We need to compensate each probe point by what the Mesh says that location's height is)
399
+
400
+        ubl.save_ubl_active_state_and_disable();
401
+        z1 -= ubl.get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y)) /* + zprobe_zoffset */ ;
402
+        z2 -= ubl.get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_2_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_2_Y)) /* + zprobe_zoffset */ ;
403
+        z3 -= ubl.get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_3_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_3_Y)) /* + zprobe_zoffset */ ;
404
+
405
+        do_blocking_move_to_xy(0.5 * (UBL_MESH_MAX_X - (UBL_MESH_MIN_X)), 0.5 * (UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)));
406
+        ubl.tilt_mesh_based_on_3pts(z1, z2, z3);
407
+        ubl.restore_ubl_active_state_and_leave();
408
+      }
391 409
     }
392 410
 
393 411
     if (code_seen('P')) {
@@ -420,7 +438,7 @@
420 438
             SERIAL_PROTOCOLLNPGM(").\n");
421 439
           }
422 440
           ubl.probe_entire_mesh(x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER,
423
-                            code_seen('O') || code_seen('M'), code_seen('E'), code_seen('U')); // Warning! Use of 'M' flouts established standards.
441
+                            code_seen('O'), code_seen('E'), code_seen('U')); 
424 442
           break;
425 443
 
426 444
         case 2: {
@@ -469,7 +487,7 @@
469 487
             return;
470 488
           }
471 489
 
472
-          manually_probe_remaining_mesh(x_pos, y_pos, height, card_thickness, code_seen('O') || code_seen('M')); // Warning! Use of 'M' flouts established standards.
490
+          manually_probe_remaining_mesh(x_pos, y_pos, height, card_thickness, code_seen('O'));
473 491
           SERIAL_PROTOCOLLNPGM("G29 P2 finished.");
474 492
         } break;
475 493
 
@@ -505,7 +523,7 @@
505 523
           //
506 524
           // Fine Tune (i.e., Edit) the Mesh
507 525
           //
508
-          fine_tune_mesh(x_pos, y_pos, code_seen('O') || code_seen('M')); // Warning! Use of 'M' flouts established standards.
526
+          fine_tune_mesh(x_pos, y_pos, code_seen('O')); 
509 527
           break;
510 528
 
511 529
         case 5: ubl.find_mean_mesh_height(); break;
@@ -515,31 +533,6 @@
515 533
 
516 534
     }
517 535
 
518
-    if (code_seen('T')) {
519
-
520
-      float z1 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y), false, g29_verbose_level),
521
-            z2 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_2_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_2_Y), false, g29_verbose_level),
522
-            z3 = probe_pt(LOGICAL_X_POSITION(UBL_PROBE_PT_3_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_3_Y), true, g29_verbose_level);
523
-
524
-      if ( isnan(z1) || isnan(z2) || isnan(z3)) {   // probe_pt will return NAN if unreachable
525
-          SERIAL_ERROR_START;
526
-          SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
527
-          goto LEAVE;
528
-      }
529
-
530
-      //  We need to adjust z1, z2, z3 by the Mesh Height at these points. Just because they are non-zero doesn't mean
531
-      //  the Mesh is tilted!  (We need to compensate each probe point by what the Mesh says that location's height is)
532
-
533
-      ubl.save_ubl_active_state_and_disable();
534
-      z1 -= ubl.get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_1_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_1_Y)) /* + zprobe_zoffset */ ;
535
-      z2 -= ubl.get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_2_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_2_Y)) /* + zprobe_zoffset */ ;
536
-      z3 -= ubl.get_z_correction(LOGICAL_X_POSITION(UBL_PROBE_PT_3_X), LOGICAL_Y_POSITION(UBL_PROBE_PT_3_Y)) /* + zprobe_zoffset */ ;
537
-
538
-      do_blocking_move_to_xy(0.5 * (UBL_MESH_MAX_X - (UBL_MESH_MIN_X)), 0.5 * (UBL_MESH_MAX_Y - (UBL_MESH_MIN_Y)));
539
-      ubl.tilt_mesh_based_on_3pts(z1, z2, z3);
540
-      ubl.restore_ubl_active_state_and_leave();
541
-    }
542
-
543 536
     //
544 537
     // Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
545 538
     // good to have the extra information. Soon... we prune this to just a few items
@@ -547,12 +540,6 @@
547 540
     if (code_seen('W')) ubl.g29_what_command();
548 541
  
549 542
     //
550
-    // When we are fully debugged, the EEPROM dump command will get deleted also. But
551
-    // right now, it is good to have the extra information. Soon... we prune this.
552
-    //
553
-    if (code_seen('j')) g29_eeprom_dump(); // Warning! Use of lowercase flouts established standards.
554
-
555
-    //
556 543
     // When we are fully debugged, this may go away. But there are some valid
557 544
     // use cases for the users. So we can wait and see what to do with it.
558 545
     //
@@ -614,9 +601,12 @@
614 601
       SERIAL_PROTOCOLLNPGM("Done.\n");
615 602
     }
616 603
 
617
-    if (code_seen('O') || code_seen('M')) // Warning! Use of 'M' flouts established standards.
604
+    if (code_seen('O'))
618 605
       ubl.display_map(code_has_value() ? code_value_int() : 0);
619 606
 
607
+    /*
608
+     * This code may not be needed...   Prepare for its removal...
609
+     *
620 610
     if (code_seen('Z')) {
621 611
       if (code_has_value())
622 612
         ubl.state.z_offset = code_value_float();   // do the simple case. Just lock in the specified value
@@ -669,6 +659,7 @@
669 659
         ubl.restore_ubl_active_state_and_leave();
670 660
       }
671 661
     }
662
+    */
672 663
 
673 664
     LEAVE:
674 665
 
@@ -1069,8 +1060,8 @@
1069 1060
     }
1070 1061
 
1071 1062
     if (code_seen('J')) {
1072
-      grid_size = code_has_value() ? code_value_int() : 3;
1073
-      if (!WITHIN(grid_size, 2, 9)) {
1063
+      grid_size = code_has_value() ? code_value_int() : 0;
1064
+      if (grid_size!=0 && !WITHIN(grid_size, 2, 9)) {
1074 1065
         SERIAL_PROTOCOLLNPGM("?Invalid grid size (J) specified (2-9).\n");
1075 1066
         err_flag = true;
1076 1067
       }
@@ -1126,43 +1117,9 @@
1126 1117
       SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1127 1118
       return UBL_ERR;
1128 1119
     }
1129
-
1130
-    // Check if a map type was specified
1131
-    if (code_seen('M')) { // Warning! Use of 'M' flouts established standards.
1132
-      map_type = code_has_value() ? code_value_int() : 0;
1133
-      if (!WITHIN(map_type, 0, 1)) {
1134
-        SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1135
-        return UBL_ERR;
1136
-      }
1137
-    }
1138
-
1139 1120
     return UBL_OK;
1140 1121
   }
1141 1122
 
1142
-  /**
1143
-   * This function goes away after G29 debug is complete. But for right now, it is a handy
1144
-   * routine to dump binary data structures.
1145
-   */
1146
-  /*
1147
-  void dump(char * const str, const float &f) {
1148
-    char *ptr;
1149
-
1150
-    SERIAL_PROTOCOL(str);
1151
-    SERIAL_PROTOCOL_F(f, 8);
1152
-    SERIAL_PROTOCOLPGM("  ");
1153
-    ptr = (char*)&f;
1154
-    for (uint8_t i = 0; i < 4; i++)
1155
-      SERIAL_PROTOCOLPAIR("  ", hex_byte(*ptr++));
1156
-    SERIAL_PROTOCOLPAIR("  isnan()=", isnan(f));
1157
-    SERIAL_PROTOCOLPAIR("  isinf()=", isinf(f));
1158
-
1159
-    if (f == -INFINITY)
1160
-      SERIAL_PROTOCOLPGM("  Minus Infinity detected.");
1161
-
1162
-    SERIAL_EOL;
1163
-  }
1164
-  //*/
1165
-
1166 1123
   static int ubl_state_at_invocation = 0,
1167 1124
              ubl_state_recursion_chk = 0;
1168 1125
 

+ 6
- 31
Marlin/ubl_motion.cpp View File

@@ -55,12 +55,8 @@
55 55
                 dy = current_position[Y_AXIS] - destination[Y_AXIS],
56 56
                 xy_dist = HYPOT(dx, dy);
57 57
 
58
-    if (xy_dist == 0.0) {
59
-      return;
60
-      //SERIAL_ECHOPGM("   FPMM=");
61
-      //const float fpmm = de / xy_dist;
62
-      //SERIAL_PROTOCOL_F(fpmm, 6);
63
-    }
58
+    if (xy_dist == 0.0) 
59
+	    return;
64 60
     else {
65 61
       SERIAL_ECHOPGM("   fpmm=");
66 62
       const float fpmm = de / xy_dist;
@@ -276,16 +272,7 @@
276 272
          */
277 273
         if (y != start[Y_AXIS]) {
278 274
           if (!inf_normalized_flag) {
279
-
280
-            //on_axis_distance = y - start[Y_AXIS];
281 275
             on_axis_distance = use_x_dist ? x - start[X_AXIS] : y - start[Y_AXIS];
282
-
283
-            //on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS];
284
-            //on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS];
285
-
286
-            //on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS];
287
-            //on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS];
288
-
289 276
             e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;
290 277
             z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
291 278
           }
@@ -350,13 +337,7 @@
350 337
          */
351 338
         if (x != start[X_AXIS]) {
352 339
           if (!inf_normalized_flag) {
353
-
354
-            //on_axis_distance = x - start[X_AXIS];
355 340
             on_axis_distance = use_x_dist ? x - start[X_AXIS] : y - start[Y_AXIS];
356
-
357
-            //on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS];
358
-            //on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS];
359
-
360 341
             e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;  // is based on X or Y because this is a horizontal move
361 342
             z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
362 343
           }
@@ -613,20 +594,14 @@
613 594
         cell_xi = constrain(cell_xi, 0, (GRID_MAX_POINTS_X) - 1);
614 595
         cell_yi = constrain(cell_yi, 0, (GRID_MAX_POINTS_Y) - 1);
615 596
 
616
-        // float x0 = (UBL_MESH_MIN_X) + ((MESH_X_DIST) * cell_xi );         // lower left cell corner
617
-        // float y0 = (UBL_MESH_MIN_Y) + ((MESH_Y_DIST) * cell_yi );         // lower left cell corner
618
-        // float x1 = x0 + MESH_X_DIST;                                      // upper right cell corner
619
-        // float y1 = y0 + MESH_Y_DIST;                                      // upper right cell corner
620
-
621 597
         const float x0 = pgm_read_float(&(ubl.mesh_index_to_xpos[cell_xi  ])),  // 64 byte table lookup avoids mul+add
622 598
                     y0 = pgm_read_float(&(ubl.mesh_index_to_ypos[cell_yi  ])),  // 64 byte table lookup avoids mul+add
623 599
                     x1 = pgm_read_float(&(ubl.mesh_index_to_xpos[cell_xi+1])),  // 64 byte table lookup avoids mul+add
624
-                    y1 = pgm_read_float(&(ubl.mesh_index_to_ypos[cell_yi+1])),  // 64 byte table lookup avoids mul+add
625
-
626
-                    cx = rx - x0,   // cell-relative x
627
-                    cy = ry - y0;   // cell-relative y
600
+                    y1 = pgm_read_float(&(ubl.mesh_index_to_ypos[cell_yi+1]));  // 64 byte table lookup avoids mul+add
628 601
 
629
-        float z_x0y0 = ubl.z_values[cell_xi  ][cell_yi  ],  // z at lower left corner
602
+        float cx = rx - x0,   // cell-relative x
603
+              cy = ry - y0;   // cell-relative y
604
+              z_x0y0 = ubl.z_values[cell_xi  ][cell_yi  ],  // z at lower left corner
630 605
               z_x1y0 = ubl.z_values[cell_xi+1][cell_yi  ],  // z at upper left corner
631 606
               z_x0y1 = ubl.z_values[cell_xi  ][cell_yi+1],  // z at lower right corner
632 607
               z_x1y1 = ubl.z_values[cell_xi+1][cell_yi+1];  // z at upper right corner

Loading…
Cancel
Save