Skip to content

Commit 7e74f0c

Browse files
committed
fix(rs274ngc): MAX_UNWIND_TURNS rebase aligns angular position via shortest path
The original rebase pinned the motor at AA_current when triggered, which gave correct results only when AA_current happened to coincide with the target's mod-360 angular position (e.g. an exactly N-turn accumulation). For any off-mod-360 starting state, the motor would not move and the physical angular position would no longer match the user-frame target. Updated rebase computes the shortest-path delta into (-180, 180] and moves the motor by that sub-turn delta while absorbing the full-turn remainder in the offset. After rebase, machine angular position == target mod 360 and user_pos == target. Trace from AA=28850 (80 turns + 50 deg) with G0 A0: delta = -28850, |80.14 turns| > 10, rebase fires delta_short = -50 (shortest path to align mod 360) target_machine = 28800, motor delta = -50 new_offset = 28800, user_pos = 0 Physical angular position = 0 deg, matches programmed A0.
1 parent 7fd961b commit 7e74f0c

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/emc/rs274ngc/interp_convert.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5345,8 +5345,11 @@ int Interp::convert_straight(int move, //!< either G_0 or G_1
53455345
settings->motion_mode = move;
53465346

53475347
// Auto-rotary-rebase: on G0 with a rotary word, if the user-frame delta
5348-
// exceeds MAX_UNWIND_TURNS, shift the modulo offset so the motor stays
5349-
// put while the user-frame position jumps to the programmed target.
5348+
// exceeds MAX_UNWIND_TURNS, shift the modulo offset so the motor takes the
5349+
// shortest path to the target's angular position (within +/- 180 deg)
5350+
// while the user-frame position jumps to the programmed target. The whole
5351+
// turns of unwind are absorbed by the offset; only the sub-turn part is
5352+
// physical motion.
53505353
// Only applies in absolute mode (G90); G53 explicitly bypasses; incremental
53515354
// (G91) does not need it.
53525355
if (move == G_0 &&
@@ -5358,7 +5361,11 @@ int Interp::convert_straight(int move, //!< either G_0 or G_1
53585361
double user_pos = cur - *off;
53595362
double delta = bnum - user_pos;
53605363
if (fabs(delta) / 360.0 > max_turns) {
5361-
*off = cur - bnum;
5364+
double mod = fmod(delta + 180.0, 360.0);
5365+
if (mod < 0.0) mod += 360.0;
5366+
double delta_short = mod - 180.0;
5367+
double target_machine = cur + delta_short;
5368+
*off = target_machine - bnum;
53625369
}
53635370
};
53645371
rebase(settings->AA_current, &settings->AA_modulo_offset,

0 commit comments

Comments
 (0)