- Posts: 4739
- Thank you received: 2
Custom Hal Component
- Todd Zuercher
- Topic Author
- Offline
- Platinum Member
-
Less
More
2 years 5 months ago #301348
by Todd Zuercher
Custom Hal Component was created 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.
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 to join the conversation.
2 years 5 months ago #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.
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 to join the conversation.
- Todd Zuercher
- Topic Author
- Offline
- Platinum Member
-
Less
More
- Posts: 4739
- Thank you received: 2
2 years 5 months ago #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 to join the conversation.
2 years 5 months ago #301647
by Aciera
Replied by Aciera on topic Custom Hal Component
Why not use the tool_table information from the python status channel?
Attachment not found
Please Log in to join the conversation.
2 years 5 months ago #301649
by Aciera
Replied by Aciera on topic Custom Hal Component
Just tested it:
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]:
Code:
#!/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:
Attachment not found
[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]:
Please Log in to join the conversation.
- Todd Zuercher
- Topic Author
- Offline
- Platinum Member
-
Less
More
- Posts: 4739
- Thank you received: 2
2 years 5 months ago #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 to join the conversation.
2 years 5 months ago #301674
by Aciera
Replied by Aciera on topic Custom Hal Component
This version is a bit more concise. (I hope it retains the indentation)
#!/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 = float(s.tool_table[t].zoffset)
except KeyboardInterrupt:
raise SystemExit
Warning: Spoiler!
#!/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 = float(s.tool_table[t].zoffset)
except KeyboardInterrupt:
raise SystemExit
Please Log in to join the conversation.
- Todd Zuercher
- Topic Author
- Offline
- Platinum Member
-
Less
More
- Posts: 4739
- Thank you received: 2
2 years 5 months ago #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.)
The first version works fine, once I put in some appropriate indenting. (Stupid forum editor.)
Code:
#!/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 to join the conversation.
- Todd Zuercher
- Topic Author
- Offline
- Platinum Member
-
Less
More
- Posts: 4739
- Thank you received: 2
2 years 5 months ago #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:
this to this:
The problem was line 21, I had to change from:
Code:
h = float(s.tool_table[t].zoffset)
Code:
h['z_offset_tool_' + str(t)] = float(s.tool_table[t].zoffset)
Code:
#!/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
Please Log in to join the conversation.
2 years 5 months ago #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?
How did you get the indenting to stay in the code window?
Please Log in to join the conversation.
Time to create page: 0.436 seconds
