Sinusoidal motion from while loop?
-
I was playing with this macro that (i think) gives G1 commands along a sine wave.
In practice the amplitude of the peaks decreases over time and approaches zero.
I think I'm missing something simple about why this is happening.
Any help is appreciated!
G91 var x = 0 var y = 0 while var.x <10 set var.x = var.x + 0.05 set var.y = 2*sin(10*var.x) G1 X{var.x} Y{var.y} F600 ; echo >>"sinewave_x.txt" var.x ; echo >>"sinewave_y.txt" var.y ; echo >>"x_pos.txt" move.axes[0].machinePosition ; echo >>"y_pos.txt" move.axes[1].machinePosition
The sin wave plot and the recorded machine positions:
-
@hebigt I think it is because you are using G91, ie relative coordinates, for moves. X is increasing each loop, so it moves the distance described by var.x not to that actual position. The first time it moves a distance of 0.05mm, next it moves 0.1mm (ie to X0.15), then 0.15mm (ie to X0.3) etc. My mental maths isn't good enough to know what will happen to var.y if you switch to absolute coordinates (G90), but I'm sure there's a simple way around that, too.
Ian