Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: chris@wortz.com on October 21, 2015, 08:05:31 PM

Title: Mach4 Variable Counter
Post by: chris@wortz.com on October 21, 2015, 08:05:31 PM
Heres My code, Heres my issue:

What I'd like to implement here is ever time that M1003 loops, I want to have a variable increment like a counter
and for it to show up on the screen.   I have read all this about variable and DRO and macropump,,,.... 
My brain is smoking... Any ideas?

N01 G20 G40 G49 G54 G80 G90 G91.1
;N02 G53 Z0.

(starting Position)
N05 G00 G90 X13.000 Y-5
G00 Z-0.29  (HEATER HEAD HEIGHT)         (START POSITION)

M98 P1010 ;first purge


G91 G21
F160

M98 P1001   
M98 P1002     
M98 P1003 L27   (all colors)

G0x-76.200  (move to start pos of next plate relative to last location)

M98 P1001     
M98 P1002     
M98 P1003 L27   (all colors)

G0x2
G90
G0z50
M30
%


o1001   ; make  1 color subroutine
G0x-12.700  (Move - 1/2 inch each increment)

(ROW x  1 color)

(ON)
M200    (HEAD 1)
   (HEAD 2)
   (HEAD 3)

G0 Y63.500 F160.        (MOVE TO -5 NO CHANGE ON X AXIS F215 IS SPEED RATE)
G0 Y25.400 F180.        (MOVE TO -4 NO CHANGE ON X AXIS F200 IS SPEED RATE)
G0 Y30.480 F200.        (MOVE TO -2 NO CHANGE ON X AXIS F125 IS SPEED RATE)

M201    (HEAD 1)
M203    (HEAD 2)
M205    (HEAD 3)
(end  code)

(ROW x 2 color)
G0 Y25.400 F200   (start pos of 2)
(ON)
M200    (HEAD 1)
    (HEAD 2)
    (HEAD 3)

G0 Y63.500 F160.        (MOVE TO -5 NO CHANGE ON X AXIS F215 IS SPEED RATE)
G0 Y25.400 F180.        (MOVE TO -4 NO CHANGE ON X AXIS F200 IS SPEED RATE)
G0 Y30.480 F200.        (MOVE TO -2 NO CHANGE ON X AXIS F125 IS SPEED RATE)


M201    (HEAD 1)
M203    (HEAD 2)
M205    (HEAD 3)
(end  code)

G0 Y-264.160
m99
%


o1002   ; make  2 colors subroutine
G0x-12.700  (Move - 1/2 inch each increment)

(ROW x  1 color)

(ON)
M200    (HEAD 1)
M202    (HEAD 2)
   (HEAD 3)

G0 Y63.500 F160.        (MOVE TO -5 NO CHANGE ON X AXIS F215 IS SPEED RATE)
G0 Y25.400 F180.        (MOVE TO -4 NO CHANGE ON X AXIS F200 IS SPEED RATE)
G0 Y30.480 F200.        (MOVE TO -2 NO CHANGE ON X AXIS F125 IS SPEED RATE)

M201    (HEAD 1)
M203    (HEAD 2)
M205    (HEAD 3)
(end  code)

(ROW x M 2 color)
G0 Y25.400 F200   (start pos of  2)
(ON)
M200    (HEAD 1)
M202    (HEAD 2)
   (HEAD 3)

G0 Y63.500 F160.        (MOVE TO -5 NO CHANGE ON X AXIS F215 IS SPEED RATE)
G0 Y25.400 F180.        (MOVE TO -4 NO CHANGE ON X AXIS F200 IS SPEED RATE)
G0 Y30.480 F200.        (MOVE TO -2 NO CHANGE ON X AXIS F125 IS SPEED RATE)


M201    (HEAD 1)
M203    (HEAD 2)
M205    (HEAD 3)
(end code)

G0 Y-264.160
m99
%


o1003   ; make all 3 colors subroutine
G0x-12.700  (Move - 1/2 inch each increment)

(ROW x  1 color)

(ON)
M200    (HEAD 1)
M202    (HEAD 2)
M204    (HEAD 3)

G0 Y63.500 F160.        (MOVE TO -5 NO CHANGE ON X AXIS F215 IS SPEED RATE)
G0 Y25.400 F180.        (MOVE TO -4 NO CHANGE ON X AXIS F200 IS SPEED RATE)
G0 Y30.480 F200.        (MOVE TO -2 NO CHANGE ON X AXIS F125 IS SPEED RATE)

M201    (HEAD 1)
M203    (HEAD 2)
M205    (HEAD 3)
(end code)

(ROW x 2 color)
G0 Y25.400 F200   (start pos of  2)
(ON)
M200    (HEAD 1)
M202    (HEAD 2)
M204    (HEAD 3)

G0 Y63.500 F160.        (MOVE TO -5 NO CHANGE ON X AXIS F215 IS SPEED RATE)
G0 Y25.400 F180.        (MOVE TO -4 NO CHANGE ON X AXIS F200 IS SPEED RATE)
G0 Y30.480 F200.        (MOVE TO -2 NO CHANGE ON X AXIS F125 IS SPEED RATE)


M201    (HEAD 1)
M203    (HEAD 2)
M205    (HEAD 3)
(end code)

G0 Y-264.160
m99
%



o1010
(purge routine)
N05 G00 G90 G54 X13.0 Y-5.0
/N06 G43 H1 Z0.
G00 Z-0.29  (HEATER HEAD HEIGHT)

(PURGE POSITION)
(PURGE START ON)
M200    (HEAD 1)
G4 P.25   (PAUSE)
M201    (HEAD 1)
M202    (HEAD 2)
G4 P.25   (PAUSE)
M203    (HEAD 2)
M204    (HEAD 3)
G4 P.25   (PAUSE)
M205    (HEAD 3)

M200    (HEAD 1)
G4 P.25   (PAUSE)
M201    (HEAD 1)
M202    (HEAD 2)
G4 P.25   (PAUSE)
M203    (HEAD 2)
M204    (HEAD 3)
G4 P.25   (PAUSE)
M205    (HEAD 3)
m99
(PURGE END)
%

Title: Re: Mach4 Variable Counter
Post by: Ya-Nvr-No on October 21, 2015, 10:09:47 PM
how about creating an ireg variable (like 500) then write the new increment to it using a mcode, same as you would a parts counter routine.

Code: [Select]
function m60()
local inst = mc.mcGetInstance()
local counter = mc.mcCntlGetPoundVar(inst, 500);
counter = counter +1;
mc.mcCntlSetLastError(inst, 'Counter # ' .. tostring(counter));
mc.mcCntlSetPoundVar(inst, 500, counter); --saves it to the ireg variable
end

if (mc.mcInEditor() == 1) then
    m60()
end
Title: Re: Mach4 Variable Counter
Post by: chris@wortz.com on October 22, 2015, 07:58:08 AM
Ok, I understand your code, now I have to get the placement part understood.  The code you posted, where would I put that, since it would not work in my g code routine?  This is where I am getting lost on all the posts, trying to clarify the location of some of this stuff.  Thanks!
Title: Re: Mach4 Variable Counter
Post by: Ya-Nvr-No on October 22, 2015, 09:25:47 AM
in the "profile's" Macro Folder and also, mach4 has to be restarted to let it compile the group of mcs scripts into a common compiled script of all the files in that folder.
Title: Re: Mach4 Variable Counter
Post by: chris@wortz.com on October 22, 2015, 10:54:40 AM
ok, is there any naming convention that I should use? Or just add another file to that folder names Mymacros.mcs?
Title: Re: Mach4 Variable Counter
Post by: Ya-Nvr-No on October 22, 2015, 11:33:34 AM
it's an M code, in this case I called it m60
you can try Mymacros.msc but i doubt that mach4 will let you use that in your gcode program, but Ya-Nvr-No
Title: Re: Mach4 Variable Counter
Post by: chris@wortz.com on October 24, 2015, 07:41:22 AM
I created M60.mcs with the following code.

function m60()
   local inst = mc.mcGetInstance()
   local counter = mc.mcCntlGetPoundVar(inst, 500);
   mc.mcCntlSetLastError(inst, 'Counter # ' .. tostring(counter));
   mc.mcCntlSetPoundVar(inst, 500, counter); --saves it to the ireg variable
        SetOemDRO(dro1501,counter)
end

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

I created a g code file with the following code

#500=1

G91 G21
F160

m98 P1000 l5
m98 P1000 l5

G0x2
G90
G0z50
m60
M30
%

o1000
#500 = [#500+1]
G0x-12.700  (Move - 1/2 inch each increment)
#500 = [#500+1]
G0x-12.700  (Move - 1/2 inch each increment)
M60
m99
%

I created a dro on screen and named it
dro(1501)

Why doesn't it update?
Title: Re: Mach4 Variable Counter
Post by: Ya-Nvr-No on October 24, 2015, 09:56:17 AM
your mixing mach3 code with mach4 code for one thing
cool now your doing the counting in the gcode and is fine but you dont need the m code now you can use the plc script to update the DRO

but to set a screen =scr control you have to use the mach4 command
practice and read, read, read everything, there is so much to learn and explore.

this is closer to what you need.
scr.SetProperty(dro1501, 'Value', tostring(counter));

did the history box update with the correct value?

Note: Surprised no one noticed/commented that the pound variable "500" is not an ireg variable   :-X (Kind of my way to test observers)  :o

Title: Re: Mach4 Variable Counter
Post by: Ya-Nvr-No on October 24, 2015, 10:15:48 AM
#500=1
should be set to 0
as your first line in the sub increments it

but also forgot to add this image to show, it increments and displays

Note: Did find if I tried single stepping though the code mach4 crashed,  ??? always something
Title: Re: Mach4 Variable Counter
Post by: dude1 on October 24, 2015, 03:44:56 PM
it must be getting cold over your way Ya-Nvr-No your back
Title: Re: Mach4 Variable Counter
Post by: chris@wortz.com on October 25, 2015, 08:14:48 AM
Ok, I understand that, and I do show my info in the history line at the bottom, too.  But, how about making a dro or some kind of larger text field on screen
that I can put that value in as it increments?
Title: Re: Mach4 Variable Counter
Post by: Ya-Nvr-No on October 25, 2015, 08:22:02 AM
yep you can do that, I just showed you how I have one of my screens set up like.
Title: Re: Mach4 Variable Counter
Post by: chris@wortz.com on October 25, 2015, 10:35:35 AM
Ok, I bailed on the dro, so I opted for a UserLabel,
Edited my screen, created a label, called is UserLable25, put UserLabel25 in the text of it,
changed my vb to setuserlabel(25,"test")

Didn't work either, any thoughts?  I guess I just don't understand the way that Mach is handling it?
Title: Re: Mach4 Variable Counter
Post by: Ya-Nvr-No on October 25, 2015, 07:34:36 PM
Not sure why you keep using Mach3 VB code.

Mach4 uses LUA for coding. I provided what you needed to do what you wanted,  just have to grasp the new coding process.

Either way you have to read, read, read and practice. Most everything you need is provided in the document section of Mach4, help "F1" in the mcLuaEditor or this Mach4 forum, full of examples.

Mach4/Lua will take hundreds of hours to grasp it all.

Good Luck & Have Fun
Title: Re: Mach4 Variable Counter
Post by: dude1 on October 25, 2015, 07:40:34 PM
chris have a read through Ya Nvr No posting here http://www.machsupport.com/forum/index.php/topic,27162.0.html and do a surch in the M4 section a lot of what you wont to know is there allready.

also you can do a google search on anything to do with .Lua there is 000 of pages

also look in the manual Docs folder in M4 root folder.