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.
    • Strider007undefined
      Strider007
      last edited by

      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.

      fcwiltundefined 1 Reply Last reply Reply Quote 0
      • fcwiltundefined
        fcwilt @Strider007
        last edited by

        @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

        Strider007undefined 1 Reply Last reply Reply Quote 0
        • Strider007undefined
          Strider007 @fcwilt
          last edited by Strider007

          @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.

          zuoyanundefined fcwiltundefined 2 Replies Last reply Reply Quote 0
          • zuoyanundefined
            zuoyan @Strider007
            last edited by

            @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

            Strider007undefined 1 Reply Last reply Reply Quote 0
            • fcwiltundefined
              fcwilt @Strider007
              last edited by

              @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

              Strider007undefined 1 Reply Last reply Reply Quote 0
              • Strider007undefined
                Strider007 @fcwilt
                last edited by Strider007

                @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

                fcwiltundefined 1 Reply Last reply Reply Quote 0
                • Strider007undefined
                  Strider007 @zuoyan
                  last edited by

                  @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

                  Strider007undefined 1 Reply Last reply Reply Quote 0
                  • Strider007undefined
                    Strider007 @Strider007
                    last edited by Strider007

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

                    Thanks all

                    1 Reply Last reply Reply Quote 0
                    • fcwiltundefined
                      fcwilt @Strider007
                      last edited by

                      @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

                      Strider007undefined 1 Reply Last reply Reply Quote 0
                      • Strider007undefined
                        Strider007 @fcwilt
                        last edited by

                        @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.

                        fcwiltundefined 1 Reply Last reply Reply Quote 0
                        • fcwiltundefined
                          fcwilt @Strider007
                          last edited by

                          @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

                          Strider007undefined 1 Reply Last reply Reply Quote 0
                          • Strider007undefined
                            Strider007 @fcwilt
                            last edited by

                            @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
                            • First post
                              Last post
                            Unless otherwise noted, all forum content is licensed under CC-BY-SA