Hello Guest it is April 19, 2024, 10:21:37 AM

Author Topic: index homing mach 4  (Read 2501 times)

0 Members and 1 Guest are viewing this topic.

Offline mark4

*
  •  167 167
    • View Profile
index homing mach 4
« on: May 26, 2017, 11:08:12 PM »
hi all i have a quandry. i am upgrading a bridgeport to mach 4 with new ac servo drives a vfd the ethernet smooth stepper and the mb2 break out board which i absolutely love. the problem i have is not enough inputs but then you never have enough. so i built a daughter board to take the index signal 5v from my drives and convert it to 24vdc through an opto isolator this works fine. next i need to use only one input with my setup so i added a multiplexer to the daughter board i have plenty of outputs. i hooked two outputs to the daughter board with the mutliplexer and on/off combinations turn on the index from x y z a drives. the smooth stepper homes to the index perfectly. i need to set up the outputs so that when i am homing X a off b off, homing Y a on b off, homing Z b on a off, homing A a on b on and i havent the foggiest idea how to do this. i have been looking at the lua scripts and realize i do not understand how homing is programed. in mach 3 would have been change vb. so if anybody can assist me in this endever or point me in the right direction it would be much appreciated thank you
M  
Re: index homing mach 4
« Reply #1 on: May 26, 2017, 11:42:08 PM »
Hi,
I think I can see a way to get that to work. Of course a second MB2 and you'd be quids in with inputs to burn.

When you hit the 'RefAll' button it in fact fires up a script to do the work. What you'll need to do is overwrite that script with your own.
You may be better off leaving 'RefAll' alone and writing some new script or scripts until you've got it to work properly.

In addition to 'RefAll' you have RefX, RefY and RefZ. What I would suggest is that you assign outputs so that your multiplexer directs
the Z index signal to your input then 'RefZ'. Now reassign your outputs for the multiplexer to direct the Y index and the RefY, and so on.

If you open the screen editor in Mach4 and look at the left-up scripts for RefAll, RefX,RefY etc you will soon see that the actual functionality
is buried deeper inside Mach4. You could chase it further in but think there is a better way, from Mach API:
rc = mc.mcAxisHome(
   number mInst,
   number axisId)

This will allow you to home an individual axis which can incorporate index homing if you wish. You program is now:
1) set outputs for Z multiplex
2)mc.mcAxisHome(inst,2);       assuming axis 2 is Z, commonly the case
3) set outputs for Y multiplex
4) mc.mc.AxisHome(inst,1);      assuming axis 1 is Y, commonly the case
5) set outputs for X multiplex
6) mc.mcAxisHome(inst,0);       assuming axis 0 is X, commonly the case

and you could attach this to the RefAll button or make another button or even bundle it into a macro and call it from your Gcode job
as required.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline mark4

*
  •  167 167
    • View Profile
Re: index homing mach 4
« Reply #2 on: May 28, 2017, 09:25:48 PM »
hello thank you for your reply i put this together and pray it will work. i will be testing it tomorrow
---------------------------------------------------------------
-- Ref All Home() function.
---------------------------------------------------------------
function RefAllHome()
mc.mcAxisDerefAll(inst);  --Just to turn off all ref leds
--mc.mcAxisHomeAll(inst);
--set outputs for Z multiplex
local out2 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2)  -- OUTPUT FOR MULTIPLEXER
local out3 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT3)  -- OUTPUT FOR MULTIPLEXER
local out2 = mc.mcSignalSetState(inst,0)--output off
local out3 = mc.mcSignalSetState(inst,0)--output off
mc.mcAxisHome(inst,2);     --  assuming axis 2 is Z, commonly the case
--set outputs for Y multiplex
local out2 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2)  -- OUTPUT FOR MULTIPLEXER
local out3 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT3)  -- OUTPUT FOR MULTIPLEXER
local out2 = mc.mcSignalSetState(inst,0)--output off
local out3 = mc.mcSignalSetState(inst,1)--output on
mc.mc.AxisHome(inst,1);     -- assuming axis 1 is Y, commonly the case
-- set outputs for X multiplex
local out2 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2)  -- OUTPUT FOR MULTIPLEXER
local out3 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT3)  -- OUTPUT FOR MULTIPLEXER
local out2 = mc.mcSignalSetState(inst,0)--output off
local out3 = mc.mcSignalSetState(inst,1)--output on
mc.mcAxisHome(inst,0);     --  assuming axis 0 is X, commonly the case
coroutine.yield() --yield coroutine so we can do the following after motion stops
----see ref all home button and plc script for coroutine.creat and coroutine.resume
wx.wxMessageBox('Referencing is complete')
wx.wxMessageBox('Dont forget turn on soft limits')
end

one of the biggest problems i have with lua is turning on outputs i find it confusing and it shouldnt be i have read different accounts of how to do this but i dont know get handle, set state. i could always in vb just say output on/output off and be done. if anybody can point me to the proper text. big sign this will work to turn on an output. i understand inputs all right and have been able to get them to do what i want but outputs confuse me. thank you for reading and if you have any advise on structure please let me know
m

Offline mark4

*
  •  167 167
    • View Profile
Re: index homing mach 4
« Reply #3 on: May 28, 2017, 09:49:52 PM »
i believe this will change the existing reff all button to do my bidding and i will change the single reference when this works also not listed is one more block for a axis i dont have a fourth axis but my upgraded mills are planned for them if possible.
Re: index homing mach 4
« Reply #4 on: May 29, 2017, 12:57:45 AM »
Hi Mark,
that looks good. Very much what I had in mind.

Have to agree 'getting handles' and 'setting states' does seem a bit weird.

I think the upshot is that a handle is assigned by the machine and is therefore very readily available to
code. Further it can be assigned or reassigned on the fly whereas a variable has to be translated to a fixed address.
I don't know whether you've come across 'functions as first class values' concept. It one of the subtleties
of LUA. Once I got my head around the idea... its brilliant.

My heart bleeds for the poor sick little puppies who dream this ...it up!

Craig

'I enjoy sex at 73.....I live at 71 so its not too far to walk.'

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: index homing mach 4
« Reply #5 on: May 29, 2017, 02:56:51 AM »
The steps for signals are

1. Get the handle for the signal (this is basically a computer generated number at runtime)
2. Set the state of that handle

so to set your signal above should be

Code: [Select]
local out2 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2)  -- OUTPUT FOR MULTIPLEXER
local out3 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT3)  -- OUTPUT FOR MULTIPLEXER
mc.mcSignalSetState(out2,0)--output off
mc.mcSignalSetState(out3,0)--output off

DazTheGas
New For 2022 - Instagram: dazthegas

Offline mark4

*
  •  167 167
    • View Profile
Re: index homing mach 4
« Reply #6 on: May 29, 2017, 09:42:33 PM »
hello well i have solved my problems and successfully homed all three axises to the index pulse my code is
-- Ref All Home() function.
---------------------------------------------------------------
function RefAllHome()
mc.mcAxisDerefAll(inst);  --Just to turn off all ref leds
--mc.mcAxisHomeAll(inst);
local out2 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT2)  -- OUTPUT FOR MULTIPLEXER
local out3 = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT3)  -- OUTPUT FOR MULTIPLEXER
mc.mcSignalSetState(out2,1)--output off --set outputs for Z multiplex
mc.mcSignalSetState(out3,1)--output on --set outputs for Z multiplex
mc.mcAxisHome(inst,2);     --  assuming axis 2 is Z, commonly the case
coroutine.yield() --yield coroutine so we can do the following after motion stops
mc.mcSignalSetState(out2,0)--output on --set outputs for x multiplex
mc.mcSignalSetState(out3,0)--output off --set outputs for x multiplex
mc.mcAxisHome(inst,0);    --  assuming axis 0 is x, commonly the case
coroutine.yield() --yield coroutine so we can do the following after motion stops
mc.mcSignalSetState(out2,0)--output off -- set outputs for y multiplex
mc.mcSignalSetState(out3,1)--output off -- set outputs for y multiplex
mc.mcAxisHome(inst,1);    --   assuming axis 1 is y, commonly the case
coroutine.yield() --yield coroutine so we can do the following after motion stops
--mc.mcSignalSetState(out2,1)--output on -- set outputs for y multiplex
--mc.mcSignalSetState(out3,0)--output off -- set outputs for y multiplex
--mc.mcAxisHome(inst,3);    --   assuming axis 3 is a, commonly the case
--coroutine.yield() --yield coroutine so we can do the following after motion stops
----see ref all home button and plc script for coroutine.creat and coroutine.resume
wx.wxMessageBox('Referencing is complete')
wx.wxMessageBox('Dont forget turn on soft limits')
end
one thing i figured out you need to finish each axis with coroutine.yield or it homes the first axis and stops.
also when i was doing the initial setup i was doing one axis at a time and until i finished the z would bump when
finished homing another axis. once the x and y started moving after home all by themselves that turned out to be a
typo. with the script complete ref all button works perfect no bump. also the diagnostics screen with the individual axis
homing buttons take the orriginal home axis out and put the script into left down for each axis. that will do it
thanks for all your help
m