Machsupport Forum
Mach Discussion => VB and the development of wizards => Topic started by: moorea21 on December 24, 2010, 11:40:31 AM
-
Hi,
As part of what I'm doing, it looks like I need to write a macro that I will call from Gcode quite often. maybe 40 times a second... ie one call on each line.
My question is, how long (in microseconds I guess) does it take to call, execute and exit from a macro? The macro will only be about 5 lines long.
Any ideas?
Thanks, Richard B
-
The macro will move an axis to 3 different positions in sequence, at full speed.
-
It all depends on how busy the CPU is as each macro is called. Also NOTE using a macro there is NO garranty that all the calls will stay in synced. The basic VB loop only cycles at 10 cycles per sec IF it has time to get it all done in one loop then maybe ,maybe not.
Rememeber Mach is a GCODE machine motion controller it processes basic machine GCODE very well. Using it ouside of those parameters and you are pretty much in unknown territory.
From what I see you have pretty extreme paramaters to follow machine wise. MOve an axis to 3 sequential positions up to 40 times per sec at full speed AND process the macro up to 40 times per sec when the basic macro loop is 10 cycles per sec.
HECK give it a whirl and let us know if it works, (;-) TP
-
At the moment, the gcode runs at about that speed, with one command for the axis in question on each line. But there are god reasons to use a macro, related to file size... it's a bit more involved than that. The other alternative would be to use a supplementary output pin on my controller to trigger a picaxe microcontroller to perform the 3 positions thing.
I didn't know that macros might not be executed in the order they are written in.
Does anyone know a way around that?
-
Re my last post : - I'm assuming when you say 'NOTE using a macro there is NO garranty that all the calls will stay in synced" you mean that they could be executed in the wrong order? Could the problem be solved by adding
While IsMoving()
Sleep 10
Wend
into the macro, so that the cpu is likely to be free, and no other axes would move at the same time, so no sych problems?
-
Re "The basic VB loop only cycles at 10 cycles per sec"... does that mean you only have 1/10th of a second to execute the whole macro?
-
You don't need "Sleep 10" inside the loop. an empty IsMoving() while loop will just loop until IsMoving() = false.
-
Re "The basic VB loop only cycles at 10 cycles per sec"... does that mean you only have 1/10th of a second to execute the whole macro?
Basically, yes. The number of cycles depends on the macro. A slow running macro may only be able to execute 5 times per second. As long as the macro can finish in less than 1/10 of a second, the best you can hope for if 10 cycles per second. Brains are much faster, but I don't think you can do what you want to do in brains.
-
Not familiar with brains... I like the idea of something much faster than a macro, though.
The macro would be basically:-
While IsMoving()
Wend
Code G01 A2.5
Code G01 A0
Code G01 A1.7
That's all...
-
each time a macro is called it is opened in its own thread. It is also known that mach can skip over open threads that take too long and the results fall out of exact sync. I have also seen where a data loop was skipped over but showed up several cycles later.
Mach VB macro system is not perfect BUT works ok inside of what it was designed for.
CAN you design the system to RUN from straight Gcode? Mach does that part very well and fast.
Brains last I heard scanned at 10hz as well. the internals are much faster but IF you have to gather/scan data it will be at 10 cycles per sec as well.
OK looking at you last message IF you are just doing basic Gcode WHY wash it through a macro??? Could Gcode SubProgram work in place of the macro call?
Just a thought, (;-) TP
-
Erm...
not heard of gcode sub program. Can you direct me to any documentation on that? The documentation doesn't have a search facility. Thanks
-
I am not sure there is a good example or explaination in the manual.
But basically it is a process that allows you to call a subset of Gcode from inside a running Gcode program from somewhere else in the program OR from an outside source stored away as a reference.
IF you could post your Gcode needed in the order it is needed maybe someone here can help you sort out what you may need. There are people here that are very good at that sort of thing
(;-) TP
-
okay, thanks. And merry christmas to you! I'm following another thread on the same subject, I'll cut n paste the code suggested by someone there, for anyone following this thread to see:-
Sub run101()
While IsMoving()
Sleep 10
Wend
Code “G1 A2.5”
Code “G1 A0”
Code “G1 A1.7”
end sub
G01 X2 Y0 run101
G01 X9 run101
G01 X14 run101
G01 X15 Y5 run101
G01 X0 Y4 run101
G01 X1 run101
Thanks 5ms for that.
Does this look right? Syntax wise?
Thanks,
Rich
-
I am not sure what you have going with teh code you posted But I get the general idea of what you are trying to do. You application is really simple and really you won't save time either way. The straight Gcode would be the best approach .
Straight Gcode Example:
F20
G01 X2 Y0
A2.5
A0
A1.7
G01 X9
A2.5
A0
A1.7
G01 X14
A2.5
A0
A1.7
G01 X15 Y5
A2.5
A0
A1.7
G01 X0 Y4
A2.5
A0
A1.7
G01 X1
A2.5
A0
A1.7
M30
%
SUB program approach: THe M98 calls the sub by the o word and name o100 the L paramter tells how many times to run the sub. At the end of the sub the M99 returns to the call line then advances to the next line. At teh end of the program the M30 ends the program
F20
G01 X2 Y0 M98 P100 L1
G01 X9 M98 P100 L1
G01 X14 M98 P100 L1
G01 X15 Y5 M98 P100 L1
G01 X0 Y4 M98 P100 L1
G01 X1 M98 P100 L1
M30
o100
G1 A2.5
G1 A0
G1 A1.7
M99
%
Hope that helps, (;-) TP
-
Thanks, yes, that helps a bit. Part of the reasoning of the subroutine was because it makes the whole file size smaller than putting 2 extra lines into the gcode all the time. My maximum gcode file size ( I forget what it was) caused Mach to crash. I'll try the subroutine when the festivities are over, and post the results...
-
You can also do it one more way to save a little more space. It is the remote call method. You store your sub in the sub directory then call it with the M98.
Save the sub as a program file:
(Sub 100.tap)
o100
G1 A2.5
G1 A0
G1 A1.7
M99
%
Then you Gcode file would look like this:
F20
G01 X2 Y0 M98 C:\mach3\sub\ProgramName.tap
G01 X9 M98 C:\mach3\sub\ProgramName.tap
G01 X14 M98 C:\mach3\sub\ProgramName.tap
G01 X15 Y5 M98 C:\mach3\sub\ProgramName.tap
G01 X0 Y4 M98 C:\mach3\sub\ProgramName.tap
G01 X1 M98 C:\mach3\sub\ProgramName.tap
M30
(;-) TP