Linear Table Correction for Scissor Shape lab jack

Moderators: TomKerekes, dynomotion

Post Reply
inspectormag
Posts: 5
Joined: Sat Aug 09, 2025 7:23 am

Linear Table Correction for Scissor Shape lab jack

Post by inspectormag » Sat Aug 09, 2025 7:50 am

I am a new user of Dynomotion boards and enjoyed a lot with the strong features.
I am using Kanalog, KFlop and KStep for a scissor shape lab jack purchased from PDVCN pt-gd402:

This jack is nonlinear and I need to correct it. I have tried a lot as per your instruction in below link wiki/index.php/Linear_Table_Correction
but I have failed to fix it.
I share the MapFile_Z.txt file as follows. It workes perfect for1 to 10 but for higher values the error is very big.
To make this file, I have measured the actual distance for commanded G code (G1 Z1) and then converted to below numbers which already interpolated for actual command that should work. At the end I share the original data of measurements.
Can you help if you have any experience workign with nonlinear axis like this. is it possible to fix it? Do you recommend using Kinematics code to change.
If you need any further data, please let me know.
Thank you

104
-1
0.0
0,0
1,-2.99591
2,-5.75771
3,-8.36378
4,-11.0838
5,-13.5118
6,-15.5074
7,-17.6943
8,-19.826
9,-21.9716
10,-23.8762
11,-25.967
12,-27.7513
13,-29.6182
14,-31.4233
15,-33.1192
16,-34.7843
17,-36.4223
18,-37.9257
19,-39.4023
20,-40.8267
21,-42.1386
22,-43.5525
23,-44.8587
24,-46.2363
25,-47.5
26,-48.8147
27,-50.0721
28,-51.2949
29,-52.4646
30,-53.6167
31,-54.7539
32,-55.9166
33,-57.0276
34,-58.1306
35,-59.2079
36,-60.2521
37,-61.2195
38,-62.226
39,-63.1915
40,-64.215
41,-65.2218
42,-66.17
43,-67.1028
44,-68.0513
45,-68.9413
46,-69.8136
47,-70.6995
48,-71.5895
49,-72.4502
50,-73.2979
51,-74.1588
52,-74.9776
53,-75.7658
54,-76.5136
55,-77.2491
56,-77.9934
57,-78.6997
58,-79.392
59,-80.0756
60,-80.777
61,-81.4482
62,-82.1155
63,-82.7654
64,-83.4219
65,-84.0823
66,-84.7426
67,-85.3728
68,-85.9839
69,-86.5536
70,-87.1354
71,-87.7652
72,-88.3424
73,-88.8883
74,-89.4284
75,-89.9671
76,-90.5058
77,-91.0434
78,-91.5682
79,-92.0864
80,-92.5738
81,-93.0634
82,-93.5689
83,-94.0716
84,-94.559
85,-95.0443
86,-95.5096
87,-95.9748
88,-96.4076
89,-96.8385
90,-97.2612
91,-97.679
92,-98.0921
93,-98.4895
94,-98.887
95,-99.2688
96,-99.6444
97,-100.018
98,-100.356
99,-100.695
100,-101.033
101,-101.375
102,-101.716
103,-102.051

original measurements:
Commanded Actual(mm) error(mm)
0 0 0
-1 -0.342 -0.658
-2 -0.6595 -1.3405
-3 -1.0015 -1.9985
-4 -1.3679 -2.6321
-5 -1.6854 -3.3146
-6 -2.1006 -3.8994
-7 -2.3449 -4.6551
-8 -2.8578 -5.1422
-9 -3.2487 -5.7513
-10 -3.5418 -6.4582
-11 -3.957 -7.043
-12 -4.47 -7.53
-13 -4.7875 -8.2125
-14 -5.2027 -8.7973
-15 -5.7645 -9.2355
-16 -6.2286 -9.7714
-17 -6.6439 -10.3561
-18 -7.1568 -10.8432
-19 -7.5965 -11.4035
-20 -8.085 -11.915
-21 -8.5491 -12.4509
-22 -9.0132 -12.9868
-23 -9.5506 -13.4494
-24 -10.0635 -13.9365
-25 -10.5276 -14.4724
-26 -11.0161 -14.9839
-27 -11.5779 -15.4221
-28 -12.1397 -15.8603
-29 -12.6527 -16.3473
-30 -13.2145 -16.7855
-31 -13.7518 -17.2482
-32 -14.3381 -17.6619
-33 -14.9243 -18.0757
-34 -15.5594 -18.4406
-35 -16.1212 -18.8788
-36 -16.7318 -19.2682
-37 -17.3669 -19.6331
-38 -18.0508 -19.9492
-39 -18.7347 -20.2653
-40 -19.3942 -20.6058
-41 -20.127 -20.873
-42 -20.9086 -21.0914
-43 -21.5681 -21.4319
-44 -22.3498 -21.6502
-45 -23.107 -21.893
-46 -23.8153 -22.1847
-47 -24.597 -22.403
-48 -25.403 -22.597
-49 -26.1358 -22.8642
-50 -26.9419 -23.0581
-51 -27.7479 -23.2521
-52 -28.6028 -23.3972
-53 -29.4577 -23.5423
-54 -30.3371 -23.6629
-55 -31.2164 -23.7836
-56 -32.0713 -23.9287
-57 -32.9751 -24.0249
-58 -33.8788 -24.1212
-59 -34.807 -24.193
-60 -35.7352 -24.2648
-61 -36.7855 -24.2145
-62 -37.7626 -24.2374
-63 -38.8129 -24.1871
-64 -39.7899 -24.2101
-65 -40.767 -24.233
-66 -41.8173 -24.1827
-67 -42.892 -24.108
-68 -43.9424 -24.0576
-69 -45.066 -23.934
-70 -46.214 -23.786
-71 -47.3376 -23.6624
-72 -48.4612 -23.5388
-73 -49.658 -23.342
-74 -50.8061 -23.1939
-75 -52.0274 -22.9726
-76 -53.2975 -22.7025
-77 -54.6654 -22.3346
-78 -56.0088 -21.9912
-79 -57.4255 -21.5745
-80 -58.8911 -21.1089
-81 -60.3322 -20.6678
-82 -61.8222 -20.1778
-83 -63.361 -19.639
-84 -64.8754 -19.1246
-85 -66.3898 -18.6102
-86 -68.0264 -17.9736
-87 -69.7851 -17.2149
-88 -71.3727 -16.6273
-89 -73.2047 -15.7953
-90 -75.0611 -14.9389
-91 -76.9174 -14.0826
-92 -78.8227 -13.1773
-93 -80.8745 -12.1255
-94 -82.853 -11.147
-95 -84.9047 -10.0953
-96 -87.0542 -8.9458
-97 -89.3747 -7.6253
-98 -91.7684 -6.2316
-99 -94.2843 -4.7157
-100 -96.9468 -3.0532
-101 -99.9023 -1.0977
-102 -102.8334 0.8334

User avatar
TomKerekes
Posts: 2868
Joined: Mon Dec 04, 2017 1:49 am

Re: Linear Table Correction for Scissor Shape lab jack

Post by TomKerekes » Sat Aug 09, 2025 5:55 pm

Hi,

The function InvertTransformCADtoActuators() in Kinematics.cpp performs a numerical solution by starting at zero and iterating toward the solution. To avoid overshooting the solution in highly non-linear cases, it was limited to maximum steps of 0.1 inches and stopped after 100 iterations. This limited values to +/-10 inches. Version 5.0.6 changed this to steps of 1.0 inches so then values up to +/- 100 inches.

What Version are you using?
Regards,

Tom Kerekes
Dynomotion, Inc.

inspectormag
Posts: 5
Joined: Sat Aug 09, 2025 7:23 am

Re: Linear Table Correction for Scissor Shape lab jack

Post by inspectormag » Sun Aug 10, 2025 2:15 pm

Hi Tom,
KMotion 5.4.0
Z Traveling range is 110mm.
I tried for 10 days and everyday I try a different way and different measurements but result is almost same.
something is wrong that I don't understand.

I changed kinematics.cpp and defined an array (hard coded mesurement data) but still have problem.
when I command z1 to z10 the distance is correct but after z10 the error becomes very big.

before correction, when I commanded Z-103 the stage could move whole range (110mm) but now after uploading correction table (or kinematics change) the commanded Z-35 can result 110mm.

if you check my measurements, you will find that the center of stage has maximum error and the edges (top and bottom) has minimum error. I think I should change the data in a different way.

Thanks for your kind guide and help.
Last edited by inspectormag on Mon Aug 11, 2025 12:13 pm, edited 1 time in total.

inspectormag
Posts: 5
Joined: Sat Aug 09, 2025 7:23 am

Re: Linear Table Correction for Scissor Shape lab jack

Post by inspectormag » Mon Aug 11, 2025 8:26 am

Hello Tom,
I did a debug on KmotionCNC and GCodeInterpreter and found that the Z count calculation in Kinematics.cpp is based on inch unit and the linear correction table should be prepared in inch.
This was the main source of error.
I will check again with inch unit and inform you the result.

By the way, I appreciate your quick response and once again I should tell you your controllers are really amazing except that they are not easy for beginners but it is a good start for them to study and become pro.

Thank you.

inspectormag
Posts: 5
Joined: Sat Aug 09, 2025 7:23 am

Re: Linear Table Correction for Scissor Shape lab jack

Post by inspectormag » Mon Aug 11, 2025 12:13 pm

Hello Tom,
The linear table should be prepared in inch unit.
I made a macro to make the corrected data after measurement. If youy want, I will share it.

Also please mention the unit in your guide/help.
Thanks & regards,

User avatar
TomKerekes
Posts: 2868
Joined: Mon Dec 04, 2017 1:49 am

Re: Linear Table Correction for Scissor Shape lab jack

Post by TomKerekes » Mon Aug 11, 2025 4:56 pm

Ahh, sorry for the confusion. I added a note to the wiki. For simplicity all calculations are performed internally in inches or degrees.

Yes please share your macro it may be helpful to someone.

Thanks
Regards,

Tom Kerekes
Dynomotion, Inc.

inspectormag
Posts: 5
Joined: Sat Aug 09, 2025 7:23 am

Re: Linear Table Correction for Scissor Shape lab jack

Post by inspectormag » Wed Aug 13, 2025 8:08 am

No problem Tom! Such problems should happen in order to learn!
I made a VBA macro by ChatGPT that reads the table in col A = Commanded and col B = Actual and writes an inverse, interpolated table into col C (Desired Actual) and col D (Interpolated Commanded). The macro asks for start/end/step.

Paste this into a module (Alt+F11 → Insert → Module) and run `BuildInverseTable`.

```vb
Option Explicit

Sub BuildInverseTable()
Dim ws As Worksheet: Set ws = ActiveSheet
Dim startRow As Long, lastRowA As Long, lastRowB As Long, lastRow As Long
Dim i As Long, n As Long, r As Long

' detect possible header in row 1
If Not IsNumeric(ws.Cells(1, "A").Value) And Not IsNumeric(ws.Cells(1, "B").Value) Then
startRow = 2
Else
startRow = 1
End If

lastRowA = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
lastRowB = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
lastRow = Application.WorksheetFunction.Max(lastRowA, lastRowB)
If lastRow < startRow Then
MsgBox "No numeric data found in columns A/B.", vbExclamation
Exit Sub
End If

n = lastRow - startRow + 1
Dim cmdArr() As Double, actArr() As Double
ReDim cmdArr(1 To n)
ReDim actArr(1 To n)

For i = 1 To n
r = startRow + i - 1
If IsNumeric(ws.Cells(r, "A").Value) Then cmdArr(i) = CDbl(ws.Cells(r, "A").Value) Else cmdArr(i) = 0
If IsNumeric(ws.Cells(r, "B").Value) Then actArr(i) = CDbl(ws.Cells(r, "B").Value) Else actArr(i) = 0
Next i

' compute min/max of Actual column
Dim minAct As Double, maxAct As Double
minAct = actArr(1): maxAct = actArr(1)
For i = 2 To n
If actArr(i) < minAct Then minAct = actArr(i)
If actArr(i) > maxAct Then maxAct = actArr(i)
Next i

' Ask user for desired range and step (you can enter same start=end for single value)
Dim sIn As Variant, eIn As Variant, stIn As Variant
sIn = Application.InputBox("Enter Desired-Actual START (e.g. -2)", "Start", -2, Type:=1)
If sIn = False Then Exit Sub
eIn = Application.InputBox("Enter Desired-Actual END (e.g. -4.18)", "End", minAct, Type:=1)
If eIn = False Then Exit Sub
stIn = Application.InputBox("Enter STEP (use negative step to count downward, e.g. -0.04)", "Step", -0.04, Type:=1)
If stIn = False Then Exit Sub

Dim desiredStart As Double, desiredEnd As Double, step As Double
desiredStart = CDbl(sIn)
desiredEnd = CDbl(eIn)
step = CDbl(stIn)
If step = 0 Then MsgBox "Step cannot be zero. Aborting.", vbCritical: Exit Sub

' prepare output headers
ws.Columns("C:D").ClearContents
ws.Cells(1, "C").Value = "DesiredActual"
ws.Cells(1, "D").Value = "InterpolatedCommanded"

Dim desired As Double, rowOut As Long
rowOut = 2
desired = desiredStart

Do While (step > 0 And desired <= desiredEnd + 1E-12) Or (step < 0 And desired >= desiredEnd - 1E-12)
' find bracketing segment
Dim idx As Long: idx = -1
For i = 1 To n - 1
If (actArr(i) <= desired And actArr(i + 1) >= desired) Or (actArr(i) >= desired And actArr(i + 1) <= desired) Then
idx = i
Exit For
End If
Next i

If idx = -1 Then
' outside bounds -> choose end segment for extrapolation
If desired < minAct Then
idx = n - 1 ' use last two points
ElseIf desired > maxAct Then
idx = 1 ' use first two points
Else
idx = 1
End If
ws.Cells(rowOut, "C").Interior.Color = vbYellow ' mark extrapolated rows
End If

Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
x1 = actArr(idx): x2 = actArr(idx + 1)
y1 = cmdArr(idx): y2 = cmdArr(idx + 1)

Dim interp As Double
If Abs(x2 - x1) < 1E-12 Then
interp = y1 ' degenerate case
Else
interp = y1 + (desired - x1) * (y2 - y1) / (x2 - x1)
End If

ws.Cells(rowOut, "C").Value = desired
ws.Cells(rowOut, "D").Value = interp
ws.Cells(rowOut, "C").NumberFormat = "0.000000000"
ws.Cells(rowOut, "D").NumberFormat = "0.000000000"

rowOut = rowOut + 1
desired = desired + step
Loop

MsgBox "Done. Inverse table written to columns C (Actual) and D (Commanded)." , vbInformation
End Sub
```

How to use — quick:

1. Put your original data in **A (Commanded)** and **B (Actual)** (header in row1 is OK).
2. Run `BuildInverseTable`.
3. When asked enter the **start actual**, **end actual**, and **step** (use a negative step if you want to sweep from 0 down to -4.18).

* Example to get a single interpolated command for Actual = -2: enter Start `-2`, End `-2`, Step `0.1` (any non-zero step works for a single value).
* Example to build from 0 to -4.18 with 0.04 increments: Start `0`, End `-4.18`, Step `-0.04`.

Notes:

* Column C = Desired Actual (the values you asked for).
* Column D = Interpolated Commanded (this is what you should send as G-code to reach that actual).
* Rows that require *extrapolation* (outside measured Actual range) are highlighted yellow.

Post Reply