Hello Guest it is May 07, 2021, 07:33:39 AM

Author Topic: Jog steps  (Read 1458 times)

0 Members and 1 Guest are viewing this topic.

Jog steps
« on: March 10, 2018, 03:22:15 AM »
I use script for motor remapping (CNC has two carriage on X axis)

function cnc2plc:selectX1()
   -- Disable X axis, unmap Motor2, map Motor1, reenable X axis
   local rc = mc.mcCntlConfigStart(inst)
   if rc ~= 0 then
      mc.mcCntlSetLastError(inst, "Failed to switch axis!")
   rc = mc.mcAxisUnmapMotors(inst, mc.X_AXIS)
   rc = mc.mcAxisMapMotor(inst, mc.X_AXIS, mc.MOTOR1)
   mc.mcCntlSetLastError(inst, "Selected axis X1")

All work in metric units, but after motor switched JOG start working in imperial. All DRO still in mm, and G21 is still active. I reexecute G21 from MDI, and JOG start working normally :)

Mach4 Hobby, same issue with ESS motion controller and simulator.
Re: Jog steps
« Reply #1 on: March 10, 2018, 06:31:34 AM »
I think this issue results from the configuration. You could try a later version to see if it has been fixed. or you might try issuing the following after configuration and prior to jogging:

    local defUnits = mc.mcCntlGetUnitsDefault(inst)
    rc = mc.mcJogSetUnitsMode(inst, axis, defUnits)

Re: Jog steps
« Reply #2 on: March 10, 2018, 09:02:29 AM »
Yes, this works. All fine if I do this for all my axises.

One more question: where find full documentation on API? There is not documentation about mcJogSetUnitsMode in Docs, but it is in all *.exe and plugins headers.
Re: Jog steps
« Reply #3 on: March 10, 2018, 09:20:25 AM »
As I found, my code change SetDefaultUnitsOnStart from 1 to 0. What can cause this change?
Re: Jog steps
« Reply #4 on: March 10, 2018, 09:39:44 AM »
Look at:


You may need to install a viewer such as xchm to read this file.

I'm not sure why DefUnits would change, but you could assume 21 to force metric for jogging:

  rc = mc.mcJogSetUnitsMode(inst, axis, 21)

Re: Jog steps
« Reply #5 on: March 10, 2018, 09:43:09 AM »
There is nothing about mcJogSetUnitsMode. And some other functions not described, but exists in Lua interface.
Re: Jog steps
« Reply #6 on: March 10, 2018, 11:33:40 AM »
Sadly the documentation tends to lag behind development - a consequence of the low price of Mach4.

Sorry I cannot remember where I found the above API call. I assume it must have been in a forum post or in the change notes, but I've just done a quick search and nothing showed up.

Re: Jog steps
« Reply #7 on: March 10, 2018, 11:44:26 AM »
Great thanks for trick! It work and I will use it. (One more variant - call G21 via MDI execute from same script, but it slower).
Re: Jog steps
« Reply #8 on: March 10, 2018, 12:31:30 PM »
Glad it worked for you.

I assume (why I'm not sure) that issuing G21 sets the current units mode to metric. If you're inclined, you could test this using mcCntlGetUnitsCurrent().


Re: Jog steps
« Reply #9 on: March 11, 2018, 10:21:10 AM »
I had another look and found mention of mcJogSetUnitsMode() in the change log on the ftp site, so I guess that is where I found it.

There was no detail as to its use so I would just test it and fix any errors as they occurred.