switchkins: one dispatch for kinematics modules, halcompile components and out-of-tree modules - #4595
Open
grandixximo wants to merge 5 commits into
Open
grandixximo wants to merge 5 commits into
grandixximo wants to merge 5 commits into
Conversation
BsAtHome
reviewed
Sep 28, 2026
BsAtHome
reviewed
Sep 28, 2026
BsAtHome
reviewed
Sep 28, 2026
grandixximo
force-pushed
the
switchkins-unify
branch
2 times, most recently
from
September 28, 2026 13:00
8143f5b to
4cc39d7
Compare
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.
grandixximo
force-pushed
the
switchkins-unify
branch
from
September 30, 2026 15:21
4cc39d7 to
cbbf36a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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.