Skip to content

Commit

Permalink
Include remaining arc length in trapezoidal calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
tombrazier committed Jun 19, 2022
1 parent d1dcae7 commit b99c13e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Marlin/src/gcode/motion/G2_G3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#define ARC_LIJKUVW_CODE(L,I,J,K,U,V,W) CODE_N(SUB2(NUM_AXES),L,I,J,K,U,V,W)
#define ARC_LIJKUVWE_CODE(L,I,J,K,U,V,W,E) ARC_LIJKUVW_CODE(L,I,J,K,U,V,W); CODE_ITEM_E(E)

float arc_mm_remaining = 0.0f;

/**
* Plan an arc in 2 dimensions, with linear motion in the other axes.
* The arc is traced with many small linear segments according to the configuration.
Expand Down Expand Up @@ -180,6 +182,7 @@ void plan_arc(

// Millimeters in the arc, assuming it's flat
const float flat_mm = radius * abs_angular_travel;
arc_mm_remaining = flat_mm;

// Return if the move is near zero
if (flat_mm < 0.0001f
Expand Down Expand Up @@ -214,6 +217,7 @@ void plan_arc(
const uint16_t segments = nominal_segment_mm > (MAX_ARC_SEGMENT_MM) ? CEIL(flat_mm / (MAX_ARC_SEGMENT_MM)) :
nominal_segment_mm < (MIN_ARC_SEGMENT_MM) ? _MAX(1, FLOOR(flat_mm / (MIN_ARC_SEGMENT_MM))) :
nominal_segments;
float segment_mm = flat_mm / segments;

#if ENABLED(SCARA_FEEDRATE_SCALING)
const float inv_duration = (scaled_fr_mm_s / flat_mm) * segments;
Expand Down Expand Up @@ -345,6 +349,8 @@ void plan_arc(
planner.apply_leveling(raw);
#endif

arc_mm_remaining -= segment_mm;

if (!planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, 0
OPTARG(SCARA_FEEDRATE_SCALING, inv_duration), i > 1 ? radius : 0.0))
break;
Expand All @@ -367,6 +373,8 @@ void plan_arc(
planner.apply_leveling(raw);
#endif

arc_mm_remaining = 0.0f;

planner.buffer_line(raw, scaled_fr_mm_s, active_extruder, 0 OPTARG(SCARA_FEEDRATE_SCALING, inv_duration));

#if ENABLED(AUTO_BED_LEVELING_UBL)
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ void Planner::calculate_trapezoid_for_block(block_t * const block, const_float_t
to compute an optimal plan, so select carefully.
*/

extern float arc_mm_remaining;

// The kernel called by recalculate() when scanning the plan from last to first entry.
void Planner::reverse_pass_kernel(block_t * const current, const block_t * const next) {
if (current) {
Expand All @@ -960,7 +962,7 @@ void Planner::reverse_pass_kernel(block_t * const current, const block_t * const

const float new_entry_speed_sqr = TEST(current->flag, BLOCK_BIT_NOMINAL_LENGTH)
? max_entry_speed_sqr
: _MIN(max_entry_speed_sqr, max_allowable_speed_sqr(-current->acceleration, next ? next->entry_speed_sqr : sq(float(MINIMUM_PLANNER_SPEED)), current->millimeters));
: _MIN(max_entry_speed_sqr, max_allowable_speed_sqr(-current->acceleration, next ? next->entry_speed_sqr : sq(float(MINIMUM_PLANNER_SPEED)), current->millimeters + (next ? 0.0 : arc_mm_remaining)));
if (current->entry_speed_sqr != new_entry_speed_sqr) {

// Need to recalculate the block speed - Mark it now, so the stepper
Expand Down

2 comments on commit b99c13e

@DerAndere1
Copy link

@DerAndere1 DerAndere1 commented on b99c13e Jun 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent overhead in line 965 if ARC_SUPPORT is disabled, maybe:
: _MIN(max_entry_speed_sqr, max_allowable_speed_sqr(-current->acceleration, next ? next->entry_speed_sqr : sq(float(MINIMUM_PLANNER_SPEED)), current->millimeters TERN_(ARC_SUPPORT, + (next ? 0.0 : arc_mm_remaining))));

@tombrazier
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely conditional on ARC_SUPPORT. (Or perhaps also one day BEZIER_CURVE_SUPPORT.)

I don't like the secret knowledge passed between G2_G3.cpp and planner.cpp via a global variable. So this is a long way from what I imagine the final code looking like. I have suggested a new block type here.

Please sign in to comment.