Hello Guest it is May 15, 2021, 06:52:31 PM

Author Topic: re-mapping motors and home switch inputs through lua script  (Read 4245 times)

0 Members and 1 Guest are viewing this topic.

Offline smurph

*
  • *
  •  1,402 1,402
  • "That there... that's an RV."
    • View Profile
Re: re-mapping motors and home switch inputs through lua script
« Reply #10 on: January 03, 2017, 11:00:57 PM »
The config dialog just reads the profile's Machine.ini file and displays those values.  NOT values that may have been modified at run time by scripts and API calls.  When you hit OK (or Apply) on the config dialog, the profile's Machine.ini will be updated with the values in the dialog (changed or not) and then when the dialog closes, the core will re-read the profile's Machine.ini.  Thus "undoing" any run time modifications.  Even if you hit CANCEL in the config dialog, the run time modification will be undone, as the core will ALWAYS re-read the profile's Machine.ini file.  The core does not know if you pressed OK, or CANCEL on the configuration dialog.  

If you modify the values at run time and then shutdown Mach (without entering the config dialog), the modified values WILL be written to the profile's Machine.ini at shutdown and then next time you start Mach, those values will be used.  

So if you ever want to see the run time modifications in the config dialog, you must also modify the Machine.ini file with the mcProfileWrite*() functions (with the appropriate keys and values) and call mcProfileFlush() afterwards to write them to the disk BEFORE entering the config dialog.

Steve
Re: re-mapping motors and home switch inputs through lua script
« Reply #11 on: January 05, 2017, 03:20:34 AM »
Hi smurph,
that's describes exactly what I see happening... thanks for the explanation. While I might have floundered around
for a bit I've learnt stuff on the way, good fun.

Having a bit of trouble with:
mc.mcGoCookMeSteakand Eggs()
maybe in the next build...LOL

Craig
My wife left with my best friend...
     and I miss him!
Re: re-mapping motors and home switch inputs through lua script
« Reply #12 on: January 24, 2017, 04:19:42 PM »
So after working with Mach support I've found that it is possible to use the mcAxisMap and mcAxisUnmap to modify the axis mappings.
The trick is to save or flush the profile at the end of the script using either mcProfileSave() or mcProfileFlush()

Unfortunately it is not possible to edit the pins that each motor has assigned for homing. As I am using a PMDXsmartBOB this is necessary to change from a 2 axis home to a 4 axis.

I've been continually working on this and found that mach can be homed with the 4 axis configuration and then switched to 2 axis without issue (unless you try to home it without changing back)

The problem there is that the changes must be done manually as far as I can tell. Every time I try to home in the middle of a script I can't get it to wait until the homing is complete before continuing. any code after the fact is run immediately and my attempts at pausing/waiting until it's complete with loops seem to cause it to disregard the remaining code entirely.

Does anyone have any tips on how to automatically run code after the homing is complete. I've also tried editing the PLC script and the screenload script to no avail.
Re: re-mapping motors and home switch inputs through lua script
« Reply #13 on: January 24, 2017, 04:25:31 PM »
For references here is my code to change from X,Y axes to X,Y,A,B axes

Code: [Select]
------------4 Axis Mapping-----------
inst = mc.mcGetInstance()
local xAxis = 0
local yAxis = 1
local aAxis = 3
local bAxis = 4
xAxis = tonumber(xAxis)
yAxis = tonumber(yAxis)
aAxis = tonumber(aAxis)
bAxis = tonumber(bAxis)

--motorId, rc = mc.mcAxisGetMotorId(number mInst, number axis, number childId)
local motorIdX, rc = mc.mcAxisGetMotorId(inst, 0, 0);
local motorIdY, rc = mc.mcAxisGetMotorId(inst, 1, 0);
local motorIdA, rc = mc.mcAxisGetMotorId(inst, 0, 1);
local motorIdB, rc = mc.mcAxisGetMotorId(inst, 1, 1);


--rc = mc.mcAxisUnmapMotor(number mInst, number axisId, number motor)
mc.mcAxisUnmapMotor(inst, 0, motorIdX) --Unmap from X axis
mc.mcAxisUnmapMotor(inst, 1, motorIdY) --Unmap from Y axis
mc.mcAxisUnmapMotor(inst, 0, motorIdA) --Unmap motor 2 from X axis
mc.mcAxisUnmapMotor(inst, 1, motorIdB) --Unmap motor 3 from Y axis

--rc = mc.mcAxisMapMotor(number mInst, number axisId, number motorId)
mc.mcAxisMapMotor(inst, 0, 0)    --Map motor 0 to X axis
mc.mcAxisMapMotor(inst, 1, 1)    --Map motor 1 to Y axis
mc.mcAxisMapMotor(inst, 3, 2)    --Map Motor 2 to A axis
mc.mcAxisMapMotor(inst, 4, 3)    --Map motor 3 to B axis

--rc = mc.mcAxisEnable(number mInst, number axisId, number enabled)
mc.mcAxisEnable(inst, 3, true)  --Enable A axis
mc.mcAxisEnable(inst, 4, true)  --Enable B axis

--rc = mc.mcProfileSave(number mInst)
mc.mcProfileSave(inst)


Code: [Select]
-------------2 Axis Mapping-------------
inst = mc.mcGetInstance()
local xAxis = 0
local yAxis = 1
local aAxis = 3
local bAxis = 4
xAxis = tonumber(xAxis)
yAxis = tonumber(yAxis)
aAxis = tonumber(aAxis)
bAxis = tonumber(bAxis)


--rc = mc.mcAxisUnmapMotor(number mInst, number axisId, number motor)
mc.mcAxisUnmapMotor(inst, xAxis, 0) --Unmap motor 0 from X axis
mc.mcAxisUnmapMotor(inst, yAxis, 1) --Unmap motor 1 from Y axis
mc.mcAxisUnmapMotor(inst, aAxis, 2) --Unmap motor 2 from A axis
mc.mcAxisUnmapMotor(inst, bAxis, 3) --Unmap motor 3 from B axis

--rc = mc.mcAxisMapMotor(number mInst, number axisId, number motorId)
mc.mcAxisMapMotor(inst, xAxis, 0)    --Map motor 0 to X axis
mc.mcAxisMapMotor(inst, yAxis, 1)    --Map motor 1 to Y axis
mc.mcAxisMapMotor(inst, xAxis, 2)    --Map Motor 2 to X axis
mc.mcAxisMapMotor(inst, yAxis, 3)    --Map motor 3 to Y axis

--rc = mc.mcAxisEnable(number mInst, number axisId, number enabled)
mc.mcAxisEnable(inst, aAxis, false)  --Disable A axis
mc.mcAxisEnable(inst, bAxis, false)  --Disable B axis

--rc = mc.mcProfileSave(number mInst)
mc.mcProfileSave(inst)

Offline DazTheGas

*
  •  753 753
  • DazTheGas
    • View Profile
Re: re-mapping motors and home switch inputs through lua script
« Reply #14 on: January 24, 2017, 04:45:35 PM »
I am stripping my X gantry off this coming weekend and will leave me with 2 Y plates, its one off the things I want to play with is autosquaring, will let you know how it goes.

DazTheGas
Theres always time for a choccy biccy