Calculating in Marlin gcode ... Possible?

Hello and an urgent question for me…

Is it possible to do some calculations within the marlin gcode? Means I have a variable parameter value near at the start of the gcodes and in dependence of this parameter some gcode commands change.

If no … o.k.

If yes …do you have an/some example(s) for me how to modify the gcode please?

 

Greetings Ernst-Dieter

I don’t believe so. I think the “big boy” gcode interpreters like LinuxCNC can run gcode with variables and even procedures.

An alternative for you might be to implement a templating system using something like ruby and erb.

https://www.stuartellis.name/articles/erb/

(I’m sure there are other templating systems, thats just one that came to mind that I’ve used in the past)

no, it can’t calculate
it only supports 5 slots for gcode macros


/**
 * G-code Macros
 *
 * Add G-codes M810-M819 to define and run G-code macros.
 * Macros are not saved to EEPROM.
 */
//#define GCODE_MACROS
#if ENABLED(GCODE_MACROS)
  #define GCODE_MACROS_SLOTS       5  // Up to 10 may be used
  #define GCODE_MACROS_SLOT_SIZE  50  // Maximum length of a single macro
#endif

1 Like

Thanks for the macro hint!

Can you give me an example how to do something useful with these macros … sorry I am a newbie with gcode programming…

 

Honestly i haven’t obvious use case for those macros. May be it’s some case when you need a sequence of commands that you can change without regenerate main gcode file used in this file

Nevertheless thanks