Skip to content

switchkins: one dispatch for kinematics modules, halcompile components and out-of-tree modules - #4595

Open
grandixximo wants to merge 5 commits into
LinuxCNC:masterfrom
grandixximo:switchkins-unify
Open

grandixximo wants to merge 5 commits into
LinuxCNC:masterfrom
grandixximo:switchkins-unify

Conversation

@grandixximo

@grandixximo grandixximo commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

switchkins.c owned rtapi_app_main(), so only a module with no main of its own could use it. The four switchable kinematics in hal/components (millturn, xyzab_tdr_kins, xyzacb_trsrn, xyzbca_trsrn) each carried a private copy of the dispatch, and an out-of-tree module had to reimplement it.

  • rtapi_app_main() and the coordinates= and sparm= parameters move to switchkins_main.c; switchkins.c gets one entry point, switchkinsInit(), and every type goes through switchkinsRegister(), so a double registration is refused. The eight in-tree modules add switchkins_main.o and are otherwise untouched.
  • The four components link the core and call switchkinsInit() from EXTRA_SETUP(), about 300 lines shorter between them. Pin names are unchanged except millturn's unused template pins; a bad motion.switchkins-type is now refused instead of stranding the module.
  • switchkins_core is the implementation as a module of its own, with no kinematics types. An out-of-tree module includes the exported switchkins.h, registers its types and calls switchkinsInit(); the HAL file loads switchkins_core ahead of it. switchkinscomp.comp is the template, built in tree like any other component.
  • saicanon reports a kinematics switch through its own macro, in the canon output with a line number, instead of a raw printf.

Tested: tests/kins-switchkins-core runs the template behind switchkins_core through homing, moves in both types, switches and a refused type; the kins, halcompile and interp tests pass; every touched module loads with motmod; the template, renamed and compiled with halcompile out of tree, loads behind switchkins_core.

It conflicts in src/Makefile with #4461 (one SRCHEADERS line); whichever merges second takes the other's layout. Part of the plan in #4374.

Comment thread src/hal/components/millturn.comp Outdated
Comment thread src/hal/components/switchkinscomp.comp Outdated
Comment thread src/Makefile.modinc.in Outdated
@grandixximo
grandixximo force-pushed the switchkins-unify branch 2 times, most recently from 8143f5b to 4cc39d7 Compare September 28, 2026 13:00
switchkins.c owned rtapi_app_main(), so a module could only use it by having no main of its own, which ruled out halcompile components: the switchable kinematics in hal/components each carry a private copy of the dispatch.

Move rtapi_app_main(), rtapi_app_exit() and the coordinates= and sparm= parameters to switchkins_main.c and give switchkins.c one entry point, switchkinsInit(comp_id, kp, coordinates), which counts and validates the registered types, creates the pins and starts on type 0. The caller owns the component. The types switchkinsSetup() supplies now go through switchkinsRegister() like any others, so one registration path checks every type and a double registration is refused. The eight existing modules add switchkins_main.o to their objects and are otherwise untouched.
millturn, xyzab_tdr_kins, xyzacb_trsrn and xyzbca_trsrn each carried a copy of the switchkins dispatch, a private switchkins_type, a hand-written kinematicsSwitch() and a setup that had to hal_set_unready() the component again. Now that the dispatch is separate from the main program a component links it and calls switchkinsInit() from EXTRA_SETUP().

Two build changes: the generated per-comp .mak takes a <component>-extra-objs list, and switchkins.h is copied to ../include and installed so <switchkins.h> resolves from a generated source. Each of the four registers its types and calls switchkinsInit(); their identity type comes from kins_util.c, which gets them the coordinates= parameter, and a bad motion.switchkins-type is refused instead of stranding the module. Pin names are unchanged except millturn's unused in/out template pins. The four sim configs give the same positions through the same MDI sequence as before, in every kinematics type.
The kinematics modules are users of switchkins, not part of it, so they
take the header the way any other user would.  switchkins.c and
switchkins_main.c keep the quoted form, being the source itself.
An out-of-tree module could not reach the switchkins implementation, so it reimplemented kinematicsSwitch() and the kinstype.is-N pins or did without. A realtime module cannot link a library, and including the implementation as source puts C files and an extra include path in every module build.

switchkins_core is the implementation as a module of its own: switchkins.c and kins_util.c with no kinematics types. switchkins.c already exports its interface, since motion reaches the kinematics entry points in another module; kins_util.c now exports the identity kinematics and helpers kinematics.h declares. A module loaded after switchkins_core includes <switchkins.h>, registers its types and calls switchkinsInit() from EXTRA_SETUP(); motion finds the kinematics entry points in switchkins_core. The in-tree modules keep linking the objects, so their configs are unchanged.

switchkinscomp.comp is the template, built in tree like any other component. tests/kins-switchkins-core loads it behind switchkins_core, homes, moves in both of its types, switches between them and has a type it does not provide refused. Renamed and built with halcompile out of tree it loads the same way.
saicanon.cc printed SELECT_KINS_TYPE with a raw printf, beside the canon output on stdout. saicanon exists to echo the canonical commands, so it now reports through the same macro as the rest of the file, with a line number and the argument.
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.

2 participants