Writing HAL components with AXIS's 'hal' module: Feed Override Wheel

This short Python program uses the 'hal' module, part of the development version of AXIS, to control feed override with an external jog wheel.

Place hal_feedoverride_wheel.py in your emc2 bin directory with the name hal_feedoverride_wheel (no extension). Then, load it with halcmd 'loadusr -W hal_feedoverride_wheel', and link up the 'enable' and 'count' signals.

The 'hal' module is only available when using the development versions of AXIS and EMC2.

Creating the component takes only a few lines of code:

    h = hal.component("hal_feedoverride_wheel")
    h.newpin("count", hal.HAL_S32, hal.HAL_RD)
    h.newpin("enable", hal.HAL_BIT, hal.HAL_RD)
    h.ready() 

It then drops into a loop that runs until emc2 exits:

    while 1:
        time.sleep(sleep_interval)

        enable = h.enable
        count = h.count 
followed by code to act on 'count' and 'enable'. By creating local variables from the pin values, you "latch" them. Otherwise, referring to 'h.count' several times in the loop body may give you different values because the realtime thread saw the wheel move in the meantime.

So far there are several Python HAL components I'm playing with: Included in the development tree, there is 'hal_manualtoolchange' which pops up a dialog when it's time to change tools. And there's also mousejog.py, which captures the mouse's X, Y and mouse wheel movement, intended to be hooked to the 'axis.N.jog-counts' pins.

Files currently attached to this page:

hal_feedoverride_wheel.py1.4kB
mousejog.py1.3kB


(originally posted on the AXIS blog)

Entry first conceived on 4 August 2006, 15:28 UTC, last modified on 15 January 2012, 3:46 UTC
Website Copyright © 2004-2024 Jeff Epler