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

    extracting the machine unit from object model

    Scheduled Pinned Locked Moved
    CNC
    2
    3
    219
    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.
    • baird1faundefined
      baird1fa
      last edited by

      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.

      baird1faundefined 1 Reply Last reply Reply Quote 0
      • baird1faundefined
        baird1fa @baird1fa
        last edited by

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

        dc42undefined 1 Reply Last reply Reply Quote 1
        • dc42undefined
          dc42 administrators @baird1fa
          last edited by

          @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 is state.thisInput. So you would normally request inputs[state.thisInput].distanceUnit.

          Duet WiFi hardware designer and firmware engineer
          Please do not ask me for Duet support via PM or email, use the forum
          http://www.escher3d.com, https://miscsolutions.wordpress.com

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