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

Need help changing an X or Y coordinate into a variable

Scheduled Pinned Locked Moved
Gcode meta commands
3
12
285
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.
  • undefined
    Strider007
    last edited by 4 Mar 2025, 18:35

    I need to be able to take an unknown X or Y coordinate and set it as a variable in a macro.

    I'm using the G38.2 command to find an edge for use in a calculation. The G38.2 command works as expected and stops correctly at the location it is triggered. I can see the X and Y locations on the DWC or by using a M114 command but I do not understand how to change that into a variable I can use in a macro for a calibration calculation.

    With a G30 command I can get the Z coordinate using
    "global.autoz_tempx0 = sensors.probes[0].lastStopHeight

    How can I accomplish this with the G38.2 command, having it provide the X or Y coordinate?

    Any help or direction would be greatly appreciated.

    undefined 1 Reply Last reply 4 Mar 2025, 18:42 Reply Quote 0
    • undefined
      fcwilt @Strider007
      last edited by 4 Mar 2025, 18:42

      @Strider007

      Are you asking how to get the X and Y values to use in some gcode?

      Frederick

      Printers: a small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

      undefined 1 Reply Last reply 4 Mar 2025, 18:49 Reply Quote 0
      • undefined
        Strider007 @fcwilt
        last edited by Strider007 3 Apr 2025, 20:18 4 Mar 2025, 18:49

        @fcwilt Yes, I send a "G38.2 X10 F100" command, the machine moves until the sensor is tripped and stops. I want that exact X coordinate where it stopped as a number to be used in in alignment calculations.

        undefined undefined 2 Replies Last reply 4 Mar 2025, 20:19 Reply Quote 0
        • undefined
          zuoyan @Strider007
          last edited by 4 Mar 2025, 20:19

          @Strider007 You can search "duet object model", it should be move.axes[0-1].machinePosittion -- You can also explore the object model list in DWC

          undefined 1 Reply Last reply 4 Mar 2025, 20:42 Reply Quote 0
          • undefined
            fcwilt @Strider007
            last edited by 4 Mar 2025, 20:20

            @Strider007

            See if this will work:

            For the X:

            move.axes[0].machinePosition or move.axes[0].userPosition

            For the Y:

            move.axes[1].machinePosition or move.axes[1].userPosition

            Frederick

            Printers: a small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

            undefined 1 Reply Last reply 4 Mar 2025, 20:25 Reply Quote 0
            • undefined
              Strider007 @fcwilt
              last edited by Strider007 3 Apr 2025, 20:38 4 Mar 2025, 20:25

              @fcwilt Thanks,
              Ok, tried all combinations of your suggestions and only got error messages as follows:

              move.axes[0].machinePosition
              Error: Bad command: move.axes[0].
              Error: Bad command: machinePosition

              I had hoped that would work and had tried it already. What am I missing here?

              I

              undefined 1 Reply Last reply 4 Mar 2025, 22:19 Reply Quote 0
              • undefined
                Strider007 @zuoyan
                last edited by 4 Mar 2025, 20:42

                @zuoyan
                Its a long list, and I've looked through it multiple times. I probably should have mentioned that. That's when I found the two suggestions that fcwilt gave me but no success so far. Thanks

                undefined 1 Reply Last reply 4 Mar 2025, 20:58 Reply Quote 0
                • undefined
                  Strider007 @Strider007
                  last edited by Strider007 3 Apr 2025, 22:19 4 Mar 2025, 20:58

                  @Strider007 Ok, now studying M409, and I think I got this working.

                  Thanks all

                  1 Reply Last reply Reply Quote 0
                  • undefined
                    fcwilt @Strider007
                    last edited by 4 Mar 2025, 22:19

                    @Strider007

                    Those are not to be executed - they are merely variables holding those values.

                    To use such values, say, to move to a position, you would do something like

                    G1 X{move.axes[0].machinePosition} Y{move.axes[1].machinePosition}

                    The question is do those variables hold the values you desire. Compare them against what you see in the DWC, assuming the DWC is showing the values you seek.

                    Frederick

                    Printers: a small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

                    undefined 1 Reply Last reply 5 Mar 2025, 03:23 Reply Quote 0
                    • undefined
                      Strider007 @fcwilt
                      last edited by 5 Mar 2025, 03:23

                      @fcwilt
                      Yes, when I echo, that is the number I want to store as a temp variable then use in calculations of tool offsets.

                      echo "it is", move.axes[0].machinePosition
                      it is -118.088

                      Thank you for your guidance. I believe I 've got it from here.

                      undefined 1 Reply Last reply 5 Mar 2025, 03:55 Reply Quote 0
                      • undefined
                        fcwilt @Strider007
                        last edited by 5 Mar 2025, 03:55

                        @Strider007

                        To save a value from the Object Model (OM) into a local variable you do something like:

                        var Xvalue = move.axes[0].machinePosition
                        var Yvalue = move.axes[1].machinePosition

                        Or it you want it to be persistent so you can use it later or in other code:

                        global Xvalue = move.axes[0].machinePosition
                        global Yvalue = move.axes[1].machinePosition

                        Good Luck.

                        Frederick

                        Printers: a small Utilmaker style, a small CoreXY and a E3D MS/TC setup. Various hotends. Using Duet 3 hardware running 3.4.6

                        undefined 1 Reply Last reply 5 Mar 2025, 06:34 Reply Quote 0
                        • undefined
                          Strider007 @fcwilt
                          last edited by 5 Mar 2025, 06:34

                          @fcwilt Exactly what I needed to get past my mental roadblock. Some small code blocks doing just what I need. Now to refine the hardware to go with it. Most appreciated Gilly

                          1 Reply Last reply Reply Quote 0
                          9 out of 12
                          • First post
                            9/12
                            Last post
                          Unless otherwise noted, all forum content is licensed under CC-BY-SA