G code conditional execution (possibly looping) #309
Replies: 15 comments 72 replies
-
It is on my radar for macros... I know I possibly opened a can of worms by adding G65 (call macro) support, there are several inherent problems related to this that I am aware of. Conditional execution and looping is one set, error handling and reporting another - both can be overcome. It would be nice to hear about use cases that can be solved by G65 macro calls, especially those who would benefit from conditional execution and looping. Advanced probing with proper error handling is one? A bit of background: grblHAL is the only Grbl variant that I am aware of that supports variables (parameters) and expression in gcode as an option. When enabled G65 macro calls can be made a lot more flexible than with plain gcode. |
Beta Was this translation helpful? Give feedback.
-
Also, I personally don't think it is worth holding back GRBLHAL to maintain compatibility with plain GRBL senders. The sender developers that I know (bCNC updates for example) would be very interested in supporting more advanced features like this. As long as there is reasonable feedback to the sender that the controller is executing an sd or internal macro I think they will be generally supportive as it makes the whole package more interesting for users. |
Beta Was this translation helpful? Give feedback.
-
I have fixed some bugs (and hopefully not introduced some new ones), added a debugging comment and bit of documentation. |
Beta Was this translation helpful? Give feedback.
-
Can somebody write an example macro for ATC with linear tool magazine? Tell me the parameter settings also if required to be changed. My setup is getting almost ready so I will be able to test it soon. If ATC is not viable this way (macro), I have to use plugin with IOports where I am really weak (C language). |
Beta Was this translation helpful? Give feedback.
-
The latest edge version of ioSender now accepts flow control statements and will pass them on to the controller as-is. I have yet to add validation of any expressions related to those though. |
Beta Was this translation helpful? Give feedback.
-
Hi @terjeio
This line in your example ATC code doesn't set selected tool as current tool, instead it throws an "error:47 in Program file at line 8". I have also tried: |
Beta Was this translation helpful? Give feedback.
-
1.) Awesome! Cool to see someone utilizing the ATC macros. |
Beta Was this translation helpful? Give feedback.
-
I also noticed that in my board map file, I can't define more than 2 AUXINPUTs even though I have free pins available, while I can define more AUXOUTPUTs. This may not have relation with above issue as I am defining those pins first time. Any clues? |
Beta Was this translation helpful? Give feedback.
-
Hi @terjeio,
Further, I was thinking about some features that can help:
|
Beta Was this translation helpful? Give feedback.
-
hi @terjeio but I was hampered when I wanted to implement ATC. I myself use a cnc3018 whose board I have replaced with a nucleof446re here is what my $$ and $I+ look like $$ < $0=10.0 I've read this discussion from start to finish but I can't find how to set ATC correctly. like @karoria in the #309 (reply in thread) Can you explain to me the correct steps, and can be understood by lay people? I have done several things such as setting $341 to values 1,2 and 3 but still can't get newopt:atc to appear and I have also changed #define N_TOOLS 6 and #define NGC_EXPRESSIONS_ENABLE 1 but the results are still the same |
Beta Was this translation helpful? Give feedback.
-
Thought I give some feedback on my current attempt to use the macros... Spent the day getting to understand how everything worked together. My goal was/is to create atc macro to support the RapidChange ATC line of products. Since each product has a different spacing based on collet size I tried to create a script that would calculate X and Y for a specific tool position. This could would be used multiple times in the code (tool drop off and pickup location). Turns out we don't support nesting macros so calling a macro from a macro to get the co-ordinates didn't work. In this project there are many use cases where the ability to call a macro or subfunction would make things much cleaner... Open and Close the dust cover (done in different parts of the code) Check collet us mounted tightly or that collet came off for unloading (there is a IR sensor for this).... etc etc I'm going to write this as a top down approach copy and pasting the code for the different functions. Anyways my 2 cents worth.... |
Beta Was this translation helpful? Give feedback.
-
Testers wanted, must compile locally. Here is an example file that seems to run correctly, I am currently away so cannot verify on a machine - at least it runs to completion. |
Beta Was this translation helpful? Give feedback.
-
More than happy to try and refactor the toolchange script to use this new functionality.. Count me in |
Beta Was this translation helpful? Give feedback.
-
Not 100% sure if this is the correct discussion to ask this, but is there a way to write to a programmatically determined parameter? I see that you have added a built-in macro for reading a parameter value (G65P1Q[Param]), but I would love to have one to write a value (lets call it G65P2Q[Param]V[Value]). The reason is that I am making a RapidChange ATC style tool rack, but I don't want to reuse tool numbers, so I want to loop through my tool rack to find the slot to park the current tool, and for picking up the next tool. For this it would be lovely to have "arrays" I can iterate through, which could be defined by the starting parameter and the number of items, so that I could use a while loop, and then use the index to write back which tool is stored in that slot (debug, find available slot for tool)
#<tool>=#20; 20 is T parameter
#<index>=0
#<rack_start>=500
#<rack_size>=5
while [#<index> LT #<rack_size>]
#<slotTool>=G65P1Q[rack_start + index]
if [#<slotTool> EQ -1]
G65P2Q[rack_start + index]V[#<tool>]
(debug,Place T#<tool> in slot #<index>)
M99
endif
endwhile
(debug,Unable to find slot to store tool)
M99 My goal would be that params 500-504 would be dynamically set by the macros. I have currently solved this with a chain of if's, but the ability to write to a numbered param would just make it so much simpler P.S; It would also be awesome if it was possible to have M0 show any comment on the same line as a dialog to the operator (cncjs did this) M0; Place T#<tool> in slot #<index> P.P.S; Realized my P.S probably belongs in ioSender discussion 🤔 |
Beta Was this translation helpful? Give feedback.
-
Is it technically possible to store strings in parameters? I would like to provide the operator with a short description of the tool to load, but since the messages to operator to load/unload tools etc is inside macros, I have no way of passing the tool description to the location 🤔 I am considering writing a macro for this with the descriptions for all the tools in my library hard-coded, and do a huge if/then to print the correct message, but this seems a bit awkward and error-prone 😅 I could, however, quite easily modify my post processor to store tool descriptions in parameters if it was possible. I get that this might be a lot of work, so I am just asking if you think it would be technically possible before I might spend time figuring out how I might do something like this 😅 I think I might want to implement P.S; Yes, I do realize storing strings in parameters could be a memory-hog if used indiscriminately. So it would be up to the macro-developer to keep memory-usage in mind 😅 🙈 |
Beta Was this translation helpful? Give feedback.
-
I think these are the key things are are left to make the macro functions in GRBLHAL transformative for the platform - and this is currently the biggest difference between GRBLHAL and other platforms with branching macros like Reprapfirmware and linuxcnc.
Implementing this functionality in the controller is inherently difficult because of the buffered nature of the GRBL interpreter and the fact that it does not keep track of where it is in the execution. But I think that since the macro functions always have the complete g-code it might be possible to track the current line being executed and manage branching that way?
Just throwing the topic out there for discussion.
Beta Was this translation helpful? Give feedback.
All reactions