Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: DAAD on March 22, 2020, 03:41:57 PM
-
Still trying to figure out how to create a proper function...
Next one should be the M6 dual head... long way to go... :-(
Try to get a function where the gcode loaded depends on the axis / motor combination that is up at the moment.
What am i doing wrong?
local inst = mc.mcGetInstance()
function Zspindle()
local AxisZ = mc.mcAxisGetMotorId (0,2) --motor Id van Z axis (Motor 2 = Z, Motor 4 = A)
if AxisZ == "2" then mc.mcCntlGcodeExecute(inst, "G90 G53 X80 Y200 F10000")
else mc.mcCntlGcodeExecute(inst, "G90 G53 X72.1993 Y42.2352 F10000")
end
end
-
Hi,
couple of pointers:
1) Put the local inst = mc.mcGetInstance() INSIDE the function, thus the variable in in scope when the function executes.
local inst = mc.mcGetInstance()
function Zspindle()
local inst = mc.mcGetInstance()
........
.......
2) put parentheses around the conditional:
if (AxisZ == "2") then mc.mcCntlGcodeExecute(inst, "G90 G53 X80 Y200 F10000")
Craig
-
Many thanks!
Will try this tomorrow!
-
Another few things, the API mc.mcAxisGetMotorId requires the following..
motorId, rc = mc.mcAxisGetMotorId(
number mInst,
number axis,
number childId)
You are missing the child Id.
It also returns the motorId as a number so in your if statement you have
if AxisZ == "2"
this should be
if AxisZ == 2
-
Thanks,
What does the child ID mean?
Do i need to put in something there? If yes what?
-
If you look at the Axis Mapping in the Mach4 control config you can get an idea of what child ID could be. I'm thinking it could be the position of master/slave boxes for each motor. So X axis master you would use 0 for the axis and 0 for child ID. To get the slave 1 motor id for the X axis you would use 0 for the axis and 1 for the child ID.
Are you trying to get the axis ID or the motor ID?
There is also this function from the API:
axisId, rc = mc.mcMotorGetAxis(number mInst, number motorId)
-
Just need the motor ID.
Would the child id be the slave motor id? -> What if there is only one motor?
-
...X axis master you would use 0 for the axis and 0 for child ID.
Try zero for child ID it should be the master index.
-
Will do, thanks!
-
Did adjust the function, and did a compile succesfully but the function does not work.
I would like to use the axis id and the motor id info to determine which is active Spindle or router.
still not shure what child_id number would be.. Problem with filling in 0 is that there is a motor (x in my case) with number zero...
Any pointers? let me know!
local inst = mc.mcGetInstance()
--z axis = 2
-- A axis =4
--Motor 2 = Z
--Motor 4 = A
function Zspindle()
local AxisZ = mc.mcAxisGetMotorId (0,2,0) --get motor id from axis 2
if AxisZ == 2 then mc.mcCntlGcodeExecute(inst, "G90 G53 X80 Y200 F10000")
else mc.mcCntlGcodeExecute(inst, "G90 G53 X72.1993 Y42.2352 F10000")
end
end
ps: Gcode excecute only for testing purposes...
-
Hi,
to start with put local inst = mc.mcGetInstance()
inside the function otherwise 'inst' is out of scope.
Craig
-
thanks for the basics tip!
-
If you look at the Axis Mapping in the Mach4 control config you can get an idea of what child ID could be. I'm thinking it could be the position of master/slave boxes for each motor. So X axis master you would use 0 for the axis and 0 for child ID. To get the slave 1 motor id for the X axis you would use 0 for the axis and 1 for the child ID.
Are you trying to get the axis ID or the motor ID?
There is also this function from the API:
axisId, rc = mc.mcMotorGetAxis(number mInst, number motorId)
Searched inside the ini file and foud the following info:
Axis 3 = Child ID0 = Motor 4, Child ID1 = No motor found. So your info seems correct. If i want the value of the motor in need 0 in the child ID.
still don't get the function working tho...
do i need to do something special for the number to return?