How to Copy Axis Position Into a Variable?
-
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.
-
You can get all the object model details here
https://github.com/Duet3D/RepRapFirmware/wiki/Object-Model-DocumentationYou 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. -
@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.
-
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 -
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
-
@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
-
@Tinman Also note that you can browse the object model interactively by enabling the "Object Model Browser" plugin in the DWC settings.
-
@chrishamm Yes, I've been poking around the object model. It is useful for confirming what is going on with the machine.
-
@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?"