Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Raymondo on April 18, 2019, 03:13:14 AM
-
I would like to edit the cycle stop button to have it lift the tool to machine zero and turn of the coolant
I go into screen edit and click on cycle stop and can get to a cyclestop macro but when I add what is needed there is does not seem to take effect
what am I doing wrong
I have also tried editing the screenscript but this is marked as read only so I am a but reluctant to edit it
Regards Ray
-
Hi,
I think you may be mistaking the screen script with the .lua extension as opposed to the screen load script which
can be edited.
The screen script (with the .lua extension) is read only. All the Lua code of the GUI gets rolled into one large chunk
and it has the .lua extension. You can't edit it, you must edit those individual bits that make it up.
Open the screen editor, open the screen load script and find the cyclestop() function. That's what you need to edit.
Craig
-
Hi I think I am doing that I click on edit screen then click on the cycle stop button and then the tab that brings up the cyclestop script
the header is there but the functions has the -- in the front that shows them as a comment and not run I have been altering these and making the script active in there but it does not seem to work and I am not sure why I will not be back at the machine till Saturday and will try more things then
I do save it exit then program and restart as this is where the scripts are compiled but nothing I seem to do makes a difference
Regards Ray
-
This is in screenscript.lua
---------------------------------------------------------------
function CycleStop()
mc.mcCntlCycleStop(inst);
mc.mcSpindleSetDirection(inst, 0);
mc.mcCntlSetLastError(inst, "Cycle Stopped");
end
-----------------------------------------------------------
This is in a macro I saved in the profiles macro directory
CycleStop()
local inst = mc.mcGetInstance();
mc.mcCntlCycleStop(inst);
mc.mcSpindleSetDirection(inst, 0);
mc.mcCntlSetLastError("Cycle Stopped");
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 Z0")
--if not idle loop
----mc.mcCntlMdiExecute ("G01 G53 Z0.000");
--ocal inst = mc.mcGetInstance()
---mc.mcCntlMdiExecute(inst, "G00 G53 Z1\nG00 X0 Y0 A0\nG00 Z0")
a macro I have created for tool changing in the macro directory works fine but this does not seem to make ant difference
Regards Ray
-
Hi,
well you need to edit the CycleStop() function. As I explained you cannot edit this script, it is screenscript.lua
and is read only.
You need to find CycleStop() in the screen load script and edit there to do as you require.
CycleStop is not a macro. You can write and save code there and is useful in that you can single step through the code
in debug mode to debug prior to installation in its final location....the screen load script.
Craig
-
Hi,
To edit the screenload script, go to Operator>Edit Screen. Click the name of the screen at the very top of the screen tree manager. In the bottom, in the Properties section, click on the small Events tab (button with a little lightning bolt). The first item on that tab is the Screen Load Script. Click the button with '...' to open and edit that script. You can use Ctrl+F to search for the function you are looking for. As always, I recommend saving your screen with a unique name after changes are made, rather than altering the default screen set. To save your screen with a new name, go to Screen>Save Screen As.
Best wishes,
Bryanna
-
Hi,
CycleStop() is defined in the screen load script around line 183.
There are a few occasions where you will see a function called but be followed by what looks to be compliant
Gcode but all commented out. It is done simply to give you a glance at what you might expect to find if you were to
dig through the screen load script for the real function definition. If you wish to change the behavior of the machine
you must dig up the one and only real function definition in the screen load script and edit it there to enact the behavior
that you want.
Craig
-
Hi
Thanks I do not think I would ever have found that without help it is all logical once you have found out what the logic is
Regards Ray
-
Hi,
logic is overrated.....my motto is go mad now and beat the rush. ;D
Craig
-
Hi
Well I have had a little play still can't get it to work but put cycle stop back to the unedited version when I noticed this in History I have not read the history before
The first cyclestop error comes even before cyclestop is pressed
Any ideas ?
history.txt
Lua: Error while running chunk
?:0: attempt to call field 'CycleStop' (a nil value)
stack traceback:
?: in main chunk
?: in main chunk
Home switch Z Home tripped!Home switch Y Home tripped!Home switch X Home tripped!Home switch A Home tripped!Cycle StoppedLua: Error while running chunk
C:\Mach4Hobby\ScreenScript.lua:689: wxLua: Expected a 'string' or 'wxString' for parameter 2, but got a 'no value'.
Function called: 'mcCntlSetLastError(string)'
01. mcCntlSetLastError(number, string)
stack traceback:
[C]: in function 'mcCntlSetLastError'
C:\Mach4Hobby\ScreenScript.lua:689: in function <C:\Mach4Hobby\ScreenScript.lua:684>
-
Hi,
well you got an interesting problem there.
C]: in function 'mcCntlSetLastError'
C:\Mach4Hobby\ScreenScript.lua:689: in function <C:\Mach4Hobby\ScreenScript.lua:684>
This is good info, this is where the ***.lua script (recall, is the combination of ALL Lua scripts in Mach) shows its value.
Open the script and scan down to the line 684 and then you can start to diagnose the fault. Note that to fix
the fault, say bad syntax, you will have to go and find the script which is responsible for its inclusion in the ***.lua
script, say the screen load script or whatever.
Craig
-
C:\Mach4Hobby\ScreenScript.lua:689: wxLua: Expected a 'string' or 'wxString' for parameter 2, but got a 'no value'.
Function called: 'mcCntlSetLastError(string)'
01. mcCntlSetLastError(number, string)
From this part of the error message, you have an mc.mcCntlSetLastError API call but are only use a single parameter (string). It requires two (number, string). These are all listed in the API docs. For mc.mcCntlSetLastError it needs the instance for 'number' and your desired error message for 'string'.
As Craig said, you can use the line number to find where the error is in the screen script.
-
Well I have fixed the errors I now get no errors but the cyclestop function does not work how I want it to
I changed the error message return so am sure the function is being run through in the program
But I want to retract the tool and send the machine to machine home as well as turn of the coolant but it just seems to ignore the Gcode commands
Here is a copy of the function you can see the "Cycle Sxxstopped" i change this so i can tell the function is actually run
function CycleStop()
mc.mcCntlCycleStop(inst);
mc.mcSpindleSetDirection(inst, 0);
mc.mcCntlGcodeExecute(inst, "G90 G53 Z0 Y0");
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 Z0")
mc.mcCntlGcodeExecuteWait(inst, "G90 G0 G54 X0 Y0" )
mc.mcCntlSetLastError(inst, "Cycle Sxxstopped");
end
-
Hi,
you need to put the:
mc.mcCntlCycleStop(inst);
last thing. You have it near the top, so Mach encounters a Cycle Stop command , so it does and all subsequent
statements are ignored.
Craig
-
Hi
I already tried that and still no joy I assumed that mc.mcCntlCycleStop(inst); would stop all Gcode running so put it at the bottom I tried both the
mc.mcCntlGcodeExecute(inst, "G90 G53 Z0 Y0");
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 Z0")
I am a bit stuck it seems to me it should work
Regards Ray
-
Hi,
what motion mode was active prior to:
mc.mcCntlGcodeExecuteWait(inst, "G90 G53 Z0")
If there is any doubt I would include a g0:
mc.mcCntlGcodeExecuteWait(inst, "g90 g53 g0 z0")
Note I deliberately reduced to lowercase all the 'g's' etc.....Machs Gcode interpreter reduces all uppercase to lowercase, strips
out leading zeros and whitespace. Despite being somewhat less readable you will have fewer error if you follow Mach's
interpreter.
Craig
-
I assume a G1 feed mode would have been activated
I have had a couple of program lock ups when fiddling around with order of things in the cyclestop function
I will have another play tomorrow but I also tried a M9 to just stop the coolant and that did not work either
Regards Ray
-
Hi,
that's 'm9' not M9.
Craig
-
Well if I put the command above the cyclestop it executes the command but locks the screen up it actualy keeps running and reverts back to running the gcode program but the screen fades no readouts work and the screen is locked up
Mach4 can then only be stopped with widows task manager
with commands below the cyclestop the program stops and no commands work I put in the reset command before the cgode I wanted to run but it does a reset and then just runs the original program again so the reset command after cycle stop works it is almost like i need to do a cycle start I tried that but it restarts the program again
It seems to me i need to reactivate the program in some way after a cyclestop so that a gcode commands will work like in the MDI
I looked at using the retract comand to stop and do what I want
This command I do not understand how it works it stops the spindle retracts and goes to machine home but the scrip for it just looks to me to have a signal state altered I can not see where these other command are coming form
Regards Ray
-
Hi,
you are not testing return codes and will therefore struggle to make sense of it.
Take for example:
LUA Syntax:
rc = mc.mcCntlGcodeExecute(
number mInst,
string commands)
Description:
Execute G code as a unit of work and wait until it is complete.
Parameters: Parameter Description
mInst The controller instance.
commands A string buffer containing G code.
Returns: Return Code Description
MERROR_NOERROR No Error.
MERROR_INVALID_INSTANCE The mInst parameter was out of range.
MERROR_NOT_NOW The operation could not be completed at this time.
MERROR_NOT_COMPILED The macro scripts could not be compiled.
Note in particular MERROR_NOT_NOW which is a common error when attempting to use this API. You need to test for
it otherwise the code could fail and you would have no idea when or how or why it failed.
Try this for example:
local rc=mc.mcCntlGcodeExecuteWait(inst, "G90 G53 Z0")
if rc==mc.MERROR_NOT_NOW then
wx.wxMessageBox( "Houston....we have a problem")
end
At least now if the API did not proceed you will know when and probably why.
Smurph recommends EVERY API return code be testedI'm lazy and don't do it as much as I should but after many
frustrating hours trying to debug code I'm getting better at it.
Craig
-
I'd say you need run the CycleStop() function as a coroutine using the wait coroutine in the PLC, yield the coroutine after mc.mcCycleStop(inst) so that it waits for mach state to be idle, and then use the GCodeExecute API when it resumes.
-
That kind off makes sense do you have a example of how I could wait till the program comes to idle I sort of think the program is busy after the cyclestop it runs the mc.mcCntlGcodeExecuteWait(inst, "G90 G53 Z0") line and it is then lost and does not execute but I do not know haw to poll for idle state and wait till it is achieved
But it seems like some thing like this is happening
The Retract button code is also a mystery to me
-- button left down event script raises the signal
local inst = mc.mcGetInstance();
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_RTRCT);
if (rc == mc.MERROR_NOERROR) then
mc.mcSignalSetState(hSig, 1);
end
and yet it turns of the spindle raises the spindle and returns to machine home this is almost what I want but I want to turn off the coolant as well at the same time I see no code here that performs what Retract actually does just a signal state changed
Regards Ray
-
Hi,
when using mc.mcCntlGcodeExecute***() type statements you have seen that the machine needs to be in idle state
before it can accept such a command.
As you know the GUI and Machs Gcode interpreter are in different chunks. Thus a command such as mcCntlGcodeExecute()
would fail if the GUI chunk is currently running. If however the GUI chunk never runs then the screen is frozen, live
updates to DRO's the tool path display or anything else is possible. In the normal operation of Mach it is necessary for both
chunks to run and yet they cannot run simultaneously.
At other times Machs motion planner is under control of another instruction set, an MDI command string for example.
Thus any instruction like mcCntlGcodeExecute() would have to wait until that string were concluded before the motion planner
can be engaged.
It might in some circumstances be possible to add a wait period within your code so that a particular command could
be progressed where it had been unable to be progressed a few milliseconds before.
When I suggested testing the return codes it was more about alerting you to the clash rather than solving it.
If you are aware that a clash is occurring then you have the opportunity to study the circumstances where it occurs
and a subtle change of approach might avoid the clash altogether.
There is a list of all machine states in:
https://www.machsupport.com/forum/index.php?topic=40051.0 (https://www.machsupport.com/forum/index.php?topic=40051.0)
Craig
-
In your PLC script you should have the following code already if you're using the standard Mach4 screens. This bit of code monitors the state of mach, and when it is idle it will resume the coroutine from where it yielded.
-------------------------------------------------------
-- Coroutine resume
-------------------------------------------------------
if (wait ~= nil) and (machState == 0) then --wait exist and state == idle
local state = coroutine.status(wait)
if state == "suspended" then --wait is suspended
coroutine.resume(wait)
end
end
The CycleStop() function will go in the screen load script. This will also turn off the COOLANT ON output, but you can change this to whatever output you have mapped for your coolant output.
function CycleStop()
local inst = mc.mcGetInstance()
local rc, hSig
mc.mcCntlCycleStop(inst)
mc.mcSpindleSetDirection(inst, 0)
hSig = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON)
if (hSig == mc.MERROR_NOERROR) then
mc.mcSignalSetState(hSig, mc.MC_OFF)
end
mc.mcCntlSetLastError(inst, "Cycle Stopped")
coroutine.yield() --This is where the function yields and the code in the PLC comes into play
rc = mc.mcCntlMdiExecute(inst, "G90 G53 Z0 Y0")
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error moving to Z0 Y0")
end
end
This will go in the button script for your stop button
--Create a coroutine called 'wait'
wait = coroutine.create(CycleStop)
--Start the coroutine
coroutine.resume(wait)
This worked for me in the simulator, but always take caution when trying bits of code off the internet!
-
Hi
I did as you said and I understand what we are trying to do (I think) this is the error message
and the history
this is line 198 coroutine.yield() --This is where the function yields and the code in the PLC comes into play
This is 694 to 699
function btnStop_Left_Up_Script(...)
CycleStop()
--Create a coroutine called 'wait'
wait = coroutine.create(CycleStop)
--Start the coroutine
coroutine.resume(wait)
I am running in simulation mode as I took a copy home there is a large time difference to where I am to where you are so I work on it at night after work and do testing on the machine in the day
Regards Ray
Lua: Error while running chunk
?:0: attempt to call field 'CycleStop' (a nil value)
stack traceback:
?: in main chunk
?: in main chunk
Cycle StoppedLua: Error while running chunk
attempt to yield from outside a coroutine
stack traceback:
[C]: in function 'yield'
C:\Mach4Hobby\ScreenScript.lua:198: in function 'CycleStop'
C:\Mach4Hobby\ScreenScript.lua:695: in function <C:\Mach4Hobby\ScreenScript.lua:694>
Cycle StoppedLua: Error while running chunk
attempt to yield from outside a coroutine
stack traceback:
[C]: in function 'yield'
C:\Mach4Hobby\ScreenScript.lua:198: in function 'CycleStop'
C:\Mach4Hobby\ScreenScript.lua:695: in function <C:\Mach4Hobby\ScreenScript.lua:694>
This is what I placed in the stop button script is this correct
CycleStop()
--Create a coroutine called 'wait'
wait = coroutine.create(CycleStop)
--Start the coroutine
coroutine.resume(wait)
-
Remove CycleStop() from your button script so it just says:
--Create a coroutine called 'wait'
wait = coroutine.create(CycleStop)
--Start the coroutine
coroutine.resume(wait)
-
Thank you is now works in simulation mode
I will try it on the machine tomorrow
I will let you know how it goes but it is looking good
Thanks
Regards Ray
-
I have run the machine and low and behold it now works perfectly I have done a few moree modifications it now returns to home and resets the Gcode I had to run coroutine a second time to allow the moves to finish
I use M9 in the command instead of playing with turning off the output directly
I have to say a big THANK YOU I do not think I could have figured it out by myself and it for me just makes a already great machine just that bit better to use for what I am using it for
Thanks again I never recommend Mach4 highly enough it is just fantastic and the help received invaluable
Regards Ray
-
Sorry,
I know what you have achieved
BUT perhaps there is a easier way in MACH4 config - hidden somewhere.
In MACH3, all you need is a few clicks in Config | General config to achieve what you want to do.
(see attached)
And MACH4 is supposed to be BETTER!! Or we should tell NFS to make some changes in next version.
-
Hi
I wanted to do a few more things including turning of the coolant and from a stop I would never restart from that point but I am sure A lot of people in fact most people it works just fine for them as it is and would be the standard way most controllers in the commercial world work But and a big BUT
Mach4 is really configurable and I think just fantastic and are sure you can make it do what ever you wish I just wanted some thing more than what most people would want am are still learning the Lua script though I did write the script for a 8 tool rotary tool changer and that works great but this I could not at first find where and how to edit what I wanted but Mach4 help is the best bar none
Regards Ray
-
Hi
If you look at attached for MACH4, it is possible to use check FEED HOLD to stop Spindle and exiting FEED HOLD restores Spindle.
Now a VFD driver usually has an output relay so that when spindle is spinning that output relay can turn on coolant. So when the spindle stops spinning, the coolant would be off too.
Also in the second attachment, there are already buttons to manually turn off/on coolants too.
I know people like programming, I was an IBM MVS Cobol, CICS programmer long time ago. And I know LUA since more than 10 years ago.
BUT why do things that to me are superfluous yet seemingly so difficult to many?
It could only put off more hobbyist from buying MACH4.
-
Hi,
It could only put off more hobbyist from buying MACH4.
don't you get it.....Mach4 is primarily an industrial CNC software solution ideal for OEMs. To be an effective solution
in such a market it MUST be very configurable.
The fact that it is released cheaply under favorable license conditions by NFS for hobby use is a happy circumstance
for hobbyists.
Craig
-
Hi
The feed hold did not do what I wanted though I could have configured that button to do what I want but I wanted the feed hold button to do what it does as I do use it on occasion the stop button was the only logical choice to program up though I did consider just adding a new button this would have been in fact much easier to implement but not what I wanted
I have a few cnc lathes etc with commercial controllers on them so have seen both sides I have Mach4 on a commercial router that I retro fitted with a PC and tool changer at least I can make the mach4 do what I want and need I did look at buying a commercial Controller for the router a GSK was going to be my choice as I have used these with great success and like them but the mach4 leaves them in the dust
-
Hi,
It could only put off more hobbyist from buying MACH4.
don't you get it.....Mach4 is primarily an industrial CNC software solution ideal for OEMs. To be an effective solution
in such a market it MUST be very configurable.
The fact that it is released cheaply under favorable license conditions by NFS for hobby use is a happy circumstance
for hobbyists.
Craig
Correction:
MACH4 INDUSTRIAL VERSION is VERY CONFIGURABLE.
You can even change or create Gcodes.
MACH4 hobby version is NOT "very configurable".
Yes you can change screens.
YOU cannot change or create G CODES.
NOT all Mcodes are scriptable/configurable (see attached)
-
Hi,
MACH4 hobby version is NOT "very configurable".
Absolute rubbish, Mach4Hobby is, excepting MacroB, indentical to Mach4Industrial.
YOU cannot change or create G CODES
Correct, there is no control software anywhere that allows you to write your own Gcodes.
NOT all Mcodes are scriptable/configurable
m1, m2......you really need to be able to change those....you should take up knitting.
Craig
-
Haas M00 Stop Program
The M00 code is used to stop a program.
Haas M00 stops the
o axes
o spindle
o turns off the coolant (including Through Spindle Coolant)
Fanuc M00 stops following cnc functions.
o Motion of all axes
o Rotation of the spindle
o Coolant function
o Further program execution
Weeks of customization in this thread just to make the CYCLESTOP button also do the
M00 command ?
-
Hi,
Weeks of customization in this thread just to make the CYCLESTOP button also do the
M00 command ?
No, hours or less....if you know what you are doing.
If you favor Hass or Fanuc, and who wouldn't, pay up $20k and you can have one.
Craig
-
Hi
I think you are missing the point
I did not want to just turn of the coolant
I wanted to do a stop
turn of the spindle
Retract the tool to machine zero in Z axis
turn of the coolant and the air to the mist
and or the extraction system off
return machine to X and Y machine zero
then do a reset of the Gcode
in that order
Why any one would want to write Gcode in the controller is beyond me unless you are doing the simplest of parts or don't have access to a drawing program and even then you have the MDI for set up moves and simple parts any complicated part will need to be done in some thing like Mastercam etc
More than half the professional controllers out there still have to have a usb or serial communications this way I have wifi and instant communication
Having used many systems in the real world and had maybe 30 different cnc machines in the last 30 years in my own shop I think Mach4 is the best thing since sliced bread
I am new to Lau and learning as I go still the time I spent was still maybe 6 hours in total but and I must stress this the help I have received has been fantastic and a reason in itself to buy and use Mach4
Well that is it for this thread the problem is solved to my satisfaction
Thanks again to all who helped me come to the solution that I wanted
-
FEEDHOLD is supposed to be the equivalent of the MOO on the screen.
The problem with MACH4 is that it's M0 (M00) command does not include the M9 internally to turn off all the coolants (unless the manual is WRONG) - unlike the M00 of Fanuc and Haas.
From Mach4 manual
"M00 – Mandatory Program Stop: To pause a program at any point specify an M00. All motion will be halted and the spindle stopped. To resume operation press the cycle start button."
Doesn't stop coolants.
And I also pointed out that M00 is among the M codes that USERS are NOT ALLOWED to make changes.
I also pointed out that Hobby users can simply use the VFD drive output relay to turn off and on the coolants making use of the FEEDHOLD options available to do that. So IMO there is no need to change the meaning/function of the [STOP] button.
-
Thats fine this is a thread about programming the stop button and that has is already completed and now every thing works as I want which is the only point to this thread
Mach4 does not need a M00 as the are at least a dozen ways to achieve that if that is what you want to set up your machine
-
It is NOT fine for general public understanding. And it gives a false impression of MACH4 to potential customers as being inadequate
"A [STOP] button that makes moves" is NOT even ENGLISH.
Sorry.
-
You will be pleased to know I have renamed the STOP button the JESUS button so there will be no confusion
Lucky for me and other Mach4 users it is totally configurable so this was easy to do with Mach4 you can easily get the machine to do what you want and how you want it done