Hello Guest it is March 28, 2024, 05:19:31 AM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - alanbredbury

Pages: 1 2 3 »
1
Mach4 General Discussion / Re: lua in Mach 4
« on: August 22, 2022, 09:21:53 AM »
hey you know what would have been really handy is a link to this topic. pretty much what I have been struggling with so anyone following this for a solution try the one below. looks like it will do the trick. I learn best from examples.

https://www.machsupport.com/forum/index.php?topic=36577.msg251136#msg251136

2
Mach4 General Discussion / Re: lua in Mach 4
« on: August 18, 2022, 03:11:55 PM »
Did a bit more searching and I think these guys are going to do what I need once I get the usage through my thick skull. Me smart like tractor.

These next two functions are very helpful inside lua macros (scripts) since they will stop the machine if an error condition occurs (provided you check for and handle that error condition). Either of these functions will stop the execution of the GCode after the macro ends, but will not halt the execution of the macro itself. You will need to put "return" statements in after the calling of these functions, in order to halt the macro itself.
mcCntlMacroAlarm(...)
number: rc = mc.mcCntlMacroAlarm(number: inst, number: error_number, string: error_message)

mcCntlMacroStop(...)
    number: rc = mc.mcCntlMacroStop(number: inst, number: error_number, string: error_message)

3
Mach4 General Discussion / Re: lua in Mach 4
« on: August 18, 2022, 02:45:14 PM »
got back to this, the code that you provided below just dumps me out of the macro when I paste it in to my M6 macro. Please keep in mind I do not want to become an expert lua programmer I just want a single usable piece of code to run my tool changer. first question do I need to put this code in my program every time I call a gcode string and every time I change an output? this seems really bulky and inefficient. I tried putting the  mc.mcSignalSetState(hsig, 1) in this function where it says "some gcode string" yup that just dumps me out of the program and un-clamps the drawbar. I am clearly not getting this language. thoughts? examples? Thanks

local rc
rc = mc.mcCntlGcodeExecuteWait(inst, "some gcode string")
if (rc ~= mc.MERROR_NOERROR) then
     mc.mcCntlMacroStop(inst, 6, "Error moving to tool change position")  --The 6 can be replaced with any number, it is just an error number you want to assign. Also custom message can be used
     return --exit the m6 macro
end

4
Mach4 General Discussion / Re: lua in Mach 4
« on: August 12, 2022, 10:26:33 AM »
That is so far from any of my prior programming experience that it is nearly incomprehensible. I do see what it is doing though I think. Thanks I will try to incorporate it into the code.
Here is another question. the code I have does one really irritating thing if I hit the stop button it drops the tool and raises and drops the tool change station. I assume its completing the code after the stop is pressed. I am willing to bet someone here knows how to fix that. It also changes the tool number even though it never happened kinda. Thoughts? everyone here has been a great help.

5
Mach4 General Discussion / Re: lua in Mach 4
« on: August 11, 2022, 03:45:07 PM »
Got it, still needs a bit of cleanup, just had to get the way a function works in this thing
thanks

function TchgStation(SelectedTool, CurrentTool)

   local Tsig1 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2)
   local Tsig2 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT3)
   local Tsig3 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4)
   local Tsig4 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5)
   if (SelectedTool == 1) then
      TsigSout = Tsig1
   elseif (SelectedTool == 2) then
      TsigSout = Tsig2
   elseif (SelectedTool == 3) then
      TsigSout = Tsig3
   elseif (SelectedTool == 4) then
      TsigSout = Tsig4
   end
   if (CurrentTool == 1) then
      TsigCout = Tsig1
   elseif (CurrentTool == 2) then
      TsigCout = Tsig2
   elseif (CurrentTool == 3) then
      TsigCout = Tsig3
   elseif (CurrentTool == 4) then
      TsigCout = Tsig4
   end   

   return TsigSout, TsigCout;
end
   
TchgStation(SelectedTool, CurrentTool)

------ Move to current tool change position ------
local GCode = ""
GCode = GCode .. "G00 G90 G53 Z0.0\n"
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos1 + 1.3, YPos1)
GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos1 + 1.0)
GCode = GCode .. string.format("G01 G90 G53 Z%.4f F15.0\n", ZPos1)
mc.mcCntlGcodeExecuteWait(inst, GCode)
---Raise tool change holder #1
mc.mcSignalSetState(TsigCout, 1)
---Move x axis to place too in change holder
GCode = ""
GCode = GCode .. string.format("G00 G90 G53 X%.4f\n", XPos1)
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Release drawbar ------
local DrawBarOut = mc.OSIG_OUTPUT7
local hsig = mc.mcSignalGetHandle(inst, DrawBarOut)
mc.mcSignalSetState(hsig, 1)
---drop tool change holder #1
mc.mcSignalSetState(TsigCout, 0)
------ Move to next tool change position ------
GCode = ""
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos2, YPos2)
mc.mcCntlGcodeExecuteWait(inst, GCode)
----Raise tool change holder #2
mc.mcSignalSetState(TsigSout, 1)
--- give it a bit of time
wx.wxSleep(1)
------ Clamp drawbar ------
mc.mcSignalSetState(hsig, 0)
---- move x axis to slide tool out of holder #2
GCode = ""
GCode = GCode .. string.format("G00 G90 G53 X%.4f\n", XPos1 + 1.3)
mc.mcCntlGcodeExecuteWait(inst, GCode)
----- lower tool change holder #2
mc.mcSignalSetState(TsigSout, 0)
------ Move Z to home position ------
mc.mcCntlGcodeExecuteWait(inst, "G00 G90 G53 Z0.0\n")

6
Mach4 General Discussion / Re: lua in Mach 4
« on: August 11, 2022, 02:23:51 PM »
well that's nice and all but what about when the current tool is 2 and it calls for tool 4. I know what tool it has and wants but I need to move the correct change station. I need to get the number from the tool into the tool change number. in prior languages I have used I could just make a text string Tsig# whatever I wanted and use it as the variable apparently there is no way to use a text value as a variable in this language.
Thanks

7
Mach4 General Discussion / Re: lua in Mach 4
« on: August 11, 2022, 11:54:50 AM »
Ok I got back at it today, here is my code that works to change from tool one to tool two.
I keep getting stuck as to how to use a tool change output variable that I can't build in a text string.
sure I can put a bunch of complex if statements for every time I use Tsig# but it will be so bulky
Tsig# needs to change based on

local SelectedTool = 2 ---mc.mcToolGetSelected(inst)
local CurrentTool = 1 --- mc.mcToolGetCurrent(inst)

I hard coded the 1 and 2 for debugging as you can see the tool changer is unfortunately more complex than would be optimal.
any help would be appreciated, thanks

local Tsig1 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2)
local Tsig2 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT3)
local Tsig3 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT4)
local Tsig4 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT5)
   
----mc.mcSignalSetState(Tsig1out, 1)

------ Move to current tool change position ------
local GCode = ""
GCode = GCode .. "G00 G90 G53 Z0.0\n"
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos1 + 1.3, YPos1)
GCode = GCode .. string.format("G00 G90 G53 Z%.4f\n", ZPos1 + 1.0)
GCode = GCode .. string.format("G01 G90 G53 Z%.4f F15.0\n", ZPos1)
mc.mcCntlGcodeExecuteWait(inst, GCode)
---Raise tool change holder #1
mc.mcSignalSetState(Tsig1, 1)
---Move x axis to place too in change holder
GCode = ""
GCode = GCode .. string.format("G00 G90 G53 X%.4f\n", XPos1)
mc.mcCntlGcodeExecuteWait(inst, GCode)
------ Release drawbar ------
local DrawBarOut = mc.OSIG_OUTPUT7
local hsig = mc.mcSignalGetHandle(inst, DrawBarOut)
mc.mcSignalSetState(hsig, 1)
---drop tool change holder #1
mc.mcSignalSetState(Tsig1, 0)
------ Move to next tool change position ------
GCode = ""
GCode = GCode .. string.format("G00 G90 G53 X%.4f Y%.4f\n", XPos2, YPos2)
mc.mcCntlGcodeExecuteWait(inst, GCode)
----Raise tool change holder #2
mc.mcSignalSetState(Tsig2, 1)
--- give it a bit of time
wx.wxSleep(1)
------ Clamp drawbar ------
mc.mcSignalSetState(hsig, 0)
---- move x axis to slide tool out of holder #2
GCode = ""
GCode = GCode .. string.format("G00 G90 G53 X%.4f\n", XPos1 + 1.3)
mc.mcCntlGcodeExecuteWait(inst, GCode)
----- lower tool change holder #2
mc.mcSignalSetState(Tsig2, 0)
------ Move Z to home position ------
mc.mcCntlGcodeExecuteWait(inst, "G00 G90 G53 Z0.0\n")
------ Reset state ------

8
Mach4 General Discussion / Re: lua in Mach 4
« on: August 10, 2022, 09:10:40 PM »
Thanks for all the input, I had to do other stuff today and probably won't get back to it till Friday. I am sure I will succeed with all the advise here my code just may not be as elegant as I would like. I don't expect to do much more coding after this, I just want to run the machine so it's kinda a one shot deal I think. Thank you again for all the help.

9
Mach4 General Discussion / Re: lua in Mach 4
« on: August 09, 2022, 06:37:41 PM »
In short i want to build a text variable that contains mc.OSIG_OUTPUT# as text and use that value in the statement seems that would be the most efficient. Im fustrated that i dont seem to be able to do long command strings as i also have SQL background. Can I pass that function the tool number  and prefered status and get a return to raise or lower the tool change station as needed? I am accustomed to visual basic and before that foxpro it's pretty different both many years ago. I mean yes I can do it all with if statements but it seems like it's going to get pretty verbose. I will play with what you provided and see what I can do with it as a function. With the old languages I could just build a text string and use it as a variable and to make a call to an address. I saw some stuff about a load command, that didn't seem to work.

10
Mach4 General Discussion / Re: lua in Mach 4
« on: August 09, 2022, 04:23:56 PM »
Well I am far past that, thanks anyway. What I an trying to do is build the mc.OSIG_OUTPUT2 through 5 based on the tool number. In other words I have successfully built a variable that holds the text string but when I out the variable in place of mc.Osig_output# it reads it as text and will not return the handle but throws an error because ots text not the machine function or whatever. There has to be a way to turn text into a usable variable. Thanks in most languages its some function, special character or brackets. For instance you combine text with .. in this language.

Pages: 1 2 3 »