Browse Source

Fix UBL mesh editor on delta (#13478)

Thomas Moore 6 years ago
parent
commit
13a12f8a87
1 changed files with 39 additions and 13 deletions
  1. 39
    13
      Marlin/src/lcd/menu/menu_ubl.cpp

+ 39
- 13
Marlin/src/lcd/menu/menu_ubl.cpp View File

@@ -431,9 +431,21 @@ void _lcd_ubl_map_lcd_edit_cmd() {
431 431
  * UBL LCD Map Movement
432 432
  */
433 433
 void ubl_map_move_to_xy() {
434
-  current_position[X_AXIS] = pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]);
435
-  current_position[Y_AXIS] = pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]);
436
-  planner.buffer_line(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
434
+  REMEMBER(fr, feedrate_mm_s, MMM_TO_MMS(XY_PROBE_SPEED));
435
+
436
+  set_destination_from_current();          // sync destination at the start
437
+
438
+  #if ENABLED(DELTA)
439
+    if (current_position[Z_AXIS] > delta_clip_start_height) {
440
+      destination[Z_AXIS] = delta_clip_start_height;
441
+      prepare_move_to_destination();
442
+    }
443
+  #endif
444
+
445
+  destination[X_AXIS] = pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]);
446
+  destination[Y_AXIS] = pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]);
447
+
448
+  prepare_move_to_destination();
437 449
 }
438 450
 
439 451
 /**
@@ -461,22 +473,33 @@ void _lcd_ubl_output_map_lcd() {
461 473
   if (ui.encoderPosition) {
462 474
     step_scaler += (int32_t)ui.encoderPosition;
463 475
     x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
464
-    if (ABS(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0;
465 476
     ui.encoderPosition = 0;
466 477
     ui.refresh(LCDVIEW_REDRAW_NOW);
467 478
   }
468 479
 
469
-  // Encoder to the right (++)
470
-  if (x_plot >= GRID_MAX_POINTS_X) { x_plot = 0; y_plot++; }
471
-  if (y_plot >= GRID_MAX_POINTS_Y) y_plot = 0;
480
+  #if IS_KINEMATIC
481
+    #define KEEP_LOOPING true   // Loop until a valid point is found
482
+  #else
483
+    #define KEEP_LOOPING false
484
+  #endif
485
+
486
+  do {
487
+    // Encoder to the right (++)
488
+    if (x_plot >= GRID_MAX_POINTS_X) { x_plot = 0; y_plot++; }
489
+    if (y_plot >= GRID_MAX_POINTS_Y) y_plot = 0;
472 490
 
473
-  // Encoder to the left (--)
474
-  if (x_plot <= GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1)) { x_plot = GRID_MAX_POINTS_X - 1; y_plot--; }
475
-  if (y_plot <= GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1)) y_plot = GRID_MAX_POINTS_Y - 1;
491
+    // Encoder to the left (--)
492
+    if (x_plot < 0) { x_plot = GRID_MAX_POINTS_X - 1; y_plot--; }
493
+    if (y_plot < 0) y_plot = GRID_MAX_POINTS_Y - 1;
476 494
 
477
-  // Prevent underrun/overrun of plot numbers
478
-  x_plot = constrain(x_plot, GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1), GRID_MAX_POINTS_X + 1);
479
-  y_plot = constrain(y_plot, GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1), GRID_MAX_POINTS_Y + 1);
495
+    #if IS_KINEMATIC
496
+      const float x = pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]),
497
+                  y = pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]);
498
+      if (position_is_reachable(x, y)) break; // Found a valid point
499
+      x_plot += (step_scaler < 0) ? -1 : 1;
500
+    #endif
501
+
502
+  } while(KEEP_LOOPING);
480 503
 
481 504
   // Determine number of points to edit
482 505
   #if IS_KINEMATIC
@@ -487,6 +510,9 @@ void _lcd_ubl_output_map_lcd() {
487 510
     n_edit_pts = yc ? (xc ? 9 : 6) : (xc ? 6 : 4); // Corners
488 511
   #endif
489 512
 
513
+  // Cleanup
514
+  if (ABS(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0;
515
+
490 516
   if (ui.should_draw()) {
491 517
     ui.ubl_plot(x_plot, y_plot);
492 518
 

Loading…
Cancel
Save