# 5 axis kinematics setup

10 Nov 2017 14:28 #101606 by agsarg
Hello everyone sorry if this post is repeated but couldn t find the answer, so here it goes:
I m trying to set the 5 axis kinematics looking at the xyzac kins c source code

struct haldata {
hal_float_t *z_offset;
hal_float_t *y_offset;
hal_float_t *tool_offset;
} *haldata;

int kinematicsForward(const double *joints,
EmcPose * pos,
const KINEMATICS_FORWARD_FLAGS * fflags,
KINEMATICS_INVERSE_FLAGS * iflags)
{
double dy = *(haldata->y_offset);
double dz = *(haldata->z_offset);
double dt = *(haldata->tool_offset);

dz = dz + dt;

pos->tran.x = + cos(c_rad) * (joints[JX] )

pos->tran.y = - sin(c_rad) * (joints[JX] )

pos->tran.z = + 0
- sin(a_rad) * (joints[JY] - dy)
+ cos(a_rad) * (joints[JZ] - dz)
+ dz;

pos->a = joints[JA];
pos->c = joints[JC];

pos->b = 0;
pos->w = 0;
pos->u = 0;
pos->v = 0;

return 0;
}

where dy is the distance from a axis rotation center to c axis rotation center
and dz is the height from c table to a axis rotation center as explained on linuxcnc.org/docs/ja/html/motion/5-axis-kinematics.html

Is tool offset the tool diameter?

now how/where do i declare the offsets values? units for the offsets?

##### Attachments:
12 Nov 2017 11:10 - 12 Nov 2017 11:12 #101686 by andypugh
Replied by andypugh on topic 5 axis kinematics setup
I would expect "tool offset" to be the tool length. (especially with the line dz = dz + dt)
The offsets appear to come from HAL pins, are any created by the kins module?
Last edit: 12 Nov 2017 11:12 by andypugh.
13 Nov 2017 18:51 #101739 by agsarg
Replied by agsarg on topic 5 axis kinematics setup
Hi andy thanks for your reply that was the right question so i started looking and found this (think this info it s great to start undertanding the kins source file and hal implementation) github.com/LinuxCNC/linuxcnc/blob/master...-axis-kinematics.txt which basically has all the info for implementing the module. So i followed the steps and added the halpins that are created here

if((res = hal_pin_float_new("xyzac-trt-kins.y-offset",
HAL_IO, &(haldata->y_offset), comp_id)) < 0) goto error;
if((res = hal_pin_float_new("xyzac-trt-kins.z-offset",
HAL_IO, &(haldata->z_offset), comp_id)) < 0) goto error;
if((res = hal_pin_float_new("xyzac-trt-kins.tool-offset",
HAL_IN, &(haldata->tool_offset), comp_id)) < 0) goto error;

to the hal file:

net :tool-offset motion.tooloffset.z xyzac-trt-kins.tool-offset
setp xyzac-trt-kins.y-offset 0
setp xyzac-trt-kins.z-offset 20

Obviously i compiled the module with sudo halcompile --install xyzackins.c (my guess is that it turned out fine as i tested installing
another kinematics module for a 3 axis mill with axis deviation and it worked)

Still when i try to run lcnc i get this:

Debug file information:
.
3847
PID TTY STAT TIME COMMAND
/usr/bin/linuxcnc_module_helper: Invalid usage with args: remove xyzac-trt-kins

Usage: /usr/bin/linuxcnc_module_helper insert /path/to/module.ext [param1=value1 ...]

where module is one of:
rtai_math
rtai_sem
rtai_shm
rtai_fifos
rtai_up
rtai_lxrt
rtai_hal
rtai_sched
rtai_smi
rtai
rt_mem_mgr

the path starts with one of:
/lib/modules
/usr/realtime-3.4-9-rtai-686-pae

and the extension is one of:
.ko

or the module is in the directory /usr/realtime-3.4-9-rtai-686-pae/modules/linuxcnc

OR

/usr/bin/linuxcnc_module_helper remove module

where module is one of the modules listed above.

<commandline>:0: exit value: 1
<commandline>:0: rmmod failed, returned -1
Error: Module hal_lib is in use by: xyzackins1
Error: Module rtapi is in use by: hal_lib
Error: Module rtai_sched is in use by: rtapi
Error: Module rtai_hal is in use by: rtapi rtai_sched

the xyzackins.ko (compiled file) is locaded at usr/realtimexxx/modules/linuxcnc with trivkins.ko and all other modules.
"invalid usage with args" don t understand what seems to be the problem here. Thanks everyone ill keep updating as this post may be helpful to fresh boarders.
13 Nov 2017 19:40 - 13 Nov 2017 19:41 #101744 by andypugh
Replied by andypugh on topic 5 axis kinematics setup

agsarg wrote: Hi andy thanks for your reply that was the right question so i started looking and found this (think this info it s great to start undertanding the kins source file and hal implementation) github.com/LinuxCNC/linuxcnc/blob/master...-axis-kinematics.txt which basically has all the info for implementing the module.

That file creates this (more legible) documentation section:
linuxcnc.org/docs/devel/html/motion/5-axis-kinematics.html
And there is also this:
linuxcnc.org/docs/2.7/html/motion/kinematics.html

/usr/bin/linuxcnc_module_helper: Invalid usage with args: remove xyzac-trt-kins
.

What does the "loadrt xyzackins-trt" line in the HAL look like, and what does your kinematics file look like?

(It sounds like you are trying to pass command-line parameters to you kins module and it is not expecting them.)
Last edit: 13 Nov 2017 19:41 by andypugh.
13 Nov 2017 21:11 #101746 by agsarg
Replied by agsarg on topic 5 axis kinematics setup
i replaced the default line
"loadrt trivkins" for "loadrt xyzackins1" as that s the name of the source code i compiled (xyzackins1.c)
even tried adding in the ini file
[KINS]
KINEMATICS = xyzackins1 but the msg error is the same (tried rebooting and replacing the kinematics mod to trivkins
and it worked just fine even removing this part from the ini works fine.

and my kinematics file is the exact one from here github.com/LinuxCNC/linuxcnc/blob/master...ics/xyzac-trt-kins.c
i used the pins as written "xyzac-trt-kins.tool-offset" "xyzac-trt-kins.z-offset" "xyzac-trt-kins.y-offset"
to wire up the hal file

net :tool-offset motion.tooloffset.z xyzac-trt-kins.tool-offset
setp xyzac-trt-kins.y-offset 0
setp xyzac-trt-kins.z-offset 20

being the pin "motion.tooloffset.z" an out pin from motion controller
13 Nov 2017 22:46 #101749 by andypugh
Replied by andypugh on topic 5 axis kinematics setup
So, you are not actually passing any arguments to xyzackins in the loadrt line?

Which version of LinuxCNC are you using? (I am wondering why you needed to compile a kins module that is a standard part of LinuxCNC)
14 Nov 2017 13:54 #101776 by agsarg
Replied by agsarg on topic 5 axis kinematics setup
First time i see i have to give command loadusr the arguments for the module i read the hal manual 2.6.13 the loadusr section and kinematics implementation section and didn t found any examples like that. sorry if my questions sound silly
14 Nov 2017 14:03 #101780 by andypugh
Replied by andypugh on topic 5 axis kinematics setup
It is "loadrt" for a kins module. You can't "loadusr" one, that won't work.
Was that a typo, or is that the problem?
14 Nov 2017 14:21 #101783 by agsarg
Replied by agsarg on topic 5 axis kinematics setup
just a typo i meant loadrt
14 Nov 2017 15:01 - 14 Nov 2017 15:02 #101784 by andypugh
Replied by andypugh on topic 5 axis kinematics setup
github.com/LinuxCNC/linuxcnc/blob/9d99a3.../module_helper.c#L78

It seems to be a hint that "more info follows" and it might actually be complaining that the kins module can't be removed.
So, then the question has to be why it is trying.

Just as an experiment (I would do this myself, but I am not at a LinuxCNC machine) try the following in a terminal window.

halrun