Skip to content

[Go Migration] Fix endstop_home clock=0 timing differences #8

@AndySze

Description

@AndySze

Problem

The endstop_home clock=0 (homing reset command) appears at different positions in Go vs Python output. This affects multiple tests including out_of_bounds, gcode_arcs, and z_virtual_endstop.

Example diff:

 queue_step oid=5 interval=40000 count=20 add=0
+endstop_home oid=3 clock=0 sample_ticks=0 sample_count=0 rest_ticks=0 pin_value=0 trsync_oid=0 trigger_reason=0
 queue_step oid=5 interval=40000 count=1 add=0
-endstop_home oid=3 clock=0 sample_ticks=0 sample_count=0 rest_ticks=0 pin_value=0 trsync_oid=0 trigger_reason=0

Root Cause

Go and Python have different code paths for step commands vs endstop_home commands:

  • Step commands go through steppersync_flush which orders by req_clock
  • endstop_home commands go directly to serialqueue via sendLine()
  • These two paths don't merge for ordering

The fundamental issue is that Python flushes steps at different points relative to when it emits the endstop_home clock=0 (reset) command.

Current Workaround

Added a generic fix in fixHostH4OutOfBoundsOrdering() to swap [endstop_home clock=0, queue_step] patterns, but this only works when they're adjacent.

Affected Tests

  • out_of_bounds.test (reduced to 19 diff lines)
  • gcode_arcs.test
  • z_virtual_endstop.test
  • Other homing-related tests

Proposed Fix

Option A: Fix at source

  • Modify homeStop() in runtime.go to flush step generation before sending endstop_home clock=0
  • Use advanceFlushTime() or similar to ensure steps are flushed

Option B: Enhanced workaround

  • Extend fix functions to handle non-adjacent cases
  • May require looking at broader context windows

Files

  • go/pkg/hosth4/runtime.go - homeStop(), homeAxis(), homePolarArm()
  • go/cmd/klipper-go-golden/main.go - workaround fixes

Verification

./scripts/go_migration_golden.py compare --only out_of_bounds --mode strict
./scripts/go_migration_golden.py compare --only gcode_arcs --mode strict
./scripts/go_migration_golden.py compare --only z_virtual_endstop --mode strict

Parent Issue

Part of #1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions