|
@@ -158,7 +158,7 @@
|
158
|
158
|
* only done between probe points. You will need to press and hold the switch until the
|
159
|
159
|
* Phase 1 command can detect it.)
|
160
|
160
|
*
|
161
|
|
- * P2 Phase 2 Probe areas of the Mesh that can not be automatically handled. Phase 2 respects an H
|
|
161
|
+ * P2 Phase 2 Probe areas of the Mesh that can't be automatically handled. Phase 2 respects an H
|
162
|
162
|
* parameter to control the height between Mesh points. The default height for movement
|
163
|
163
|
* between Mesh points is 5mm. A smaller number can be used to make this part of the
|
164
|
164
|
* calibration less time consuming. You will be running the nozzle down until it just barely
|
|
@@ -303,25 +303,17 @@
|
303
|
303
|
volatile int8_t ubl_encoderDiff = 0; // Volatile because it's changed by Temperature ISR button update
|
304
|
304
|
|
305
|
305
|
// The simple parameter flags and values are 'static' so parameter parsing can be in a support routine.
|
306
|
|
- static int g29_verbose_level = 0, phase_value = -1, repetition_cnt = 1,
|
307
|
|
- storage_slot = 0, map_type = 0, test_pattern = 0, unlevel_value = -1;
|
308
|
|
- static bool repeat_flag = UBL_OK, c_flag = false, x_flag = UBL_OK, y_flag = UBL_OK, statistics_flag = UBL_OK, business_card_mode = false;
|
309
|
|
- static float x_pos = 0.0, y_pos = 0.0, height_value = 5.0, measured_z, card_thickness = 0.0, constant = 0.0;
|
|
306
|
+ static int g29_verbose_level, phase_value = -1, repetition_cnt,
|
|
307
|
+ storage_slot = 0, map_type; //unlevel_value = -1;
|
|
308
|
+ static bool repeat_flag, c_flag, x_flag, y_flag;
|
|
309
|
+ static float x_pos, y_pos, measured_z, card_thickness = 0.0, ubl_constant = 0.0;
|
310
|
310
|
|
311
|
311
|
#if ENABLED(ULTRA_LCD)
|
312
|
312
|
void lcd_setstatus(const char* message, bool persist);
|
313
|
313
|
#endif
|
314
|
314
|
|
315
|
315
|
void gcode_G29() {
|
316
|
|
- float Z1, Z2, Z3;
|
317
|
|
-
|
318
|
|
- g29_verbose_level = 0; // These may change, but let's get some reasonable values into them.
|
319
|
|
- repeat_flag = UBL_OK;
|
320
|
|
- repetition_cnt = 1;
|
321
|
|
- c_flag = false;
|
322
|
|
-
|
323
|
316
|
SERIAL_PROTOCOLLNPAIR("ubl_eeprom_start=", ubl_eeprom_start);
|
324
|
|
-
|
325
|
317
|
if (ubl_eeprom_start < 0) {
|
326
|
318
|
SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it");
|
327
|
319
|
SERIAL_PROTOCOLLNPGM("with M502, M500, M501 in that order.\n");
|
|
@@ -350,53 +342,46 @@
|
350
|
342
|
|
351
|
343
|
if (code_seen('Q')) {
|
352
|
344
|
|
353
|
|
- if (code_has_value()) test_pattern = code_value_int();
|
354
|
|
-
|
355
|
|
- if (test_pattern < 0 || test_pattern > 4) {
|
356
|
|
- SERIAL_PROTOCOLLNPGM("Invalid test_pattern value. (0-4)\n");
|
|
345
|
+ const int test_pattern = code_has_value() ? code_value_int() : -1;
|
|
346
|
+ if (test_pattern < 0 || test_pattern > 2) {
|
|
347
|
+ SERIAL_PROTOCOLLNPGM("Invalid test_pattern value. (0-2)\n");
|
357
|
348
|
return;
|
358
|
349
|
}
|
359
|
350
|
SERIAL_PROTOCOLLNPGM("Loading test_pattern values.\n");
|
360
|
351
|
switch (test_pattern) {
|
361
|
352
|
case 0:
|
362
|
|
- for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++) { // Create a bowl shape. This is
|
363
|
|
- for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++) { // similar to what a user would see with
|
364
|
|
- Z1 = 0.5 * (UBL_MESH_NUM_X_POINTS) - x; // a poorly calibrated Delta.
|
365
|
|
- Z2 = 0.5 * (UBL_MESH_NUM_Y_POINTS) - y;
|
366
|
|
- z_values[x][y] += 2.0 * HYPOT(Z1, Z2);
|
|
353
|
+ for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++) { // Create a bowl shape - similar to
|
|
354
|
+ for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++) { // a poorly calibrated Delta.
|
|
355
|
+ const float p1 = 0.5 * (UBL_MESH_NUM_X_POINTS) - x,
|
|
356
|
+ p2 = 0.5 * (UBL_MESH_NUM_Y_POINTS) - y;
|
|
357
|
+ z_values[x][y] += 2.0 * HYPOT(p1, p2);
|
367
|
358
|
}
|
368
|
359
|
}
|
369
|
|
- break;
|
|
360
|
+ break;
|
370
|
361
|
case 1:
|
371
|
|
- for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++) { // Create a diagonal line several Mesh
|
372
|
|
- z_values[x][x] += 9.999; // cells thick that is raised
|
373
|
|
- if (x < UBL_MESH_NUM_Y_POINTS - 1)
|
374
|
|
- z_values[x][x + 1] += 9.999; // We want the altered line several mesh points thick
|
375
|
|
- if (x > 0)
|
376
|
|
- z_values[x][x - 1] += 9.999; // We want the altered line several mesh points thick
|
|
362
|
+ for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++) { // Create a diagonal line several Mesh cells thick that is raised
|
|
363
|
+ z_values[x][x] += 9.999;
|
|
364
|
+ z_values[x][x + (x < UBL_MESH_NUM_Y_POINTS - 1) ? 1 : -1] += 9.999; // We want the altered line several mesh points thick
|
377
|
365
|
}
|
378
|
366
|
break;
|
379
|
367
|
case 2:
|
380
|
|
- // Allow the user to specify the height because 10mm is
|
381
|
|
- // a little bit extreme in some cases.
|
|
368
|
+ // Allow the user to specify the height because 10mm is a little extreme in some cases.
|
382
|
369
|
for (uint8_t x = (UBL_MESH_NUM_X_POINTS) / 3; x < 2 * (UBL_MESH_NUM_X_POINTS) / 3; x++) // Create a rectangular raised area in
|
383
|
370
|
for (uint8_t y = (UBL_MESH_NUM_Y_POINTS) / 3; y < 2 * (UBL_MESH_NUM_Y_POINTS) / 3; y++) // the center of the bed
|
384
|
|
- z_values[x][y] += code_seen('C') ? constant : 9.99;
|
385
|
|
- break;
|
386
|
|
- case 3:
|
|
371
|
+ z_values[x][y] += code_seen('C') ? ubl_constant : 9.99;
|
387
|
372
|
break;
|
388
|
373
|
}
|
389
|
374
|
}
|
390
|
375
|
|
391
|
|
-/*
|
|
376
|
+ /*
|
392
|
377
|
if (code_seen('U')) {
|
393
|
378
|
unlevel_value = code_value_int();
|
394
|
|
-// if (unlevel_value < 0 || unlevel_value > 7) {
|
395
|
|
-// SERIAL_PROTOCOLLNPGM("Invalid Unlevel value. (0-4)\n");
|
396
|
|
-// return;
|
397
|
|
-// }
|
|
379
|
+ //if (unlevel_value < 0 || unlevel_value > 7) {
|
|
380
|
+ // SERIAL_PROTOCOLLNPGM("Invalid Unlevel value. (0-4)\n");
|
|
381
|
+ // return;
|
|
382
|
+ //}
|
398
|
383
|
}
|
399
|
|
-*/
|
|
384
|
+ //*/
|
400
|
385
|
|
401
|
386
|
if (code_seen('P')) {
|
402
|
387
|
phase_value = code_value_int();
|
|
@@ -430,9 +415,9 @@
|
430
|
415
|
code_seen('O') || code_seen('M'), code_seen('E'), code_seen('U'));
|
431
|
416
|
break;
|
432
|
417
|
//
|
433
|
|
- // Manually Probe Mesh in areas that can not be reached by the probe
|
|
418
|
+ // Manually Probe Mesh in areas that can't be reached by the probe
|
434
|
419
|
//
|
435
|
|
- case 2:
|
|
420
|
+ case 2: {
|
436
|
421
|
SERIAL_PROTOCOLLNPGM("Manually probing unreachable mesh locations.\n");
|
437
|
422
|
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
|
438
|
423
|
if (!x_flag && !y_flag) { // use a good default location for the path
|
|
@@ -451,32 +436,34 @@
|
451
|
436
|
y_pos = current_position[Y_AXIS];
|
452
|
437
|
}
|
453
|
438
|
|
454
|
|
- height_value = code_seen('H') && code_has_value() ? code_value_float() : Z_CLEARANCE_BETWEEN_PROBES;
|
|
439
|
+ const float height = code_seen('H') && code_has_value() ? code_value_float() : Z_CLEARANCE_BETWEEN_PROBES;
|
455
|
440
|
|
456
|
|
- if ((business_card_mode = code_seen('B'))) {
|
457
|
|
- card_thickness = code_has_value() ? code_value_float() : measure_business_card_thickness(height_value);
|
|
441
|
+ if (code_seen('B')) {
|
|
442
|
+ card_thickness = code_has_value() ? code_value_float() : measure_business_card_thickness(height);
|
458
|
443
|
|
459
|
444
|
if (fabs(card_thickness) > 1.5) {
|
460
|
|
- SERIAL_PROTOCOLLNPGM("?Error in Business Card measurment.\n");
|
|
445
|
+ SERIAL_PROTOCOLLNPGM("?Error in Business Card measurement.\n");
|
461
|
446
|
return;
|
462
|
447
|
}
|
463
|
448
|
}
|
464
|
|
- manually_probe_remaining_mesh(x_pos, y_pos, height_value, card_thickness, code_seen('O') || code_seen('M'));
|
465
|
|
- break;
|
|
449
|
+ manually_probe_remaining_mesh(x_pos, y_pos, height, card_thickness, code_seen('O') || code_seen('M'));
|
|
450
|
+
|
|
451
|
+ } break;
|
|
452
|
+
|
466
|
453
|
//
|
467
|
454
|
// Populate invalid Mesh areas with a constant
|
468
|
455
|
//
|
469
|
|
- case 3:
|
470
|
|
- height_value = 0.0; // Assume 0.0 until proven otherwise
|
471
|
|
- if (code_seen('C')) height_value = constant;
|
|
456
|
+ case 3: {
|
|
457
|
+ const float height = code_seen('C') ? ubl_constant : 0.0;
|
472
|
458
|
// If no repetition is specified, do the whole Mesh
|
473
|
459
|
if (!repeat_flag) repetition_cnt = 9999;
|
474
|
460
|
while (repetition_cnt--) {
|
475
|
461
|
const mesh_index_pair location = find_closest_mesh_point_of_type(INVALID, x_pos, y_pos, 0, NULL, false); // The '0' says we want to use the nozzle's position
|
476
|
462
|
if (location.x_index < 0) break; // No more invalid Mesh Points to populate
|
477
|
|
- z_values[location.x_index][location.y_index] = height_value;
|
|
463
|
+ z_values[location.x_index][location.y_index] = height;
|
478
|
464
|
}
|
479
|
|
- break;
|
|
465
|
+ } break;
|
|
466
|
+
|
480
|
467
|
//
|
481
|
468
|
// Fine Tune (Or Edit) the Mesh
|
482
|
469
|
//
|
|
@@ -491,36 +478,56 @@
|
491
|
478
|
break;
|
492
|
479
|
|
493
|
480
|
case 10:
|
494
|
|
- // Debug code... Pay no attention to this stuff
|
495
|
|
- // it can be removed soon.
|
|
481
|
+ // [DEBUG] Pay no attention to this stuff. It can be removed soon.
|
496
|
482
|
SERIAL_ECHO_START;
|
497
|
483
|
SERIAL_ECHOLNPGM("Checking G29 has control of LCD Panel:");
|
498
|
|
- wait_for_user = true;
|
|
484
|
+ KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
485
|
+ ubl_has_control_of_lcd_panel++;
|
499
|
486
|
while (!ubl_lcd_clicked()) {
|
500
|
487
|
safe_delay(250);
|
501
|
|
- SERIAL_ECHO((int)ubl_encoderDiff);
|
502
|
|
- ubl_encoderDiff = 0;
|
503
|
|
- SERIAL_EOL;
|
|
488
|
+ if (ubl_encoderDiff) {
|
|
489
|
+ SERIAL_ECHOLN((int)ubl_encoderDiff);
|
|
490
|
+ ubl_encoderDiff = 0;
|
|
491
|
+ }
|
|
492
|
+ }
|
|
493
|
+ SERIAL_ECHOLNPGM("G29 giving back control of LCD Panel.");
|
|
494
|
+ ubl_has_control_of_lcd_panel = false;
|
|
495
|
+ KEEPALIVE_STATE(IN_HANDLER);
|
|
496
|
+ break;
|
|
497
|
+
|
|
498
|
+ case 11:
|
|
499
|
+ // [DEBUG] wait_for_user code. Pay no attention to this stuff. It can be removed soon.
|
|
500
|
+ SERIAL_ECHO_START;
|
|
501
|
+ SERIAL_ECHOLNPGM("Checking G29 has control of LCD Panel:");
|
|
502
|
+ KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
503
|
+ wait_for_user = true;
|
|
504
|
+ while (wait_for_user) {
|
|
505
|
+ safe_delay(250);
|
|
506
|
+ if (ubl_encoderDiff) {
|
|
507
|
+ SERIAL_ECHOLN((int)ubl_encoderDiff);
|
|
508
|
+ ubl_encoderDiff = 0;
|
|
509
|
+ }
|
504
|
510
|
}
|
505
|
511
|
SERIAL_ECHOLNPGM("G29 giving back control of LCD Panel.");
|
|
512
|
+ KEEPALIVE_STATE(IN_HANDLER);
|
506
|
513
|
break;
|
507
|
514
|
}
|
508
|
515
|
}
|
509
|
516
|
|
510
|
517
|
if (code_seen('T')) {
|
511
|
|
- Z1 = probe_pt(ubl_3_point_1_X, ubl_3_point_1_Y, false /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset;
|
512
|
|
- Z2 = probe_pt(ubl_3_point_2_X, ubl_3_point_2_Y, false /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset;
|
513
|
|
- Z3 = probe_pt(ubl_3_point_3_X, ubl_3_point_3_Y, true /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset;
|
|
518
|
+ float z1 = probe_pt(ubl_3_point_1_X, ubl_3_point_1_Y, false /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset,
|
|
519
|
+ z2 = probe_pt(ubl_3_point_2_X, ubl_3_point_2_Y, false /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset,
|
|
520
|
+ z3 = probe_pt(ubl_3_point_3_X, ubl_3_point_3_Y, true /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset;
|
514
|
521
|
|
515
|
|
- // We need to adjust Z1, Z2, Z3 by the Mesh Height at these points. Just because they are non-zero doesn't mean
|
|
522
|
+ // We need to adjust z1, z2, z3 by the Mesh Height at these points. Just because they are non-zero doesn't mean
|
516
|
523
|
// the Mesh is tilted! (We need to compensate each probe point by what the Mesh says that location's height is)
|
517
|
524
|
|
518
|
|
- Z1 -= ubl.get_z_correction(ubl_3_point_1_X, ubl_3_point_1_Y);
|
519
|
|
- Z2 -= ubl.get_z_correction(ubl_3_point_2_X, ubl_3_point_2_Y);
|
520
|
|
- Z3 -= ubl.get_z_correction(ubl_3_point_3_X, ubl_3_point_3_Y);
|
|
525
|
+ z1 -= ubl.get_z_correction(ubl_3_point_1_X, ubl_3_point_1_Y);
|
|
526
|
+ z2 -= ubl.get_z_correction(ubl_3_point_2_X, ubl_3_point_2_Y);
|
|
527
|
+ z3 -= ubl.get_z_correction(ubl_3_point_3_X, ubl_3_point_3_Y);
|
521
|
528
|
|
522
|
529
|
do_blocking_move_to_xy((X_MAX_POS - (X_MIN_POS)) / 2.0, (Y_MAX_POS - (Y_MIN_POS)) / 2.0);
|
523
|
|
- tilt_mesh_based_on_3pts(Z1, Z2, Z3);
|
|
530
|
+ tilt_mesh_based_on_3pts(z1, z2, z3);
|
524
|
531
|
}
|
525
|
532
|
|
526
|
533
|
//
|
|
@@ -610,13 +617,16 @@
|
610
|
617
|
save_ubl_active_state_and_disable();
|
611
|
618
|
//measured_z = probe_pt(x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER, ProbeDeployAndStow, g29_verbose_level);
|
612
|
619
|
|
613
|
|
- ubl_has_control_of_lcd_panel = true;// Grab the LCD Hardware
|
|
620
|
+ ubl_has_control_of_lcd_panel++; // Grab the LCD Hardware
|
614
|
621
|
measured_z = 1.5;
|
615
|
622
|
do_blocking_move_to_z(measured_z); // Get close to the bed, but leave some space so we don't damage anything
|
616
|
623
|
// The user is not going to be locking in a new Z-Offset very often so
|
617
|
624
|
// it won't be that painful to spin the Encoder Wheel for 1.5mm
|
618
|
625
|
lcd_implementation_clear();
|
619
|
626
|
lcd_z_offset_edit_setup(measured_z);
|
|
627
|
+
|
|
628
|
+ KEEPALIVE_STATE(PAUSED_FOR_USER);
|
|
629
|
+
|
620
|
630
|
do {
|
621
|
631
|
measured_z = lcd_z_offset_edit();
|
622
|
632
|
idle();
|
|
@@ -628,6 +638,8 @@
|
628
|
638
|
// or here. So, until we are done looking for a long Encoder Wheel Press,
|
629
|
639
|
// we need to take control of the panel
|
630
|
640
|
|
|
641
|
+ KEEPALIVE_STATE(IN_HANDLER);
|
|
642
|
+
|
631
|
643
|
lcd_return_to_status();
|
632
|
644
|
|
633
|
645
|
const millis_t nxt = millis() + 1500UL;
|
|
@@ -637,7 +649,6 @@
|
637
|
649
|
SERIAL_PROTOCOLLNPGM("\nZ-Offset Adjustment Stopped.");
|
638
|
650
|
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
|
639
|
651
|
lcd_setstatus("Z-Offset Stopped", true);
|
640
|
|
- ubl_has_control_of_lcd_panel = false;
|
641
|
652
|
restore_ubl_active_state_and_leave();
|
642
|
653
|
goto LEAVE;
|
643
|
654
|
}
|
|
@@ -702,14 +713,14 @@
|
702
|
713
|
for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
|
703
|
714
|
for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
|
704
|
715
|
if (!isnan(z_values[x][y]))
|
705
|
|
- z_values[x][y] -= mean + constant;
|
|
716
|
+ z_values[x][y] -= mean + ubl_constant;
|
706
|
717
|
}
|
707
|
718
|
|
708
|
719
|
void shift_mesh_height() {
|
709
|
720
|
for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
|
710
|
721
|
for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
|
711
|
722
|
if (!isnan(z_values[x][y]))
|
712
|
|
- z_values[x][y] += constant;
|
|
723
|
+ z_values[x][y] += ubl_constant;
|
713
|
724
|
}
|
714
|
725
|
|
715
|
726
|
/**
|
|
@@ -728,9 +739,7 @@
|
728
|
739
|
SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
|
729
|
740
|
lcd_quick_feedback();
|
730
|
741
|
STOW_PROBE();
|
731
|
|
- while (ubl_lcd_clicked() ) {
|
732
|
|
- idle();
|
733
|
|
- }
|
|
742
|
+ while (ubl_lcd_clicked()) idle();
|
734
|
743
|
ubl_has_control_of_lcd_panel = false;
|
735
|
744
|
restore_ubl_active_state_and_leave();
|
736
|
745
|
safe_delay(50); // Debounce the Encoder wheel
|
|
@@ -739,14 +748,18 @@
|
739
|
748
|
|
740
|
749
|
location = find_closest_mesh_point_of_type(INVALID, lx, ly, 1, NULL, do_furthest ); // the '1' says we want the location to be relative to the probe
|
741
|
750
|
if (location.x_index >= 0 && location.y_index >= 0) {
|
742
|
|
- const float xProbe = ubl.map_x_index_to_bed_location(location.x_index),
|
743
|
|
- yProbe = ubl.map_y_index_to_bed_location(location.y_index);
|
744
|
|
- if (xProbe < MIN_PROBE_X || xProbe > MAX_PROBE_X || yProbe < MIN_PROBE_Y || yProbe > MAX_PROBE_Y) {
|
745
|
|
- SERIAL_PROTOCOLLNPGM("?Error: Attempt to probe off the bed.");
|
|
751
|
+
|
|
752
|
+ const float rawx = ubl.map_x_index_to_bed_location(location.x_index),
|
|
753
|
+ rawy = ubl.map_y_index_to_bed_location(location.y_index);
|
|
754
|
+
|
|
755
|
+ // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
|
|
756
|
+ if (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y)) {
|
|
757
|
+ SERIAL_ERROR_START;
|
|
758
|
+ SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
|
746
|
759
|
ubl_has_control_of_lcd_panel = false;
|
747
|
760
|
goto LEAVE;
|
748
|
761
|
}
|
749
|
|
- const float measured_z = probe_pt(xProbe, yProbe, stow_probe, g29_verbose_level);
|
|
762
|
+ const float measured_z = probe_pt(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy), stow_probe, g29_verbose_level);
|
750
|
763
|
z_values[location.x_index][location.y_index] = measured_z + zprobe_zoffset;
|
751
|
764
|
}
|
752
|
765
|
|
|
@@ -831,6 +844,7 @@
|
831
|
844
|
}
|
832
|
845
|
|
833
|
846
|
float use_encoder_wheel_to_measure_point() {
|
|
847
|
+ KEEPALIVE_STATE(PAUSED_FOR_USER);
|
834
|
848
|
while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
|
835
|
849
|
idle();
|
836
|
850
|
if (ubl_encoderDiff) {
|
|
@@ -838,34 +852,35 @@
|
838
|
852
|
ubl_encoderDiff = 0;
|
839
|
853
|
}
|
840
|
854
|
}
|
|
855
|
+ KEEPALIVE_STATE(IN_HANDLER);
|
841
|
856
|
return current_position[Z_AXIS];
|
842
|
857
|
}
|
843
|
858
|
|
844
|
|
- float measure_business_card_thickness(const float &height_value) {
|
|
859
|
+ float measure_business_card_thickness(const float &in_height) {
|
845
|
860
|
|
846
|
861
|
ubl_has_control_of_lcd_panel++;
|
847
|
862
|
save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
|
848
|
863
|
|
849
|
864
|
SERIAL_PROTOCOLLNPGM("Place Shim Under Nozzle and Perform Measurement.");
|
850
|
|
- do_blocking_move_to_z(height_value);
|
|
865
|
+ do_blocking_move_to_z(in_height);
|
851
|
866
|
do_blocking_move_to_xy((float(X_MAX_POS) - float(X_MIN_POS)) / 2.0, (float(Y_MAX_POS) - float(Y_MIN_POS)) / 2.0);
|
852
|
867
|
//, min( planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS])/2.0);
|
853
|
868
|
|
854
|
|
- const float Z1 = use_encoder_wheel_to_measure_point();
|
|
869
|
+ const float z1 = use_encoder_wheel_to_measure_point();
|
855
|
870
|
do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
|
856
|
871
|
ubl_has_control_of_lcd_panel = false;
|
857
|
872
|
|
858
|
873
|
SERIAL_PROTOCOLLNPGM("Remove Shim and Measure Bed Height.");
|
859
|
|
- const float Z2 = use_encoder_wheel_to_measure_point();
|
|
874
|
+ const float z2 = use_encoder_wheel_to_measure_point();
|
860
|
875
|
do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
|
861
|
876
|
|
862
|
877
|
if (g29_verbose_level > 1) {
|
863
|
878
|
SERIAL_PROTOCOLPGM("Business Card is: ");
|
864
|
|
- SERIAL_PROTOCOL_F(abs(Z1 - Z2), 6);
|
|
879
|
+ SERIAL_PROTOCOL_F(abs(z1 - z2), 6);
|
865
|
880
|
SERIAL_PROTOCOLLNPGM("mm thick.");
|
866
|
881
|
}
|
867
|
882
|
restore_ubl_active_state_and_leave();
|
868
|
|
- return abs(Z1 - Z2);
|
|
883
|
+ return abs(z1 - z2);
|
869
|
884
|
}
|
870
|
885
|
|
871
|
886
|
void manually_probe_remaining_mesh(const float &lx, const float &ly, const float &z_clearance, const float &card_thickness, const bool do_ubl_mesh_map) {
|
|
@@ -881,21 +896,23 @@
|
881
|
896
|
if (do_ubl_mesh_map) ubl.display_map(map_type);
|
882
|
897
|
|
883
|
898
|
location = find_closest_mesh_point_of_type(INVALID, lx, ly, 0, NULL, false); // The '0' says we want to use the nozzle's position
|
884
|
|
- // It doesn't matter if the probe can not reach the
|
885
|
|
- // NAN location. This is a manual probe.
|
|
899
|
+ // It doesn't matter if the probe can't reach the NAN location. This is a manual probe.
|
886
|
900
|
if (location.x_index < 0 && location.y_index < 0) continue;
|
887
|
901
|
|
888
|
|
- const float xProbe = ubl.map_x_index_to_bed_location(location.x_index),
|
889
|
|
- yProbe = ubl.map_y_index_to_bed_location(location.y_index);
|
|
902
|
+ const float rawx = ubl.map_x_index_to_bed_location(location.x_index),
|
|
903
|
+ rawy = ubl.map_y_index_to_bed_location(location.y_index);
|
890
|
904
|
|
891
|
|
- // Modify to use if (position_is_reachable(pos[XYZ]))
|
892
|
|
- if (xProbe < (X_MIN_POS) || xProbe > (X_MAX_POS) || yProbe < (Y_MIN_POS) || yProbe > (Y_MAX_POS)) {
|
893
|
|
- SERIAL_PROTOCOLLNPGM("?Error: Attempt to probe off the bed.");
|
|
905
|
+ // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
|
|
906
|
+ if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) {
|
|
907
|
+ SERIAL_ERROR_START;
|
|
908
|
+ SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
|
894
|
909
|
ubl_has_control_of_lcd_panel = false;
|
895
|
910
|
goto LEAVE;
|
896
|
911
|
}
|
897
|
912
|
|
898
|
|
- const float dx = xProbe - last_x,
|
|
913
|
+ const float xProbe = LOGICAL_X_POSITION(rawx),
|
|
914
|
+ yProbe = LOGICAL_Y_POSITION(rawy),
|
|
915
|
+ dx = xProbe - last_x,
|
899
|
916
|
dy = yProbe - last_y;
|
900
|
917
|
|
901
|
918
|
if (HYPOT(dx, dy) < BIG_RAISE_NOT_NEEDED)
|
|
@@ -908,8 +925,10 @@
|
908
|
925
|
last_x = xProbe;
|
909
|
926
|
last_y = yProbe;
|
910
|
927
|
|
|
928
|
+ KEEPALIVE_STATE(PAUSED_FOR_USER);
|
911
|
929
|
ubl_has_control_of_lcd_panel = true;
|
912
|
|
- while (!ubl_lcd_clicked) { // we need the loop to move the nozzle based on the encoder wheel here!
|
|
930
|
+
|
|
931
|
+ while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
|
913
|
932
|
idle();
|
914
|
933
|
if (ubl_encoderDiff) {
|
915
|
934
|
do_blocking_move_to_z(current_position[Z_AXIS] + float(ubl_encoderDiff) / 100.0);
|
|
@@ -926,6 +945,7 @@
|
926
|
945
|
lcd_quick_feedback();
|
927
|
946
|
while (ubl_lcd_clicked()) idle();
|
928
|
947
|
ubl_has_control_of_lcd_panel = false;
|
|
948
|
+ KEEPALIVE_STATE(IN_HANDLER);
|
929
|
949
|
restore_ubl_active_state_and_leave();
|
930
|
950
|
return;
|
931
|
951
|
}
|
|
@@ -933,7 +953,7 @@
|
933
|
953
|
|
934
|
954
|
z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - card_thickness;
|
935
|
955
|
if (g29_verbose_level > 2) {
|
936
|
|
- SERIAL_PROTOCOL("Mesh Point Measured at: ");
|
|
956
|
+ SERIAL_PROTOCOLPGM("Mesh Point Measured at: ");
|
937
|
957
|
SERIAL_PROTOCOL_F(z_values[location.x_index][location.y_index], 6);
|
938
|
958
|
SERIAL_EOL;
|
939
|
959
|
}
|
|
@@ -943,52 +963,40 @@
|
943
|
963
|
|
944
|
964
|
LEAVE:
|
945
|
965
|
restore_ubl_active_state_and_leave();
|
|
966
|
+ KEEPALIVE_STATE(IN_HANDLER);
|
946
|
967
|
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
|
947
|
968
|
do_blocking_move_to_xy(lx, ly);
|
948
|
969
|
}
|
949
|
970
|
|
950
|
971
|
bool g29_parameter_parsing() {
|
951
|
|
-
|
952
|
972
|
#if ENABLED(ULTRA_LCD)
|
953
|
973
|
lcd_setstatus("Doing G29 UBL !", true);
|
954
|
974
|
lcd_quick_feedback();
|
955
|
975
|
#endif
|
956
|
976
|
|
957
|
|
- x_pos = current_position[X_AXIS];
|
958
|
|
- y_pos = current_position[Y_AXIS];
|
959
|
|
- x_flag = y_flag = repeat_flag = false;
|
960
|
|
- map_type = 0;
|
961
|
|
- constant = 0.0;
|
962
|
|
- repetition_cnt = 1;
|
963
|
|
-
|
964
|
|
- if ((x_flag = code_seen('X'))) {
|
965
|
|
- x_pos = code_value_float();
|
966
|
|
- if (x_pos < X_MIN_POS || x_pos > X_MAX_POS) {
|
967
|
|
- SERIAL_PROTOCOLLNPGM("Invalid X location specified.\n");
|
968
|
|
- return UBL_ERR;
|
969
|
|
- }
|
|
977
|
+ g29_verbose_level = code_seen('V') ? code_value_int() : 0;
|
|
978
|
+ if (g29_verbose_level < 0 || g29_verbose_level > 4) {
|
|
979
|
+ SERIAL_PROTOCOLLNPGM("Invalid Verbose Level specified. (0-4)\n");
|
|
980
|
+ return UBL_ERR;
|
970
|
981
|
}
|
971
|
982
|
|
972
|
|
- if ((y_flag = code_seen('Y'))) {
|
973
|
|
- y_pos = code_value_float();
|
974
|
|
- if (y_pos < Y_MIN_POS || y_pos > Y_MAX_POS) {
|
975
|
|
- SERIAL_PROTOCOLLNPGM("Invalid Y location specified.\n");
|
976
|
|
- return UBL_ERR;
|
977
|
|
- }
|
|
983
|
+ x_flag = code_seen('X') && code_has_value();
|
|
984
|
+ x_pos = x_flag ? code_value_float() : current_position[X_AXIS];
|
|
985
|
+ if (x_pos < LOGICAL_X_POSITION(X_MIN_POS) || x_pos > LOGICAL_X_POSITION(X_MAX_POS)) {
|
|
986
|
+ SERIAL_PROTOCOLLNPGM("Invalid X location specified.\n");
|
|
987
|
+ return UBL_ERR;
|
978
|
988
|
}
|
979
|
989
|
|
980
|
|
- if (x_flag != y_flag) {
|
981
|
|
- SERIAL_PROTOCOLLNPGM("Both X & Y locations must be specified.\n");
|
|
990
|
+ y_flag = code_seen('Y') && code_has_value();
|
|
991
|
+ y_pos = y_flag ? code_value_float() : current_position[Y_AXIS];
|
|
992
|
+ if (y_pos < LOGICAL_Y_POSITION(Y_MIN_POS) || y_pos > LOGICAL_Y_POSITION(Y_MAX_POS)) {
|
|
993
|
+ SERIAL_PROTOCOLLNPGM("Invalid Y location specified.\n");
|
982
|
994
|
return UBL_ERR;
|
983
|
995
|
}
|
984
|
996
|
|
985
|
|
- g29_verbose_level = 0;
|
986
|
|
- if (code_seen('V')) {
|
987
|
|
- g29_verbose_level = code_value_int();
|
988
|
|
- if (g29_verbose_level < 0 || g29_verbose_level > 4) {
|
989
|
|
- SERIAL_PROTOCOLLNPGM("Invalid Verbose Level specified. (0-4)\n");
|
990
|
|
- return UBL_ERR;
|
991
|
|
- }
|
|
997
|
+ if (x_flag != y_flag) {
|
|
998
|
+ SERIAL_PROTOCOLLNPGM("Both X & Y locations must be specified.\n");
|
|
999
|
+ return UBL_ERR;
|
992
|
1000
|
}
|
993
|
1001
|
|
994
|
1002
|
if (code_seen('A')) { // Activate the Unified Bed Leveling System
|
|
@@ -997,8 +1005,8 @@
|
997
|
1005
|
ubl.store_state();
|
998
|
1006
|
}
|
999
|
1007
|
|
1000
|
|
- if ((c_flag = code_seen('C') && code_has_value()))
|
1001
|
|
- constant = code_value_float();
|
|
1008
|
+ c_flag = code_seen('C') && code_has_value();
|
|
1009
|
+ ubl_constant = c_flag ? code_value_float() : 0.0;
|
1002
|
1010
|
|
1003
|
1011
|
if (code_seen('D')) { // Disable the Unified Bed Leveling System
|
1004
|
1012
|
ubl.state.active = 0;
|
|
@@ -1018,29 +1026,28 @@
|
1018
|
1026
|
}
|
1019
|
1027
|
#endif
|
1020
|
1028
|
|
1021
|
|
- if ((repeat_flag = code_seen('R'))) {
|
1022
|
|
- repetition_cnt = code_has_value() ? code_value_int() : 9999;
|
1023
|
|
- if (repetition_cnt < 1) {
|
1024
|
|
- SERIAL_PROTOCOLLNPGM("Invalid Repetition count.\n");
|
1025
|
|
- return UBL_ERR;
|
1026
|
|
- }
|
|
1029
|
+ repeat_flag = code_seen('R');
|
|
1030
|
+ repetition_cnt = repeat_flag ? (code_has_value() ? code_value_int() : 9999) : 1;
|
|
1031
|
+ if (repetition_cnt < 1) {
|
|
1032
|
+ SERIAL_PROTOCOLLNPGM("Invalid Repetition count.\n");
|
|
1033
|
+ return UBL_ERR;
|
1027
|
1034
|
}
|
1028
|
1035
|
|
1029
|
|
- if (code_seen('O')) { // Check if a map type was specified
|
1030
|
|
- map_type = code_value_int() ? code_has_value() : 0;
|
1031
|
|
- if ( map_type<0 || map_type>1) {
|
1032
|
|
- SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
|
1033
|
|
- return UBL_ERR;
|
1034
|
|
- }
|
|
1036
|
+ map_type = code_seen('O') && code_has_value() ? code_value_int() : 0;
|
|
1037
|
+ if (map_type < 0 || map_type > 1) {
|
|
1038
|
+ SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
|
|
1039
|
+ return UBL_ERR;
|
1035
|
1040
|
}
|
1036
|
1041
|
|
|
1042
|
+ /*
|
1037
|
1043
|
if (code_seen('M')) { // Check if a map type was specified
|
1038
|
|
- map_type = code_value_int() ? code_has_value() : 0;
|
1039
|
|
- if ( map_type<0 || map_type>1) {
|
|
1044
|
+ map_type = code_has_value() ? code_value_int() : 0;
|
|
1045
|
+ if (map_type < 0 || map_type > 1) {
|
1040
|
1046
|
SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
|
1041
|
1047
|
return UBL_ERR;
|
1042
|
1048
|
}
|
1043
|
1049
|
}
|
|
1050
|
+ //*/
|
1044
|
1051
|
|
1045
|
1052
|
return UBL_OK;
|
1046
|
1053
|
}
|
|
@@ -1054,20 +1061,15 @@
|
1054
|
1061
|
|
1055
|
1062
|
SERIAL_PROTOCOL(str);
|
1056
|
1063
|
SERIAL_PROTOCOL_F(f, 8);
|
1057
|
|
- SERIAL_PROTOCOL(" ");
|
|
1064
|
+ SERIAL_PROTOCOLPGM(" ");
|
1058
|
1065
|
ptr = (char*)&f;
|
1059
|
|
- for (uint8_t i = 0; i < 4; i++) {
|
1060
|
|
- SERIAL_PROTOCOL(" ");
|
1061
|
|
- prt_hex_byte(*ptr++);
|
1062
|
|
- }
|
1063
|
|
- SERIAL_PROTOCOL(" isnan()=");
|
1064
|
|
- SERIAL_PROTOCOL(isnan(f));
|
1065
|
|
- SERIAL_PROTOCOL(" isinf()=");
|
1066
|
|
- SERIAL_PROTOCOL(isinf(f));
|
|
1066
|
+ for (uint8_t i = 0; i < 4; i++)
|
|
1067
|
+ SERIAL_PROTOCOLPAIR(" ", hex_byte(*ptr++));
|
|
1068
|
+ SERIAL_PROTOCOLPAIR(" isnan()=", isnan(f));
|
|
1069
|
+ SERIAL_PROTOCOLPAIR(" isinf()=", isinf(f));
|
1067
|
1070
|
|
1068
|
|
- constexpr float g = INFINITY;
|
1069
|
|
- if (f == -g)
|
1070
|
|
- SERIAL_PROTOCOL(" Minus Infinity detected.");
|
|
1071
|
+ if (f == -INFINITY)
|
|
1072
|
+ SERIAL_PROTOCOLPGM(" Minus Infinity detected.");
|
1071
|
1073
|
|
1072
|
1074
|
SERIAL_EOL;
|
1073
|
1075
|
}
|
|
@@ -1104,7 +1106,6 @@
|
1104
|
1106
|
*/
|
1105
|
1107
|
void g29_what_command() {
|
1106
|
1108
|
const uint16_t k = E2END - ubl_eeprom_start;
|
1107
|
|
- statistics_flag++;
|
1108
|
1109
|
|
1109
|
1110
|
SERIAL_PROTOCOLPGM("Unified Bed Leveling System Version 1.00 ");
|
1110
|
1111
|
if (ubl.state.active)
|
|
@@ -1117,8 +1118,7 @@
|
1117
|
1118
|
if (ubl.state.eeprom_storage_slot == -1)
|
1118
|
1119
|
SERIAL_PROTOCOLPGM("No Mesh Loaded.");
|
1119
|
1120
|
else {
|
1120
|
|
- SERIAL_PROTOCOLPGM("Mesh: ");
|
1121
|
|
- prt_hex_word(ubl.state.eeprom_storage_slot);
|
|
1121
|
+ SERIAL_PROTOCOLPAIR("Mesh ", ubl.state.eeprom_storage_slot);
|
1122
|
1122
|
SERIAL_PROTOCOLPGM(" Loaded.");
|
1123
|
1123
|
}
|
1124
|
1124
|
SERIAL_EOL;
|
|
@@ -1136,7 +1136,7 @@
|
1136
|
1136
|
|
1137
|
1137
|
SERIAL_PROTOCOLPGM("X-Axis Mesh Points at: ");
|
1138
|
1138
|
for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
|
1139
|
|
- SERIAL_PROTOCOL_F( ubl.map_x_index_to_bed_location(i), 1);
|
|
1139
|
+ SERIAL_PROTOCOL_F(LOGICAL_X_POSITION(ubl.map_x_index_to_bed_location(i)), 1);
|
1140
|
1140
|
SERIAL_PROTOCOLPGM(" ");
|
1141
|
1141
|
safe_delay(50);
|
1142
|
1142
|
}
|
|
@@ -1144,7 +1144,7 @@
|
1144
|
1144
|
|
1145
|
1145
|
SERIAL_PROTOCOLPGM("Y-Axis Mesh Points at: ");
|
1146
|
1146
|
for (uint8_t i = 0; i < UBL_MESH_NUM_Y_POINTS; i++) {
|
1147
|
|
- SERIAL_PROTOCOL_F( ubl.map_y_index_to_bed_location(i), 1);
|
|
1147
|
+ SERIAL_PROTOCOL_F(LOGICAL_Y_POSITION(ubl.map_y_index_to_bed_location(i)), 1);
|
1148
|
1148
|
SERIAL_PROTOCOLPGM(" ");
|
1149
|
1149
|
safe_delay(50);
|
1150
|
1150
|
}
|
|
@@ -1162,13 +1162,9 @@
|
1162
|
1162
|
SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
|
1163
|
1163
|
SERIAL_EOL;
|
1164
|
1164
|
safe_delay(50);
|
1165
|
|
- SERIAL_PROTOCOLPGM("Free EEPROM space starts at: 0x");
|
1166
|
|
- prt_hex_word(ubl_eeprom_start);
|
1167
|
|
- SERIAL_EOL;
|
|
1165
|
+ SERIAL_PROTOCOLLNPAIR("Free EEPROM space starts at: 0x", hex_word(ubl_eeprom_start));
|
1168
|
1166
|
|
1169
|
|
- SERIAL_PROTOCOLPGM("end of EEPROM : ");
|
1170
|
|
- prt_hex_word(E2END);
|
1171
|
|
- SERIAL_EOL;
|
|
1167
|
+ SERIAL_PROTOCOLLNPAIR("end of EEPROM : ", hex_word(E2END));
|
1172
|
1168
|
safe_delay(50);
|
1173
|
1169
|
|
1174
|
1170
|
SERIAL_PROTOCOLLNPAIR("sizeof(ubl) : ", (int)sizeof(ubl));
|
|
@@ -1177,18 +1173,14 @@
|
1177
|
1173
|
SERIAL_EOL;
|
1178
|
1174
|
safe_delay(50);
|
1179
|
1175
|
|
1180
|
|
- SERIAL_PROTOCOLPGM("EEPROM free for UBL: 0x");
|
1181
|
|
- prt_hex_word(k);
|
1182
|
|
- SERIAL_EOL;
|
|
1176
|
+ SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: 0x", hex_word(k));
|
1183
|
1177
|
safe_delay(50);
|
1184
|
1178
|
|
1185
|
|
- SERIAL_PROTOCOLPGM("EEPROM can hold 0x");
|
1186
|
|
- prt_hex_word(k / sizeof(z_values));
|
|
1179
|
+ SERIAL_PROTOCOLPAIR("EEPROM can hold ", k / sizeof(z_values));
|
1187
|
1180
|
SERIAL_PROTOCOLLNPGM(" meshes.\n");
|
1188
|
1181
|
safe_delay(50);
|
1189
|
1182
|
|
1190
|
|
- SERIAL_PROTOCOLPGM("sizeof(ubl.state) :");
|
1191
|
|
- prt_hex_word(sizeof(ubl.state));
|
|
1183
|
+ SERIAL_PROTOCOLPAIR("sizeof(ubl.state) : ", (int)sizeof(ubl.state));
|
1192
|
1184
|
|
1193
|
1185
|
SERIAL_PROTOCOLPAIR("\nUBL_MESH_NUM_X_POINTS ", UBL_MESH_NUM_X_POINTS);
|
1194
|
1186
|
SERIAL_PROTOCOLPAIR("\nUBL_MESH_NUM_Y_POINTS ", UBL_MESH_NUM_Y_POINTS);
|
|
@@ -1222,12 +1214,12 @@
|
1222
|
1214
|
SERIAL_ECHOLNPGM("EEPROM Dump:");
|
1223
|
1215
|
for (uint16_t i = 0; i < E2END + 1; i += 16) {
|
1224
|
1216
|
if (!(i & 0x3)) idle();
|
1225
|
|
- prt_hex_word(i);
|
|
1217
|
+ print_hex_word(i);
|
1226
|
1218
|
SERIAL_ECHOPGM(": ");
|
1227
|
1219
|
for (uint16_t j = 0; j < 16; j++) {
|
1228
|
1220
|
kkkk = i + j;
|
1229
|
1221
|
eeprom_read_block(&cccc, (void *)kkkk, 1);
|
1230
|
|
- prt_hex_byte(cccc);
|
|
1222
|
+ print_hex_byte(cccc);
|
1231
|
1223
|
SERIAL_ECHO(' ');
|
1232
|
1224
|
}
|
1233
|
1225
|
SERIAL_EOL;
|
|
@@ -1259,9 +1251,8 @@
|
1259
|
1251
|
eeprom_read_block((void *)&tmp_z_values, (void *)j, sizeof(tmp_z_values));
|
1260
|
1252
|
|
1261
|
1253
|
SERIAL_ECHOPAIR("Subtracting Mesh ", storage_slot);
|
1262
|
|
- SERIAL_PROTOCOLPGM(" loaded from EEPROM address "); // Soon, we can remove the extra clutter of printing
|
1263
|
|
- prt_hex_word(j); // the address in the EEPROM where the Mesh is stored.
|
1264
|
|
- SERIAL_EOL;
|
|
1254
|
+ SERIAL_PROTOCOLLNPAIR(" loaded from EEPROM address ", hex_word(j)); // Soon, we can remove the extra clutter of printing
|
|
1255
|
+ // the address in the EEPROM where the Mesh is stored.
|
1265
|
1256
|
|
1266
|
1257
|
for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
|
1267
|
1258
|
for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
|
|
@@ -1269,7 +1260,6 @@
|
1269
|
1260
|
}
|
1270
|
1261
|
|
1271
|
1262
|
mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType type, const float &lx, const float &ly, const bool probe_as_reference, unsigned int bits[16], bool far_flag) {
|
1272
|
|
- int i, j, k, l;
|
1273
|
1263
|
float distance, closest = far_flag ? -99999.99 : 99999.99;
|
1274
|
1264
|
mesh_index_pair return_val;
|
1275
|
1265
|
|
|
@@ -1282,8 +1272,8 @@
|
1282
|
1272
|
const float px = lx - (probe_as_reference ? X_PROBE_OFFSET_FROM_EXTRUDER : 0),
|
1283
|
1273
|
py = ly - (probe_as_reference ? Y_PROBE_OFFSET_FROM_EXTRUDER : 0);
|
1284
|
1274
|
|
1285
|
|
- for (i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
|
1286
|
|
- for (j = 0; j < UBL_MESH_NUM_Y_POINTS; j++) {
|
|
1275
|
+ for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
|
|
1276
|
+ for (uint8_t j = 0; j < UBL_MESH_NUM_Y_POINTS; j++) {
|
1287
|
1277
|
|
1288
|
1278
|
if ( (type == INVALID && isnan(z_values[i][j])) // Check to see if this location holds the right thing
|
1289
|
1279
|
|| (type == REAL && !isnan(z_values[i][j]))
|
|
@@ -1292,42 +1282,45 @@
|
1292
|
1282
|
|
1293
|
1283
|
// We only get here if we found a Mesh Point of the specified type
|
1294
|
1284
|
|
1295
|
|
- const float mx = LOGICAL_X_POSITION(ubl.map_x_index_to_bed_location(i)), // Check if we can probe this mesh location
|
1296
|
|
- my = LOGICAL_Y_POSITION(ubl.map_y_index_to_bed_location(j));
|
|
1285
|
+ const float rawx = ubl.map_x_index_to_bed_location(i), // Check if we can probe this mesh location
|
|
1286
|
+ rawy = ubl.map_y_index_to_bed_location(j);
|
1297
|
1287
|
|
1298
|
|
- // If we are using the probe as the reference there are some locations we can't get to.
|
1299
|
|
- // We prune these out of the list and ignore them until the next Phase where we do the
|
1300
|
|
- // manual nozzle probing.
|
|
1288
|
+ // If using the probe as the reference there are some unreachable locations.
|
|
1289
|
+ // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
|
1301
|
1290
|
|
1302
|
1291
|
if (probe_as_reference &&
|
1303
|
|
- (mx < (MIN_PROBE_X) || mx > (MAX_PROBE_X) || my < (MIN_PROBE_Y) || my > (MAX_PROBE_Y))
|
|
1292
|
+ (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y))
|
1304
|
1293
|
) continue;
|
1305
|
1294
|
|
1306
|
|
- // We can get to it. Let's see if it is the closest location to the nozzle.
|
|
1295
|
+ // Unreachable. Check if it's the closest location to the nozzle.
|
1307
|
1296
|
// Add in a weighting factor that considers the current location of the nozzle.
|
1308
|
1297
|
|
|
1298
|
+ const float mx = LOGICAL_X_POSITION(rawx), // Check if we can probe this mesh location
|
|
1299
|
+ my = LOGICAL_Y_POSITION(rawy);
|
|
1300
|
+
|
1309
|
1301
|
distance = HYPOT(px - mx, py - my) + HYPOT(current_x - mx, current_y - my) * 0.1;
|
1310
|
1302
|
|
1311
|
|
- if (far_flag) { // If doing the far_flag action, we want to be as far as possible
|
1312
|
|
- for (k = 0; k < UBL_MESH_NUM_X_POINTS; k++) { // from the starting point and from any other probed points. We
|
1313
|
|
- for (l = 0; l < UBL_MESH_NUM_Y_POINTS; l++) { // want the next point spread out and filling in any blank spaces
|
1314
|
|
- if ( !isnan(z_values[k][l])) { // in the mesh. So we add in some of the distance to every probed
|
1315
|
|
- distance += (i-k)*(i-k)*MESH_X_DIST*.05; // point we can find.
|
1316
|
|
- distance += (j-l)*(j-l)*MESH_Y_DIST*.05;
|
1317
|
|
- }
|
|
1303
|
+ if (far_flag) { // If doing the far_flag action, we want to be as far as possible
|
|
1304
|
+ for (uint8_t k = 0; k < UBL_MESH_NUM_X_POINTS; k++) { // from the starting point and from any other probed points. We
|
|
1305
|
+ for (uint8_t l = 0; l < UBL_MESH_NUM_Y_POINTS; l++) { // want the next point spread out and filling in any blank spaces
|
|
1306
|
+ if (!isnan(z_values[k][l])) { // in the mesh. So we add in some of the distance to every probed
|
|
1307
|
+ distance += sq(i - k) * (MESH_X_DIST) * .05 // point we can find.
|
|
1308
|
+ + sq(j - l) * (MESH_Y_DIST) * .05;
|
|
1309
|
+ }
|
1318
|
1310
|
}
|
1319
|
|
- }
|
1320
|
|
- }
|
|
1311
|
+ }
|
|
1312
|
+ }
|
1321
|
1313
|
|
1322
|
|
- if ( (!far_flag&&(distance < closest)) || (far_flag&&(distance > closest)) ) { // if far_flag, look for furthest away point
|
1323
|
|
- closest = distance; // We found a closer location with
|
|
1314
|
+ if (far_flag == (distance > closest) && distance != closest) { // if far_flag, look for farthest point
|
|
1315
|
+ closest = distance; // We found a closer/farther location with
|
1324
|
1316
|
return_val.x_index = i; // the specified type of mesh value.
|
1325
|
1317
|
return_val.y_index = j;
|
1326
|
1318
|
return_val.distance = closest;
|
1327
|
1319
|
}
|
1328
|
1320
|
}
|
1329
|
|
- }
|
1330
|
|
- }
|
|
1321
|
+ } // for j
|
|
1322
|
+ } // for i
|
|
1323
|
+
|
1331
|
1324
|
return return_val;
|
1332
|
1325
|
}
|
1333
|
1326
|
|
|
@@ -1356,27 +1349,30 @@
|
1356
|
1349
|
bit_clear(not_done, location.x_index, location.y_index); // Mark this location as 'adjusted' so we will find a
|
1357
|
1350
|
// different location the next time through the loop
|
1358
|
1351
|
|
1359
|
|
- const float xProbe = ubl.map_x_index_to_bed_location(location.x_index),
|
1360
|
|
- yProbe = ubl.map_y_index_to_bed_location(location.y_index);
|
1361
|
|
- if (xProbe < X_MIN_POS || xProbe > X_MAX_POS || yProbe < Y_MIN_POS || yProbe > Y_MAX_POS) { // In theory, we don't need this check.
|
1362
|
|
- SERIAL_PROTOCOLLNPGM("?Error: Attempt to edit off the bed."); // This really can't happen, but for now,
|
1363
|
|
- ubl_has_control_of_lcd_panel = false; // Let's do the check.
|
|
1352
|
+ const float rawx = ubl.map_x_index_to_bed_location(location.x_index),
|
|
1353
|
+ rawy = ubl.map_y_index_to_bed_location(location.y_index);
|
|
1354
|
+
|
|
1355
|
+ // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
|
|
1356
|
+ if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) { // In theory, we don't need this check.
|
|
1357
|
+ SERIAL_ERROR_START;
|
|
1358
|
+ SERIAL_ERRORLNPGM("Attempt to edit off the bed."); // This really can't happen, but do the check for now
|
|
1359
|
+ ubl_has_control_of_lcd_panel = false;
|
1364
|
1360
|
goto FINE_TUNE_EXIT;
|
1365
|
1361
|
}
|
1366
|
1362
|
|
1367
|
1363
|
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE); // Move the nozzle to where we are going to edit
|
1368
|
|
- do_blocking_move_to_xy(xProbe, yProbe);
|
|
1364
|
+ do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy));
|
1369
|
1365
|
float new_z = z_values[location.x_index][location.y_index];
|
1370
|
1366
|
|
1371
|
1367
|
round_off = (int32_t)(new_z * 1000.0); // we chop off the last digits just to be clean. We are rounding to the
|
1372
|
1368
|
new_z = float(round_off) / 1000.0;
|
1373
|
1369
|
|
|
1370
|
+ KEEPALIVE_STATE(PAUSED_FOR_USER);
|
1374
|
1371
|
ubl_has_control_of_lcd_panel = true;
|
1375
|
1372
|
|
1376
|
1373
|
lcd_implementation_clear();
|
1377
|
1374
|
lcd_mesh_edit_setup(new_z);
|
1378
|
1375
|
|
1379
|
|
- wait_for_user = true;
|
1380
|
1376
|
do {
|
1381
|
1377
|
new_z = lcd_mesh_edit();
|
1382
|
1378
|
idle();
|
|
@@ -1393,13 +1389,12 @@
|
1393
|
1389
|
idle();
|
1394
|
1390
|
if (ELAPSED(millis(), nxt)) {
|
1395
|
1391
|
lcd_return_to_status();
|
1396
|
|
-// SERIAL_PROTOCOLLNPGM("\nFine Tuning of Mesh Stopped.");
|
|
1392
|
+ //SERIAL_PROTOCOLLNPGM("\nFine Tuning of Mesh Stopped.");
|
1397
|
1393
|
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
|
1398
|
1394
|
lcd_setstatus("Mesh Editing Stopped", true);
|
1399
|
1395
|
|
1400
|
1396
|
while (ubl_lcd_clicked()) idle();
|
1401
|
1397
|
|
1402
|
|
- ubl_has_control_of_lcd_panel = false;
|
1403
|
1398
|
goto FINE_TUNE_EXIT;
|
1404
|
1399
|
}
|
1405
|
1400
|
}
|
|
@@ -1415,6 +1410,7 @@
|
1415
|
1410
|
FINE_TUNE_EXIT:
|
1416
|
1411
|
|
1417
|
1412
|
ubl_has_control_of_lcd_panel = false;
|
|
1413
|
+ KEEPALIVE_STATE(IN_HANDLER);
|
1418
|
1414
|
|
1419
|
1415
|
if (do_ubl_mesh_map) ubl.display_map(map_type);
|
1420
|
1416
|
restore_ubl_active_state_and_leave();
|