Spindle gearbox
Ctrl reserves M16 P<gear> for selecting a spindle gear. The operator panel and part programs use the same machine remap. The operator panel displays the published gearbox feedback; the machine controller owns interlocks, physical sequencing, and completion.
Select a gear
Section titled “Select a gear”M16 P1 (Select gear 1)M16 P2 (Select gear 2)P is required and must be a positive integer identifying a supported gear. Selecting the already-engaged gear succeeds without shifting. Unsupported gears fail. Completion means the requested gear is engaged and qualified, not merely that a command was accepted.
In the GUI, press the gearbox button to cycle 1 → 2 → … → n-gears → 1. Right-click the button to select a specific gear from the context menu, with the engaged gear marked as current. The button shows the current gear and waits for valid current-gear and gear-count feedback before allowing a request. It submits M16 P<gear> through MDI and waits until the remap completes. The GUI does not directly drive a gearbox HAL output.
M16 has this meaning on every Ctrl machine. A machine without a gearbox can leave it unconfigured but must not repurpose it. See code availability.
Publish machine feedback
Section titled “Publish machine feedback”Ctrl declares these status inputs on every machine:
| Pin | Type | Meaning |
|---|---|---|
ctrl.spindle-gearbox.has-gearbox |
bit input | A gearbox is fitted |
ctrl.spindle-gearbox.automatic |
bit input | The machine supports commanded gear selection |
ctrl.spindle-gearbox.n-gears |
s32 input | Number of gears, numbered consecutively from 1; wire controller feedback or set a fixed positive count |
ctrl.spindle-gearbox.gear |
s32 input | Qualified, engaged gear identifier |
ctrl.spindle-gearbox.changing-gear |
bit input | A physical gear selection is in progress |
For example, in post-GUI HAL:
setp ctrl.spindle-gearbox.has-gearbox truesetp ctrl.spindle-gearbox.automatic truenet gearbox-engaged-gear machine-gearbox.gear => ctrl.spindle-gearbox.gearnet gearbox-changing machine-gearbox.busy => ctrl.spindle-gearbox.changing-gearmachine-gearbox.* represents your machine controller; Ctrl does not supply that component. A manual gearbox sets automatic false and displays feedback without an editable selection. Gear and shift status represent physical feedback and are not persisted or replayed at startup.
For a fixed four-gear machine, set ctrl.spindle-gearbox.n-gears to 4 in post-GUI HAL. Gear count is machine feedback, not an INI setting.
Remap the standard command
Section titled “Remap the standard command”Complete the shared peripheral remap setup. Add to the existing [RS274NGC] section:
REMAP = M16 modalgroup=10 argspec=P python=m16_spindle_select_gearAdd before component.ready() in the shared toplevel.py initializer:
self.spindle_gearbox = HalExecutor(self, "spindle-gearbox", component)Add to remap.py, alongside the shared executor_execute import:
from math import isfinitefrom interpreter import INTERP_ERROR
def m16_spindle_select_gear(self, **words): gear = words["p"] if not isfinite(gear) or gear < 1 or gear != int(gear): self.set_errormsg("M16 requires a positive integer gear number in P") yield INTERP_ERROR return
yield from executor_execute(self, self.spindle_gearbox, request=int(gear))The executor opcode is the requested gear number. The machine controller validates whether that gear exists and applies the machine’s standstill and shift interlocks. Disabling the spindle command alone does not prove physical standstill.
Connect the executor directly to the machine controller in post-GUI HAL:
net gearbox-request-id remap.executor.spindle-gearbox.request-id => machine-gearbox.request-idnet gearbox-target remap.executor.spindle-gearbox.opcode => machine-gearbox.opcodenet gearbox-request remap.executor.spindle-gearbox.request => machine-gearbox.requestnet gearbox-cancel remap.executor.spindle-gearbox.cancel => machine-gearbox.cancelnet gearbox-response-id machine-gearbox.response-id => remap.executor.spindle-gearbox.response-idnet gearbox-state machine-gearbox.state => remap.executor.spindle-gearbox.statenet gearbox-result machine-gearbox.result => remap.executor.spindle-gearbox.resultThe machine controller must implement the executor protocol: arbitrate requests, qualify engagement, and publish a terminal response with the matching request ID. It reports Succeeded only for the requested engaged gear, including an already-engaged selection. Failed, cancelled, or timed-out requests stop the remap with an interpreter error. Define diagnostic result codes beside the controller implementation.
The shared helper’s default timeout is ten seconds. Override it in the remap when the mechanism needs a justified different limit. The controller must handle cancellation according to its physical abort policy before accepting a new request.