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

    Save and recall variables from file

    Scheduled Pinned Locked Moved Solved
    Gcode meta commands
    2
    3
    202
    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.
    • MaxGyverundefined
      MaxGyver
      last edited by MaxGyver

      In my CNC setup, the spindle control value does not linearly correspond to spindle speed. I have a macro that slowly dials in the control value until the desired spindle speed is reached. I would like to save both values, spindle speed and corresponding control value to a .csv or macro file. My goal is to recall these values to get the rough spindle speed from the file and only do the fine adjustment with the "dial in"-macro

      -Cheers
      Max

      OwenDundefined 1 Reply Last reply Reply Quote 0
      • MaxGyverundefined MaxGyver marked this topic as a question
      • OwenDundefined
        OwenD @MaxGyver
        last edited by

        @maxgyver
        You can use
        echo >>filename and echo >filename to create and append to a file.
        Then just send the commands you want to run

        e.g.

        echo >>"mymacro.g" M3 S{spindles[0].current} ;create/overwrite file
        
        echo >"my macro.g" "G1 X0 Y0 Z{move.axes[2].max} ; append to file
        
        
        MaxGyverundefined 1 Reply Last reply Reply Quote 0
        • MaxGyverundefined
          MaxGyver @OwenD
          last edited by MaxGyver

          @owend thank you, it works flawless! 😊 👍

          To whomever it might concern/interest:

          I have a CNC-setup where the spindle speed is controlled by manually adjusting a potentiometer.
          In order to control the spindle speed via the duet, I have built a contraption that uses a small RC servo to turn the potentiometer for me.

          I have created some global variables for better debugging. But the macro will also work with normal variables. But these have to be defined!

          my "create lookup macro":

          echo >>"lookup.g""" ;create lookup.g
          M280 P0 S0	;reset servo position
          G4 S1	;wait for servo
          M80	;turn on Power
          G4 S1	;wait for power
          set global.servo=0	;reset servo position
          M3 P0 S650	;switch on spindle
          G4 S2	;wait for spindle to get up to speed
          
          echo "LookupTable START"
          while global.servo<=180 ;repear until servo arm is at 180°
           if spindles[0].active-fans[1].rpm>1 || spindles[0].active-fans[1].rpm <-1 ; the loop is repeated as long as the difference between spindles[0].active (set RPM) and fans[1].rpm (measured RPM) >+-1 RPM
            set global.servo={global.servo+((spindles[0].active-fans[1].rpm)/100)} ; set global.servo depending on the difference between spindles[0].active (set RPM) and fans[1].rpm (measured RPM)
            M280 P0 S{global.servo} ; use global.servo to set servo position
            G4 S0.5 ;wait for servo and spindle to get to new RPM
           else ;if the difference between spindles[0].active (set RPM) and fans[1].rpm (measured RPM) <+-1 RPM
            echo >>"lookup.g" "if spindles[0].active >= "^spindles[0].active^"" ;append to lookup.g as a new line
            echo >>"lookup.g" " M280 P0 S{"^ global.servo ^"}" ;append to lookup.g as a new line
            G4 S1 ;wait
            M3 P0 S{spindles[0].active+25} ; increase spindle speed by 25RPM
          echo "LookupTable END"
          M5 ;turn off spindle
          M280 P0 S0; reset servo position
          
          1 Reply Last reply Reply Quote 0
          • MaxGyverundefined MaxGyver has marked this topic as solved
          • First post
            Last post
          Unless otherwise noted, all forum content is licensed under CC-BY-SA