conditional
-
Hi. Im playing a little with conditional gcode, and I have some questions:
1.- is there any "repository" of usefull macros created by users?2.- I have this Gcoe (machine is a corexy) . My objetive is that once the print is finished, the plate goes to the middle only if it is a small print. If it is a tall print, I lower down the bed a little more. So I wrote the macro calle lowerz.g:
if {move.axes[2].machinePosition <=20}
G1 Z200 F400
else {move.axes[2].machinePosition > 20}
G1 {move.axes[2].machinePosition+20} F400I tried it, the first IF seems to work, but not the else. For some reason when Z position > 20 the code is not executed. What Im doing wrong?
Thanks in advance
-
@tinchus said in conditional:
if {move.axes[2].machinePosition <=20}
G1 Z200 F400
else {move.axes[2].machinePosition > 20}
G1 {move.axes[2].machinePosition+20} F400Are any error messages shown on the console?
Try this:
if {move.axes[2].machinePosition <=20} G1 Z200 F400 else G1 {move.axes[2].machinePosition+20} F400
-
You have used a condition after "else"
Either just put the move code after "else" or use "elif" before your condition
The "else" part will run if all previous "if" sections have notif {move.axes[2].machinePosition <=20} G1 Z200 F400 else G1 {move.axes[2].machinePosition+20} F400
or
if {move.axes[2].machinePosition <=20} G1 Z200 F400 elif {move.axes[2].machinePosition > 20} G1 {move.axes[2].machinePosition+20} F400 else echo "this will never be true in this case"
-
-
@tinchus
I didn't notice you missed the axis in the second G1
G1 {move.axes[2].machinePosition+20} F400
Should be
G1 Z{move.axes[2].machinePosition+20} F400
-
@tinchus said in conditional:
is there any "repository" of usefull macros created by users?
See here: https://forum.duet3d.com/category/34/gcode-meta-commands
-
-
@owend jajajajajjajajajaja CANT BELIEve it!!!!!!!!!! THANKS!!!!!
-
-
-
@Tinchus, you also asked about a repository of useful macros. I believe there is one somewhere, but there are also some in the Cgode meta commands section of this forum.
I can share a couple of things I've been working on.
First is a reference of code snippits I've been building up as I figure things out.
; BUILD A FILENAME ;var outfile = "0:/macros/data/"^+state.time^".csv" ; This is the current time in seconds since the datum, a good unique filename ;TIME echo "current time ", state.time ; in readable format echo "current time ", +state.time, " in seconds since the datum" ; in seconds since the datum echo "Uptime ", state.upTime, "seconds" echo "millisecond fraction of up time, in msec = ", state.msUpTime echo "Uptime to the msec ", mod(+state.upTime,10000) + state.msUpTime/1000 , "sec" echo "Uptime to the msec ", state.upTime + state.msUpTime/1000 , "sec" ;To time an event less than 2/77 hours (9999sec) long: var start_time = mod(+state.upTime,10000) + state.msUpTime/1000 G4 P125 ; pause for 125 msec ; This line for testing, replace with your event to be times. var end_time = mod(+state.upTime,10000) + state.msUpTime/1000 var delta_t = var.end_time - var.start_time if var.delta_t < 0 ; this IF /ELSE is needed because of the mod function use in capturing the time. set var.delta_t = 10000+var.delta_t echo "elapsed time = ", var.delta_t, "sec"
I also have some macros I've written and would be happy to share
Z_probe _evaluation - Evaluate the repeatability of probe measurement in one location after a short move in a random direction and and return to the original place. You can set X and Y location and the number of times to repeat the probing. All data is written to a csv file.
Clear logfile - clears the logfile
line-maker.g - make a move of a specified distance in a specified direction at a specified sped and return to the starting point. repeat a specified number of times. Used to checkout odd behaviors or sounds on particular moves.
OK_CANCEL_checker.g - Collect user input during macro execution. This is a short macro Intended as a macro to be called from another macro. Posts an M291 blocking message. You pass it a parameter that becomes the message posted in the M291. Something like "select OK for option 1, or CANCEL for option 2" When the user responds a global variable called global.OK_CANCEL is set to either "OK" or "CANCEL". Then the calling macro can interpret the global variable and infer the user input. As far as I can tell, this is the best user input there is that works with both DWC and PanelDu.
Lots of other macros that are simple one liners like "move without homing", "clear heater fault", "allow cold extrude". These are useful when interfacing with teh PanelDue and when you can remember those darn gcodes.
-
@mikeabuilder those snippets sound wonderful! Why not throw them up somewhere on github so people can, uh, kibbitz?
-
@oliof - I'll do that and share with this forum in a new post when I get it in place. I'm a little scared of the kibbitzing part because I'm a poor github repo manager. My usual response to github requests for changes is to stop sharing things on github. Also, a lot of the macros I write are to get me over a specific small issue and then I don't use them much after that and my interest in spiffing them up kind of dies away. But I do try to put in a lot of comments to explain what I'm trying to do so they might be useful inspiration for other people to grab and run with.