Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: backlashphoenix on March 14, 2018, 04:47:44 PM

Title: Help Modifying RefAllHome
Post by: backlashphoenix on March 14, 2018, 04:47:44 PM
I would like to modify my Mach 4 RefAllHome script so that it homes only my X and Y axes and not the Z axis. Is this possible? Thanks.
Title: Re: Help Modifying RefAllHome
Post by: joeaverage on March 14, 2018, 04:59:22 PM
Hi,
yes thats pretty straight forward, I'm at work at the moment but could help laterif someone hasn't already
pointed you in the right direction.

Craig
Title: Re: Help Modifying RefAllHome
Post by: backlashphoenix on March 14, 2018, 09:31:35 PM
Hi Craig,

Yeah, if I could get this figured out by the time I go back to work on Friday that would be great. I'm sure it's an easy change, but I haven't been able to find any guidance on this specific topic. Also, I was hoping to get some clarification on how to use a limit switch as a home/limit switch. Everything I've tried so far has resulted in Mach 4 either not being able to jog, or crapping itself and running past the switch and crashing. I have a Bridgeport Series 1. Z axis has separate limit switches which work fine as limit switches, but with the switch set as a limit/home at the same time, I can't RefAllHome without bad things happening. With the Z switches set as limit switches, I can't ref the other axes home, hence the need to change the RefAllHome script. With the switch set as Home only RefAllHome works great, but then I don't have a limit switch which is obviously bad.

On a related but separate topic, my X and Y axes each have only 1 limit switch that trips at the extents of travel. Mach 3 was smart enough to recognize that a limit switch triggered moving in one direction was either a -- or a ++ depending on the direction of travel at the time the switch was triggered and allowed you to jog back off of it. So far I haven't figured out a way to use only 1 limit switch as a -- and ++ limit switch. I never used the homing function when the machine was set up with Mach3, but I'm certain that the limit switches were operational the way I described. It sure would be nice if there was a way to use 1 switch as Home/--/++, but maybe that's impossible in Mach 4 and I need to lower my expectations. Thanks
Title: Re: Help Modifying RefAllHome
Post by: joeaverage on March 14, 2018, 10:01:44 PM
Hi,
you want ONE switch to do THREE jobs. Ideally you would have one limit switch at the end of each axis and one
separate home switch on each axis for total 9 switches. As it turns out switches are cheap, crashing because you've
tried to economise on switches is expensive.

Craig
Title: Re: Help Modifying RefAllHome
Post by: backlashphoenix on March 14, 2018, 10:05:47 PM
Okay. Thanks for that, I'll keep that in mind.

So about modifying the Homing script...
Title: Re: Help Modifying RefAllHome
Post by: joeaverage on March 14, 2018, 10:23:08 PM
Hi,
modifying the ref all home script is easy but what are you going to do for home switches?

Homing works by Mach driving an axis until it detects the activation of a home switch. Without a home switch Mach
has nothing to detect. If you have a limit switch you could use that, not my preferred option but you can
do it. It will mean that while the homing function is operating that the limit switches must be ignored. Just when
you are likely to have a stuff up you have to disregard your limit switches??? Thats like going to a race track
in your car but taking your seat belt off when you get there to go racing...it just doesn't make sense.

Craig
Title: Re: Help Modifying RefAllHome
Post by: backlashphoenix on March 14, 2018, 10:29:03 PM
Thank you for your concern about my limit switches. I very much understand the importance of limit switches, and if I could, I would put all of the limit switches on every axis. Rest assured that I eventually will put the correct amount of switches on my machine at a future date, but until then I just need it to work, and part of that means having RefAllHome on only the X and Y axes. If you know how to modify that code and would like to tell me how then I would really appreciate your doing so. Thanks
Title: Re: Help Modifying RefAllHome
Post by: joeaverage on March 14, 2018, 11:33:33 PM
Hi,
to get the code, any code, to work you need home switches on your X and Y axes.

Do you have home switches on them?

Craig
Title: Re: Help Modifying RefAllHome
Post by: joeaverage on March 14, 2018, 11:34:44 PM
Hi,
I don't really care about limit switches, but you absolutely need home switches in order for a homing routine to work.

Craig
Title: Re: Help Modifying RefAllHome
Post by: backlashphoenix on March 14, 2018, 11:45:28 PM
Hi,
Yes, I have home switches on my X and Y axes. For the past year I've used the switches as they're currently configured as home switches. Now I want to use the switches on my Z axis as limit switches only. In the future I'll probably add a third switch to do homing on the Z axis, but for now I don't really need to home the Z axis, as I typically rezero between operations or tool changes anyway. Thanks
Title: Re: Help Modifying RefAllHome
Post by: joeaverage on March 14, 2018, 11:53:12 PM
Hi,
kool. You only need home switches on the axes you wish to home, if your not worried about Z thats fine.

As youv'e probably already discovered to use the standard Ref All Home button that ships with Mach4 is intended
to home the Z axis in addition to X and Y. When Mach doesn't find a Z axis switch it will hang up and have a fit/meltdown.

Due to finish work in the next 15 min or so and hour plus drive home. Will post some pointers on what to do.
When you see hoe it works you will think to yourself 'Gee that was easy...why didn't I think of that'

Craig
Title: Re: Help Modifying RefAllHome
Post by: joeaverage on March 15, 2018, 01:41:09 AM
Hi,
two ways to do this, simply or very simply....

This is the standard Ref All Home function in the screen load script, around line 200 depending on the build version and whether you've added any extra code preceeding
this.

Code: [Select]
function RefAllHome()
    mc.mcAxisDerefAll(inst)  --Just to turn off all ref leds
    mc.mcAxisHomeAll(inst)
    coroutine.yield() --yield coroutine so we can do the following after motion stops
    ----See ref all home button and plc script for coroutine.create and coroutine.resume
    wx.wxMessageBox('Referencing is complete')
end

Notice the API call  mc.mcAxisHomeAll(inst)
Just replace the Home All with homing individual axes:
mc.mcAxisHome(inst,mc.X_AXIS)
mc.mcAxisHome(inst,mc.Y_AXIS)
 
The code would now be:

Code: [Select]
function RefAllHome()
    mc.mcAxisDerefAll(inst)  --Just to turn off all ref leds
    --mc.mcAxisHomeAll(inst)
    mc.mcAxisHome(inst,mc.X_AXIS)
    mc.mcAxisHome(inst,mc.Y_AXIS)
    coroutine.yield() --yield coroutine so we can do the following after motion stops
    ----See ref all home button and plc script for coroutine.create and coroutine.resume
    wx.wxMessageBox('Referencing is complete')
end

Note rather than delete the original API call I commented it out ( put '--' in front of it ) so that if I want to revert back to standard I can do so easily.

That was the simple way but there is an even simpler way:
In the pic attached is the home order of my machine, Z axis first. If I assigned 0 to the Z axis home order it wouldn't be homed at all. Just assign 1 and 2 as
home order for X and Y axes and your done. No coding at all!
Title: Re: Help Modifying RefAllHome
Post by: backlashphoenix on March 15, 2018, 03:55:23 PM
Wow, you're right, I can't believe I didn't think of just setting the home order for Z to 0, haha. Thanks for the help!
Title: Re: Help Modifying RefAllHome
Post by: backlashphoenix on March 16, 2018, 08:50:33 AM
Ok, it looks like just changing the home order to 0 on Z didn't work. I need to edit the screen load script but I don't know how to do that. I can see it on the operator tab, but I don't know where the file is to actually edit it. I know this is a very basic question but I'm new to Mach4 and haven't needed to change much since I upgraded. Thanks
Title: Re: Help Modifying RefAllHome
Post by: backlashphoenix on March 16, 2018, 09:12:45 AM
I figured out how to modify the screen load script. Changed the code to make it Ref X and Y individually, but now I'm getting this error code. I don't think any settings changed on X or Y since I had the RefAllHome working with all 3 axes. Thanks
Title: Re: Help Modifying RefAllHome
Post by: joeaverage on March 16, 2018, 04:28:56 PM
Hi,
the reduced Ref All Home button works fine here, that is that only X and Y axes home.

Can you post a screen shot of the motor assignment page?

Craig
Title: Re: Help Modifying RefAllHome
Post by: backlashphoenix on March 16, 2018, 05:08:04 PM
Hey I got everything working. Turns out I was getting signal interference on my USB cable. I moved it to a location away from everything else and haven't had any problems since. Thanks for the help, the programming changes worked perfectly. Thanks again!