Custom Hal Component

More
24 May 2024 18:59 #301348 by Todd Zuercher
How would one go about building a hal component that would read the values of several Z tool offsets from the tool table, then place those values on individual hal pins?  I need to get the values saved for the Z offset of tools 1-8 and have them exposed as hal pins. 

This is for an 8 spindle gang router that has individual Z axis joints for each of the 8 spindles.  I want to be able to apply, save, and change the a tool offset for each spindle.  The tool offset will not be applied using G43.  They will be permanently connected in hal with each spindle joint along with the Z axis command.

At this point the only thing I can do is load each tool offset one at a time with G43Hn, and parameter #5403 then save that value to a hal pin using M68.  But I don't want to have to go through that for each spindle joint every time the machine is started or an offset is changed. 

Please Log in or Create an account to join the conversation.

More
24 May 2024 19:09 #301350 by cmorley
Replied by cmorley on topic Custom Hal Component
Read the tool file directly with python and make HAL pins for them.
The only problem is that the info can become stale as the motion controller doesn't save info immediately.
This is how the GUIs do it.

Please Log in or Create an account to join the conversation.

More
28 May 2024 07:27 #301646 by Todd Zuercher
Replied by Todd Zuercher on topic Custom Hal Component
Thanks, for the suggestion but I'm afraid that coding it might be beyond my ability.

Please Log in or Create an account to join the conversation.

More
28 May 2024 08:57 #301647 by Aciera
Replied by Aciera on topic Custom Hal Component
Why not use the tool_table information from the python status channel?
 
Attachments:

Please Log in or Create an account to join the conversation.

More
28 May 2024 09:34 - 28 May 2024 12:04 #301649 by Aciera
Replied by Aciera on topic Custom Hal Component
Just tested it:

#!/usr/bin/env python3

import hal
import linuxcnc

h = hal.component("tool-info-comp")

h.newpin("z_offset_tool_1", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_2", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_3", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_4", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_5", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_6", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_7", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_8", hal.HAL_FLOAT, hal.HAL_OUT)

h.ready()

# create a connection to the status channel
s = linuxcnc.stat()

try:
while 1:
s.poll() # get current values
if s.tool_table[1]:
h['z_offset_tool_1'] = float(s.tool_table[1].zoffset)
h['z_offset_tool_2'] = float(s.tool_table[2].zoffset)
h['z_offset_tool_3'] = float(s.tool_table[3].zoffset)
h['z_offset_tool_4'] = float(s.tool_table[4].zoffset)
h['z_offset_tool_5'] = float(s.tool_table[5].zoffset)
h['z_offset_tool_6'] = float(s.tool_table[6].zoffset)
h['z_offset_tool_7'] = float(s.tool_table[7].zoffset)
h['z_offset_tool_8'] = float(s.tool_table[8].zoffset)


except KeyboardInterrupt:
raise SystemExit

gives me:
 

[edit]
Had to add this line in the code above otherwise the component would crash if the tool table was changed:
if s.tool_table[1]:
Attachments:
Last edit: 28 May 2024 12:04 by Aciera.
The following user(s) said Thank You: Todd Zuercher

Please Log in or Create an account to join the conversation.

More
28 May 2024 13:04 #301673 by Todd Zuercher
Replied by Todd Zuercher on topic Custom Hal Component
Thank you very much. I'm eager to test it out.

Please Log in or Create an account to join the conversation.

More
28 May 2024 13:20 #301674 by Aciera
Replied by Aciera on topic Custom Hal Component
This version is a bit more concise. (I hope it retains the indentation)
Warning: Spoiler!
The following user(s) said Thank You: Todd Zuercher, tommylight

Please Log in or Create an account to join the conversation.

More
28 May 2024 14:45 #301679 by Todd Zuercher
Replied by Todd Zuercher on topic Custom Hal Component
I am having trouble making your 2nd version work, for some reason no hal pins are created.

The first version works fine, once I put in some appropriate indenting. (Stupid forum editor.)
#!/usr/bin/env python3

import hal
import linuxcnc

h = hal.component("tool-info-comp")

h.newpin("z_offset_tool_1", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_2", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_3", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_4", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_5", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_6", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_7", hal.HAL_FLOAT, hal.HAL_OUT)
h.newpin("z_offset_tool_8", hal.HAL_FLOAT, hal.HAL_OUT)

h.ready()

# create a connection to the status channel
s = linuxcnc.stat()

try:
    while 1:
          s.poll() # get current values
          if s.tool_table[1]:
               h['z_offset_tool_1'] = float(s.tool_table[1].zoffset)
               h['z_offset_tool_2'] = float(s.tool_table[2].zoffset)
               h['z_offset_tool_3'] = float(s.tool_table[3].zoffset)
               h['z_offset_tool_4'] = float(s.tool_table[4].zoffset)
               h['z_offset_tool_5'] = float(s.tool_table[5].zoffset)
               h['z_offset_tool_6'] = float(s.tool_table[6].zoffset)
               h['z_offset_tool_7'] = float(s.tool_table[7].zoffset)
               h['z_offset_tool_8'] = float(s.tool_table[8].zoffset)


except KeyboardInterrupt:
     raise SystemExit

Please Log in or Create an account to join the conversation.

More
28 May 2024 15:16 - 28 May 2024 16:10 #301680 by Todd Zuercher
Replied by Todd Zuercher on topic Custom Hal Component
This seems to work (see code below).
The problem was line 21, I had to change from:
                h = float(s.tool_table[t].zoffset)
this to this:
                h['z_offset_tool_' + str(t)] = float(s.tool_table[t].zoffset)
#!/usr/bin/env python3

import hal
import linuxcnc

h = hal.component("tool-info-comp")
# number of tools to expose
n = 8
for t in range(1, n+1):
    h.newpin("z_offset_tool_" + str(t), hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()

# create a connection to the status channel
s = linuxcnc.stat()

try:
    while 1:
        s.poll() # get current values
        if s.tool_table[1]:
            for t in range(1, n+1):
                h['z_offset_tool_' + str(t)] = float(s.tool_table[t].zoffset)

except KeyboardInterrupt:
    raise SystemExit

 
Last edit: 28 May 2024 16:10 by Todd Zuercher. Reason: Stupid Forum Editor screwing up the code.
The following user(s) said Thank You: pietvr

Please Log in or Create an account to join the conversation.

More
28 May 2024 15:44 - 28 May 2024 15:45 #301683 by Aciera
Replied by Aciera on topic Custom Hal Component
Oh, my apologies, the editor consumes the contents of the rectangular brackets. Although not the [t]

How did you get the indenting to stay in the code window?
Last edit: 28 May 2024 15:45 by Aciera.

Please Log in or Create an account to join the conversation.

Time to create page: 0.158 seconds
Powered by Kunena Forum