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

    How to Copy Axis Position Into a Variable?

    Scheduled Pinned Locked Moved
    CNC
    4
    9
    588
    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.
    • Tinmanundefined
      Tinman
      last edited by

      OK, I'm stuck. It doesn't sound hard but for the life of me I can't find a way to get an RRF macro to do this simple thing. How can I get the current position of a single axis and copy it into a variable to do some calculations with it?

      M114 doesn't seem to help. I've also been querying the object model with M409 but there doesn't seem to be a way to cut down on the verbosity and how do you get the result into a variable anyway? I am using a touchprobe to find the top or an edge of a workpiece and I want to copy that axis value into a variable. The purpose is to set the WCS based on where the workpiece is.

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

        @Tinman

        You can get all the object model details here
        https://github.com/Duet3D/RepRapFirmware/wiki/Object-Model-Documentation

        You probably want to use move.axes[?].machinePosition
        However you may need to use M400 first to ensure that the machine is at rest when you grab the value.

        Tinmanundefined 1 Reply Last reply Reply Quote 0
        • Tinmanundefined
          Tinman @OwenD
          last edited by

          @OwenD nice to hear from you. So I’ve already had the object model reporting the coordinate using M409. Problem is it gives back a lot of other information (brackets and object model syntax) that I don’t need and also I don’t know how to get a macro to plug that value into a variable so that I can use it in macro calculations.

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

            @Tinman

            var xPosition = move.axes[0].machinePosition
            var yPosition = move.axes[1].machinePosition
            var zPosition = move.axes[2].machinePosition
            echo "machine position is X" ^ var.xPosition ^ " Y" ^ var.yPosition ^ " Z" ^ var.zPosition
            

            Edit to show all axes usage
            I imagine you'll use G10 Y{var.yPosition} or something similar to set your WCS

            achrnundefined 1 Reply Last reply Reply Quote 0
            • achrnundefined
              achrn @OwenD
              last edited by

              I think userPosition is often what you want to use - it is the position at the end of the last move currently fed into the queue, so if this routine acts on the variable by putting something into the queue, this will be the position at the time that the 'something' is reached, as I understand it

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

                @achrn said in How to Copy Axis Position Into a Variable?:

                I think userPosition is often what you want to use - it is the position at the end of the last move currently fed into the queue, so if this routine acts on the variable by putting something into the queue, this will be the position at the time that the 'something' is reached, as I understand it

                That is correct in general (and maybe even in this case too).
                I took the case to be the OP was using some sort of "edge finder" rather than an electronic probe probe such as a Z probe.
                So he would be manually jogging until the edge finder touched the work piece.

                Something like

                M291 P"Jog to position" S3 X1 Y1 Z1
                M400
                G4 P500
                var xPos = move.axes[0].machinePosition
                var yPos = move.axes[1].machinePosition
                var zPos = move.axes[2].machinePosition
                echo "Positions are X" ^ var.xPos ^ " Y" ^ var.yPos ^ " Z" ^ var.zPos
                
                Tinmanundefined 1 Reply Last reply Reply Quote 2
                • chrishammundefined
                  chrishamm administrators @Tinman
                  last edited by

                  @Tinman Also note that you can browse the object model interactively by enabling the "Object Model Browser" plugin in the DWC settings.

                  Duet software engineer

                  Tinmanundefined 1 Reply Last reply Reply Quote 0
                  • Tinmanundefined
                    Tinman @chrishamm
                    last edited by

                    @chrishamm Yes, I've been poking around the object model. It is useful for confirming what is going on with the machine.

                    1 Reply Last reply Reply Quote 0
                    • Tinmanundefined
                      Tinman @OwenD
                      last edited by

                      @OwenD This is the very definition of a helpful answer. Amazing when it is explained properly how you think to yourself "that was so easy, why couldn't I figure it out?"

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