Hello Guest it is April 25, 2024, 07:34:44 AM

Author Topic: Trying to write a simple function need help  (Read 1554 times)

0 Members and 1 Guest are viewing this topic.

Offline DAAD

*
  •  103 103
    • View Profile
Trying to write a simple function need help
« 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?

Code: [Select]
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




Re: Trying to write a simple function need help
« Reply #1 on: March 22, 2020, 03:59:14 PM »
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
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DAAD

*
  •  103 103
    • View Profile
Re: Trying to write a simple function need help
« Reply #2 on: March 22, 2020, 04:07:12 PM »
Many thanks!

Will try this tomorrow!
Re: Trying to write a simple function need help
« Reply #3 on: March 22, 2020, 04:31:51 PM »
Another few things,  the API mc.mcAxisGetMotorId requires the following..
Code: [Select]
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
Code: [Select]
if AxisZ == "2"
this should be
Code: [Select]
if AxisZ == 2

Offline DAAD

*
  •  103 103
    • View Profile
Re: Trying to write a simple function need help
« Reply #4 on: March 22, 2020, 05:27:39 PM »
Thanks,

What does the child ID mean?
Do i need to put in something there? If yes what?
Re: Trying to write a simple function need help
« Reply #5 on: March 23, 2020, 01:03:06 AM »
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:
Code: [Select]
axisId, rc = mc.mcMotorGetAxis(number mInst, number motorId)

Offline DAAD

*
  •  103 103
    • View Profile
Re: Trying to write a simple function need help
« Reply #6 on: March 23, 2020, 01:07:25 AM »
Just need the motor ID.

Would the child id be the slave motor id? -> What if there is only one motor?
Re: Trying to write a simple function need help
« Reply #7 on: March 23, 2020, 01:13:22 AM »
Quote
...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.

Offline DAAD

*
  •  103 103
    • View Profile
Re: Trying to write a simple function need help
« Reply #8 on: March 23, 2020, 01:16:54 AM »
Will do, thanks!

Offline DAAD

*
  •  103 103
    • View Profile
Re: Trying to write a simple function need help
« Reply #9 on: March 25, 2020, 01:44:19 AM »
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!

Code: [Select]
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...
« Last Edit: March 25, 2020, 01:53:25 AM by DAAD »