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

    Declaring variables in config.g

    Scheduled Pinned Locked Moved
    Gcode meta commands
    3
    14
    615
    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.
    • OwenDundefined
      OwenD @Nightowl
      last edited by

      @nightowl999
      Your expressions in your condition should be enclosed in brackets.
      As you are using CNC mode, you would need to use curly brackets.

      if {state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}

      https://docs.duet3d.com/User_manual/Reference/Gcode_meta_commands#use-of-expressions-within-gcode-commands

      Also you are correct, it should be spindleRpm in both instances.
      You can check the correct syntax and work out which object model values to use by making use of the object model browser plugin in DWC.

      1648946894350-capture.png

      This will let you see the object model and drill down to get the info you need.
      If you select a value, the correct path can be copied to the clipboard using the copy button at top right.

      1648947327098-screenshot-2022-04-03-105251.png

      Nightowlundefined 1 Reply Last reply Reply Quote 1
      • Nightowlundefined
        Nightowl @OwenD
        last edited by

        @owend So the original line should be changed to this:

        if {state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}
              set {global.savedSpindleSpeed} = {tools[state.currentTool].SpindleRpm}
        ...
        

        ... or should the lower line be enclosed within a single pair of curly parentheses?

        As an aside, is "SpindleRPM" the same as "spindlerpm" and SPINDLERPM?

        Thanks

        Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
        I'm still on my learning curve, so take everything I say with caution!

        RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

        OwenDundefined 2 Replies Last reply Reply Quote 0
        • OwenDundefined
          OwenD @Nightowl
          last edited by

          @nightowl999
          No, you only need the curly brackets when doing a comparison using OR or AND
          This groups and separates the parts of the equations
          You don't need them when setting the value of the variable.

          if {global.A = global.B} & {global.B<global.C}
             set global.D = global.B
          
          if {global.A = global.B} || {global.B<global.C}
             set global.D = global.B
          

          You also need them when you must calculate something as part of a standard command such as using a variable in a speed setting

          G1 X100 Y100 F{global.D}
          
          Nightowlundefined 1 Reply Last reply Reply Quote 0
          • OwenDundefined
            OwenD @Nightowl
            last edited by

            @nightowl999 said in Declaring variables in config.g:

            As an aside, is "SpindleRPM" the same as "spindlerpm" and SPINDLERPM?

            No they are not the same.
            The object model values and variable names are case sensitive.

            1 Reply Last reply Reply Quote 0
            • Nightowlundefined
              Nightowl @OwenD
              last edited by Nightowl

              @owend Well, I'm definitely missing something, because the resume.g file doesn't restart the spindle, when I expect it should.

              This is the declared variable in config.g:

              global savedSpindleSpeed = 0
              

              This is my pause.g file:

              G1 Z{max(move.axes[2].userPosition+5,move.axes[2].max-5)}			; move the Z axis to a safe height
              if {state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}
              	set global.savedSpindleSpeed = tools[state.currentTool].spindleRpm	; save current spindle speed
              G1 X273.5 Y560 F2400								; move XY to a safe place
              M5										; turn the spindle off
              echo "Spindle speed saved at", global.savedSpindleSpeed, "RPM"			; spindle speed saved
              

              ...and this my resume.g:

              if {state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}
              	M3 S{global.savedSpindleSpeed}	; resume saved spindle speed
              G4 S1					; wait 1 second to allow the spindle to spin up
              echo "Spindle speed resumed at ", global.savedSpindleSpeed, "RPM"
              G1 R1 X0 Y0 F2400			; go above the paused XY position
              

              This should be easy with all the help I've had, but what have I missed..?

              Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
              I'm still on my learning curve, so take everything I say with caution!

              RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

              OwenDundefined 1 Reply Last reply Reply Quote 0
              • OwenDundefined
                OwenD @Nightowl
                last edited by

                @nightowl999 said in Declaring variables in config.g:

                Can you try this to ensure that the condition is being met.

                if {state.currentTool >= 0} & {tools[state.currentTool].spindleRpm >= 0}
                       M3 S{global.savedSpindleSpeed}	; resume saved spindle speed
                       G4 S1					; wait 1 second to allow the spindle to spin up
                       echo "Spindle speed resumed at ", global.savedSpindleSpeed, "RPM"
                       G1 R1 X0 Y0 F2400	
                else
                       echo "condition not met.  Spindle speed remains at " ^ tools[state.currentTool].spindleRpm ^  "RPM"
                
                Nightowlundefined 1 Reply Last reply Reply Quote 1
                • Nightowlundefined
                  Nightowl @OwenD
                  last edited by

                  I can, @owend, but running pause.g indicates the spindle speed of 0RPM is saved, not the 18,000RPM it's running at, so it seems to be an issue with pause.g?

                  Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                  I'm still on my learning curve, so take everything I say with caution!

                  RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                  Nightowlundefined 1 Reply Last reply Reply Quote 0
                  • Nightowlundefined
                    Nightowl @Nightowl
                    last edited by

                    @OwenD here we are, the text from the Console:

                    27/05/2022, 19:43:24 	M0
                    Printing paused at X128.8 Y168.9 Z64.0
                    Cancelled printing file 0:/gcodes/Calibration Toolpath.gcode, print time was 0h 0m
                    27/05/2022, 19:43:12 	Spindle speed saved at 0 RPM
                    27/05/2022, 19:43:10 	M25
                    Resume state saved
                    27/05/2022, 19:43:08 	Printing resumed
                    27/05/2022, 19:42:56 	M24
                    Error: in file macro line 14 column 63: meta command: array index out of bounds
                    27/05/2022, 19:42:52 	Printing paused at X125.6 Y125.8 Z65.0
                    27/05/2022, 19:42:40 	Spindle speed saved at 0 RPM
                    27/05/2022, 19:42:37 	M25
                    Resume state saved
                    27/05/2022, 19:42:29 	M32 "0:/gcodes/Calibration Toolpath.gcode"
                    File 0:/gcodes/Calibration Toolpath.gcode selected for printing
                    27/05/2022, 19:42:16 	File 0:/gcodes/Calibration Toolpath.gcode will print in 0h 3m plus heating time
                    27/05/2022, 19:42:15 	M37 P"0:/gcodes/Calibration Toolpath.gcode"
                    Simulating print of file 0:/gcodes/Calibration Toolpath.gcode
                    27/05/2022, 19:42:04 	G10 L20 P1
                    Origin of workplace 1: X97.00 Y94.00 Z67.00
                    27/05/2022, 19:41:37 	g1 x147
                    27/05/2022, 19:41:20 	g1 y84
                    27/05/2022, 19:41:06 	g1 y660
                    27/05/2022, 19:40:34 	Connected to weeble
                    

                    Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                    I'm still on my learning curve, so take everything I say with caution!

                    RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                    OwenDundefined 1 Reply Last reply Reply Quote 0
                    • OwenDundefined
                      OwenD @Nightowl
                      last edited by

                      @nightowl999 said in Declaring variables in config.g:

                      Error: in file macro line 14 column 63: meta command: array index out of bounds

                      This will be the problem.
                      See the other thread.

                      Nightowlundefined 1 Reply Last reply Reply Quote 1
                      • Nightowlundefined
                        Nightowl @OwenD
                        last edited by

                        @owend

                        This is Line 14 from resume.g...

                           echo "condition not met.  Spindle speed remains at " ^ tools[state.currentTool].spindleRpm ^ "RPM"
                        

                        with the same error when I changed it to:

                           echo "condition not met.  Spindle speed remains at ", tools[state.currentTool].spindleRpm, "RPM"
                        

                        Few things are more dangerous than taking the advice of someone who thinks he knows what he's doing.
                        I'm still on my learning curve, so take everything I say with caution!

                        RatRig 1075, Duet3 MB6HC, Sorotec SFM 1000 PV-ER milling motor, Hobbyist

                        OwenDundefined 1 Reply Last reply Reply Quote 0
                        • OwenDundefined
                          OwenD @Nightowl
                          last edited by

                          @nightowl999
                          See the other thread.
                          I suspect you have no tool defined when the resume starts.

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