Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: dandonegan on June 27, 2015, 03:19:56 PM

Title: Resetting machine coordinates in G code program
Post by: dandonegan on June 27, 2015, 03:19:56 PM
I am working on a wire bending machine. I am trying to find a way to reset the machine coordinates to home after each part.

The wire that I am bending has perforations. What I would like to do is have a block of code at the beginning of the program that would run the X axis homing sequence. This would work in conjunction with a photo eye to align the notches for the next part. It would also prevent the DRO from running up to ridiculous numbers. Particularly seeing as how we are running in millimeters. There is a button on the current machine diagnostics page that performs the function that would work for me; it is labeled "RefX". Is there a way to execute this function from within a G code program?

Many thanks in advance to those of you who are way smarter than me.

dan
Title: Re: Resetting machine coordinates in G code program
Post by: RDR on June 27, 2015, 04:56:02 PM
G28.1 Reference Axis
Program G28.1 X~ Y~ Z~ A~ B~ C~ to reference the given axes. The axes will move at the current feed rate towards the home switch(es), as defined by the Configuration. When the absolute machine coordinate reaches the value given by an axis word then the feed rate is set to that defined by Configure>Config Referencing. Provided the current absolute position is approximately correct, then this will give a soft stop onto the reference switch(es).

I found this on machmotions website not sure if this will help you.  This was for mach3 but I would think mach4 will also do this but not sure if they have it working yet I have not tried
Title: Re: Resetting machine coordinates in G code program
Post by: dandonegan on June 28, 2015, 10:59:46 AM
Unfortunately G 28.1 comes up as "unrecognized command". Does anyone know of a way to execute the "RefX" button functionality through G code or some other type of command that I can insert into a program?
Title: Re: Resetting machine coordinates in G code program
Post by: ger21 on June 28, 2015, 11:51:11 AM
I believe that Mach4 uses G30 instead of G28.1.
You might want to look at the Mach4 g-code manual.
Title: Re: Resetting machine coordinates in G code program
Post by: dandonegan on June 28, 2015, 12:14:43 PM
I am not trying to return to a predetermined axis position but instead create one from the current location. I want to load the wire in the machine and then when I run the program the first thing that will happen is that it will run through the X axis machine home function which will find the next perforation in the wire. It will then set machine zero based on that location. The part program will then run and bend the wire. When I go to run the program again it will do the same reset the X axis 0 location function and then bend the next part.

Saw not trying to return to a predetermined point I'm trying to create a new one.

dan
Title: Re: Resetting machine coordinates in G code program
Post by: Screwie Louie on June 28, 2015, 08:59:09 PM
Write a script using the 'AxisSetMachinePos' function. I believe that is the function that would apply to your requirement. I.e., setting a new offset for Xaxis. (This is just off the top of my head, look at mach4.api to find the right function for your application.) Hope this helps a little and points you in the right direction...
Title: Re: Resetting machine coordinates in G code program
Post by: Screwie Louie on June 30, 2015, 12:48:28 AM
or write a macro using mc.mcAxisSetPos function call...

"Set the position of the axis by changing the current Fixture offset."

Try both functions and see which one is best for ya.    mc.mcAxisSetPos or mc.mcAxisSetMachinePos

the macro would be called after each iteration, resetting your axis back to 0 in your work coordinates.
Title: Re: Resetting machine coordinates in G code program
Post by: dude1 on June 30, 2015, 01:55:19 AM
 mc.mcAxisSetPos is work position

mc.mcAxisSetMachinePos is machine position you would start with this one for the first spots so it a home position, then use the first one for the magic eye when it see the gap or what ever reset`s to x work zero
Title: Re: Resetting machine coordinates in G code program
Post by: Screwie Louie on June 30, 2015, 02:46:57 AM
Cool, thanx Dan!
Title: Re: Resetting machine coordinates in G code program
Post by: dude1 on June 30, 2015, 03:05:00 AM
mc.mcAxisSetPos is work position

mc.mcAxisSetMachinePos is machine position you would start with this one for the first spots so it a home position, then use the first one for the magic eye when it see the gap or what ever reset`s to x work zero

if the wire is in a long run you wont need to home each time just once then work zero what axis`s need to be zeroed then run the bends then when magic eye see`s the gap reset to work zero start again.

if it`s a sort run and you change wire homing is a good idea each run

you can use mcAxisSetMachinePos (mInst, 0, 0.0 /* set part zero */);

you can do this in lua or a macro b for you to get help you need to make a start on the code unless one of the mach boys helps you and have a look in the M4 api you can get to it through the Lua editor 
Title: Re: Resetting machine coordinates in G code program
Post by: dandonegan on June 30, 2015, 10:03:54 AM
There are two reasons I want to reset machine coordinates to home after each piece.

First off the preconfigured homing sequence would put the wire in just the right spot. I can even use the home off of switch distance to calibrate the exact distance easily.

These pieces are being bent off of a spool. With the DRO reading in millimeters and each part being roughly 2.5 to 3 meters long the DRO numbers get very big quick.
Title: Re: Resetting machine coordinates in G code program
Post by: dandonegan on June 30, 2015, 10:21:02 AM
So, is there a way to execute the function that is triggered by the screen button called "btnRefX"? If I couldn't execute this button from within my G code program all of my problems would be solved.

dan
Title: Re: Resetting machine coordinates in G code program
Post by: Screwie Louie on June 30, 2015, 01:05:32 PM
Can you use G53? G53 can send the axis back to home position in machine coordinates.  btnRefX just calls mc.mcAxisHome(inst, 0)  --0 is the X axis id

G53 X0.0

although, try this instead....it would make me feel better, haha

G53 Z0.0
G53 X0.0

If you must "Re-home" the axis and not just send the axis back to home position (machine coordinates) then you would have to pause the run, execute mc.mcAxisHome(inst,0), then return and restart the run (similar to the m6 Tool Change macro) We can code this so it is automated like you wish. I would just have to work on it....I have an idea, to be continued...
Title: Re: Resetting machine coordinates in G code program
Post by: Screwie Louie on June 30, 2015, 01:29:04 PM
It just clicked in my head, nevermind G53...it isn't what you want.
Title: Re: Resetting machine coordinates in G code program
Post by: dandonegan on June 30, 2015, 02:21:46 PM
Inks Louie,

That is exactly what I want to do. I tried executing this but it said "Lua error occurred while opening file" when I entered M 100 in the MDI field. Any suggestions would be greatly appreciated.

function m100()
    inst=mc. mc.mcAxisHome(inst, 0)
   
end

if (mc.mcInEditor() == 1) then
    m100()
end

dan
Title: Re: Resetting machine coordinates in G code program
Post by: Screwie Louie on June 30, 2015, 03:17:00 PM
close!...for example this macro just resets the X DRO in work coordinates:

function m100 ()
    local inst = mc.mcGetInstance ()
    mc.mcAxisSetPos (inst, 0, 0.0)
    mc.mcCntlSetLastError (inst, "Reset X Axis position.")
end

It will not change the machine coordinate DRO.

But you want to actually go through the homing process. For this we need to put the machine state into idle in order to let the axis home, then wait until the axis is homed before moving onto the next block. There are a couple things I'm gonna try and let ya know.
Title: Re: Resetting machine coordinates in G code program
Post by: dandonegan on June 30, 2015, 03:42:26 PM
Louie

I don't really understand the first part of your last email. If it's not resetting the machine coordinates DRO what did it do?

Thank you very much for your offer to poke around with running the  axis homing sequence somehow. Very much appreciated.

dan
Title: Re: Resetting machine coordinates in G code program
Post by: Screwie Louie on June 30, 2015, 03:55:11 PM
It resets your X axis work offset coordinates back to zero.
Title: Re: Resetting machine coordinates in G code program
Post by: dude1 on June 30, 2015, 05:57:01 PM
dandonegan there`s lot`s of ways to do what you wont can you supply more info on how you are going to go about running the wire bender are you going to use a gcode, dro`s to set bend`s
 and how you are moving the wire into the machine.

if you are doing it in a G code just have it goto machine zero at the end of the G code, just give Screwie Louie all and any info you can and ideas
Title: Re: Resetting machine coordinates in G code program
Post by: dandonegan on June 30, 2015, 09:57:34 PM
I am mending wire are similar to a spring forming machine. The material is being set off of a spool and being fed into the machine by the X axis motor. Those z-axis has a roller which is moving back and forth to bend of the wire as the X axis feeds it passed. I am currently using G code with X and Z movements. The wire that I am bending has perforations. What I would like to do is have a block of code at the beginning of each cycle of the program that would run the X axis homing sequence. This would work in conjunction with a photo eye to align the notches for the next part. It would also prevent the DRO from running up to ridiculous numbers. Particularly seeing as how we are running in millimeters. There is a button on the current machine diagnostics page that performs the function that would work for me; it is labeled "RefX". Is there a way to execute this function from within a G code program?

dan
Title: Re: Resetting machine coordinates in G code program
Post by: dude1 on June 30, 2015, 10:35:53 PM
that`s better yes there is using a Macro b or a Macro call at the end of the G code or what may be easier is a trigger when the eye see the notches it stop all motion then re zero the axis`s you don't need to re home if the distance between each notch is the same, you just need to do a Work Zero.

if it`s not then you will need to home the axis`s every time you do a run

a macro like what you did would work how mad lou did it with a trigger to make it happen first so trigger, stop all motion de ref the machine re home start again if notches not the same or stop all motion zero all axis back to work zero start again if notches are the same if they are, zeroing in work will not change home if you home first home is where the machine is in spaces, work is where the work is retaliative to home
Title: Re: Resetting machine coordinates in G code program
Post by: Screwie Louie on July 01, 2015, 12:05:24 AM
Here ya go. Try this. I had to put Lua to sleep for 5 seconds to let Mach4 report, exit, enter the appropriate machine state to continue.

The 5 seconds should be reset to the time it takes for your machine to home the X axis. To fast and Mach4 cannot properly communicate with the controller. In the simulator, I had it as fast as 2 seconds. But that's the sim and not real life. After the m101 macro, the X axis is re-homed, the next block of gCode is executed.

function m101 ()
    local inst = mc.mcGetInstance ()
    mc.mcCntlCycleStop (inst)
    mc.mcAxisHome (inst, 0)
    wx.wxSleep (5)
    mc.mcCntlCycleStart (inst)
end

Sample gCode:
    G00 G90 Z0.0
    X4.5 Y3.5
    m101
    X2.5 Y1.5
    m101
    X1.333 Z2.123
    X3.6 Z4.234
    m101
    X1.0 Y1.0 Z0.0
    m02

Hope this helps a little.  --josh


Title: Re: Resetting machine coordinates in G code program
Post by: dude1 on July 01, 2015, 12:25:01 AM
on to it
Title: Re: Resetting machine coordinates in G code program
Post by: dandonegan on July 10, 2015, 08:28:35 AM
I think I'm doing something wrong.

I got the machine back together and attempted to run Louie's macro but I am having no luck. I copied and pasted it into the machine profile macro folder and named it m100.mcs. I noticed all of the other macros that are in there such as M3 have two folders one that looks like it's compiled. What am I doing wrong? Can someone explain in layman's terms?

dan
Title: Re: Resetting machine coordinates in G code program
Post by: poppabear on July 10, 2015, 03:05:38 PM
--Try this code for your m101() macro

function m101 ()
    local inst = mc.mcGetInstance(0);
    mc.mcCntlCycleStop(inst);
    mc.mcAxisHome(inst, 0);
    wx.wxSleep(5);
    mc.mcCntlCycleStart(inst);
end

if (mc.mcInEditor() == 1) then --this was missing from the above post
    m101();
end

--Scott
Title: Re: Resetting machine coordinates in G code program
Post by: dandonegan on July 22, 2015, 06:34:01 AM
Gentlemen,

I am not getting any errors when I run this code but it is not doing anything. Does anyone have any other suggestions?

Getting desperate. I should've stayed in school like my mom said.

dan
Title: Re: Resetting machine coordinates in G code program
Post by: dude1 on July 22, 2015, 06:54:53 AM
have you tried it in the editor with a g code running it works that way

local inst = mc.mcGetInstance(0);
    mc.mcCntlCycleStop(inst);
    mc.mcAxisHome(inst, 0);
    wx.wxSleep(5);
    mc.mcCntlCycleStart(inst);

this works in a button it`s not the best way to do it
Title: Re: Resetting machine coordinates in G code program
Post by: dandonegan on July 22, 2015, 11:00:21 AM
Well, I started over and deleted and then reinstalled Mach. Now it's working fine.

Thanks to all of you very smart people for the help, it is greatly appreciated.

Please see my new post about how to make a program repeat.

dan