Category: Show Your Stuff
I built my own CNC router with the long axis (I called it X for various reasons) at about 2.7m. It's all on 8020 profile and no matter how I tweaked it, I could never get the gantry to move in a straight line. It would shift reliably +/- 0.1mm (or about 0.005in), so I had an accuracy problem that was too large for my liking.
I got this same plot over and over at multiple Y locations, so
lincurve
would be a good solution here together with
offset
.
Essentially, lincurve lets you define an equation of sorts, then lets you map the x value to the y value. In this case, I would map the input of my X of where the spindle is to the output offset I want to move my Y axis. The reverse of the error you see in the graph above. Then I use that offset and implement it in the controller using HAL offset.
The "equation" that you give lincurve however is not your usual y=f(x), but multiple points (up to 16) on the x,y graph. The lincurve link above explains it better than I would.
Here is a snippet from my HAL:
net y-index-enable => pid.y.index-enable
net y-enable => pid.y.enable
net y-pos-cmd => pid.y.command
net y-pos-fb => pid.y.feedback
net y-output <= pid.y.output
# Step Gen signals/setup
setp hm2_7i76e.0.stepgen.01.dirsetup [JOINT_2]DIRSETUP
setp hm2_7i76e.0.stepgen.01.dirhold [JOINT_2]DIRHOLD
setp hm2_7i76e.0.stepgen.01.steplen [JOINT_2]STEPLEN
setp hm2_7i76e.0.stepgen.01.stepspace [JOINT_2]STEPSPACE
setp hm2_7i76e.0.stepgen.01.position-scale [JOINT_2]STEP_SCALE
setp hm2_7i76e.0.stepgen.01.step_type 0
setp hm2_7i76e.0.stepgen.01.control-type 1
setp hm2_7i76e.0.stepgen.01.maxaccel [JOINT_2]STEPGEN_MAXACCEL
setp hm2_7i76e.0.stepgen.01.maxvel [JOINT_2]STEPGEN_MAXVEL
# ---closedloop stepper signals---
# Alter Y position dependent on X position in order to straighten X axis
setp x_straight.x-val-00 0.0
setp x_straight.y-val-00 0.04341242632711628
setp x_straight.x-val-01 607.2917010709281
setp x_straight.y-val-01 -0.0941465387965644
setp x_straight.x-val-02 1150.4857125892602
setp x_straight.y-val-02 0.06777797847289474
setp x_straight.x-val-03 1405.8006869324868
setp x_straight.y-val-03 0.10253790211206171
setp x_straight.x-val-04 1662.603323359967
setp x_straight.y-val-04 0.07153820324398952
setp x_straight.x-val-05 1963.5065299510084
setp x_straight.y-val-05 -0.04292886830166562
setp x_straight.x-val-06 2341.4825252892224
setp x_straight.y-val-06 -0.053798901184427095
setp x_straight.x-val-07 2435.0
setp x_straight.y-val-07 -0.10441928397325695
net x-pos-fb => x_straight.in
net y-offset <= x_straight.out
net y-offset => x_straight_offset.offset
net y-pos-cmd-raw <= joint.2.motor-pos-cmd
net y-pos-cmd-raw => x_straight_offset.in
net y-pos-fb-raw <= hm2_7i76e.0.stepgen.01.position-fb
net y-pos-fb-raw => x_straight_offset.fb-in
net y-pos-cmd <= x_straight_offset.out
net y-vel-cmd <= joint.2.vel-cmd
net y-output => hm2_7i76e.0.stepgen.01.velocity-cmd
net y-pos-fb <= x_straight_offset.fb-out
net y-pos-fb => joint.2.motor-pos-fb
net y-enable <= joint.2.amp-enable-out
net y-enable => hm2_7i76e.0.stepgen.01.enable
And voila: