6262#include <kinematics.h>
6363
6464#include "switchkins.h"
65+ #include "hal_priv.h"
66+ #include "kinematics_params.h"
6567
6668/* ========================================================================
6769 * Internal math (was in 5axiskins_math.h)
@@ -162,6 +164,9 @@ struct haldata {
162164} * haldata ;
163165static int fiveaxis_max_joints ;
164166
167+ /* Userspace-accessible params in HAL shmem */
168+ static kinematics_params_t * uspace_params ;
169+
165170// Joint mapping struct
166171static fiveaxis_joints_t jmap ;
167172
@@ -182,35 +187,61 @@ static int fiveaxis_KinematicsForward(const double *joints,
182187 const KINEMATICS_FORWARD_FLAGS * fflags ,
183188 KINEMATICS_INVERSE_FLAGS * iflags )
184189{
185- (void )fflags ;
186- (void )iflags ;
190+ (void )fflags ; (void )iflags ;
187191 fiveaxis_params_t params ;
192+
193+ if (!haldata ) {
194+ /* userspace path: read params from HAL shmem set up by nonrt_attach */
195+ kinematics_params_t local ;
196+ KINS_SHMEM_READ (uspace_params , local );
197+ params .pivot_length = local .params .fiveaxis .pivot_length ;
198+ fiveaxis_joints_t jm = {
199+ local .axis_to_joint [0 ], local .axis_to_joint [1 ], local .axis_to_joint [2 ],
200+ local .axis_to_joint [3 ], local .axis_to_joint [4 ], local .axis_to_joint [5 ],
201+ local .axis_to_joint [6 ], local .axis_to_joint [7 ], local .axis_to_joint [8 ]
202+ };
203+ return fiveaxis_forward_impl (& params , & jm , joints , pos );
204+ }
205+
188206 params .pivot_length = * (haldata -> pivot_length );
207+ if (uspace_params ) {
208+ uspace_params -> head ++ ;
209+ uspace_params -> params .fiveaxis .pivot_length = params .pivot_length ;
210+ uspace_params -> tail = uspace_params -> head ;
211+ }
189212 return fiveaxis_forward_impl (& params , & jmap , joints , pos );
190- } //fiveaxis_KinematicsForward()
213+ }
191214
192215static int fiveaxis_KinematicsInverse (const EmcPose * pos ,
193216 double * joints ,
194217 const KINEMATICS_INVERSE_FLAGS * iflags ,
195218 KINEMATICS_FORWARD_FLAGS * fflags )
196219{
197- (void )iflags ;
198- (void )fflags ;
220+ (void )iflags ; (void )fflags ;
199221 fiveaxis_params_t params ;
200- params .pivot_length = * (haldata -> pivot_length );
201222
202- // Compute axis values using pure math function
223+ if (!haldata ) {
224+ /* userspace path: read params from HAL shmem set up by nonrt_attach */
225+ kinematics_params_t local ;
226+ KINS_SHMEM_READ (uspace_params , local );
227+ params .pivot_length = local .params .fiveaxis .pivot_length ;
228+ fiveaxis_joints_t jm = {
229+ local .axis_to_joint [0 ], local .axis_to_joint [1 ], local .axis_to_joint [2 ],
230+ local .axis_to_joint [3 ], local .axis_to_joint [4 ], local .axis_to_joint [5 ],
231+ local .axis_to_joint [6 ], local .axis_to_joint [7 ], local .axis_to_joint [8 ]
232+ };
233+ EmcPose axis_values ;
234+ fiveaxis_inverse_impl (& params , pos , & axis_values );
235+ fiveaxis_axis_to_joints (& jm , & axis_values , joints );
236+ return 0 ;
237+ }
238+
239+ params .pivot_length = * (haldata -> pivot_length );
203240 EmcPose P ;
204241 fiveaxis_inverse_impl (& params , pos , & P );
205-
206- // update joints with support for
207- // multiple-joints per-coordinate letter:
208- // based on computed position
209- position_to_mapped_joints (fiveaxis_max_joints ,
210- & P ,
211- joints );
242+ position_to_mapped_joints (fiveaxis_max_joints , & P , joints );
212243 return 0 ;
213- } // fiveaxis_kinematicsInverse()
244+ }
214245
215246int fiveaxis_KinematicsSetup (const int comp_id ,
216247 const char * coordinates ,
@@ -278,6 +309,28 @@ int fiveaxis_KinematicsSetup(const int comp_id,
278309
279310 * haldata -> pivot_length = DEFAULT_PIVOT_LENGTH ;
280311
312+ /* Publish kinematics params to HAL shmem for userspace planner */
313+ uspace_params = (kinematics_params_t * )hal_malloc (sizeof (kinematics_params_t ));
314+ if (!uspace_params ) {
315+ rtapi_print_msg (RTAPI_MSG_ERR , "5axiskins: hal_malloc for uspace_params failed\n" );
316+ goto error ;
317+ }
318+ result = hal_param_s32_newf (HAL_RO , & uspace_params -> self_offset , comp_id ,
319+ "%s.uspace-params-offset" , kp -> halprefix );
320+ if (result < 0 ) goto error ;
321+
322+ memset (uspace_params , 0 , sizeof (* uspace_params ));
323+ uspace_params -> num_joints = fiveaxis_max_joints ;
324+ uspace_params -> axis_to_joint [0 ] = JX ; uspace_params -> axis_to_joint [1 ] = JY ;
325+ uspace_params -> axis_to_joint [2 ] = JZ ; uspace_params -> axis_to_joint [3 ] = JA ;
326+ uspace_params -> axis_to_joint [4 ] = JB ; uspace_params -> axis_to_joint [5 ] = JC ;
327+ uspace_params -> axis_to_joint [6 ] = JU ; uspace_params -> axis_to_joint [7 ] = JV ;
328+ uspace_params -> axis_to_joint [8 ] = JW ;
329+ uspace_params -> params .fiveaxis .pivot_length = DEFAULT_PIVOT_LENGTH ;
330+ uspace_params -> valid = 1 ;
331+ uspace_params -> is_identity = 0 ;
332+ uspace_params -> self_offset = (int )SHMOFF (uspace_params );
333+
281334 rtapi_print ("Kinematics Module %s\n" ,__FILE__ );
282335 rtapi_print (" module name = %s\n"
283336 " coordinates = %s Requires: [KINS]JOINTS>=%d\n"
@@ -333,66 +386,17 @@ int switchkinsSetup(kparms* kp,
333386
334387/* ========================================================================
335388 * Non-RT interface for userspace trajectory planner
389+ *
390+ * nonrt_attach() is the only exported symbol. It sets uspace_params so the
391+ * !haldata branch in fiveaxis_KinematicsForward/Inverse reads live shmem,
392+ * then registers those functions directly — no separate nonrt functions.
336393 * ======================================================================== */
337- #include "kinematics_params.h"
338-
339- int nonrt_kinematicsForward (const void * params ,
340- const double * joints ,
341- EmcPose * pos )
342- {
343- const kinematics_params_t * kp = (const kinematics_params_t * )params ;
344- fiveaxis_params_t p ;
345- fiveaxis_joints_t jm ;
346-
347- p .pivot_length = kp -> params .fiveaxis .pivot_length ;
348- jm .jx = kp -> axis_to_joint [0 ]; jm .jy = kp -> axis_to_joint [1 ];
349- jm .jz = kp -> axis_to_joint [2 ]; jm .ja = kp -> axis_to_joint [3 ];
350- jm .jb = kp -> axis_to_joint [4 ]; jm .jc = kp -> axis_to_joint [5 ];
351- jm .ju = kp -> axis_to_joint [6 ]; jm .jv = kp -> axis_to_joint [7 ];
352- jm .jw = kp -> axis_to_joint [8 ];
353-
354- return fiveaxis_forward_impl (& p , & jm , joints , pos );
355- }
356-
357- int nonrt_kinematicsInverse (const void * params ,
358- const EmcPose * pos ,
359- double * joints )
360- {
361- const kinematics_params_t * kp = (const kinematics_params_t * )params ;
362- fiveaxis_params_t p ;
363- fiveaxis_joints_t jm ;
364- EmcPose axis_values ;
365-
366- p .pivot_length = kp -> params .fiveaxis .pivot_length ;
367- jm .jx = kp -> axis_to_joint [0 ]; jm .jy = kp -> axis_to_joint [1 ];
368- jm .jz = kp -> axis_to_joint [2 ]; jm .ja = kp -> axis_to_joint [3 ];
369- jm .jb = kp -> axis_to_joint [4 ]; jm .jc = kp -> axis_to_joint [5 ];
370- jm .ju = kp -> axis_to_joint [6 ]; jm .jv = kp -> axis_to_joint [7 ];
371- jm .jw = kp -> axis_to_joint [8 ];
372-
373- fiveaxis_inverse_impl (& p , pos , & axis_values );
374- fiveaxis_axis_to_joints (& jm , & axis_values , joints );
375- return 0 ;
376- }
377394
378- int nonrt_refresh (void * params ,
379- int (* read_float )(const char * , double * ),
380- int (* read_bit )(const char * , int * ),
381- int (* read_s32 )(const char * , int * ))
395+ void nonrt_attach (char * shmem_base , int offset , nonrt_ops_t * ops )
382396{
383- kinematics_params_t * kp = (kinematics_params_t * )params ;
384- (void )read_bit ; (void )read_s32 ;
385-
386- if (read_float ("5axiskins.pivot-length" ,
387- & kp -> params .fiveaxis .pivot_length ) != 0 )
388- return -1 ;
389-
390- return 0 ;
397+ uspace_params = (kinematics_params_t * )(shmem_base + offset );
398+ ops -> forward = fiveaxis_KinematicsForward ;
399+ ops -> inverse = fiveaxis_KinematicsInverse ;
391400}
392401
393- int nonrt_is_identity (void ) { return 0 ; }
394-
395- EXPORT_SYMBOL (nonrt_kinematicsForward );
396- EXPORT_SYMBOL (nonrt_kinematicsInverse );
397- EXPORT_SYMBOL (nonrt_refresh );
398- EXPORT_SYMBOL (nonrt_is_identity );
402+ EXPORT_SYMBOL (nonrt_attach );
0 commit comments