using HAL to correct axis errors

More
15 Feb 2018 23:21 #105999 by pgf
This is a topic of some shame -- the axes on my home-built X-Y mill aren't square to one another, and they've been that way for a very long time. Sigh.

When I built the mill (mid-90s?) it didn't occur to me that I might not get the axis alignment exactly correct on the first try, and I provided no means for adjustment. So yes, I've been living with this for forever. You might guess, correctly, that I don't use the mill much.

It occurred to me that there was probably a way to fix this error from within linuxcnc, and sure enough I found this post:
forum.linuxcnc.org/10-advanced-configura...on-with-2-7-11#99833
which proposes a simple HAL component to work around an uneven table.

So I'd like to try it, but I'm stuck.

Based on that post of Andy Pugh's, my component looks like:
component nonsquare_table;
license "GPL"; // GPL v2 or later
pin in float x-in;
pin in float y-in;
pin out float y-out;
function _;
;;

FUNCTION(_){
    y_out = y_in + 0.0095 * x_in;   // approx 3/32" in 10"
}

It builds and installs fine with halcompile. But then what? There's obviously some other configuration required to get this into the pipeline.

As an initial step, I've added a line with
loadrt nonsquare_table.ko 
to the file "custom.hal" in my mill's config directory. When I fire up linuxcnc, it quickly dies. While I didn't expect the component to actuall work, I didn't expect it to kill the whole system so quickly! :-) Clearly I'm missing something basic that I didn't glean from a quick read through the HAL docs. The logs aren't terribly useful, except perhaps that they're so short -- perhaps that's meaningful..

Debug:

22841
PID TTY STAT TIME COMMAND
Stopping realtime threads
Unloading hal components


and print:

RUN_IN_PLACE=no
LINUXCNC_DIR=
LINUXCNC_BIN_DIR=/usr/bin
LINUXCNC_TCL_DIR=/usr/lib/tcltk/linuxcnc
LINUXCNC_SCRIPT_DIR=
LINUXCNC_RTLIB_DIR=/usr/realtime-3.4-9-rtai-686-pae/modules/linuxcnc
LINUXCNC_CONFIG_DIR=
LINUXCNC_LANG_DIR=/usr/share/linuxcnc/tcl/msgs
INIVAR=inivar
HALCMD=halcmd
LINUXCNC_EMCSH=/usr/bin/wish8.5
INIFILE=/home/pgf/linuxcnc/configs/my-mill/my-mill.ini
PARAMETER_FILE=linuxcnc.var
TASK=milltask
HALUI=
DISPLAY=axis
Starting LinuxCNC server program: linuxcncsvr
Loading Real Time OS, RTAPI, and HAL_LIB modules
Killing task linuxcncsvr, PID=22841
Removing HAL_LIB, RTAPI, and Real Time OS modules
Removing NML shared memory segments


Any suggestions appreciated!

paul
More
16 Feb 2018 00:34 #106000 by PCW
On RTAI systems, you also need to look at the kernel log (with dmesg) to see all the errors
More
16 Feb 2018 14:01 #106017 by pgf
oops -- sorry about that. i did look at dmesg, and saw nothing, but then forgot to include it in my post:

[833862.224577] I-pipe: head domain RTAI registered.
[833862.224588] RTAI[hal]: compiled with gcc version 4.7.2 (Debian 4.7.2-5) .
[833862.224597] RTAI[hal]: mounted (IPIPE-NOTHREADS, IMMEDIATE (INTERNAL IRQs DISPATCHED), ISOL_CPUS_MASK: 0).
[833862.224602] SYSINFO: CPUs 1, LINUX APIC IRQ 2312, TIM_FREQ 12498508, CLK_FREQ 1799736000, CPU_FREQ 1799736000
[833862.224606] RTAI_APIC_TIMER_IPI: RTAI DEFINED 2314, VECTOR 2314; LINUX_APIC_TIMER_IPI: RTAI DEFINED 2312, VECTOR 2312
[833862.224611] TIMER NAME: lapic; VARIOUSLY FOUND APIC FREQs: 12498508, 12498508, 12406500
[833862.248194] RTAI[malloc]: global heap size = 2097152 bytes, <BSD>.
[833862.248251] , <uses LINUX SYSCALLs>, kstacks pool size = 524288 bytes.
[833862.248257] RTAI[sched]: hard timer type/freq = APIC/12498508(Hz); default timing: oneshot; linear timed lists.
[833862.248262] RTAI[sched]: Linux timer freq = 250 (Hz), TimeBase freq = 1799736000 hz.
[833862.248266] RTAI[sched]: timer setup = 999 ns, resched latency = 2944 ns.
[833862.265376] RTAI[math]: loaded.
[833862.448021] config string '0x378 out'
[833865.181952] RTAI[math]: unloaded.
[833865.185313] SCHED releases registered named ALIEN PEDV$D
[833865.193131] RTAI[malloc]: unloaded.
[833865.292023] RTAI[sched]: unloaded (forced hard/soft/hard transitions: traps 0, syscalls 0).
[833865.294674] I-pipe: head domain RTAI unregistered.
[833865.294688] RTAI[hal]: unmounted.

More
16 Feb 2018 14:39 #106018 by pgf
And, for completeness, the component does load under halrun, and looks like this:
==stump,pgf(1)>> halrun
.
halcmd: loadrt nonsquare_table 
halcmd: show all
Loaded HAL Components:
ID      Type  Name                                            PID   State
     4  RT    nonsquare_table                                       ready
     3  User  halcmd28457                                     28457 ready

Component Pins:
Owner   Type  Dir         Value  Name
     4  s32   OUT             0  nonsquare-table.0.time
     4  float IN              0  nonsquare-table.0.x-in
     4  float IN              0  nonsquare-table.0.y-in
     4  float OUT             0  nonsquare-table.0.y-out

Pin Aliases:
 Alias                                            Original Name

Signals:
Type          Value  Name     (linked to)

Parameters:
Owner   Type  Dir         Value  Name
     4  s32   RW              0  nonsquare-table.0.tmax
     4  bit   RO          FALSE  nonsquare-table.0.tmax-increased

Parameter Aliases:
 Alias                                            Original Name

Exported Functions:
Owner   CodeAddr  Arg       FP   Users  Name
 00004  f8373000  f89070c8  YES      0   nonsquare-table.0

Realtime Threads:
     Period  FP     Name               (     Time, Max-Time )

halcmd: quit
More
16 Feb 2018 15:08 #106020 by PCW
Wierd that there are no complaints

You might try a bit further with halrun, that is setting up a thread and
addf'ing your components function to that thread (this would alo let you test the math)
The following user(s) said Thank You: pgf
More
16 Feb 2018 15:48 #106021 by pgf
Good suggestion. I added a thread, addf'ed my function, and played with the x-in and y-in inputs. The y-in output changes appropriately. So nothing suspicious found there.

paul
More
16 Feb 2018 16:08 #106023 by pgf
I've set DEBUG to the value of EMC_DEBUG_ALL (0x7FFFFFFF) in my .ini file. No more information to be had.

During a failed startup, I get:
LINUXCNC - 2.7.12
Machine configuration directory is '/home/pgf/linuxcnc/configs/my-mill'
Machine configuration file is 'my-mill.ini'
Starting LinuxCNC...
iocontrol: machine: 'my-mill'  version 'unknown'
Found file(REL): ./my-mill.hal
Found file(REL): ./custom.hal
Shutting down and cleaning up LinuxCNC...
LinuxCNC terminated with an error.  You can find more information in the log:
    /home/pgf/linuxcnc_debug.txt
and
    /home/pgf/linuxcnc_print.txt
as well as in the output of the shell command 'dmesg' and in the terminal

This reminded me that perhaps the clue is elsewhere in the rest of my mill's config, so here are the .ini and .hal files:
==stump,pgf(1)>> cat my-mill.ini
# Generated by stepconf 1.1 at Sat Jan 20 17:31:10 2018
# If you make changes to this file, they will be
# overwritten when you run stepconf again

[EMC]
MACHINE = my-mill
DEBUG = 0x7FFFFFFF

[DISPLAY]
DISPLAY = axis
EDITOR = gedit
POSITION_OFFSET = RELATIVE
POSITION_FEEDBACK = ACTUAL
ARCDIVISION = 64
GRIDS = 10mm 20mm 50mm 100mm 1in 2in 5in 10in
MAX_FEED_OVERRIDE = 1.2
MIN_SPINDLE_OVERRIDE = 0.5
MAX_SPINDLE_OVERRIDE = 1.2
DEFAULT_LINEAR_VELOCITY = 0.10
MIN_LINEAR_VELOCITY = 0
MAX_LINEAR_VELOCITY = 0.90
INTRO_GRAPHIC = linuxcnc.gif
INTRO_TIME = 5
PROGRAM_PREFIX = /home/pgf/linuxcnc/nc_files
INCREMENTS = .1in .05in .01in .005in .001in .0005in .0001in

[FILTER]
PROGRAM_EXTENSION = .png,.gif,.jpg Greyscale Depth Image
PROGRAM_EXTENSION = .py Python Script
png = image-to-gcode
gif = image-to-gcode
jpg = image-to-gcode
py = python

[TASK]
TASK = milltask
CYCLE_TIME = 0.010

[RS274NGC]
PARAMETER_FILE = linuxcnc.var

[EMCMOT]
EMCMOT = motmod
COMM_TIMEOUT = 1.0
COMM_WAIT = 0.010
BASE_PERIOD = 100000
SERVO_PERIOD = 1000000

[HAL]
HALFILE = my-mill.hal
HALFILE = custom.hal
POSTGUI_HALFILE = custom_postgui.hal

[TRAJ]
AXES = 3
COORDINATES = X Y Z
LINEAR_UNITS = inch
ANGULAR_UNITS = degree
CYCLE_TIME = 0.010
DEFAULT_VELOCITY = 0.10
MAX_VELOCITY = 0.90

[EMCIO]
EMCIO = io
CYCLE_TIME = 0.100
TOOL_TABLE = tool.tbl

[AXIS_0]
TYPE = LINEAR
HOME = 0.0
MAX_VELOCITY = 0.9
MAX_ACCELERATION = 2.0
STEPGEN_MAXACCEL = 2.5
SCALE = 2400.0
FERROR = 0.05
MIN_FERROR = 0.01
MIN_LIMIT = -13.0
MAX_LIMIT = 13.0
HOME_OFFSET = 0.0

[AXIS_1]
TYPE = LINEAR
HOME = 0.0
MAX_VELOCITY = 0.9
MAX_ACCELERATION = 2.0
STEPGEN_MAXACCEL = 2.5
SCALE = 2400.0
FERROR = 0.05
MIN_FERROR = 0.01
MIN_LIMIT = -13.0
MAX_LIMIT = 13.0
HOME_OFFSET = 0.0

[AXIS_2]
TYPE = LINEAR
HOME = 0.0
MAX_VELOCITY = 0.12
MAX_ACCELERATION = 0.5
STEPGEN_MAXACCEL = 0.625
SCALE = 28800.0
FERROR = 0.05
MIN_FERROR = 0.01
MIN_LIMIT = -2.0
MAX_LIMIT = 4.0
HOME_OFFSET = 0.0

and
==stump,pgf(1)>> cat my-mill.hal
# Generated by stepconf 1.1 at Sat Jan 20 17:31:10 2018
# If you make changes to this file, they will be
# overwritten when you run stepconf again
loadrt trivkins
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt hal_parport cfg="0x378 out"
loadrt stepgen step_type=0,0,0

addf parport.0.read base-thread
addf stepgen.make-pulses base-thread
addf parport.0.write base-thread

addf stepgen.capture-position servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf stepgen.update-freq servo-thread
net spindle-cmd-rpm     <= motion.spindle-speed-out
net spindle-cmd-rpm-abs <= motion.spindle-speed-out-abs
net spindle-cmd-rps     <= motion.spindle-speed-out-rps
net spindle-cmd-rps-abs <= motion.spindle-speed-out-rps-abs
net spindle-at-speed    => motion.spindle-at-speed

net probe-in => motion.probe-input

net estop-out       => parport.0.pin-01-out
net xstep           => parport.0.pin-02-out
setp parport.0.pin-03-out-invert 1
net xdir            => parport.0.pin-03-out
net ystep           => parport.0.pin-04-out
net ydir            => parport.0.pin-05-out
net zstep           => parport.0.pin-06-out
net zdir            => parport.0.pin-07-out
setp parport.0.pin-17-out-invert 1
net xenable         => parport.0.pin-17-out
net both-x          <= parport.0.pin-10-in-not
net both-y          <= parport.0.pin-11-in
net both-z          <= parport.0.pin-12-in-not
net probe-in        <= parport.0.pin-13-in-not

setp stepgen.0.position-scale [AXIS_0]SCALE
setp stepgen.0.steplen 1
setp stepgen.0.stepspace 1
setp stepgen.0.dirhold 100000
setp stepgen.0.dirsetup 100000
setp stepgen.0.maxaccel [AXIS_0]STEPGEN_MAXACCEL
net xpos-cmd axis.0.motor-pos-cmd => stepgen.0.position-cmd
net xpos-fb stepgen.0.position-fb => axis.0.motor-pos-fb
net xstep <= stepgen.0.step
net xdir <= stepgen.0.dir
net xenable axis.0.amp-enable-out => stepgen.0.enable
net both-x => axis.0.neg-lim-sw-in
net both-x => axis.0.pos-lim-sw-in

setp stepgen.1.position-scale [AXIS_1]SCALE
setp stepgen.1.steplen 1
setp stepgen.1.stepspace 1
setp stepgen.1.dirhold 100000
setp stepgen.1.dirsetup 100000
setp stepgen.1.maxaccel [AXIS_1]STEPGEN_MAXACCEL
net ypos-cmd axis.1.motor-pos-cmd => stepgen.1.position-cmd
net ypos-fb stepgen.1.position-fb => axis.1.motor-pos-fb
net ystep <= stepgen.1.step
net ydir <= stepgen.1.dir
net yenable axis.1.amp-enable-out => stepgen.1.enable
net both-y => axis.1.neg-lim-sw-in
net both-y => axis.1.pos-lim-sw-in

setp stepgen.2.position-scale [AXIS_2]SCALE
setp stepgen.2.steplen 1
setp stepgen.2.stepspace 1
setp stepgen.2.dirhold 100000
setp stepgen.2.dirsetup 100000
setp stepgen.2.maxaccel [AXIS_2]STEPGEN_MAXACCEL
net zpos-cmd axis.2.motor-pos-cmd => stepgen.2.position-cmd
net zpos-fb stepgen.2.position-fb => axis.2.motor-pos-fb
net zstep <= stepgen.2.step
net zdir <= stepgen.2.dir
net zenable axis.2.amp-enable-out => stepgen.2.enable
net both-z => axis.2.neg-lim-sw-in
net both-z => axis.2.pos-lim-sw-in

net estop-out <= iocontrol.0.user-enable-out
net estop-out => iocontrol.0.emc-enable-in

loadusr -W hal_manualtoolchange
net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change
net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed
net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
More
16 Feb 2018 18:28 #106034 by rodw
Try removing (or commenting out) the very first line in your HAL file.

It looks like its been accidentally pasted in.It appears to be invalid syntax to me.
More
16 Feb 2018 18:36 #106035 by pgf
Are you referring to the "==stump,pgf(1)>> cat my-mill.hal" line? My apologies, if so -- that's not in the file. That's my shell prompt, and the command I used to produce the file output. I copied/pasted one too many lines of text.

If you're referring to some other line, can you be more specific?

Thanks!
paul
More
16 Feb 2018 19:37 #106039 by rodw
Thats what I was looking at. Sorry, I could see cat there but did not recognise the command prompt

The only other thing i noticed is in your first post you said you used
loadrt nonsquare_table.ko
and in halrun you used
loadrt nonsquare_table
probably not significant but worth checking.
Did you also add it to your hal file with addf?I have had some odd errors where I've forgotten to do that.
did you compile and install as follows?
halcompile --install nonsquare_table.comp
Time to create page: 0.095 seconds
Powered by Kunena Forum