Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: danilo93 on April 07, 2018, 02:55:21 PM
-
Hello everyone. I ask for help because I've lost the last two days trying to make a button work to turn the OUTPUT on or off, now I've built two simple M functions, which work individually but I can not combine them. can someone give me help or tell me why these two tests do not work that I attach below? I'm not a programming expert but I would like to be able to have this function on my machine. thank you all and sorry for my bad english.
first test
function M101()
local inst = mc.mcGetInstance()
hReg, rc = mc.mcIoGetHandle(inst, OSIG_OUTPUT0);
BoolPointValue = mc.mcIoGetState(hReg);
if (OSIG_OUTPUT0 == 0) then ---- SE è SPENTO
mc.mcCntlMdiExecute(inst, "M15") ---ACCENDI POMPA
else
mc.mcCntlMdiExecute(inst, "M16") ----SPEGNI POMPA
end
end
if (mc.mcInEditor() == 1) then
M101()
end
second test
function M101()
local inst = mc.mcGetInstance()
mc.mcSignalGetHandle (inst, OSIG_OUTPUT0) --- LEGGI STATO OUTPUT 0
mc.mcSignalGetState (inst, OSIG_OUTPUT0) --- LEGGI STATO OUTPUT 0
if (OSIG_OUTPUT0 == 0) then ---- SE è SPENTO
mc.mcCntlMdiExecute(inst, "M15") ---ACCENDI POMPA
else
mc.mcCntlMdiExecute(inst, "M16") ----SPEGNI POMPA
end
end
if (mc.mcInEditor() == 1) then
M101()
end
-
Hi,
you have a number of syntax errors:
hReg, rc = mc.mcIoGetHandle(inst, OSIG_OUTPUT0);
Should be:
hReg,rc=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT0)
because OSIG_OUTPUT0 is a signal not an IO and mc.OSIG_OUTPUT0 correctly identifies the signal within Machs core.
BoolPointValue = mc.mcIoGetState(hReg);
Should be:
BoolPointValue=mc.mcSignalGetState(hReg)
if (OSIG_OUTPUT0 == 0) then ---- SE è SPENTO
Should be:
if(BoolPointValue==0) then
Because OSIG_OUTPUT0 is only a human readable representation of a signal, its true identity during this instance of Mach is hReg and you have enquired
and got its state and copied it to a variable BoolPointValue.
One other point is that Machs Lua interpreter always reduces uppercase function names to lowercase and strips out leading zeros and spaces.
Thus your M101 is seen by Mach as m101.
M0101 would be seen as m101
M 101 would be seen as m101
In most cases Mach will correctly indentify and use the code you intended but it can go wrong sometimes. Do yourself a favour use lowercase without leading zeros or spaces,
you'll have fewer mistakes.
Look in Mach4Hobby/Docs for Mach4CoreAPI.chm and ScriptingManual.pdf, they will help a lot.
Craig
-
thank you very much for the reply.
Now i'm Able to set mach4 Output, but fisic button don't work. this output are mapped good to csmio IO modules.
attached two screen of the problem.
have you other advice?
thank you
-
Hi,
that looks to be a problem with the controller, I'm not familiar with CSMIO boards.
On the screen pic of the CSMIO plugin it has modules...to what do they refer? Is it possible the pic is displaying one module whereas the signals you wish to view are in another?
Craig
-
Modules are additional 16 input and 8 output boards. We can use up to 16 boards and then have a total of 280 inputs and 144 outputs.
Also I thought of a similar problem but if I program in mach / output:
SpindleOn ---> CS MIO IO (0) ---> Output 4, M3 activates the output well.
So M3 on that same output works and the other functions M no.
So I was thinking of a MACH problem, in your opinion is my M17 script good?
I thank you very much for your help.
Danilo
-
Maybe silly questions, but:
1. Do the relevant LEDs on the I/O module light?
2. have you connected both 0V and 24V for output group 0-3?
3. Have you connected the other side of your load to 0V, as the CSMIO can only source current?
Allan
-
Hi,
yes there is some confusion between the Enable outputs and user Outputs. Try the same script but with OSIG_OUTPUT20 say.
May I suggest also that you not use M17 as a function name, use M100 or greater as user macros and M99 and under
are Mach Macros prehaps with modification. My concern is that your M17 macro may have unintended consequences
as regular Mach may already have an M17 which you have overwritten.
Allan has considerable experience with CSLabs boards and Mach4. Note CSLabs by their own admission their Mach4 plugin is a work
in progress. Allan has, in another thread, claimed CSLabs treatment of Mach outputs is mature however there are some
questions in my mind about them.
Craig
-
Hello guys,
I'll be back to update you. I managed to solve with your advice even if I had to use only the outputs above # 20 in mach 4, otherwise they will not work. I have no idea why.
Now I'll be able to work on ATC, and I'll definitely ask for help again about management of the Spindle's safeties, I will mount an HSD ES950.
thank you
Danilo
-
Hi,
ask CSLabs, its their device, they are collecting money from customers for a product that does not work as advertised. Until customers like you hassle
them no changes will occur. Remember these board are sold at a premium but perform very much less well than my ESS at a third the price.
Craig
-
Hello guys,
I already warned cs lab and they replied that they are working on a release to fix.
I would like to have information on some aspects that I can not really understand:
following the manuals I managed to use the tool change, even if I do not understand how to program logical sequences, for all the security functions:
for example, after an m6 t2 command I would like:
- open protection
- wait for the open protection signal to be on
- go to position (it works)
- release tool (works)
-Wait signal no tool (I can read but I can not use it)
- move to another position (works)
- hook tool (works)
-Wait signal tool ok (I can read but I can not use it)
- return to z safe (it works)
- close protection
- wait for closed protection signal
-m6 end
individually I can do everything, but I can not make them work in this sequence in the same macro, can you explain to me how is logic?
from the manuals I can not understand and I can not find examples even sifting through the whole forum.
moreover I would like to implement the safety devices also in M3 (if tool = 0 spindle does not have to turn on, if door is not closed spindle it does not have to turn on)
or, if low air pressure blocks everything.
or again:
if input x = 1:
- close doors
- wait for a closed door signal
- start cycle
I know that there are many questions, but I would like to understand only where to intervene, then I want to understand for myself how to develop everything, I would need an input from you experts.
Thank you so much for the help
Danilo
-
Hi,
sometimes it is easier to program a function, in this case a toolchange, without too many or even any interlocks. Once you have the function working THEN start applying
interlocks for safety.
If I understand your machine requires air pressure to run. Thus if you'll have an air pressure switch. It is a fairly simple matter to have the function not start if the air pressure is not OK, but what happens
if the pressure drops part way through the toolchange? I can well imagine you want your program to respond to that situation and that is very much harder. May I suggest that to start with do the easy
option and later decide whether the extra protection is really required and how you might do it.
As an example, say:
ISIG_INPUT10=air pressure OK
ISIG_INPUT11=tool present
ISIG_INPUT12=door closed
Then:
Function m6()
local hsig=mc.mcSignalGetHandle(inst,mc.ISIG_INPUT10)
AirOK=mc.mcSignalGetState(hsig)
hsig=mc.mcSignalGetHandle(inst,mc.ISIG_INPUT11)
ToolPresent=mc.mcSignalGetState(hsig)
hsig=mc.mcSignalGetHandle(inst,mc.ISIG_INPUT12)
DoorClosed=mc.mcSignalGetState(hsig)
If AirOK ~=1 then
mc.mcCntlSetLastError(inst,' Air Pressure Fault')
return --If the air pressure is bad then message the fault then abort the toolchange by returning to the calling program
else
-go to position
-release tool
-....
-.... -- the body of the toolchange function
end
if (AirOK and DoorClosed and ToolPresent)==1 then
m3
mc.mcCntlCycleStart(inst) -- if all the interlocks are OK THEN start the spindle and 'push' cycle start
end
end
Maybe a few ideas.
Craig
-
thanks Craig,
I had taken many steps forward, up to this problem.
do you know what it's due to?
thanks
Danilo
-
I solved alone, it was a banality
-
Hey Danilo
Here is a way to wait for a signal.
--Wait for signal.
--The number on the end of the statement tells Mach how long to wait before continuing. Use 0 on the end to wait indefinitely. 10 would be 10 seconds. ETC...
--This is all the code you have to have to wait for a signal.
mc.mcSignalWait(inst, mc.ISIG_INPUT1, mc.WAIT_MODE_HIGH, 0)
--Wait for signal with rc. This will let you know if there is an error while waiting for the signal.
--rc is the return code. If it takes longer than the allotted time or another error occurs it will return something besides 0.
--if rc == 0 then there was no problem. If rc ~= 0 there is a problem.
rc = mc.mcSignalWait(inst, mc.ISIG_INPUT1, mc.WAIT_MODE_HIGH, 0)
if (rc ~= 0 then)
wx.wxMessageBox("There is a problem")
mc.mcCntlCycleStop(inst)
end
-
Hi Danilo,
I've used that API too, it works well. Be aware though it works only with input signals numbered 0 to 63,
ie ISIG_INPUT1 through ISIG_INPUT64.
Also it is highly advisable to test the return code for all possible returns, its easy to get caught out by a return
that you did not expect.
Craig
-
Hello to all guys,
Thank you so much for the support. Now I'm able to use all the necessary safety devices in the tool change. I have included preliminary checks in the PMC editor (door, air, etc.).
I attach my script to other users who will need it in the future, at the end, the right G43 H, which is in the tool table, is also set, the next step will be to set it automatically by a touch probe.
Use with caution.
Now the other problem is: how to behave to put the tool at 0?
I made a macro that works alone, but with the current script I can not insert it.
moreover it does not manage the tool 0, it would not know where to start to resume the selected one