line movement macro
-
I'm working to characterize my home-made printer and made this little macro that drives the print head in a straight line from the current location. Parameters are the angle (degrees, not radians), the length of line, the max speed, and the number of round trips to make before stopping. I'm finding it useful for ferreting out odd sounds I sometimes hear when printing - like a vibration when moving at 25 +/- 1mm/sec and within 5 degrees of the X axis. Haven't root caused it, but I can repeat it at will with this tool.
; Macro for making short, repeated print head excursions on a line ; Typical usage M98 P"0:/macros/line_maker.g" A45 L30 S25 N2 ; CHECK INPUTS var angle = null ;angle of line, 0-360 degrees if exists(param.A) ; see if a parameter "A" was provided set var.angle = param.A else M291 P"Angle of line (param A) not provided. Cancelling macro." S0 T5 ; S0 means no buttons, t5 means wait 5 seconds and move on. M99 var len = null ;length of line, in mm if exists(param.L) ; see if a parameter "L" was provided set var.len = param.L ;length of line, in mm else M291 P"Length of line (param L) not provided. Cancelling macro." S0 T5 ; S0 means no buttons, t5 means wait 5 seconds and move on. M99 var speed = null ;max speed of travel, in mm/sec if exists(param.S) ; see if a parameter "S" was provided set var.speed = 60 * param.S else M291 P"travel speed (param S) not provided. Cancelling macro." S0 T5 ; S0 means no buttons, t5 means wait 5 seconds and move on. M99 var loops = 1 if exists(param.N) ; see if a parameter "N" was provided set var.loops = param.N ;max speed of travel, in mm/sec else M291 P"Number of roundtrips (param N) not provided. Useing default of 1." S0 T5 ; S0 means no buttons, t5 means wait 5 seconds and move on. ; Gather current position (endpoint 0) var X_0 = move.axes[0].machinePosition var Y_0 = move.axes[1].machinePosition ;Calculate other endpoint (endpoint 1) var X_1 = {var.X_0 + var.len * cos(pi * var.angle / 180)} var Y_1 = {var.Y_0 + var.len * sin(pi * var.angle / 180)} ;Loop while drawing the line while iterations < {var.loops} G0 X{var.X_1} Y{var.Y_1} F{var.speed} G0 X{var.X_0} Y{var.Y_0} F{var.speed}