G-code is the most hilariously bad language. Keywords are G + a number, e.g. G01, with wildly different effects, varying arg lists and no standard. E.g. G01 move to position, G20 set the machine units to inches. Its often stateful.
Obviously its coz its old and works, but i chuckle everytime i have to look up the codes at how comically awful it is compared to anything else i see
The g-code variant my machines use contains most of the control structures of modern programming languages. It has variables, comparisons, loops, subroutines, the codes are all fairly straight forward and honestly a lot of g-code is produced automatically with CAM software rather than being written manually these days.
It's a simple language, you don't have to memorize the codes and you end up memorizing the few you use most often anyway.
Honestly the actual math and figuring out the toolpaths for your machine ia far harder than writing the g-code for it.
Have you been able to arrive at any clear repeatable structure in your macro programming, or is it just ad-hoc make it fit for this job and this machine?
Asking, because I am trying to level up cnc programming to "normal" programming.
Not so much no. About the closest i come is reusing the same program for pieces that are identical. This rarely happens.
The cam software i use does come with a few handy baked in things. Stuff like automatically lowering the feedrate for corners under a certain radius or for setting up z-level ramps.
There's a couple i can think of being handy. Functions for automatically decreasing feedrates at certain axis loads or horsepowers would be nice.
I think it would come down to something more like a handy library of functions for little things like that rather than anything really repeatable. Even that would likely be specific to whatever machine you use though.
Looks like more of a programming language than a list of commands like g-code. That's not a good design in my opinion. I mean do you expect CNC machines and CAD programs to embed JavaScript interpreters? Or does it export to g-code? In which case it isn't really an alternative.
Let's do a web site programming analogy(weak but relatable), because JS is now a mature programming language with advanced interpreters. This was not the case back when JS was used to make text dance and a few other useful ad-hoc solutions.
-Early web days with just html is like plain g-code spit out from cam systems.
-Early javascript is like macro options available on industrial cnc[1][2][3].
-Mid years javascript is where cnc macro program is heading, isolated shops doing some awesome things but no industry wide adoption of a coherent system.
-Late years javascript is where cnc macro programming needs to be if we want proper revision control and all the other benefits that normal programmers have afforded themselves.
Which brings us to real digital twins(monozygotic, not the fraternal state of the art), a single source of truth digital file should manifest as both a real world part on the shop floor and a virtual object in the top floor to be used by all the departments.
To close the analogy, like nodejs affords developing on the backend and the frontend with the same language.
What would a good G-Code variant look like? For all its flaws, it's pretty good at encoding the exact thing you want the CNC machine to do and while there certainly are different post-processors for different machines and in most cases they're not optional, it's also not like they're entirely different.
I think of G-code as ASM. For high-performance work you might write code differently for different (related) machines, but it's still a pretty OK compilation target.
A good G-Code variant would roll up the un-rolled loops and separate the geometry data from the tool config data. This is what the view of a CAM IDE presents, G-Code source can be structured the same. If you change the semantics on some of the syntax you get lexically scoped blocks, macro-b subsystem which has existed for decades needs to be fully utilized for this to happen.
A fully implemented system would provide the CAM GUI engineer and the CNC CLI machinist to work on the same file, skipping post-processing entirely.
And, finally implement what was originally envisioned but not possible on even the most powerful mainframes of the late 50's: https://youtu.be/ob9NV8mmm20
Eventually, something actuates a servo, and servos don’t understand iteration. Do you agree eventually something with g-codes level of detail must exist (even if it’s just unspecified internal commands)? If so, do you agree you’re just advocating for that layer to be part of the machine?
That's because the above would be highly wasteful on a slow serial link, like the ones gcode was made on and for.
That said, I bet vim syntax highlighting could get you most of what you want. Color code movement, configuration, values, maybe display the toolhead status and position at your current line in the status bar...
Well, a gcode file is usually entirely composed of "move" operations. I'm adding one extra character on a 8 characters (at a minimum) line, for an increase of 12.5% at the worst case.
A CNC moves with speeds on the mm/s range. So does a 3D printer (unless you ask for larger movements, but those take less codes/s). They also have a precision on the 100's of µm, but let's push it down to 10's here so we overestimate things by an order of magnitude.
That means they'll need around 1000 codes/s, with a minimum of 64kbps on the 8 character case, or 72kbps with my codes. I don't think there is any serial interface chipset on the market that can't do 512kbps even on a 100's of meters long cable. Not to say that everything nowadays runs over USB anyway.
The gcodes are a leggacy that isn't needed anymore. And since both sides of the CNC link are composed of overpowered computers doing anything on software, the only reason it didn't change already is because nobody bothered to do something better. I'm not much bothered by them either so, I'm not jumping over it, but it is suboptimal.
Obviously its coz its old and works, but i chuckle everytime i have to look up the codes at how comically awful it is compared to anything else i see
https://en.m.wikipedia.org/wiki/G-code