# Q: Uneven table compensation with 2.7.11

20 Sep 2017 22:10 #99185
Hi !

I run into problem with uneven table compensation (or minuscule X / Y cemented shaft bending under weight of the portal).
After googling, found that I should use either probekins or trivkins.
Mach3 has formula setup for this purpose, however, it didn't work correctly and produced bizarre unusable results.
A ready to use receipt (in Russian) with probekins described here:
www.cnc-club.ru/forum/viewtopic.php?f=15&t=1909&start=20

Probekins seem to use STL file generated from matrix to get offset, which is not very optimal (and as someone stated, not always work correctly).
I have quite complex polynomial formulas which calculate Z height adjustments over given X and Y points.
Formulas are 100% OK for sure because they show correct results in Excel / LibreOffice Calc.

Anyone can suggest how to properly implement such feature in LinuxCNC 2.7.11 for simple 3D milling router ?

I would prefer some kind of callback and use my Z=f(X) and Z = f(Y) polynomial formulas instead of awkward STL.

Thanks in advance for any suggestion(s).

23 Sep 2017 10:52 #99320
Make your own Kinematic model that calculates Z offsets.

you can write it as .c file and use math you like in there to calculate offsets.

I run multi point linear interpolation to correct rotary axis non-linearity.
Deviation is really small ... but leads further from rotating center to 0.2mm error.
Same principle could be used to correct thermal expansion and ball screw lead deviations.

Use some ready kinematic file for basis and write you own corrections there.

Install it with :
sudo halcompile -- install kinematisfilename.c

at the HAL setup just call your own kinematis and that basically it.

03 Oct 2017 12:37 #99808 by andypugh
kinematics is certainly one way.
An alternative, for small offsets, would be a simple HAL component that has inputs for X Y and Z and outputs an offset value for Z.
You could also consider using the external-offsets feature branch. But that might not get updates indefinitely, though my hope would be that it makes it into the main branch.
The following user(s) said Thank You: LinuksGuru

03 Oct 2017 18:32 #99831

andypugh wrote: kinematics is certainly one way.
An alternative, for small offsets, would be a simple HAL component that has inputs for X Y and Z and outputs an offset value for Z.

OK, thanks a lot, this is what I'm looking for. Do you have any examples of such HAL component ?
Unfortunately, I can't get enough info from online docs n order to properly construct compensation function z=f(x,y).
linuxcnc.org/docs/html/hal/tutorial.html

03 Oct 2017 19:01 - 03 Oct 2017 19:02 #99833 by andypugh
It would look a bit like this:
```component wobbly_table;
pin in float x-in;
pin in float y-in;
pin in float z-in;
pin out float z-out;
function _;
;;

FUNCTION(_){
zout = z_in + 0.1 * x_in + 0.2 * y_in + 0.01 * x_in * y_in;
}```

linuxcnc.org/docs/2.7/html/hal/comp.html
Last edit: 03 Oct 2017 19:02 by andypugh.
The following user(s) said Thank You: LinuksGuru

03 Oct 2017 19:33 #99837

andypugh wrote: It would look a bit like this:

```component wobbly_table;
pin in float x-in;
pin in float y-in;
pin in float z-in;
pin out float z-out;
function _;
;;

FUNCTION(_){
zout = z_in + 0.1 * x_in + 0.2 * y_in + 0.01 * x_in * y_in;
}```

Am I correctly understood that this HAL module will be interpreted into C code and compiled by halcompile?
Does it mean its possible to use all standard C functions like pow(x, y) ?
#include <math.h> still necessary ?

03 Oct 2017 19:37 #99839 by andypugh
You only get to use functions included in rtapi_math.h

github.com/LinuxCNC/linuxcnc/blob/master/src/rtapi/rtapi_math.h

(And halcompile can find those automatically)
The following user(s) said Thank You: LinuksGuru

03 Oct 2017 19:40 #99840

andypugh wrote: You only get to use functions included in rtapi_math.h

github.com/LinuxCNC/linuxcnc/blob/master/src/rtapi/rtapi_math.h

(And halcompile can find those automatically)

OK, great, thanks, now picture is clear. pow(x, y) is there.
I'll try to setup and report back.