hal module to help with touching off

More
04 Aug 2022 13:17 #249036 by mattroberts
I've created a simple hal module to help with touching off, I've attached the code and a sample pyvcp fragment to demonstrate how to use it.  Here is a brief description of what it does so you can see if you're interested:
# hal_touchoff_helper defines the following hal pins:
#
# input pins:
#     hal_touchoff_helper.[AXIS].zero
#         on a rising edge will use 'G10 L20' to zero the axis
#     hal_touchoff_helper.[AXIS].half
#         on a rising edge will use 'G10 L20' to set the axis to half the
#         current (relative) value
#     hal_touchoff_helper.[AXIS].set
#         on a rising edge will use 'G10 L20' to set the axis to a user entered
#         value (will prompt to enter the value)
#     hal_touchoff_helper.[CSYS].select
#         on a rising edge will issue to corresponding gcode to select the
#         coordinate system
#     hal_touchoff_helper.prompt
#         when TRUE; prompt the user for confirmation when zeroing or halving an
#         axis
#
# output pins:
#     hal_touchoff_helper.[CSYS].active
#         TRUE when the coordinate system is currently selected
#         (FALSE otherwise)
#     hal_touchoff_helper.G5x.index
#         is the index of the current coordinate system
#         (1 for G54, 2 for G55, ..., 9 for G59.3)
#     hal_touchoff_helper.G5x.name
#         is the 'name' of the current coordinate system
#         (54 for G54, 55 for G55, ..., 59.3 for G59.3)
#
# [AXIS] is one of x, y, z, a, b, c, u, v, w
# [CSYS] is one of G54, G55, G56, G57, G58, G59, G59_1, G59_2, G59_3
#
# a rising edge is defined as a transition of the input pin from FALSE to TRUE.
# you'll probably want to the debounce hal module if you wish to attach these
# pins to physical buttons.

In principle the "half" function could be easily implemented using the halui MDI command stuff, but I wanted to add a confirmation prompt to save me from myself.  (if you're interested in the command to half the X axis is "G10 L20 P0 X[#5420/2]"). Anyway, given I was creating the "half" function it made sense to have "zero" and "set" as well.

The "set" function is almost the same as the touch off button from the AXIS frontend.  The difference is that my "set" always talks in the same units as the gcode (i.e. inches when G20 is set and mm when G21 is set) and always refers to the current coordinate system.  This is to be consistent with the "zero" and "half" functions.

If you are wondering why a half function is useful at all, consider finding the centre of a hole:
  • go to roughly the centre of the hole in the Y axis
  • use an edge finder to find, the left side of the hole and use x.zero
  • use an edge finder to find, the right side of the hole and use x.half
  • go to X=0 (I use the jog wheels, but you could easily use "G1 X0")
  • use an edge finder to find, the back side of the hole and use y.zero
  • use an edge finder to find, the front side of the hole and use y.half
  • go to Y=0 (I use the jog wheels, but you could easily use "G1 Y0")
  • now X=0,Y=0 is in the centre of the hole

clearly you can find the centre of a piece of stock this way as well, just be careful to not to move the edge finder into the stock!

Anyway... here's the stuff to add to your main hal file:
loadusr -W hal_touchoff_helper
setp hal_touchoff_helper.prompt 1 # optional, this line will enable the prompt feature

As I mentioned before, I've included a sample pyvcp.xml file (and postgui hal file) in the attached zip file as a starting point.
Attachments:
The following user(s) said Thank You: tommylight

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

Time to create page: 0.070 seconds
Powered by Kunena Forum