extracting the machine unit from object model
-
Hello everyone,
I'm looking for some help to extract the machine unit, set by G20 and G21, from the object model to use in macros.
Essentially I want to be able to run my machine in either mm or inches. The issue I have is when my Gcode sets the machine to inches all the macros and such don't work as they were written expecting the machine to be in inches.
I'd like to add a small script at the beginning of any macro that checks if the machine is in machine is in inches and if it is sets it G21 (mm) before proceeding and then sets it back to G20 if needed to continue running the job.
I want to do this because I have macros that will run during a job and they need to be in known unit.
I have found an object model (inputs[].distanceUnit) but I'm not sure how to utilize it.
Thank you.
-
@baird1fa I think I found the solution. It looks like the G20 and G21 are only changed temporarily when called inside of a macro and revert back once the macro is completed.
-
@baird1fa that is correct, the inches/mm setting is saved on entry to any macro and restored when it exits, along with some other parameters e.g. the feed rate and whether distances are absolute or relative. So you can safely use G20 or G21 at the start of your macro to ensure that movement commands in the macro are always interpreted the same way.
If you do need to detect whether inches or mm are being used, this is set separately for every input (so a job that changes the units to inches won't affect the behaviour of the jog commands in DWC or PanelDue). The current setting can be found in the object model as
inputs[N].distanceUnit
. The value of N for the input making the query isstate.thisInput
. So you would normally requestinputs[state.thisInput].distanceUnit
.