After PRB_GCODE_END definition is complete
The macro value must be G92 X-26.50 Y23.50 Z15.00
Do you have any idea how to put these variables into the definition when I defining the PRB_GCODE_END ?
The correct answer depends on how you are using PRB_GCODE, so please post your entire sketch. Please follow the forum guidelines for posting code, using code tags.
aarg:
The correct answer depends on how you are using PRB_GCODE, so please post your entire sketch. Please follow the forum guidelines for posting code, using code tags.
[color=#202124]thanks i updated my problem[/color]
I do not think there is a way to put a calculated value into that #define statement, just do the calculations and insert the answer yourself. If you are intending to do the calculations at run-time it will not work anyway, because the resulting text string is being stored in program memory, which cannot be altered at run-time.
I do not think there is a way to put a calculated value into that #define statement, just do the calculations and insert the answer yourself. If you are intending to do the calculations at run-time it will not work anyway, because the resulting text string is being stored in program memory, which cannot be altered at run-time.
ok thanks,
String zxyPRBgcend = "G92 X-" + String(float(XOFF)) + " Y" + String(float(YOFF)) + " Z" + String(float(ZOFF)) + "\n";
Could there be a way to define the variable zxyPRBgcend with #define in this definition? For example: #define PRB_GCODE_END zxyPRBgcend
xyPRBgcend with #define in this definition? For example: #define PRB_GCODE_END zxyPRBgcend
No . That is simply the best answer i can come up with. You have to understand what '#define' actually does.
As i understand, the pre-compiler, replaces the keyword anywhere within the sketch with whatever 'literal' value (or data, basically whatever comes right after the keyword on the same line)
A variables value is typically unknown at pre-compile time, and although the optimizer may decide that it is known, that step only happens afterwards.
Now of course one could do #define zxyPRBgcend = "G92 X-" + String(float(XOFF)) + " Y" + String(float(YOFF)) + " Z" + String(float(ZOFF)) + "\n";and then create an alias by #define PRB_GCODE_END zxyPRBgcendbut why ?
i use #define to create better overview within my program and to create values which i do known at compile time, but that i may use throughout the program and i define them all at the beginning of my program so i don't need to look for them. When reducing memory consumption, sometimes the optimizer may need some extra help. Consider this on an ATtiny13
david_2018:
Why do you need to calculate these values at run-time?
Hello there,
In this project, the Origin point is determined for the XYZ probe used in the CNC machine, the offset distances for the probe used for the probing process and the diameter value for the insert may vary. In order to send these changes to the software and Gcode system, changes are required during the program's running.
You cannot do this using the enqueue_and_echo_commands_P() function, that requires a string stored in program memory, which cannot be changed at run-time. I'm not familiar enough with Marlin to know if there is an equivalent command that takes a string stored in ram, you may want to ask in a forum that is specific to Marlin, but in that case you would not use a #define to create the string so do not confuse people by asking the wrong question.
In order to send these changes to the software and Gcode system, changes are required during the program's running.
Then using #define is not the proper way to do this. If you want to retain the overview you could make the desired value as a return value to a function, though using the 'String' class may get you into trouble on an AVR (so using char array is recommended.)