Z Touch Off

More
29 Aug 2022 02:50 #250668 by dzawacki
Z Touch Off was created by dzawacki
I think I'm at my wits end here. I am trying to add a touch probe for setting the z-height automatically, but I cannot seem to figure it out. I honestly didn't think this would be such the ordeal, but here we are.

So far, I've connected the touch plate to one of the inputs on my 7i96 and verified that it is triggering correctly when the circuit is connect by monitoring through the HAL meter. That was the easy part.

What I'd like to do now is have a button or a command on the UI in AXIS where I can run a simple routine to lower the z-axis to hit the plate, back off, and then approach it again before storing the coordinate. I found the following code (pulled from here ):
o<touch_plate_z> sub

#<PlateThickness> =      .2505   ( Thickness of your touch plate when proving in the Z orientation, this is used to re-calculate your new zero after touching off )
#<FastProbe> =            10     ( This is the probe speed used for your initial search, this should be a slow value to avoid damaging your tool, but doesn't not need to "crawl"  )
#<SlowProbe> =             5     ( This is the probe speed for the final search, this should be a very slow value to improve the accuracy of the probing )
#<ZProbeRange> =          -.50   ( This is the distance the probe will travel on its initial search before erroring out, should be a negative value )
#<ProbeLift> =             0.10  ( This is the distance the probe will lift off the touch plate prior to starting the second search )
#<ProbeRetract> =         1.00   ( This is the distance the probe will lift from the touch plate after successfulprobing to allow for removal of the plate )
#<tempParam> = #1

( Set current Z position to 0 so that we will always be moving down )
G10 L20 P0 Z0

( Probe quickly for initial contact )
G91
F[#<FastProbe>]
G38.2 Z[#<ZProbeRange>]

( Move off plate for slow search )
F[#<SlowProbe>]
G1 Z[#<Probelift>]

( Pause for 0.5 Sec )
G4 P0.5

( Slow probe search )
g38.2 Z[-2 * #<ProbeLift>]

( Move up to set new zero )
G1 Z[#<ProbeRetract>] F[#<FastProbe>]

( Set Z0 at point where probe triggers with offset of plate thickness)
G10 L20 P0 Z[#<ProbeRetract> + #<PlateThickness>]

o<touch_plate_z> endsub

M2
Thanks to the author for putting in copious amounts of comments so I can follow and confirm it will roughly do what I'm looking for. 
I also followed the instructions on that page and have triple checked that I have things set correctly, but I'm beginning to suspect I missed some key information elsewhere that is part of the printnc setup, which I don't have in place for my setup.

I read through all of the posts I can find on the forums here and I cannot seem to find one that matches my situation. One thing I suspect is that this cannot be done by just using AXIS and I would need another user interface to get this setup. 
I have been able to add a button, but I could not find any documentation on how to tie that button to an action. 
I have been able to add a new tab/panel that runs the subroutine, but from what I can tell, that subroutine replaces the existing gcode that is loaded and that isn't ideal for tool changes mid-program.

So, what I'm hoping to find an answer to:
  • Can this be done in AXIS?
  • Am I taking the correct approach, as in the one from the printnc instructions?
  • Do I need to learn Python to accomplish this
  • And I guess, how come there isn't a simple setup for this already? I know there are a lot of variations to how this could be implemented but just seems like at least one route could exist for those of use who cannot code for LinuxCNC. /shrug
Thanks in advance!

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

More
29 Aug 2022 03:40 #250669 by cmorley
Replied by cmorley on topic Z Touch Off
What version on linuxcnc are you using?

if master version:
sim/axis/gladevcp/gladevcp_panel_tester shows adding a couple of buttons to AXIS that can call other things.

from that folder copy test.ui and test_handler to your config
add this to your INI file:
[DISPLAY]
GLADEVCP= -u test_handler.py test.ui

if that works it's pretty easy to make it do something else.

in 2.8 the same thing is possible but a bit more work.

Chris

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

More
29 Aug 2022 03:42 #250670 by cmorley
Replied by cmorley on topic Z Touch Off
oh it might be in 2.8.x too

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

More
29 Aug 2022 16:38 #250696 by dzawacki
Replied by dzawacki on topic Z Touch Off
I'm using version 2.8.3.

I've added the GladeVCP panel, so I'll futz with that a bit and see if I can make some progress.

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

More
29 Aug 2022 17:22 #250703 by cmorley
Replied by cmorley on topic Z Touch Off
Ya 2.8.3 is just a little more work.
The gladevcp docs shoukd have an example how to call an oword in mdi. I assume that would work for you.

After work I'll post an example if you don't get it figured by then
 

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

More
30 Aug 2022 02:27 #250743 by cmorley
Replied by cmorley on topic Z Touch Off
I have tested this test_handler.py file in master but it should work in 2.8 too.

import linuxcnc

def get_handlers(halcomp,builder,useropts):
    return [HandlerClass(halcomp,builder,useropts)]

class HandlerClass:
    def __init__(self, halcomp,builder,useropts):
        self.halcomp = halcomp
        self.builder = builder
        self.cmd = linuxcnc.command()
        self.stat = linuxcnc.stat()

    # check if linuxcnc is not running code
    def running(self, s, do_poll=True):
        if do_poll: s.poll()
        return s.task_mode == linuxcnc.MODE_AUTO and s.interp_state != linuxcnc.INTERP_IDLE

    # ensure linuxcnc is in the requested mode
    def ensure_mode(self, s, c, *modes):
        s.poll()
        if not modes: return False
        if s.task_mode in modes: return True
        if self.running(s, do_poll=False): return False
        c.mode(modes[0])
        c.wait_complete()
        return True

    # run an MDI command on button press
    def on_button_press(self, widget, data=None):
        print ('MDI button Pressed')
        if self.ensure_mode(self.stat, self.cmd, linuxcnc.MODE_MDI):
            self.cmd.mdi('(MSG, MDI Worked!)')
 

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

More
31 Aug 2022 18:03 #250873 by dzawacki
Replied by dzawacki on topic Z Touch Off
Okay, I have the panel set up with a button on it. I based it off of the gvcp-panel.ui and updated the associated files to get LinuxCNC to load. I commented out the actions in the associated gvcp_options.hal file because I removed the interface items.

However, what I cannot seem to find is how to call the subroutine in the .ngc file. I tried this command and it failed:
net MDI-probez gladevcp.probe-z        => o<touch_plate_z>

The error message I received while loading LinuxCNC indicated that the o<touch_plate_z> routine was causing the error. 

Am I on the right path? What would be the proper way to call the subroutine from the hal file? I couldn't find this in any of the documentation.

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

More
31 Aug 2022 20:50 #250891 by cmorley
Replied by cmorley on topic Z Touch Off
 Could you posr the relative files?
 

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

More
31 Aug 2022 22:37 #250901 by dzawacki
Replied by dzawacki on topic Z Touch Off
I added them to the zip file.

I included: 
Woodsmith_2x4_CNC.ini
Woodsmith_2x4_CNC.hal
probe-z-panel.ui
probe-gvcp_call_list.hal
probe_gvcp_options.hal
macros/touchplate.ngc

Let me know if something different is needed.

File Attachment:

File Name: ZTouchOffFiles.zip
File Size:6 KB
Attachments:

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

More
01 Sep 2022 03:56 - 01 Sep 2022 03:57 #250906 by cmorley
Replied by cmorley on topic Z Touch Off
Try these files.
change the INI line to:

EMBED_TAB_COMMAND = halcmd loadusr -Wn gladevcp gladevcp -c gladevcp -x {XID} probe_z.ui

If that works it will print a message on the button press.
If that works then in the probe_z_handler.py file change:
self.cmd.mdi('(MSG, MDI Worked!)')

to:
self.cmd.mdi('o<touch_plate_z> call')

Chris
Attachments:
Last edit: 01 Sep 2022 03:57 by cmorley.

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

Time to create page: 0.082 seconds
Powered by Kunena Forum