Browse Source

Misc. Clean Up (#6822)

* Misc. Clean Up

Mostly UBL related clean up.
- But fixed a bug in the thermistortables.
- Made G26 more responsive to user aborts.
- Added sanity checks for older name for UBL_MESH_VALIDATION.
- Made G29 P4 able to edit invalidated mesh points
- Restore a reasonable Fade Height for UBL when creating new state information
- Get UBL's Topology Map to look a little bit better
- Make sure the user doesn't see a blank screen when doing Mesh Editing.

* Huh???   GitHub Desktop screwed up!

* get the planner object in scope

* Fix out of scope z_fade_height

* Travis timed out...

I need a change so I can force a new commit and sync.
Roxy-3D 8 years ago
parent
commit
3129260c44
6 changed files with 106 additions and 91 deletions
  1. 46
    50
      Marlin/G26_Mesh_Validation_Tool.cpp
  2. 2
    0
      Marlin/SanityCheck.h
  3. 1
    1
      Marlin/thermistortables.h
  4. 8
    5
      Marlin/ubl.cpp
  5. 47
    35
      Marlin/ubl_G29.cpp
  6. 2
    0
      Marlin/ultralcd.cpp

+ 46
- 50
Marlin/G26_Mesh_Validation_Tool.cpp View File

144
 
144
 
145
   void un_retract_filament(float where[XYZE]);
145
   void un_retract_filament(float where[XYZE]);
146
   void retract_filament(float where[XYZE]);
146
   void retract_filament(float where[XYZE]);
147
-  void look_for_lines_to_connect();
147
+  bool look_for_lines_to_connect();
148
   bool parse_G26_parameters();
148
   bool parse_G26_parameters();
149
   void move_to(const float&, const float&, const float&, const float&) ;
149
   void move_to(const float&, const float&, const float&, const float&) ;
150
   void print_line_from_here_to_there(const float&, const float&, const float&, const float&, const float&, const float&);
150
   void print_line_from_here_to_there(const float&, const float&, const float&, const float&, const float&, const float&);
249
     }
249
     }
250
 
250
 
251
     do {
251
     do {
252
-
253
-      if (ubl_lcd_clicked()) {              // Check if the user wants to stop the Mesh Validation
254
-        #if ENABLED(ULTRA_LCD)
255
-          lcd_setstatuspgm(PSTR("Mesh Validation Stopped."), 99);
256
-          lcd_quick_feedback();
257
-        #endif
258
-        while (!ubl_lcd_clicked()) {         // Wait until the user is done pressing the
259
-          idle();                            // Encoder Wheel if that is why we are leaving
260
-          lcd_reset_alert_level();
261
-          lcd_setstatuspgm(PSTR(""));
262
-        }
263
-        while (ubl_lcd_clicked()) {          // Wait until the user is done pressing the
264
-          idle();                            // Encoder Wheel if that is why we are leaving
265
-          lcd_setstatuspgm(PSTR("Unpress Wheel"), 99);
266
-        }
267
-        goto LEAVE;
268
-      }
269
-
270
       location = continue_with_closest
252
       location = continue_with_closest
271
         ? find_closest_circle_to_print(current_position[X_AXIS], current_position[Y_AXIS])
253
         ? find_closest_circle_to_print(current_position[X_AXIS], current_position[Y_AXIS])
272
         : find_closest_circle_to_print(x_pos, y_pos); // Find the closest Mesh Intersection to where we are now.
254
         : find_closest_circle_to_print(x_pos, y_pos); // Find the closest Mesh Intersection to where we are now.
317
         }
299
         }
318
 
300
 
319
         for (tmp = start_angle; tmp < end_angle - 0.1; tmp += 30.0) {
301
         for (tmp = start_angle; tmp < end_angle - 0.1; tmp += 30.0) {
302
+
303
+          // this sequence to detect an ubl_lcd_clicked() debounce it and leave if it is
304
+          // a Press and Hold is repeated in a lot of places (including ubl_G29.cpp).   This
305
+          // should be redone and compressed.
306
+          if (ubl_lcd_clicked()) {              // Check if the user wants to stop the Mesh Validation
307
+            #if ENABLED(ULTRA_LCD)
308
+              lcd_setstatuspgm(PSTR("Mesh Validation Stopped."), 99);
309
+              lcd_quick_feedback();
310
+            #endif
311
+            while (!ubl_lcd_clicked()) {         // Wait until the user is done pressing the
312
+              idle();                            // Encoder Wheel if that is why we are leaving
313
+              lcd_reset_alert_level();
314
+              lcd_setstatuspgm(PSTR(""));
315
+            }
316
+            while (ubl_lcd_clicked()) {          // Wait until the user is done pressing the
317
+              idle();                            // Encoder Wheel if that is why we are leaving
318
+              lcd_setstatuspgm(PSTR("Unpress Wheel"), 99);
319
+            }
320
+            goto LEAVE;
321
+          }
322
+
320
           int tmp_div_30 = tmp / 30.0;
323
           int tmp_div_30 = tmp / 30.0;
321
           if (tmp_div_30 < 0) tmp_div_30 += 360 / 30;
324
           if (tmp_div_30 < 0) tmp_div_30 += 360 / 30;
322
           if (tmp_div_30 > 11) tmp_div_30 -= 360 / 30;
325
           if (tmp_div_30 > 11) tmp_div_30 -= 360 / 30;
349
           print_line_from_here_to_there(LOGICAL_X_POSITION(x), LOGICAL_Y_POSITION(y), layer_height, LOGICAL_X_POSITION(xe), LOGICAL_Y_POSITION(ye), layer_height);
352
           print_line_from_here_to_there(LOGICAL_X_POSITION(x), LOGICAL_Y_POSITION(y), layer_height, LOGICAL_X_POSITION(xe), LOGICAL_Y_POSITION(ye), layer_height);
350
 
353
 
351
         }
354
         }
352
-
353
-        //debug_current_and_destination(PSTR("Looking for lines to connect."));
354
-        look_for_lines_to_connect();
355
-        //debug_current_and_destination(PSTR("Done with line connect."));
355
+        if (look_for_lines_to_connect())
356
+          goto LEAVE;
356
       }
357
       }
357
-
358
-      //debug_current_and_destination(PSTR("Done with current circle."));
359
-
360
     } while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0);
358
     } while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0);
361
 
359
 
362
     LEAVE:
360
     LEAVE:
432
     return return_val;
430
     return return_val;
433
   }
431
   }
434
 
432
 
435
-  void look_for_lines_to_connect() {
433
+  bool look_for_lines_to_connect() {
436
     float sx, sy, ex, ey;
434
     float sx, sy, ex, ey;
437
 
435
 
438
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
436
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
439
       for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
437
       for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
440
 
438
 
439
+        // this sequence to detect an ubl_lcd_clicked() debounce it and leave if it is
440
+        // a Press and Hold is repeated in a lot of places (including ubl_G29.cpp).   This
441
+        // should be redone and compressed.
442
+        if (ubl_lcd_clicked()) {              // Check if the user wants to stop the Mesh Validation
443
+          #if ENABLED(ULTRA_LCD)
444
+            lcd_setstatuspgm(PSTR("Mesh Validation Stopped."), 99);
445
+            lcd_quick_feedback();
446
+          #endif
447
+          while (!ubl_lcd_clicked()) {         // Wait until the user is done pressing the
448
+            idle();                            // Encoder Wheel if that is why we are leaving
449
+            lcd_reset_alert_level();
450
+            lcd_setstatuspgm(PSTR(""));
451
+          }
452
+          while (ubl_lcd_clicked()) {          // Wait until the user is done pressing the
453
+            idle();                            // Encoder Wheel if that is why we are leaving
454
+            lcd_setstatuspgm(PSTR("Unpress Wheel"), 99);
455
+          }
456
+          return true;
457
+        }
458
+
441
         if (i < GRID_MAX_POINTS_X) { // We can't connect to anything to the right than GRID_MAX_POINTS_X.
459
         if (i < GRID_MAX_POINTS_X) { // We can't connect to anything to the right than GRID_MAX_POINTS_X.
442
                                          // This is already a half circle because we are at the edge of the bed.
460
                                          // This is already a half circle because we are at the edge of the bed.
443
 
461
 
509
         }
527
         }
510
       }
528
       }
511
     }
529
     }
530
+    return false;
512
   }
531
   }
513
 
532
 
514
   void move_to(const float &x, const float &y, const float &z, const float &e_delta) {
533
   void move_to(const float &x, const float &y, const float &z, const float &e_delta) {
517
 
536
 
518
     bool has_xy_component = (x != current_position[X_AXIS] || y != current_position[Y_AXIS]); // Check if X or Y is involved in the movement.
537
     bool has_xy_component = (x != current_position[X_AXIS] || y != current_position[Y_AXIS]); // Check if X or Y is involved in the movement.
519
 
538
 
520
-    //if (ubl.g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to()  has_xy_component:", (int)has_xy_component);
521
-
522
     if (z != last_z) {
539
     if (z != last_z) {
523
-      //if (ubl.g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to()  changing Z to ", (int)z);
524
-
525
       last_z = z;
540
       last_z = z;
526
       feed_value = planner.max_feedrate_mm_s[Z_AXIS]/(3.0);  // Base the feed rate off of the configured Z_AXIS feed rate
541
       feed_value = planner.max_feedrate_mm_s[Z_AXIS]/(3.0);  // Base the feed rate off of the configured Z_AXIS feed rate
527
 
542
 
534
 
549
 
535
       stepper.synchronize();
550
       stepper.synchronize();
536
       set_destination_to_current();
551
       set_destination_to_current();
537
-
538
-      //if (ubl.g26_debug_flag) debug_current_and_destination(PSTR(" in move_to() done with Z move"));
539
     }
552
     }
540
 
553
 
541
     // Check if X or Y is involved in the movement.
554
     // Check if X or Y is involved in the movement.
548
     destination[Y_AXIS] = y;
561
     destination[Y_AXIS] = y;
549
     destination[E_AXIS] += e_delta;
562
     destination[E_AXIS] += e_delta;
550
 
563
 
551
-    //if (ubl.g26_debug_flag) debug_current_and_destination(PSTR(" in move_to() doing last move"));
552
-
553
     G26_line_to_destination(feed_value);
564
     G26_line_to_destination(feed_value);
554
 
565
 
555
-    //if (ubl.g26_debug_flag) debug_current_and_destination(PSTR(" in move_to() after last move"));
556
-
557
     stepper.synchronize();
566
     stepper.synchronize();
558
     set_destination_to_current();
567
     set_destination_to_current();
559
 
568
 
562
   void retract_filament(float where[XYZE]) {
571
   void retract_filament(float where[XYZE]) {
563
     if (!g26_retracted) { // Only retract if we are not already retracted!
572
     if (!g26_retracted) { // Only retract if we are not already retracted!
564
       g26_retracted = true;
573
       g26_retracted = true;
565
-      //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Decided to do retract.");
566
       move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], -1.0 * retraction_multiplier);
574
       move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], -1.0 * retraction_multiplier);
567
-      //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Retraction done.");
568
     }
575
     }
569
   }
576
   }
570
 
577
 
572
     if (g26_retracted) { // Only un-retract if we are retracted.
579
     if (g26_retracted) { // Only un-retract if we are retracted.
573
       move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], 1.2 * retraction_multiplier);
580
       move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], 1.2 * retraction_multiplier);
574
       g26_retracted = false;
581
       g26_retracted = false;
575
-      //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" unretract done.");
576
     }
582
     }
577
   }
583
   }
578
 
584
 
605
     // If the end point of the line is closer to the nozzle, flip the direction,
611
     // If the end point of the line is closer to the nozzle, flip the direction,
606
     // moving from the end to the start. On very small lines the optimization isn't worth it.
612
     // moving from the end to the start. On very small lines the optimization isn't worth it.
607
     if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < abs(line_length)) {
613
     if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < abs(line_length)) {
608
-      //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  Reversing start and end of print_line_from_here_to_there()");
609
       return print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
614
       return print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
610
     }
615
     }
611
 
616
 
613
 
618
 
614
     if (dist_start > 2.0) {
619
     if (dist_start > 2.0) {
615
       retract_filament(destination);
620
       retract_filament(destination);
616
-      //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  filament retracted.");
617
-
618
-      //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  Z bumping by 0.500 to minimize scraping.");
619
       //todo:  parameterize the bump height with a define
621
       //todo:  parameterize the bump height with a define
620
       move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + 0.500, 0.0);  // Z bump to minimize scraping
622
       move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + 0.500, 0.0);  // Z bump to minimize scraping
621
       move_to(sx, sy, sz + 0.500, 0.0); // Get to the starting point with no extrusion while bumped
623
       move_to(sx, sy, sz + 0.500, 0.0); // Get to the starting point with no extrusion while bumped
626
     const float e_pos_delta = line_length * g26_e_axis_feedrate * extrusion_multiplier;
628
     const float e_pos_delta = line_length * g26_e_axis_feedrate * extrusion_multiplier;
627
 
629
 
628
     un_retract_filament(destination);
630
     un_retract_filament(destination);
629
-
630
-    //if (ubl.g26_debug_flag) {
631
-    //  SERIAL_ECHOLNPGM("  doing printing move.");
632
-    //  debug_current_and_destination(PSTR("doing final move_to() inside print_line_from_here_to_there()"));
633
-    //}
634
     move_to(ex, ey, ez, e_pos_delta);  // Get to the ending point with an appropriate amount of extrusion
631
     move_to(ex, ey, ez, e_pos_delta);  // Get to the ending point with an appropriate amount of extrusion
635
   }
632
   }
636
 
633
 
754
   }
751
   }
755
 
752
 
756
   bool exit_from_g26() {
753
   bool exit_from_g26() {
757
-    //strcpy(lcd_status_message, "Leaving G26"); // We can't do lcd_setstatus() without having it continue;
758
     lcd_reset_alert_level();
754
     lcd_reset_alert_level();
759
     lcd_setstatuspgm(PSTR("Leaving G26"));
755
     lcd_setstatuspgm(PSTR("Leaving G26"));
760
     while (ubl_lcd_clicked()) idle();
756
     while (ubl_lcd_clicked()) idle();

+ 2
- 0
Marlin/SanityCheck.h View File

160
   #error "UBL_MESH_EDIT_ENABLED is now UBL_G26_MESH_VALIDATION. Please update your configuration."
160
   #error "UBL_MESH_EDIT_ENABLED is now UBL_G26_MESH_VALIDATION. Please update your configuration."
161
 #elif defined(UBL_MESH_EDITING)
161
 #elif defined(UBL_MESH_EDITING)
162
   #error "UBL_MESH_EDITING is now UBL_G26_MESH_VALIDATION. Please update your configuration."
162
   #error "UBL_MESH_EDITING is now UBL_G26_MESH_VALIDATION. Please update your configuration."
163
+#elif defined(BLTOUCH_HEATERS_OFF)
164
+  #error "BLTOUCH_HEATERS_OFF is now PROBING_HEATERS_OFF. Please update your configuration."
163
 #elif defined(BEEPER)
165
 #elif defined(BEEPER)
164
   #error "BEEPER is now BEEPER_PIN. Please update your pins definitions."
166
   #error "BEEPER is now BEEPER_PIN. Please update your pins definitions."
165
 #elif defined(SDCARDDETECT)
167
 #elif defined(SDCARDDETECT)

+ 1
- 1
Marlin/thermistortables.h View File

89
   #include "thermistortable_52.h"
89
   #include "thermistortable_52.h"
90
 #endif
90
 #endif
91
 #if ANY_THERMISTOR_IS(55) // 100k ATC Semitec 104GT-2 (Used on ParCan) (WITH 1kohm RESISTOR FOR PULLUP, R9 ON SANGUINOLOLU! NOT FOR 4.7kohm PULLUP! THIS IS NOT NORMAL!)
91
 #if ANY_THERMISTOR_IS(55) // 100k ATC Semitec 104GT-2 (Used on ParCan) (WITH 1kohm RESISTOR FOR PULLUP, R9 ON SANGUINOLOLU! NOT FOR 4.7kohm PULLUP! THIS IS NOT NORMAL!)
92
-  #include "thermistortable_53.h"
92
+  #include "thermistortable_55.h"
93
 #endif
93
 #endif
94
 #if ANY_THERMISTOR_IS(60) // Maker's Tool Works Kapton Bed Thermistor
94
 #if ANY_THERMISTOR_IS(60) // Maker's Tool Works Kapton Bed Thermistor
95
   #include "thermistortable_60.h"
95
   #include "thermistortable_60.h"

+ 8
- 5
Marlin/ubl.cpp View File

29
   #include "hex_print_routines.h"
29
   #include "hex_print_routines.h"
30
   #include "temperature.h"
30
   #include "temperature.h"
31
 
31
 
32
+  extern Planner planner;
33
+
32
   /**
34
   /**
33
    * These support functions allow the use of large bit arrays of flags that take very
35
    * These support functions allow the use of large bit arrays of flags that take very
34
    * little RAM. Currently they are limited to being 16x16 in size. Changing the declaration
36
    * little RAM. Currently they are limited to being 16x16 in size. Changing the declaration
76
   volatile int unified_bed_leveling::encoder_diff;
78
   volatile int unified_bed_leveling::encoder_diff;
77
 
79
 
78
   unified_bed_leveling::unified_bed_leveling() {
80
   unified_bed_leveling::unified_bed_leveling() {
79
-    ubl_cnt++;  // Debug counter to insure we only have one UBL object present in memory.
81
+    ubl_cnt++;  // Debug counter to insure we only have one UBL object present in memory.  We can eliminate this (and all references to ubl_cnt) very soon.
80
     reset();
82
     reset();
81
   }
83
   }
82
 
84
 
84
     state.active = false;
86
     state.active = false;
85
     state.z_offset = 0;
87
     state.z_offset = 0;
86
     state.storage_slot = -1;
88
     state.storage_slot = -1;
87
-
89
+    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
90
+      planner.z_fade_height = 10.0;
91
+    #endif
88
     ZERO(z_values);
92
     ZERO(z_values);
89
-
90
     last_specified_z = -999.9;
93
     last_specified_z = -999.9;
91
   }
94
   }
92
 
95
 
100
 
103
 
101
   void unified_bed_leveling::display_map(const int map_type) {
104
   void unified_bed_leveling::display_map(const int map_type) {
102
     const bool map0 = map_type == 0;
105
     const bool map0 = map_type == 0;
103
-    constexpr uint8_t spaces = 9 * (GRID_MAX_POINTS_X - 2);
106
+    constexpr uint8_t spaces = 8 * (GRID_MAX_POINTS_X - 2);
104
 
107
 
105
     if (map0) {
108
     if (map0) {
106
       SERIAL_PROTOCOLLNPGM("\nBed Topography Report:\n");
109
       SERIAL_PROTOCOLLNPGM("\nBed Topography Report:\n");
126
 
129
 
127
         const float f = z_values[i][j];
130
         const float f = z_values[i][j];
128
         if (isnan(f)) {
131
         if (isnan(f)) {
129
-          serialprintPGM(map0 ? PSTR("   .  ") : PSTR("NAN"));
132
+          serialprintPGM(map0 ? PSTR("    .   ") : PSTR("NAN"));
130
         }
133
         }
131
         else {
134
         else {
132
           // if we don't do this, the columns won't line up nicely
135
           // if we don't do this, the columns won't line up nicely

+ 47
- 35
Marlin/ubl_G29.cpp View File

1009
         }
1009
         }
1010
       }
1010
       }
1011
 
1011
 
1012
+      // this sequence to detect an ubl_lcd_clicked() debounce it and leave if it is
1013
+      // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp).   This
1014
+      // should be redone and compressed.
1012
       const millis_t nxt = millis() + 1500L;
1015
       const millis_t nxt = millis() + 1500L;
1013
       while (ubl_lcd_clicked()) {     // debounce and watch for abort
1016
       while (ubl_lcd_clicked()) {     // debounce and watch for abort
1014
         idle();
1017
         idle();
1327
 
1330
 
1328
     // Get our reference position. Either the nozzle or probe location.
1331
     // Get our reference position. Either the nozzle or probe location.
1329
     const float px = RAW_X_POSITION(lx) - (probe_as_reference == USE_PROBE_AS_REFERENCE ? X_PROBE_OFFSET_FROM_EXTRUDER : 0),
1332
     const float px = RAW_X_POSITION(lx) - (probe_as_reference == USE_PROBE_AS_REFERENCE ? X_PROBE_OFFSET_FROM_EXTRUDER : 0),
1330
-                py = RAW_Y_POSITION(ly) - (probe_as_reference == USE_PROBE_AS_REFERENCE ? Y_PROBE_OFFSET_FROM_EXTRUDER : 0),
1331
-                raw_x = RAW_CURRENT_POSITION(X), raw_y = RAW_CURRENT_POSITION(Y);
1333
+                py = RAW_Y_POSITION(ly) - (probe_as_reference == USE_PROBE_AS_REFERENCE ? Y_PROBE_OFFSET_FROM_EXTRUDER : 0);
1332
 
1334
 
1333
-    float closest = far_flag ? -99999.99 : 99999.99;
1335
+    float best_so_far = far_flag ? -99999.99 : 99999.99;
1334
 
1336
 
1335
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1337
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1336
       for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1338
       for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1339
           || (type == REAL && !isnan(ubl.z_values[i][j]))
1341
           || (type == REAL && !isnan(ubl.z_values[i][j]))
1340
           || (type == SET_IN_BITMAP && is_bit_set(bits, i, j))
1342
           || (type == SET_IN_BITMAP && is_bit_set(bits, i, j))
1341
         ) {
1343
         ) {
1342
-
1343
           // We only get here if we found a Mesh Point of the specified type
1344
           // We only get here if we found a Mesh Point of the specified type
1344
 
1345
 
1345
-          const float mx = pgm_read_float(&ubl.mesh_index_to_xpos[i]), // Check if we can probe this mesh location
1346
+          float raw_x = RAW_CURRENT_POSITION(X), raw_y = RAW_CURRENT_POSITION(Y);
1347
+          const float mx = pgm_read_float(&ubl.mesh_index_to_xpos[i]),
1346
                       my = pgm_read_float(&ubl.mesh_index_to_ypos[j]);
1348
                       my = pgm_read_float(&ubl.mesh_index_to_ypos[j]);
1347
 
1349
 
1348
           // If using the probe as the reference there are some unreachable locations.
1350
           // If using the probe as the reference there are some unreachable locations.
1352
           if (probe_as_reference ? !position_is_reachable_by_probe_raw_xy(mx, my) : !position_is_reachable_raw_xy(mx, my))
1354
           if (probe_as_reference ? !position_is_reachable_by_probe_raw_xy(mx, my) : !position_is_reachable_raw_xy(mx, my))
1353
             continue;
1355
             continue;
1354
 
1356
 
1355
-          // Reachable. Check if it's the closest location to the nozzle.
1357
+          // Reachable. Check if it's the best_so_far location to the nozzle.
1356
           // Add in a weighting factor that considers the current location of the nozzle.
1358
           // Add in a weighting factor that considers the current location of the nozzle.
1357
 
1359
 
1358
-          float distance = HYPOT(px - mx, py - my) + HYPOT(raw_x - mx, raw_y - my) * 0.1;
1360
+          float distance = HYPOT(px - mx, py - my);
1359
 
1361
 
1360
           /**
1362
           /**
1361
            * If doing the far_flag action, we want to be as far as possible
1363
            * If doing the far_flag action, we want to be as far as possible
1367
           if (far_flag) {
1369
           if (far_flag) {
1368
             for (uint8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
1370
             for (uint8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
1369
               for (uint8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
1371
               for (uint8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
1370
-                if (!isnan(ubl.z_values[k][l])) {
1371
-                  distance += sq(i - k) * (MESH_X_DIST) * .05
1372
-                            + sq(j - l) * (MESH_Y_DIST) * .05;
1372
+                if (i != k && j != l && !isnan(ubl.z_values[k][l])) {
1373
+//                distance += pow((float) abs(i - k) * (MESH_X_DIST), 2) + pow((float) abs(j - l) * (MESH_Y_DIST), 2);  // working here
1374
+                  distance += HYPOT((MESH_X_DIST),(MESH_Y_DIST)) / log(HYPOT((i - k) * (MESH_X_DIST)+.001, (j - l) * (MESH_Y_DIST))+.001);
1373
                 }
1375
                 }
1374
               }
1376
               }
1375
             }
1377
             }
1376
           }
1378
           }
1379
+          else
1380
+          // factor in the distance from the current location for the normal case
1381
+          // so the nozzle isn't running all over the bed.
1382
+            distance += HYPOT(raw_x - mx, raw_y - my) * 0.1;
1377
 
1383
 
1378
           // if far_flag, look for farthest point
1384
           // if far_flag, look for farthest point
1379
-          if (far_flag == (distance > closest) && distance != closest) {
1380
-            closest = distance;       // We found a closer/farther location with
1385
+          if (far_flag == (distance > best_so_far) && distance != best_so_far) {
1386
+            best_so_far = distance;   // We found a closer/farther location with
1381
             out_mesh.x_index = i;     // the specified type of mesh value.
1387
             out_mesh.x_index = i;     // the specified type of mesh value.
1382
             out_mesh.y_index = j;
1388
             out_mesh.y_index = j;
1383
-            out_mesh.distance = closest;
1389
+            out_mesh.distance = best_so_far;
1384
           }
1390
           }
1385
         }
1391
         }
1386
       } // for j
1392
       } // for j
1408
 
1414
 
1409
     LCD_MESSAGEPGM("Fine Tuning Mesh"); // TODO: Make translatable string
1415
     LCD_MESSAGEPGM("Fine Tuning Mesh"); // TODO: Make translatable string
1410
 
1416
 
1411
-    do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
1417
+    do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
1412
     do_blocking_move_to_xy(lx, ly);
1418
     do_blocking_move_to_xy(lx, ly);
1413
     do {
1419
     do {
1414
       location = find_closest_mesh_point_of_type(SET_IN_BITMAP, lx, ly, USE_NOZZLE_AS_REFERENCE, not_done, false);
1420
       location = find_closest_mesh_point_of_type(SET_IN_BITMAP, lx, ly, USE_NOZZLE_AS_REFERENCE, not_done, false);
1426
 
1432
 
1427
       float new_z = ubl.z_values[location.x_index][location.y_index];
1433
       float new_z = ubl.z_values[location.x_index][location.y_index];
1428
 
1434
 
1429
-      if (!isnan(new_z)) {  //can't fine tune a point that hasn't been probed
1435
+      if (isnan(new_z)) // if the mesh point is invalid, set it to 0.0 so it can be edited
1436
+        new_z = 0.0;
1430
 
1437
 
1431
-        do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);    // Move the nozzle to where we are going to edit
1432
-        do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy));
1438
+      do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);    // Move the nozzle to where we are going to edit
1439
+      do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy));
1433
 
1440
 
1434
-        new_z = floor(new_z * 1000.0) * 0.001; // Chop off digits after the 1000ths place
1441
+      new_z = floor(new_z * 1000.0) * 0.001; // Chop off digits after the 1000ths place
1435
 
1442
 
1436
-        KEEPALIVE_STATE(PAUSED_FOR_USER);
1437
-        ubl.has_control_of_lcd_panel = true;
1443
+      KEEPALIVE_STATE(PAUSED_FOR_USER);
1444
+      ubl.has_control_of_lcd_panel = true;
1438
 
1445
 
1439
-        if (do_ubl_mesh_map) ubl.display_map(map_type);  // show the user which point is being adjusted
1446
+      if (do_ubl_mesh_map) ubl.display_map(map_type);  // show the user which point is being adjusted
1440
 
1447
 
1441
-        lcd_implementation_clear();
1448
+      lcd_implementation_clear();
1442
 
1449
 
1443
-        lcd_mesh_edit_setup(new_z);
1450
+      lcd_mesh_edit_setup(new_z);
1444
 
1451
 
1445
-        do {
1446
-          new_z = lcd_mesh_edit();
1447
-          idle();
1448
-        } while (!ubl_lcd_clicked());
1452
+      do {
1453
+        new_z = lcd_mesh_edit();
1454
+        #ifdef UBL_MESH_EDIT_MOVES_Z
1455
+          do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES+new_z);  // Move the nozzle as the point is edited
1456
+        #endif
1457
+        idle();
1458
+      } while (!ubl_lcd_clicked());
1449
 
1459
 
1450
-        lcd_return_to_status();
1460
+      lcd_return_to_status();
1451
 
1461
 
1452
-        // The technique used here generates a race condition for the encoder click.
1453
-        // It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune) or here.
1454
-        // Let's work on specifying a proper API for the LCD ASAP, OK?
1455
-        ubl.has_control_of_lcd_panel = true;
1456
-      }
1462
+      // The technique used here generates a race condition for the encoder click.
1463
+      // It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune) or here.
1464
+      // Let's work on specifying a proper API for the LCD ASAP, OK?
1465
+      ubl.has_control_of_lcd_panel = true;
1457
 
1466
 
1467
+      // this sequence to detect an ubl_lcd_clicked() debounce it and leave if it is
1468
+      // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp).   This
1469
+      // should be redone and compressed.
1458
       const millis_t nxt = millis() + 1500UL;
1470
       const millis_t nxt = millis() + 1500UL;
1459
       while (ubl_lcd_clicked()) { // debounce and watch for abort
1471
       while (ubl_lcd_clicked()) { // debounce and watch for abort
1460
         idle();
1472
         idle();
1461
         if (ELAPSED(millis(), nxt)) {
1473
         if (ELAPSED(millis(), nxt)) {
1462
           lcd_return_to_status();
1474
           lcd_return_to_status();
1463
           //SERIAL_PROTOCOLLNPGM("\nFine Tuning of Mesh Stopped.");
1475
           //SERIAL_PROTOCOLLNPGM("\nFine Tuning of Mesh Stopped.");
1464
-          do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
1476
+          do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
1465
           LCD_MESSAGEPGM("Mesh Editing Stopped"); // TODO: Make translatable string
1477
           LCD_MESSAGEPGM("Mesh Editing Stopped"); // TODO: Make translatable string
1466
 
1478
 
1467
           while (ubl_lcd_clicked()) idle();
1479
           while (ubl_lcd_clicked()) idle();
1485
 
1497
 
1486
     if (do_ubl_mesh_map) ubl.display_map(map_type);
1498
     if (do_ubl_mesh_map) ubl.display_map(map_type);
1487
     ubl.restore_ubl_active_state_and_leave();
1499
     ubl.restore_ubl_active_state_and_leave();
1488
-    do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
1500
+    do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
1489
 
1501
 
1490
     do_blocking_move_to_xy(lx, ly);
1502
     do_blocking_move_to_xy(lx, ly);
1491
 
1503
 

+ 2
- 0
Marlin/ultralcd.cpp View File

958
     }
958
     }
959
 
959
 
960
     void _lcd_mesh_edit() {
960
     void _lcd_mesh_edit() {
961
+      lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
961
       _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
962
       _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
962
     }
963
     }
963
 
964
 
964
     float lcd_mesh_edit() {
965
     float lcd_mesh_edit() {
965
       lcd_goto_screen(_lcd_mesh_edit_NOP);
966
       lcd_goto_screen(_lcd_mesh_edit_NOP);
967
+      lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
966
       _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
968
       _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
967
       return mesh_edit_value;
969
       return mesh_edit_value;
968
     }
970
     }

Loading…
Cancel
Save