Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: arhimedoffs 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!")
return
end
rc = mc.mcAxisUnmapMotors(inst, mc.X_AXIS)
rc = mc.mcAxisMapMotor(inst, mc.X_AXIS, mc.MOTOR1)
mc.mcProfileSave(inst)
mc.mcCntlConfigStop(inst)
mc.mcCntlSetLastError(inst, "Selected axis X1")
end
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 4.2.0.3481, same issue with ESS motion controller and simulator.
-
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)
Allan
-
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.
-
As I found, my code change SetDefaultUnitsOnStart from 1 to 0. What can cause this change?
-
Look at:
C:\Mach4Hobby\Docs\Mach4CoreAPI.chm
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)
Allan
-
There is nothing about mcJogSetUnitsMode. And some other functions not described, but exists in Lua interface.
-
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.
Allan
-
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).
-
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().
Allan
-
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.
Allan
-
Thanks, good resource for some reading.
-
And about builds. Latest build from site 3481, but on ftp much more fresh. What about stability and practical usage of newer builds, any experience?
-
I've often used the latest development builds without any problems at all, but obviously do this at your own risk and be ready with the eStop just in case.
Allan