Hello Guest it is July 08, 2020, 01:35:32 AM

Author Topic: Flatten my G-code  (Read 3734 times)

0 Members and 1 Guest are viewing this topic.

Flatten my G-code
« 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.
Re: Flatten my G-code
« Reply #1 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.
Regards,
Ray L.

Offline BR549

*
  •  6,932 6,932
    • View Profile
Re: Flatten my G-code
« Reply #2 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
Re: Flatten my G-code
« Reply #3 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.
Regards,
Ray L.
Re: Flatten my G-code
« Reply #4 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.

Re: Flatten my G-code
« Reply #5 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.

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: Flatten my G-code
« Reply #6 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.

Bring on Lua

Cheers

Ian

Offline BR549

*
  •  6,932 6,932
    • View Profile
Re: Flatten my G-code
« Reply #7 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
Re: Flatten my G-code
« Reply #8 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.

Re: Flatten my G-code
« Reply #9 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.