Beginners question - conditional loops in gcode

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Beginners question - conditional loops in gcode

Postby AndrewG » Fri Mar 19, 2021 6:10 pm

Hi, relatively new to all this but starting to move from cad/cam and MDI commands to writing simple gcode. Have mastered subroutines that make things more modular and structured, but now want to have a conditional loop ( do while or if then).

Am I right in my understanding that to do this I must dive into macros and all that C# offers? Also is it better practise to write a small macro to evaluate a condition and then return to my gcode file....or having made the leap, wrap the gcode into the macro and then you can simply call the macro rather than open and run s gcode file?

Background:
I am cutting different size tenons with a single gcode file. I use a spreadsheet currently to calculate the required variable values and then edit them into the gcode file before running. However I would now like to to simplify the data entry by doing more calculations and looping inside the gcode.....moving to macros seem a big step.
AndrewG
 
Posts: 6
Joined: Sun Mar 14, 2021 10:40 am

Re: Beginners question - conditional loops in gcode

Postby AndrewG » Wed Mar 24, 2021 10:37 am

OK going to try and answer my own question
UCCNC does not support gcode flow commands - if you want GOTO and DO..WHILE you need to dive into the world of macros and C# programming

However it does support: Simple Loops with Subroutines
A power of subroutines is that you can define the number of times the subroutine is to be run when you call it. That is the same as a simple DO... WHILE with incremental counter. So if your gcode is to face the material with parallel passes 40mm apart and you set a parameter (#4 =310 ) at the start for material width and want the 'pass' subroutine to be called n times where n is 310/40 rounded up ie, 8 times. Cool

Now the Gcode example I have uses the operators FUP and FIX - round up and down. UCCNC had FLOOR for round down, but no equivalent of FUP. I am sure there is some arithmetic voodoo like FLOOR[#4/40+0.5] possible to make this work.

Feel I am rediscovering the wheel here. If anyone can point me in the direction of good gcode techniques and examples compatible with UCCNC I would be grateful . It was reading CNCCOOKBOOK on FANC GCode that got me into this trouble!
AndrewG
 
Posts: 6
Joined: Sun Mar 14, 2021 10:40 am

Re: Beginners question - conditional loops in gcode

Postby ger21 » Wed Mar 24, 2021 11:34 am

I don't think that very many people write parametric g-code. Imo, it's only really useful for specialized production work.

I've never had the need for it in the 27 years I've been programming CNC machines, as I can program anything with CAD/CAM faster than I can hand write g-code.

If you want more power, or want to do things that you just can't with what UCCNC g-code allows, you can create VB or C# macros and call them as M codes.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2794
Joined: Sat Sep 03, 2016 2:17 am

Re: Beginners question - conditional loops in gcode

Postby AndrewG » Wed Mar 24, 2021 11:18 pm

Appreciate the reply Gerry. The fact you don't see this as necessary is a good indicator to me that I might well be barking up the wrong tree. As I only invested in the desktop version of VCarve, I have been dabbling in Gcode when I need to do bigger tasks like surface the spoliboard or a slab.

Anyway, haven't you got a new screenset to finish?...more important than answering naïve beginners questions. But much appreciated though.
AndrewG
 
Posts: 6
Joined: Sun Mar 14, 2021 10:40 am

Re: Beginners question - conditional loops in gcode

Postby opusmatt » Tue Mar 30, 2021 12:29 am

Hi Andrew and Gerry,

this is really important to me.

I have been working in with linux and moved more and more of my workflow to conditional gcode and it has becom the most efficient way to work directly with the machine without having to redraw and postprocesss files every little change and adjustment.

id be very keen to learn macros but not sure where to start.

alternatively might have to just sell off my uccnc gear and return back to linux

quite frustrated
opusmatt
 
Posts: 2
Joined: Mon Mar 22, 2021 10:29 pm

Re: Beginners question - conditional loops in gcode

Postby opusmatt » Tue Mar 30, 2021 12:33 am

ger21 wrote:I don't think that very many people write parametric g-code. Imo, it's only really useful for specialized production work.

I've never had the need for it in the 27 years I've been programming CNC machines, as I can program anything with CAD/CAM faster than I can hand write g-code.

If you want more power, or want to do things that you just can't with what UCCNC g-code allows, you can create VB or C# macros and call them as M codes.



can you give any pointers to where to learn the construction of these macros? please.
opusmatt
 
Posts: 2
Joined: Mon Mar 22, 2021 10:29 pm

Re: Beginners question - conditional loops in gcode

Postby Battwell » Thu Apr 08, 2021 1:29 pm

programming reference manual. in your main uccnc directory- documentation
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 884
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: Beginners question - conditional loops in gcode

Postby ger21 » Thu Apr 08, 2021 6:55 pm

Best thing to do is go through the included macros, and use the manual to decipher them. Feel free to ask and questions.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2794
Joined: Sat Sep 03, 2016 2:17 am


Return to Macros

Who is online

Users browsing this forum: No registered users and 1 guest