|
@@ -32,7 +32,25 @@
|
32
|
32
|
|
33
|
33
|
extern float destination[XYZE];
|
34
|
34
|
extern void set_current_to_destination();
|
35
|
|
- extern float delta_segments_per_second;
|
|
35
|
+
|
|
36
|
+#if ENABLED(DELTA)
|
|
37
|
+
|
|
38
|
+ extern float delta[ABC],
|
|
39
|
+ endstop_adj[ABC];
|
|
40
|
+
|
|
41
|
+ extern float delta_radius,
|
|
42
|
+ delta_tower_angle_trim[2],
|
|
43
|
+ delta_tower[ABC][2],
|
|
44
|
+ delta_diagonal_rod,
|
|
45
|
+ delta_calibration_radius,
|
|
46
|
+ delta_diagonal_rod_2_tower[ABC],
|
|
47
|
+ delta_segments_per_second,
|
|
48
|
+ delta_clip_start_height;
|
|
49
|
+
|
|
50
|
+ extern float delta_safe_distance_from_top();
|
|
51
|
+
|
|
52
|
+#endif
|
|
53
|
+
|
36
|
54
|
|
37
|
55
|
static void debug_echo_axis(const AxisEnum axis) {
|
38
|
56
|
if (current_position[axis] == destination[axis])
|
|
@@ -470,51 +488,76 @@
|
470
|
488
|
#endif
|
471
|
489
|
|
472
|
490
|
// We don't want additional apply_leveling() performed by regular buffer_line or buffer_line_kinematic,
|
473
|
|
- // so we call _buffer_line directly here. Per-segmented leveling performed first.
|
|
491
|
+ // so we call _buffer_line directly here. Per-segmented leveling and kinematics performed first.
|
474
|
492
|
|
475
|
|
- static inline void ubl_buffer_line_segment(const float ltarget[XYZE], const float &fr_mm_s, const uint8_t extruder) {
|
|
493
|
+ inline void _O2 ubl_buffer_segment_raw( float rx, float ry, float rz, float le, float fr ) {
|
476
|
494
|
|
477
|
|
- #if IS_KINEMATIC
|
|
495
|
+ #if ENABLED(DELTA) // apply delta inverse_kinematics
|
478
|
496
|
|
479
|
|
- inverse_kinematics(ltarget); // this writes delta[ABC] from ltarget[XYZ] but does not modify ltarget
|
480
|
|
- float feedrate = fr_mm_s;
|
|
497
|
+ const float delta_A = rz + sqrt( delta_diagonal_rod_2_tower[A_AXIS]
|
|
498
|
+ - HYPOT2( delta_tower[A_AXIS][X_AXIS] - rx,
|
|
499
|
+ delta_tower[A_AXIS][Y_AXIS] - ry ));
|
481
|
500
|
|
482
|
|
- #if IS_SCARA // scale the feed rate from mm/s to degrees/s
|
483
|
|
- float adiff = abs(delta[A_AXIS] - scara_oldA),
|
484
|
|
- bdiff = abs(delta[B_AXIS] - scara_oldB);
|
485
|
|
- scara_oldA = delta[A_AXIS];
|
486
|
|
- scara_oldB = delta[B_AXIS];
|
487
|
|
- feedrate = max(adiff, bdiff) * scara_feed_factor;
|
488
|
|
- #endif
|
|
501
|
+ const float delta_B = rz + sqrt( delta_diagonal_rod_2_tower[B_AXIS]
|
|
502
|
+ - HYPOT2( delta_tower[B_AXIS][X_AXIS] - rx,
|
|
503
|
+ delta_tower[B_AXIS][Y_AXIS] - ry ));
|
|
504
|
+
|
|
505
|
+ const float delta_C = rz + sqrt( delta_diagonal_rod_2_tower[C_AXIS]
|
|
506
|
+ - HYPOT2( delta_tower[C_AXIS][X_AXIS] - rx,
|
|
507
|
+ delta_tower[C_AXIS][Y_AXIS] - ry ));
|
|
508
|
+
|
|
509
|
+ planner._buffer_line(delta_A, delta_B, delta_C, le, fr, active_extruder);
|
|
510
|
+
|
|
511
|
+ #elif IS_SCARA // apply scara inverse_kinematics (should be changed to save raw->logical->raw)
|
|
512
|
+
|
|
513
|
+ const float lseg[XYZ] = { LOGICAL_X_POSITION(rx),
|
|
514
|
+ LOGICAL_Y_POSITION(ry),
|
|
515
|
+ LOGICAL_Z_POSITION(rz)
|
|
516
|
+ };
|
|
517
|
+
|
|
518
|
+ inverse_kinematics(lseg); // this writes delta[ABC] from lseg[XYZ]
|
|
519
|
+ // should move the feedrate scaling to scara inverse_kinematics
|
489
|
520
|
|
490
|
|
- planner._buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], ltarget[E_AXIS], feedrate, extruder);
|
|
521
|
+ float adiff = abs(delta[A_AXIS] - scara_oldA),
|
|
522
|
+ bdiff = abs(delta[B_AXIS] - scara_oldB);
|
|
523
|
+ scara_oldA = delta[A_AXIS];
|
|
524
|
+ scara_oldB = delta[B_AXIS];
|
|
525
|
+ float s_feedrate = max(adiff, bdiff) * scara_feed_factor;
|
491
|
526
|
|
492
|
|
- #else // cartesian
|
|
527
|
+ planner._buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], le, s_feedrate, active_extruder);
|
493
|
528
|
|
494
|
|
- planner._buffer_line(ltarget[X_AXIS], ltarget[Y_AXIS], ltarget[Z_AXIS], ltarget[E_AXIS], fr_mm_s, extruder);
|
|
529
|
+ #else // CARTESIAN
|
|
530
|
+
|
|
531
|
+ // Cartesian _buffer_line seems to take LOGICAL, not RAW coordinates
|
|
532
|
+
|
|
533
|
+ const float lx = LOGICAL_X_POSITION(rx),
|
|
534
|
+ ly = LOGICAL_Y_POSITION(ry),
|
|
535
|
+ lz = LOGICAL_Z_POSITION(rz);
|
|
536
|
+
|
|
537
|
+ planner._buffer_line(lx, ly, lz, le, fr, active_extruder);
|
495
|
538
|
|
496
|
539
|
#endif
|
|
540
|
+
|
497
|
541
|
}
|
498
|
542
|
|
|
543
|
+
|
499
|
544
|
/**
|
500
|
|
- * Prepare a linear move for DELTA/SCARA/CARTESIAN with UBL and FADE semantics.
|
|
545
|
+ * Prepare a segmented linear move for DELTA/SCARA/CARTESIAN with UBL and FADE semantics.
|
501
|
546
|
* This calls planner._buffer_line multiple times for small incremental moves.
|
502
|
|
- * Returns true if the caller did NOT update current_position, otherwise false.
|
|
547
|
+ * Returns true if did NOT move, false if moved (requires current_position update).
|
503
|
548
|
*/
|
504
|
549
|
|
505
|
|
- static bool unified_bed_leveling::prepare_linear_move_to(const float ltarget[XYZE], const float &feedrate) {
|
|
550
|
+ bool _O2 unified_bed_leveling::prepare_segmented_line_to(const float ltarget[XYZE], const float &feedrate) {
|
506
|
551
|
|
507
|
552
|
if (!position_is_reachable_xy(ltarget[X_AXIS], ltarget[Y_AXIS])) // fail if moving outside reachable boundary
|
508
|
553
|
return true; // did not move, so current_position still accurate
|
509
|
554
|
|
510
|
|
- const float difference[XYZE] = { // cartesian distances moved in XYZE
|
511
|
|
- ltarget[X_AXIS] - current_position[X_AXIS],
|
512
|
|
- ltarget[Y_AXIS] - current_position[Y_AXIS],
|
513
|
|
- ltarget[Z_AXIS] - current_position[Z_AXIS],
|
514
|
|
- ltarget[E_AXIS] - current_position[E_AXIS]
|
515
|
|
- };
|
|
555
|
+ const float tot_dx = ltarget[X_AXIS] - current_position[X_AXIS],
|
|
556
|
+ tot_dy = ltarget[Y_AXIS] - current_position[Y_AXIS],
|
|
557
|
+ tot_dz = ltarget[Z_AXIS] - current_position[Z_AXIS],
|
|
558
|
+ tot_de = ltarget[E_AXIS] - current_position[E_AXIS];
|
516
|
559
|
|
517
|
|
- const float cartesian_xy_mm = HYPOT(difference[X_AXIS], difference[Y_AXIS]); // total horizontal xy distance
|
|
560
|
+ const float cartesian_xy_mm = HYPOT(tot_dx, tot_dy); // total horizontal xy distance
|
518
|
561
|
|
519
|
562
|
#if IS_KINEMATIC
|
520
|
563
|
const float seconds = cartesian_xy_mm / feedrate; // seconds to move xy distance at requested rate
|
|
@@ -534,16 +577,19 @@
|
534
|
577
|
scara_oldB = stepper.get_axis_position_degrees(B_AXIS);
|
535
|
578
|
#endif
|
536
|
579
|
|
537
|
|
- const float segment_distance[XYZE] = { // length for each segment
|
538
|
|
- difference[X_AXIS] * inv_segments,
|
539
|
|
- difference[Y_AXIS] * inv_segments,
|
540
|
|
- difference[Z_AXIS] * inv_segments,
|
541
|
|
- difference[E_AXIS] * inv_segments
|
542
|
|
- };
|
|
580
|
+ const float seg_dx = tot_dx * inv_segments,
|
|
581
|
+ seg_dy = tot_dy * inv_segments,
|
|
582
|
+ seg_dz = tot_dz * inv_segments,
|
|
583
|
+ seg_de = tot_de * inv_segments;
|
543
|
584
|
|
544
|
585
|
// Note that E segment distance could vary slightly as z mesh height
|
545
|
586
|
// changes for each segment, but small enough to ignore.
|
546
|
587
|
|
|
588
|
+ float seg_rx = RAW_X_POSITION(current_position[X_AXIS]),
|
|
589
|
+ seg_ry = RAW_Y_POSITION(current_position[Y_AXIS]),
|
|
590
|
+ seg_rz = RAW_Z_POSITION(current_position[Z_AXIS]),
|
|
591
|
+ seg_le = current_position[E_AXIS];
|
|
592
|
+
|
547
|
593
|
const bool above_fade_height = (
|
548
|
594
|
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
549
|
595
|
planner.z_fade_height != 0 && planner.z_fade_height < RAW_Z_POSITION(ltarget[Z_AXIS])
|
|
@@ -558,21 +604,24 @@
|
558
|
604
|
|
559
|
605
|
const float z_offset = state.active ? state.z_offset : 0.0;
|
560
|
606
|
|
561
|
|
- float seg_dest[XYZE]; // per-segment destination,
|
562
|
|
- COPY_XYZE(seg_dest, current_position); // starting from current position
|
|
607
|
+ do {
|
|
608
|
+
|
|
609
|
+ if (--segments) { // not the last segment
|
|
610
|
+ seg_rx += seg_dx;
|
|
611
|
+ seg_ry += seg_dy;
|
|
612
|
+ seg_rz += seg_dz;
|
|
613
|
+ seg_le += seg_de;
|
|
614
|
+ } else { // last segment, use exact destination
|
|
615
|
+ seg_rx = RAW_X_POSITION(ltarget[X_AXIS]);
|
|
616
|
+ seg_ry = RAW_Y_POSITION(ltarget[Y_AXIS]);
|
|
617
|
+ seg_rz = RAW_Z_POSITION(ltarget[Z_AXIS]);
|
|
618
|
+ seg_le = ltarget[E_AXIS];
|
|
619
|
+ }
|
563
|
620
|
|
564
|
|
- while (--segments) {
|
565
|
|
- LOOP_XYZE(i) seg_dest[i] += segment_distance[i];
|
566
|
|
- float ztemp = seg_dest[Z_AXIS];
|
567
|
|
- seg_dest[Z_AXIS] += z_offset;
|
568
|
|
- ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
|
569
|
|
- seg_dest[Z_AXIS] = ztemp;
|
570
|
|
- }
|
|
621
|
+ ubl_buffer_segment_raw( seg_rx, seg_ry, seg_rz + z_offset, seg_le, feedrate );
|
|
622
|
+
|
|
623
|
+ } while (segments);
|
571
|
624
|
|
572
|
|
- // Since repeated adding segment_distance accumulates small errors, final move to exact destination.
|
573
|
|
- COPY_XYZE(seg_dest, ltarget);
|
574
|
|
- seg_dest[Z_AXIS] += z_offset;
|
575
|
|
- ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
|
576
|
625
|
return false; // moved but did not set_current_to_destination();
|
577
|
626
|
}
|
578
|
627
|
|
|
@@ -582,14 +631,11 @@
|
582
|
631
|
const float fade_scaling_factor = fade_scaling_factor_for_z(ltarget[Z_AXIS]);
|
583
|
632
|
#endif
|
584
|
633
|
|
585
|
|
- float seg_dest[XYZE]; // per-segment destination, initialize to first segment
|
586
|
|
- LOOP_XYZE(i) seg_dest[i] = current_position[i] + segment_distance[i];
|
587
|
|
-
|
588
|
|
- const float &dx_seg = segment_distance[X_AXIS]; // alias for clarity
|
589
|
|
- const float &dy_seg = segment_distance[Y_AXIS];
|
590
|
|
-
|
591
|
|
- float rx = RAW_X_POSITION(seg_dest[X_AXIS]), // assume raw vs logical coordinates shifted but not scaled.
|
592
|
|
- ry = RAW_Y_POSITION(seg_dest[Y_AXIS]);
|
|
634
|
+ // increment to first segment destination
|
|
635
|
+ seg_rx += seg_dx;
|
|
636
|
+ seg_ry += seg_dy;
|
|
637
|
+ seg_rz += seg_dz;
|
|
638
|
+ seg_le += seg_de;
|
593
|
639
|
|
594
|
640
|
for(;;) { // for each mesh cell encountered during the move
|
595
|
641
|
|
|
@@ -600,20 +646,16 @@
|
600
|
646
|
// in top of loop and again re-find same adjacent cell and use it, just less efficient
|
601
|
647
|
// for mesh inset area.
|
602
|
648
|
|
603
|
|
- int8_t cell_xi = (rx - (UBL_MESH_MIN_X)) * (1.0 / (MESH_X_DIST)),
|
604
|
|
- cell_yi = (ry - (UBL_MESH_MIN_Y)) * (1.0 / (MESH_X_DIST));
|
|
649
|
+ int8_t cell_xi = (seg_rx - (UBL_MESH_MIN_X)) * (1.0 / (MESH_X_DIST)),
|
|
650
|
+ cell_yi = (seg_ry - (UBL_MESH_MIN_Y)) * (1.0 / (MESH_X_DIST));
|
605
|
651
|
|
606
|
652
|
cell_xi = constrain(cell_xi, 0, (GRID_MAX_POINTS_X) - 1);
|
607
|
653
|
cell_yi = constrain(cell_yi, 0, (GRID_MAX_POINTS_Y) - 1);
|
608
|
654
|
|
609
|
|
- const float x0 = mesh_index_to_xpos(cell_xi), // 64 byte table lookup avoids mul+add
|
610
|
|
- y0 = mesh_index_to_ypos(cell_yi), // 64 byte table lookup avoids mul+add
|
611
|
|
- x1 = mesh_index_to_xpos(cell_xi + 1), // 64 byte table lookup avoids mul+add
|
612
|
|
- y1 = mesh_index_to_ypos(cell_yi + 1); // 64 byte table lookup avoids mul+add
|
|
655
|
+ const float x0 = mesh_index_to_xpos(cell_xi), // 64 byte table lookup avoids mul+add
|
|
656
|
+ y0 = mesh_index_to_ypos(cell_yi);
|
613
|
657
|
|
614
|
|
- float cx = rx - x0, // cell-relative x
|
615
|
|
- cy = ry - y0, // cell-relative y
|
616
|
|
- z_x0y0 = z_values[cell_xi ][cell_yi ], // z at lower left corner
|
|
658
|
+ float z_x0y0 = z_values[cell_xi ][cell_yi ], // z at lower left corner
|
617
|
659
|
z_x1y0 = z_values[cell_xi+1][cell_yi ], // z at upper left corner
|
618
|
660
|
z_x0y1 = z_values[cell_xi ][cell_yi+1], // z at lower right corner
|
619
|
661
|
z_x1y1 = z_values[cell_xi+1][cell_yi+1]; // z at upper right corner
|
|
@@ -623,15 +665,18 @@
|
623
|
665
|
if (isnan(z_x0y1)) z_x0y1 = 0; // in order to avoid isnan tests per cell,
|
624
|
666
|
if (isnan(z_x1y1)) z_x1y1 = 0; // thus guessing zero for undefined points
|
625
|
667
|
|
|
668
|
+ float cx = seg_rx - x0, // cell-relative x and y
|
|
669
|
+ cy = seg_ry - y0;
|
|
670
|
+
|
626
|
671
|
const float z_xmy0 = (z_x1y0 - z_x0y0) * (1.0 / (MESH_X_DIST)), // z slope per x along y0 (lower left to lower right)
|
627
|
672
|
z_xmy1 = (z_x1y1 - z_x0y1) * (1.0 / (MESH_X_DIST)); // z slope per x along y1 (upper left to upper right)
|
628
|
673
|
|
629
|
|
- float z_cxy0 = z_x0y0 + z_xmy0 * cx; // z height along y0 at cx
|
|
674
|
+ float z_cxy0 = z_x0y0 + z_xmy0 * cx; // z height along y0 at cx (changes for each cx in cell)
|
630
|
675
|
|
631
|
676
|
const float z_cxy1 = z_x0y1 + z_xmy1 * cx, // z height along y1 at cx
|
632
|
677
|
z_cxyd = z_cxy1 - z_cxy0; // z height difference along cx from y0 to y1
|
633
|
678
|
|
634
|
|
- float z_cxym = z_cxyd * (1.0 / (MESH_Y_DIST)); // z slope per y along cx from y0 to y1
|
|
679
|
+ float z_cxym = z_cxyd * (1.0 / (MESH_Y_DIST)); // z slope per y along cx from y0 to y1 (changes for each cx in cell)
|
635
|
680
|
|
636
|
681
|
// float z_cxcy = z_cxy0 + z_cxym * cy; // interpolated mesh z height along cx at cy (do inside the segment loop)
|
637
|
682
|
|
|
@@ -639,8 +684,8 @@
|
639
|
684
|
// and the z_cxym slope will change, both as a function of cx within the cell, and
|
640
|
685
|
// each change by a constant for fixed segment lengths.
|
641
|
686
|
|
642
|
|
- const float z_sxy0 = z_xmy0 * dx_seg, // per-segment adjustment to z_cxy0
|
643
|
|
- z_sxym = (z_xmy1 - z_xmy0) * (1.0 / (MESH_Y_DIST)) * dx_seg; // per-segment adjustment to z_cxym
|
|
687
|
+ const float z_sxy0 = z_xmy0 * seg_dx, // per-segment adjustment to z_cxy0
|
|
688
|
+ z_sxym = (z_xmy1 - z_xmy0) * (1.0 / (MESH_Y_DIST)) * seg_dx; // per-segment adjustment to z_cxym
|
644
|
689
|
|
645
|
690
|
for(;;) { // for all segments within this mesh cell
|
646
|
691
|
|
|
@@ -650,28 +695,29 @@
|
650
|
695
|
z_cxcy *= fade_scaling_factor; // apply fade factor to interpolated mesh height
|
651
|
696
|
#endif
|
652
|
697
|
|
653
|
|
- z_cxcy += state.z_offset; // add fixed mesh offset from G29 Z
|
|
698
|
+ z_cxcy += state.z_offset; // add fixed mesh offset from G29 Z
|
654
|
699
|
|
655
|
700
|
if (--segments == 0) { // if this is last segment, use ltarget for exact
|
656
|
|
- COPY_XYZE(seg_dest, ltarget);
|
657
|
|
- seg_dest[Z_AXIS] += z_cxcy;
|
658
|
|
- ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
|
659
|
|
- return false; // did not set_current_to_destination()
|
|
701
|
+ seg_rx = RAW_X_POSITION(ltarget[X_AXIS]);
|
|
702
|
+ seg_ry = RAW_Y_POSITION(ltarget[Y_AXIS]);
|
|
703
|
+ seg_rz = RAW_Z_POSITION(ltarget[Z_AXIS]);
|
|
704
|
+ seg_le = ltarget[E_AXIS];
|
660
|
705
|
}
|
661
|
706
|
|
662
|
|
- const float z_orig = seg_dest[Z_AXIS]; // remember the pre-leveled segment z value
|
663
|
|
- seg_dest[Z_AXIS] = z_orig + z_cxcy; // adjust segment z height per mesh leveling
|
664
|
|
- ubl_buffer_line_segment(seg_dest, feedrate, active_extruder);
|
665
|
|
- seg_dest[Z_AXIS] = z_orig; // restore pre-leveled z before incrementing
|
|
707
|
+ ubl_buffer_segment_raw( seg_rx, seg_ry, seg_rz + z_cxcy, seg_le, feedrate );
|
|
708
|
+
|
|
709
|
+ if (segments == 0 ) // done with last segment
|
|
710
|
+ return false; // did not set_current_to_destination()
|
666
|
711
|
|
667
|
|
- LOOP_XYZE(i) seg_dest[i] += segment_distance[i]; // adjust seg_dest for next segment
|
|
712
|
+ seg_rx += seg_dx;
|
|
713
|
+ seg_ry += seg_dy;
|
|
714
|
+ seg_rz += seg_dz;
|
|
715
|
+ seg_le += seg_de;
|
668
|
716
|
|
669
|
|
- cx += dx_seg;
|
670
|
|
- cy += dy_seg;
|
|
717
|
+ cx += seg_dx;
|
|
718
|
+ cy += seg_dy;
|
671
|
719
|
|
672
|
720
|
if (!WITHIN(cx, 0, MESH_X_DIST) || !WITHIN(cy, 0, MESH_Y_DIST)) { // done within this cell, break to next
|
673
|
|
- rx = RAW_X_POSITION(seg_dest[X_AXIS]);
|
674
|
|
- ry = RAW_Y_POSITION(seg_dest[Y_AXIS]);
|
675
|
721
|
break;
|
676
|
722
|
}
|
677
|
723
|
|