@@ -427,19 +427,18 @@ no per-call overhead.
427427The userspace planner resolves a single symbol from the RT `.so`:
428428
429429----
430- void nonrt_attach(char *shmem_base, int offset, nonrt_ops_t *ops);
430+ void nonrt_attach(nonrt_ops_t *ops);
431431----
432432
433- `nonrt_attach` is called once at planner startup. It receives a
434- pointer to the HAL shared memory base and the byte offset of the
435- module's `kinematics_params_t` structure. It stores the pointer
436- for later use and registers the forward and inverse functions that
437- the planner will call:
433+ `nonrt_attach` is called once at planner startup. It calls
434+ `hal_struct_attach()` to map the module's `kinematics_params_t`
435+ from HAL shared memory, then registers the forward and inverse
436+ functions that the planner will call:
438437
439438----
440- void nonrt_attach(char *shmem_base, int offset, nonrt_ops_t *ops)
439+ void nonrt_attach(nonrt_ops_t *ops)
441440{
442- uspace_params = (kinematics_params_t *)(shmem_base + offset );
441+ hal_struct_attach("mykins.params", (void **)&uspace_params );
443442 ops->forward = myKinematicsForward; /* same function as RT */
444443 ops->inverse = myKinematicsInverse;
445444}
@@ -483,24 +482,29 @@ any `!haldata` guard -- there are no HAL pins to dereference.
483482==== Shared memory setup (required for planner 2)
484483
485484`rtapi_app_main()` (or `XxxKinematicsSetup()` for switchkins modules)
486- allocates the `kinematics_params_t` in HAL shmem and publishes its
487- byte offset so the userspace planner can locate it :
485+ registers the `kinematics_params_t` in HAL shmem using
486+ `hal_struct_newf()`, then attaches to it with `hal_struct_attach()` :
488487
489488----
490- uspace_params = (kinematics_params_t *)hal_malloc( sizeof(kinematics_params_t));
491- if (hal_param_s32_newf(HAL_RO, &uspace_params->self_offset, comp_id,
492- "%s.uspace- params-offset ", modname) < 0) goto error;
493- memset(uspace_params, 0, sizeof(*uspace_params)) ;
489+ if (hal_struct_newf(comp_id, sizeof(kinematics_params_t), NULL,
490+ "%s.params", modname) < 0) goto error;
491+ if (hal_struct_attach("mykins. params", (void **)&uspace_params) < 0)
492+ goto error ;
494493uspace_params->num_joints = num_joints;
495494uspace_params->is_identity = 0; /* 1 for trivial/identity kinematics */
496495/* fill initial parameter values */
497496uspace_params->valid = 1;
498497uspace_params->head = 1;
499498uspace_params->tail = 1;
500- uspace_params->self_offset = (int)SHMOFF(uspace_params);
501499----
502500
503- If the `uspace-params-offset` param is absent (old external module),
501+ `hal_struct_newf()` allocates the blob inside HAL's existing shared
502+ memory segment and registers a `HAL_RO hal_s32` parameter named
503+ `"<module>.params"` whose value is the shmem byte offset. The
504+ userspace planner calls `hal_struct_attach()` with the same name to
505+ obtain a direct pointer -- no `hal_priv.h`, no raw offsets.
506+
507+ If the `<module>.params` struct is absent (old external module),
504508the userspace planner detects this at init time and disables planner 2
505509with a logged warning. Planner 0 and 1 continue to work normally.
506510
@@ -561,13 +565,11 @@ the math, the RT interface (with shmem push), and the non-RT interface.
561565
562566/* ---- RT headers ---- */
563567#include "kinematics.h"
564- #include "hal.h"
565- #include "hal_priv.h" /* for SHMOFF() */
568+ #include <hal.h> /* hal_struct_newf/attach, hal_malloc */
566569#include "kinematics_params.h" /* for kinematics_params_t */
567570#include "rtapi.h"
568571#include "rtapi_app.h"
569572#include "rtapi_math.h"
570- #include <string.h> /* for memset() */
571573
572574/* ================================================================
573575 * Layer 1: Pure math (shared by RT and non-RT)
@@ -670,19 +672,17 @@ int rtapi_app_main(void)
670672 goto error;
671673 *(haldata->arm_length) = 100.0; /* default value */
672674
673- /* Allocate kinematics_params_t in HAL shmem and publish its offset */
674- uspace_params = (kinematics_params_t *)hal_malloc(sizeof(kinematics_params_t));
675- if (!uspace_params) goto error;
676- if (hal_param_s32_newf(HAL_RO, &uspace_params->self_offset, comp_id,
677- "mykins.uspace-params-offset") < 0) goto error;
678- memset(uspace_params, 0, sizeof(*uspace_params));
675+ /* Register kinematics parameters in HAL shmem via hal_struct_newf() */
676+ if (hal_struct_newf(comp_id, sizeof(kinematics_params_t), NULL,
677+ "mykins.params") < 0) goto error;
678+ if (hal_struct_attach("mykins.params", (void **)&uspace_params) < 0)
679+ goto error;
679680 uspace_params->num_joints = 3;
680681 uspace_params->is_identity = 0;
681682 uspace_params->params.mykins.arm_length = 100.0;
682683 uspace_params->valid = 1;
683684 uspace_params->head = 1;
684685 uspace_params->tail = 1;
685- uspace_params->self_offset = (int)SHMOFF(uspace_params);
686686
687687 hal_ready(comp_id);
688688 return 0;
@@ -696,15 +696,16 @@ void rtapi_app_exit(void) { hal_exit(comp_id); }
696696/* ================================================================
697697 * Layer 3: Non-RT entry point (for userspace trajectory planner)
698698 *
699- * nonrt_attach is called once at planner startup. It maps the
700- * shmem params pointer and registers the forward/inverse functions.
699+ * nonrt_attach is called once at planner startup. It attaches to
700+ * the kinematics_params_t registered by rtapi_app_main() via
701+ * hal_struct_newf() and registers the forward/inverse functions.
701702 * The same kinematicsForward/Inverse functions are used -- they
702703 * detect the userspace context via !haldata and read from shmem.
703704 * ================================================================ */
704705
705- void nonrt_attach(char *shmem_base, int offset, nonrt_ops_t *ops)
706+ void nonrt_attach(nonrt_ops_t *ops)
706707{
707- uspace_params = (kinematics_params_t *)(shmem_base + offset );
708+ hal_struct_attach("mykins.params", (void **)&uspace_params );
708709 ops->forward = kinematicsForward;
709710 ops->inverse = kinematicsInverse;
710711}
@@ -731,7 +732,8 @@ kinematics modules follow:
731732 is never called.
732733
733734. **Layer 3 -- Non-RT entry point**: The `nonrt_attach()` function,
734- called once at planner startup. It stores the shmem pointer and
735+ called once at planner startup. It calls `hal_struct_attach()` to
736+ map the module's `kinematics_params_t` from HAL shmem, then
735737 registers the forward/inverse function pointers. No separate
736738 non-RT math functions are needed -- the same RT functions handle
737739 both contexts via the `!haldata` guard.
@@ -791,8 +793,8 @@ RT `.so` to load and resolves `nonrt_attach` from it at startup.
791793- Use `rtapi_snprintf()` instead of `snprintf()` in RT code.
792794 Standard C library functions are not available in the RT
793795 environment.
794- - Always include `hal_priv.h ` (for `SHMOFF()`) and `<string.h>`
795- (for `memset()`) in modules that set up `uspace_params`.
796+ - Include `<hal.h> ` (angle brackets — it is a public header) and
797+ `"kinematics_params.h"` in modules that set up `uspace_params`.
796798- For modules with no runtime parameters (pure geometric transforms),
797799 register the RT functions directly in `nonrt_attach` with no
798800 `!haldata` guard -- there are no HAL pin pointers to dereference.
@@ -805,7 +807,7 @@ RT `.so` to load and resolves `nonrt_attach` from it at startup.
805807- The shmem push uses `head`/`tail` guards to protect against torn
806808 reads: increment `head` before any write, set `tail = head` after
807809 all writes. The userspace side retries the read when `head != tail`.
808- - Modules without the `uspace- params-offset` param fall back
810+ - Modules without the `<module>. params` HAL struct fall back
809811 gracefully: planner 0 and 1 work normally, planner 2 is disabled
810812 with a logged warning.
811813- Look at the existing modules in `src/emc/kinematics/` for
0 commit comments