Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Sinusoidal motion from while loop?

    Scheduled Pinned Locked Moved Unsolved
    Gcode meta commands
    2
    2
    138
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • HebigTundefined
      HebigT
      last edited by

      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:

      sinwavemacro.JPG

      droftartsundefined 1 Reply Last reply Reply Quote 0
      • droftartsundefined
        droftarts administrators @HebigT
        last edited by

        @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

        Bed-slinger - Mini5+ WiFi/1LC | RRP Fisher v1 - D2 WiFi | Polargraph - D2 WiFi | TronXY X5S - 6HC/Roto | CNC router - 6HC | Tractus3D T1250 - D2 Eth

        1 Reply Last reply Reply Quote 1
        • First post
          Last post
        Unless otherwise noted, all forum content is licensed under CC-BY-SA