Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: sittinduck on July 08, 2013, 10:42:14 AM

Title: Flatten my G-code
Post by: sittinduck on July 08, 2013, 10:42:14 AM
Is it possible Mach3 show a "flattened" view of my G-code program?  For example:
- all subroutines expanded
- all variables resolved
- all comments retained
- all calculations and variable assignments removed

The attached trace shows an example.  I think it is easy to reads.
Title: Re: Flatten my G-code
Post by: HimyKabibble on July 09, 2013, 02:30:17 AM
In a word: "No".

What you suggest is not even possible, in a general sense, as variables and value derived from them can, and often do, change value as a program runs.

Regards,
Ray L.
Title: Re: Flatten my G-code
Post by: BR549 on July 09, 2013, 04:56:20 PM
I am not even SURE what you are asking for. ??

 With Mach3 NOT having conditional G code AND does NOT run in real time it resolves all the calculations for parametrics on loading the G code. THAT is why you can see the toolpathing on screen.

Are you asking for a 2D view that is flattened in Z ?

(;-) TP
Title: Re: Flatten my G-code
Post by: HimyKabibble on July 09, 2013, 07:23:53 PM
Terry,

He's asking for the code itself to be displayed "flattened" - all parameters resolved to numeric values, all subroutines "un-rolled" into in-line code, etc.  One of your parametric programs would end up being 100,000 lines long!

Regards,
Ray L.
Title: Re: Flatten my G-code
Post by: sittinduck on July 10, 2013, 09:02:29 AM
That's correct.  I'm fine with 100,000 lines G-code if it's auto-generated by a Mach3 pre-processing step and the comments are passed though to the flatten G-code.   The only time this wouldn't work is when my G-code calculations rely on variables that are set by Mach3, like the G31 probe variables #2000, #2001, #2002.    Also, flattened G-code programs will allow the Mach3 feed hold feature to function properly inside subroutines. 

Would anyone else find this useful?

I have it working in VBA, but there's nasty bug in CB calling recursive function that erases my CB local variables.  It's like there's a maximum depth for CB recursive function calls, beyond that it starts overwriting the stack and erases some CB local variables.  Very strange.  That's why I wish the Mach3 people would do it.

Title: Re: Flatten my G-code
Post by: Ya-Nvr-No on July 10, 2013, 09:20:40 AM
Try posting your VBA and the CB code, someone might see what the issue is with CB and fix it.

Does have some interesting possibilities.
Title: Re: Flatten my G-code
Post by: stirling on July 10, 2013, 11:51:32 AM
The stack frames in CB are incorrectly implemented with regards to local variables and so recursion is somewhat flawed to say the least. I contacted Cypress way back in 2008 about this but with no joy. See this post (http://www.machsupport.com/forum/index.php/topic,6105.msg40665.html#msg40665).

Bring on Lua

Cheers

Ian
Title: Re: Flatten my G-code
Post by: BR549 on July 10, 2013, 11:34:27 PM
OK I think I see, he wants a full on parametric file converted into a standard Gcode file(;-) You are right that is NOT going to happen in MACH3 with CB.

And yes I have SOME parametrics that generate OVER 1,000,000 lines of code. The Cam Grinder Code is the worse.  MACH3 is not really happy with it BUT it will run it without errors.

It MAY/might/almost be possible as a wizard but it would take some head scratching converting all the values before posting the code and would take forever to run.

(;-) TP
Title: Re: Flatten my G-code
Post by: sittinduck on July 11, 2013, 12:47:04 PM
Attached is a code sample that you can paste into the Mach3 script editor to see the bug.  The "Now you see it... Now you don't" is explanation enough as to what's going on.  I adapted this sample code from "Ready-to-Run Visual Basic Algorithms" to do the G-code expression evaluatior.  Then wrote a complete VBA that work like a giant calculator on the G-codes to transform and make easier to read... even though it could end up generating thousands more G-codes, I think the flattened G-code much easier to read.

Title: Re: Flatten my G-code
Post by: sittinduck on July 29, 2013, 01:17:58 PM
I recommend using VBScript if your program makes recursive function calls.  You access the VBScript engine from Cypress BASIC with:
Set sc = CreateObject("MSScriptControl.ScriptControl")
And load your VBScript from a text file into the MS Script Control and run it.

And you can enable JIT Debugging to use the Visual Studio to debug your VBScripts.

In Cypress BASIC I found that the recursion hack/fix only works for numeric types, not Strings and Objects.