Skip to content

feat(turret): per-slot calibration, backlash compensation, software homing, factory parameter set - #601

Open
veerwang wants to merge 2 commits into
Cephla-Lab:masterfrom
veerwang:pr-singlemotor
Open

feat(turret): per-slot calibration, backlash compensation, software homing, factory parameter set#601
veerwang wants to merge 2 commits into
Cephla-Lab:masterfrom
veerwang:pr-singlemotor

Conversation

@veerwang

Copy link
Copy Markdown
Contributor

Summary

Two commits improving the NiMotion 4-position objective turret controller:

1. Per-slot calibration and gear backlash compensation (6918f4f)

  • OBJECTIVE_TURRET_CALIBRATED_PULSES: per-slot calibrated absolute pulse targets (slot -> pulses from homing zero). Calibrated slots are used verbatim; others fall back to the theoretical (slot-1)*pulses_per_position + OBJECTIVE_TURRET_OFFSET_PULSES.
  • OBJECTIVE_TURRET_BACKLASH_DEG: when > 0, every slot change overshoots below the target and approaches from below, so the final approach direction is constant and gear backlash cancels out.
  • Both validated at init so a bad machine .ini fails fast; defaults keep behavior identical.

2. Software homing, DI1 origin switch, factory parameters (fffd0a5)

  • Software homing replaces the driver's built-in homing modes: velocity-mode sweep toward the sensor polling the DI level → decel-stop on trigger → back off until the switch releases → fine-step back to the trigger edge → SET_ZERO there. Repeatability ±5 pulses (hardware-measured 0); ends clamped at home with holding torque. Home timeout raised to 120 s.
  • DI1 permanently "origin switch" (3) — the previous scheme (DI1 temporarily remapped to negative limit + homing method 17) faults FF0E on current drive firmware whenever a normal move passes the sensor.
  • Factory parameter set auto-calibrated on connect: accel/decel 1000, max speed 200, min speed 16 (written before max — fixes a min/max write-order bug), motor currents sized so a fully loaded turret does not lose steps, microstep pinned to 16 (fail fast asking for a power cycle on mismatch).
  • modbus_rtu: new read_input_registers() batch read so the homing sweep sees DI + position + alarm in one frame per poll (the ~50-pulse sensor window must not be crossable between polls).

Deployment notes

  • First connect on a real unit rewrites speed/current/DI parameters and saves EEPROM (one-time).
  • Machines with per-slot calibration measured under the old driver-homing zero must re-measure (the zero reference moved slightly).

Test plan

  • 66 tests pass (tests/control/test_objective_turret_controller.py, tests/control/test_modbus_rtu.py): calibration/backlash targeting, software-homing edge/sweep/timeout paths, factory-param write order, microstep-mismatch fail-fast
  • Homing repeatability verified on hardware in the source project (0-pulse deviation between runs)
  • Bench test on production hardware: startup homing, slot-switching accuracy, slot re-calibration

🤖 Generated with Claude Code

veerwang and others added 2 commits July 20, 2026 09:41
Port two positioning features from the SingleMotor source project:

- OBJECTIVE_TURRET_CALIBRATED_PULSES: per-slot calibrated absolute pulse
  targets (slot 1..4 -> pulses from homing zero). A calibrated slot is
  used verbatim; uncalibrated slots fall back to the theoretical
  (slot-1)*pulses_per_position + OBJECTIVE_TURRET_OFFSET_PULSES.
- OBJECTIVE_TURRET_BACKLASH_DEG: gear backlash compensation (0..1 turret
  degrees). When > 0 every slot change overshoots below the target and
  approaches it from below, so the final approach direction is always
  the same and gear backlash cancels out.

Both are validated at init (slot range, integer pulses, deviation bound
of one slot vs theoretical, degree range) so a bad machine .ini fails
fast. Defaults keep behavior identical to before.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… switch, factory params

Re-merge from the SingleMotor source project (2026-07-23..27 changes):

- Homing rewritten as software homing (sweep in velocity mode polling the DI
  level -> backoff -> fine-search -> SET_ZERO at the trigger edge), replacing
  the driver's built-in homing modes. Repeatability +/-5 pulses; ends clamped
  at home with holding torque. Default home timeout raised to 120s.
- DI1 is now permanently "origin switch" (3). The old scheme (DI1 temporarily
  mapped to negative limit + homing method 17) faults FF0E on the current
  firmware whenever a move passes the sensor; all homing-register calibration
  is removed.
- Factory parameter set ported and auto-calibrated on connect: accel/decel
  1000, max speed 200, min speed 16 (written before max — fixes the
  min/max write-order bug), currents overload 1.3A / idle 0.6A /
  accel+run+decel 0.95A, microstep forced to 16 (write + save + fail fast
  asking for a power cycle when it differs). Decel current is marked volatile
  (firmware drops the write) so it cannot trigger an EEPROM save every
  connect. Direction register written to RAM after the EEPROM save.
- modbus_rtu: add read_input_registers() batch read so the homing sweep gets
  DI + position + alarm in one frame per poll (the ~50-pulse sensor window
  must not be crossable between two polls).
- _def.py: fix the calibrated-pulses doc example (6640 deviates more than one
  slot and fails validation) and note that slots must be re-measured after
  upgrading from driver homing (the zero reference moved).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant