- Posts: 63
- Thank you received: 0
Macro subroutines in LinuxCNC
I found in Gcode documentation that the block of "N120 G65 X2.5 Y3.0 Z5.4" will call a macro subroutine and pass the arguments of X,Y, Z. According to Gcode documentation I can pass arguments to the macro through a system that correlates the argument words to local variable values. The X value will appear as local variable #24, Y as local variable #25, and Z as local variable #26. I am looking to write some general purpose macros and want to use this type of a macro call with arguments.
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
linuxcnc.org/docs/2.7/html/gcode/m-code.html#mcode:m100-m199
or Linuxcnc can do O<subs> that can be passed up to 30 arguments as local parameters (local vars #1-30)
linuxcnc.org/docs/2.7/html/gcode/o-code.html#ocode:subroutines
But I am pretty sure that N(number) codes are ignored by Linuxcnc, and I don't think X,Y, and Z are ever used to pass parameter information, only positioning.
Please Log in to join the conversation.
Looking up information on GCode macros, I came across the following website.
www.cnccookbook.com/CCCNCGCodeSubprograms.htm
where they talked about programing macros. While I can write a subprogram to do the special machining I want, I would have to load values into local variables before calling the subprogram. This would not be as clean as being able to call a macro and include whatever arguments I want on the same line like in the example on the CNCCookbook website. Yes I know that I can do a o<sub> and include up to 30 arguments afterwards, but then I would have to include all the arguments whether I would be using them or not. Being able to included named parameters would be a lot cleaner and I would only have to include the parameter I would be using. For any of you older folks, this would be like the difference between include input data in a datafile versus using namelists in fortran.
Please Log in to join the conversation.
JT
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
jwsigler wrote: forget about the N number, the issue is does Linuxcnc support macros with arguments?
Looking up information on GCode macros, I came across the following website.
www.cnccookbook.com/CCCNCGCodeSubprograms.htm
where they talked about programing macros. While I can write a subprogram to do the special machining I want, I would have to load values into local variables before calling the subprogram. This would not be as clean as being able to call a macro and include whatever arguments I want on the same line like in the example on the CNCCookbook website. Yes I know that I can do a o<sub> and include up to 30 arguments afterwards, but then I would have to include all the arguments whether I would be using them or not. Being able to included named parameters would be a lot cleaner and I would only have to include the parameter I would be using. For any of you older folks, this would be like the difference between include input data in a datafile versus using namelists in fortran.
Yes subs can have arguments. They can use their own local parameters, and or use global parameters and named parameters. (I don't know much about programming so I really don't understand the last half of your question. To pass 2 arguments(20 and 15.25) to a sub program called "sub" you would call it like this.
Please Log in to join the conversation.
Thanks.
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
linuxcnc.org/docs/html/gcode/overview.html#gcode:parameters
But don't let me discourage you from writing macro call support for Linuxcnc. More features/improvements are always welcome. I was just trying to point towards possible workarounds.
Please Log in to join the conversation.
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
o<sub> call (center X)[1.0] (center Y)[3.0] (diameter)[0.45]
(alternatively global or global named parameters don't even need to be passed as arguments they can just be accessed directly by the macro)
have you looked at ngcgui? It can be very useful, and it's subs are useful examples as well.
Please Log in to join the conversation.
JT
Please Log in to join the conversation.
