Custom kinematics

  • mariusl
  • mariusl's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
04 Jan 2025 11:46 #318048 by mariusl
Custom kinematics was created by mariusl
I am using master on Bookworm in a RIP setup. I am trying to compile and install a custom kinematics module but it seems that things has changed a lot since I last tried this.
halcompile will not compile and install the .c file so I tried the only other method that I can find in the documentation.

I did this:
**        LDIR is LinuxCNC git root directory
**        UDIR is user directory (not in LinuxCNC git tree)
**  1) $ cp LDIR/src/emc/kinematics/userkfuncs.c  UDIR/my_userk.c
**  2) $ edit   UDIR/my_userk.c as required
**  3) $ source LDIR/scripts/rip-environment
**  4) For genser-switchkins module use make command line option:
**     $ cd LDIR/src
**     $ userkfuncs=UDIR/my_userk.c make && sudo make setuid

The output form the compile :-
$ userkfuncs=/home/marius/mydev/my_userk.c make && sudo make setuid
Reading 203/203 dependency files
Done reading dependencies
!!!USERKFUNCS=/home/marius/mydev/my_userk.o
Reading 272/272 realtime dependency files
Done reading realtime dependencies
Compiling realtime /home/marius/mydev/my_userk.c
Linking ../rtlib/genhexkins.so
Linking ../rtlib/genserkins.so
Linking ../rtlib/xyzac-trt-kins.so
Linking ../rtlib/xyzbc-trt-kins.so
Linking ../rtlib/scarakins.so
Linking ../rtlib/pumakins.so
Linking ../rtlib/5axiskins.so
You now need to run 'sudo make setuid' in order to run in place with access to hardware.
chown root ../bin/rtapi_app
chmod 4750 ../bin/rtapi_app
chown root ../bin/linuxcnc_module_helper
chmod 4750 ../bin/linuxcnc_module_helper
I see it linking all kinds of other modules but not my module. I cannot find output of my module anywhere.
It would seem that I cannot compile and install my own custom file.
What am I doing wrong or don't I understand the process?
 

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
04 Jan 2025 12:27 - 04 Jan 2025 14:44 #318055 by Aciera
Replied by Aciera on topic Custom kinematics
Any particular reason for not using the more recent 'userkins.comp' template?

github.com/LinuxCNC/linuxcnc/blob/master...onents/userkins.comp

For switchable kinematics see:

github.com/LinuxCNC/linuxcnc/blob/master...onents/millturn.comp
Last edit: 04 Jan 2025 14:44 by Aciera.

Please Log in or Create an account to join the conversation.

  • mariusl
  • mariusl's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
04 Jan 2025 15:00 #318080 by mariusl
Replied by mariusl on topic Custom kinematics
I am following the directions of the documentation. If it was mentioned then I would follow your route.

linuxcnc.org/docs/stable/html/motion/switchkins.html

Is there documentation elsewhere that will be a bit more correct?
 

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
04 Jan 2025 15:16 - 04 Jan 2025 15:23 #318084 by Aciera
Replied by Aciera on topic Custom kinematics
See bottom here (not much more info than what I already provided above):
linuxcnc.org/docs/stable/html/motion/kinematics.html

I'm not saying that the docs you linked are incorrect but I have never tried to create a custom kinematic that way. There might be reasons to go that route depending on what includes you need.

Maybe you could provide a bit more information on what you are trying to do?
Last edit: 04 Jan 2025 15:23 by Aciera.

Please Log in or Create an account to join the conversation.

  • mariusl
  • mariusl's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
04 Jan 2025 15:42 - 04 Jan 2025 15:44 #318089 by mariusl
Replied by mariusl on topic Custom kinematics
Trying to compile a custom kinematic module for RIP uspace rt using switchkins. 
I am sure the documentation sucks as that method does not work.
I will try your method tomorrow.

Regards
Marius


www.bluearccnc.com

Last edit: 04 Jan 2025 15:44 by mariusl.

Please Log in or Create an account to join the conversation.

More
04 Jan 2025 15:56 #318090 by Aciera
Replied by Aciera on topic Custom kinematics
I believe that the method you linked to is used to add a custom kinematic to the sim configs listed under section 2. So I just tried it:

Created a file 'mykins.c':
/* userkfuncs.c: template file for a user set of
**               switchable kinematics functions.
** License GPL Version 2
**
** Example Usage (for customizing the genser-switchkins module):
** (works with rtpreempt only rtai --> Makefile needs work)
**
**        LDIR is LinuxCNC git root directory
**        UDIR is user directory (not in LinuxCNC git tree)
**  1) $ cp LDIR/src/emc/kinematics/userkfuncs.c  UDIR/my_userk.c
**  2) $ edit   UDIR/my_userk.c as required
**  3) $ source LDIR/scripts/rip-environment
**  4) For genser-switchkins module use make command line option:
**     $ cd LDIR/src
**     $ userkfuncs=UDIR/my_userk.c make && sudo make setuid
*/

// typical includes:
//#include "rtapi_math.h" // if reqd
#include "kinematics.h"
#include "hal.h"

// Add for kins based on genserkins:
// #include "genserkins.h" //includes gomath,hal

//**********************************************************************
// static local variables and functions go here

static int userk_inited = 0;
static struct udata {
    hal_s32_t *fct;
    hal_s32_t *ict;
} *udata;

//**********************************************************************
int userkKinematicsSetup(const int   comp_id,
                         const char* coordinates,
                         kparms*     kp)
{
    int res=0;
    rtapi_print("\nuserkKinematicsSetup:\n"
                  "   %s <%s> max_joints=%d allow_duplicates=%d\n\n",
                __FILE__,coordinates,
                kp->max_joints,kp->allow_duplicates);


    udata = hal_malloc(sizeof(struct udata));
    if (!udata) goto error;

    // HAL_IO used to allow resetting demo pins:
    res += hal_pin_s32_new("userk.fct", HAL_IO, &(udata->fct), comp_id);
    res += hal_pin_s32_new("userk.ict", HAL_IO, &(udata->ict), comp_id);
    if (res) goto error;

    userk_inited = 1;
    return 0; // 0 ==> OK

error:
    return -1;
}

int userkKinematicsForward(const double *joint,
                           struct EmcPose * world,
                           const KINEMATICS_FORWARD_FLAGS * fflags,
                           KINEMATICS_INVERSE_FLAGS * iflags)
{
    if (!userk_inited) {
        rtapi_print_msg(RTAPI_MSG_ERR,
             "myuserkins: not initialized\n");
        return -1;
    }

    world->tran.x = joint[1];
    world->tran.y = joint[0];
    world->tran.z = joint[2];
    world->a = joint[3];
    world->c = joint[4];

    return 0;

}

int userkKinematicsInverse(const EmcPose * pos,
                           double *joint,
                           const KINEMATICS_INVERSE_FLAGS * iflags,
                           KINEMATICS_FORWARD_FLAGS * fflags)
{

            joint[1] = pos->tran.x;
            joint[0] = pos->tran.y;
            joint[2] = pos->tran.z;
            joint[3] = pos->a;
            joint[4] = pos->c;

    return 0;
}

2. compiled on my RIP installation:
user@user-iMac:~/git/linuxcnc-master/src$ userkfuncs=emc/kinematics/mykins.c make
Reading 203/203 dependency files
Done reading dependencies
!!!USERKFUNCS=emc/kinematics/mykins.o
Reading 272/272 realtime dependency files
Done reading realtime dependencies
Compiling realtime emc/kinematics/mykins.c
Linking ../rtlib/genhexkins.so
Linking ../rtlib/genserkins.so
Linking ../rtlib/xyzac-trt-kins.so
Linking ../rtlib/xyzbc-trt-kins.so
Linking ../rtlib/scarakins.so
Linking ../rtlib/pumakins.so
Linking ../rtlib/5axiskins.so
You now need to run 'sudo make setuid' in order to run in place with access to hardware.

3. start 'xyzbc-trt.ini' and SWITCHKINS 'userk' now uses 'mykins.c'
 

SO If you do not want to add another kinematic to one of those sim configs then this likely will not do much for you.
Attachments:
The following user(s) said Thank You: mariusl

Please Log in or Create an account to join the conversation.

  • mariusl
  • mariusl's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
04 Jan 2025 17:10 #318106 by mariusl
Replied by mariusl on topic Custom kinematics
Well I would never have guessed that it was for the sims only.

Thanks for clearing it up for me.

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

Time to create page: 0.081 seconds
Powered by Kunena Forum