Hello Guest it is April 19, 2024, 09:15:09 AM

Author Topic: Mach4 Button OFFLINE  (Read 27190 times)

0 Members and 1 Guest are viewing this topic.

Re: Mach4 Button OFFLINE
« Reply #110 on: February 02, 2018, 05:21:29 AM »
I sincerely ask myself why this OFFLINE function has not already been integrated into Mach4 (as it was in Mach3).
I consider it an indispensable function for security reasons!
machine tools are not video games! a trivial error can be very expensive, both in terms of damage to the machine itself and to the operator!
by programming on the machine, manually, you must be clear that you have not made mistakes!
Re: Mach4 Button OFFLINE
« Reply #111 on: February 02, 2018, 06:24:02 AM »
Hi,
Mach4 IS NOT Mach3 and never will be. Mach3 had hundreds of little cheats and work-arounds that it became a nightmare to maintain or develop.
The 'Offline' button is an example. I know you have become used to it in Mach3 and believe it is therefore universal in the world of CNC....its not.
Every controller manufacturer has their own interpretation of it, all claim that theirs is the 'only correct way' to do it. There is no such thing as the
'only correct way'.

Mach4s strength is that it is very flexible, you can program it to behave much like Mach3 or maybe even identically, or any other way that seems right to you.
The real market for Mach4 is OEM manufacturers, they have a piece of software that they can adapt to their machine, it might be simple like a lathe
but it might also be a multiaxis grinder or 5 axis wire EDM or a 12 axis Swiss lathe or....the list goes on.

The challenge for you is to learn how to program Mach4 to behave the way you want. You can whinge and moan that it should all be done for you but its not
and NFS has no interest in doing it for you, if you can't be bothered to learn why should they be bothered to help?

This is a preliminary sketch of the code. Note that I have written it as a function so that I can use the debugger. When in service this code will
be in the screenload script and attached as an event script for your button.

Code: [Select]
function OfflineButton()
local inst=mc.mcGetInstance()
local hsigenable=mc.mcSignalGetHandle(inst,mc.OSIG_ENABLE0)
local hsigbuttonstate=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT2)
if (mc.mcSignalGetState(hsigenable)==1) then
    if (mc.mcSignalGetState(hsigbuttonstate)==1) then
        -- Mach is enabled and the servos are 'online'
        -- Need to save current position and set servos 'offline'
        local Xpos=mc.mcAxisGetMachinePos(inst,mc.X_AXIS)
        local Zpos=mc.mcAxisGetMachinePos(inst,mc.Z_AXIS)
        mc.mcCntlSetPoundVar(inst,500,Xpos)
        mc.mcCntlSetPoundVar(inst,501,Zpos)
        mc.mcSignalSetState(hsigbuttonstate,0)
    else
        --Mach enabled but servos 'offline'
        --Need to restore current position and reset servos 'online'
        local Xpos=mc.mcCntlGetPoundVar(inst,500)
        local Zpos=mc.mcCntlGetPoundVar(inst,501)
        mc.mcCntlGcodeExecuteWait(inst,'g53 g0 x'..Xpos..' z'..Zpos)
        mc.mcSignalSetState(hsigbuttonstate,1)
    end
else
    --Mach disabled....do nothing
end
end
if ( mc.mcInEditor()==1) then
    OfflineButton()
end
You may recall right at the beginning of this thread I said this would be easy. If you have a look at the code it is. Twenty lines of code.
The only real difficulty we've encountered is that the CSMIO device has a quirk I don't understand. Without that quirk it would be simpler still.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Button OFFLINE
« Reply #112 on: February 02, 2018, 06:29:07 AM »
Hi,
just noticed I used OSIG_OUTPUT2 because my screenset already has an LED for Output#2. Substitute whatever output seem good to you.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Button OFFLINE
« Reply #113 on: February 02, 2018, 06:57:23 AM »
thank you!!!! thank you!!!! thank you!!!!
because of the time, I can not test now.
Do I have to create a button on the screen, and enter this code you wrote?
as an image that I have attached?
Re: Mach4 Button OFFLINE
« Reply #114 on: February 02, 2018, 09:49:52 AM »
Craig

Sorry for the delay in responding.

I created a pair of simple macros to set and reset  OSIG_ENABLE0 and ran them manually from the MDI window of the Diagnostics tab. They had no effect on the Enable0 LED on that screen. I then changed the macros to control   OSIG_OUTPUT0 and this time the related LED reacted accordingly.

It does appear that Mach4 keeps a tight control over the motor enable  signals which are fundamental to machine control. I was using the simulator on my office PC, so it appears that the op's CSMIO is performing in the expected manner and it is your system that is behaving differently.

Personally, I just test my Gcode programs using the simulator in the office, and have never found a discrepancy between this and my CSMIO system.

Allan
Re: Mach4 Button OFFLINE
« Reply #115 on: February 02, 2018, 11:08:27 AM »

you were very kind to answer. at least now I confirm that it is not possible to use ENABLE # 0 with CSMIO
Re: Mach4 Button OFFLINE
« Reply #116 on: February 02, 2018, 02:42:34 PM »
Hi Allan,
thanks for taking the time to test this out.

I have two macros, m210 and m211, one to turn OSIG_ENABLE0 on and the other to turn it off. On my laptop I have an LED on
the screen to reflect the state of the output and it responds as I expect.

On my machine I attached an output pin of my ESS to OSIG_ENABLE0 and the output pin turns on and off as expected.

You are quite correct Mach influences control over the Enable#.... signals. When Mach is enabled the Enable#... signals go active and when Mach is disabled
they are reset. For the purpose of an 'Offline' button for the OP I wished to add to that functionality, namely be able to programmatically turn the Enable#....
signals on and off. Your investigations suggest that you cant control OSIG_ENABLE0 it that manner. I disagree, I can and do control the output as I've described
and I can and have attached the output signal to a pin on my controller.

There are two issues:
1) Why can't you cause an Enable#... to change state when I can?
2) Why can't the CSMIO device attach an output pin to Enable#0?

To OP:
no, you don't have to attach the code to a button yet. It is a stand-alone function that can be single stepped through with the debugger to test it out.
It was running as expected last night. Try running the function in the debugger. Note at the end rather than step the debugger right through the last
'end' statement and crash the debugger go <shift f5> which causes the debug session to end without crashing it.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Button OFFLINE
« Reply #117 on: February 02, 2018, 04:14:29 PM »
Craig

I have had another look at this on my office PC using SIM. The plot thickens:

If I run the macros from the debugger, the M0 Enable LED does indeed respond to the macros, as you have observed. If, on the other hand, I execute the macros from the MDI window, there is no response. Make of that what you will.

I will try to remember to go out and run this on the CSMIO over the weekend, just for the sake of completeness.

I think you are incorrect in asserting that output pins cannot be arbitrarily assigned by the CSMIO. I have never seen evidence of this.

Allan
Re: Mach4 Button OFFLINE
« Reply #118 on: February 02, 2018, 04:22:35 PM »
Hi Allan,
Quote
I think you are incorrect in asserting that output pins cannot be arbitrarily assigned by the CSMIO. I have never seen evidence of this.
I hope you are right but I cant think of any other reason which would prevent OP from attaching an output pin to a legit Mach signal.
I don't have a CSMIO device and they're not cheap so I won't be getting one any time soon so I can't test it myself.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 Button OFFLINE
« Reply #119 on: February 03, 2018, 02:13:19 AM »
Hi,
if your happy with the way the function operates then by all means attach it to your button.

To do that just copy the code EXCEPT for the last:
if (mc.mcInEditor()==1)  then
        OfflineButton()
end

and copy it into the screen load script. Put the function name in the left-up script for your button and your done.

You could put a few statements in the code that provide status messages but they don't affect how it works.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'