From 68a92bb29779328442678401f4d33f7fd6e558c8 Mon Sep 17 00:00:00 2001 From: Henrik Muehe Date: Fri, 1 May 2026 11:08:51 +0200 Subject: [PATCH] AuxAxis: pre-load home_zero via HOMECFG, drop post-home WPOS home() previously matched the wrong [home] line (firmware-side bug, fixed in auxcnc) and even when it would have matched, it tried to shift the step counter by writing 'WPOS ' after homing. The ESP's WPOS handler clears HOMED, so a bbctrl restart would forget the home state. Push the desired step counter via HOMECFG zero= (firmware writes it into the counter at the end of a successful HOME, leaving HOMED set). home() now only reads the terminal [home] line; no post-home counter fixup. --- src/py/bbctrl/AuxAxis.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/py/bbctrl/AuxAxis.py b/src/py/bbctrl/AuxAxis.py index 00914c8..907a1b9 100644 --- a/src/py/bbctrl/AuxAxis.py +++ b/src/py/bbctrl/AuxAxis.py @@ -154,22 +154,22 @@ class AuxAxis(object): def home(self): """Run the homing cycle on the ESP. Blocks until done. Raises on - failure. Updates aux_homed and aux_pos.""" + failure. Updates aux_homed and aux_pos. + + The ESP's home_zero is pre-loaded via HOMECFG so when the cycle + completes the step counter already corresponds to home_position_mm. + That way the homed-state survives a bbctrl restart correctly + (we don't need a post-home WPOS write, which would clear HOMED).""" self._require_present() + # Make sure home_zero on the ESP matches our current + # home_position_mm in case the user just edited config. + self._push_homecfg() line = self._rpc('HOME', topic='home', timeout=120.0) - # line is the body after '[home] ' + # line is the body after '[home] '. Only terminal lines use + # the [home] topic now (done / failed); progress is [home_log]. if line.startswith('done'): - # ESP set its counter to home_zero; mirror that. - new_pos = self._parse_kv_int(line, 'pos', 0) - self._pos_steps = new_pos + self._pos_steps = self._parse_kv_int(line, 'pos', 0) self._homed = True - # Translate to home_position_mm. Conceptually the host says - # "after homing, W is here in mm". We achieve that by setting - # the ESP counter (WPOS) so the mm conversion works out. - target_pos = self._mm_to_steps(self._cfg['home_position_mm']) - if target_pos != new_pos: - self._rpc('WPOS %d' % target_pos, topic='ok', timeout=2.0) - self._pos_steps = target_pos self._publish_state() return # failure @@ -312,13 +312,15 @@ class AuxAxis(object): def _push_homecfg(self): c = self._cfg + zero_steps = self._mm_to_steps(c['home_position_mm']) cmd = ('HOMECFG dir=%s fast=%d slow=%d backoff=%d maxtravel=%d ' - 'zero=0 accel=%d step_max=%d step_start=%d limit_low=%d') % ( + 'zero=%d accel=%d step_max=%d step_start=%d limit_low=%d') % ( c['home_dir'], int(c['home_fast_sps']), int(c['home_slow_sps']), int(c['home_backoff_steps']), int(c['home_maxtravel_steps']), + int(zero_steps), int(c['step_accel_sps2']), int(c['step_max_sps']), int(c['step_start_sps']),