Hello Guest it is April 19, 2024, 11:48:57 PM

Author Topic: Mach4 Variable Counter  (Read 4605 times)

0 Members and 1 Guest are viewing this topic.

Mach4 Variable Counter
« 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)
%

Re: Mach4 Variable Counter
« Reply #1 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
Re: Mach4 Variable Counter
« Reply #2 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!
Re: Mach4 Variable Counter
« Reply #3 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.
Re: Mach4 Variable Counter
« Reply #4 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?
Re: Mach4 Variable Counter
« Reply #5 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
Re: Mach4 Variable Counter
« Reply #6 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?
Re: Mach4 Variable Counter
« Reply #7 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

Re: Mach4 Variable Counter
« Reply #8 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
« Last Edit: October 24, 2015, 10:18:51 AM by Ya-Nvr-No »

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Mach4 Variable Counter
« Reply #9 on: October 24, 2015, 03:44:56 PM »
it must be getting cold over your way Ya-Nvr-No your back