Hello Guest it is March 29, 2024, 01:09:40 AM

Author Topic: A solution for more switches than inputs  (Read 2124 times)

0 Members and 1 Guest are viewing this topic.

Offline mark4

*
  •  167 167
    • View Profile
A solution for more switches than inputs
« on: February 09, 2018, 10:33:25 PM »
Hello i havent posted for a while had different problem with controllers and function. this is where i am at i have a cnc control built around the Ethernet Smooth Stepper and the MB2. i added a pokeys board to make up extra inputs i needed. i tried to use it for mpg that didnt work so i put my mpg back to the ESS and continued to use the pokeys 56e for some simple inputs two rotary switches and three push buttons. also 9 led's. none of this worked i tried to update the firmware on the pokeys. i tried capacitors and resistors like the manual said. nothing worked i kept getting false triggering that is a problem when one of your switches is cycle start. so my next solution for not enough inputs. i realize i can use two inputs to make three if i do it like this first switch input one on. 2nd switch input 2 on. 3rd switch input one and two on at the same time however on switch three use two diodes so they cant back feed.
the same thing can be done with more my second rotary has 4 positions i use 3 inputs and two diodes. and three push buttons just to cover everything. electrically they work good i can see the led's on the MB2 light up exactly as they should. so here is my problems i just guessed at the diodes can anybody help me with what size diode to use for a 24v system set up like this. probably about switch timing but i dont know. 2nd lua script is something i am working on (side note some of the manuals and examples for lua look very different to do the same thing, confusing) so this is what i set up for the 3 push buttons in screen load script.
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    ButtonEnable()
end,
[mc.ISIG_INPUT1] = function (state)
    if (state == 1) then
        Cycle()
     end
end,
[mc.ISIG_INPUT2] = function (state)
    if (state == 1) then
        Cycle()
    end
end,

---------------------------------------------------------------
-- Cycle Start, Feed Hold, Cycle Stop function
---------------------------------------------------------------
function Cycle()
--function CycleStop()
    local hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT1)
    local Input1, rc = mc.mcSignalGetState(hsig)
    local hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2)
    local Input2, rc = mc.mcSignalGetState(hsig)
    --Cycle Stop
    if Input1 == 1 and Input2 == 1 then
    mc.mcCntlCycleStop(inst);
    mc.mcSpindleSetDirection(inst, 0);
    mc.mcCntlSetLastError(inst, "Cycle Stopped");
    end
    if Input1 == 0 and Input2 == 1 then
    mc.mcCntlFeedHold(0)
    end
    if Input1 == 1 and Input2 == 0 then
    --function CycleStart()
    local rc;
    local tab, rc = scr.GetProperty("MainTabs", "Current Tab")
    local tabG_Mdione, rc = scr.GetProperty("nbGCodeMDI1", "Current Tab")
    local tabG_Mditwo, rc = scr.GetProperty("nbGCodeMDI2", "Current Tab")
    --See if we have to do an MDI command and if so, which one
        if ((tonumber(tab) == 0 and tonumber(tabG_Mdione) == 1) or (tonumber(tab) == 2 and tonumber(tabG_Mditwo) == 1 )) then
            local state = mc.mcCntlGetState(inst);
            if (state == mc.MC_STATE_MRUN_MACROH) then
            mc.mcCntlCycleStart(inst);
            mc.mcCntlSetLastError(inst, "Do Cycle Start");
            else
                if (tonumber(tab) == 0) then  
                scr.ExecMdi('mdi1');
                mc.mcCntlSetLastError(inst, "Do MDI 1");
                else
                scr.ExecMdi('mdi2');
                mc.mcCntlSetLastError(inst, "Do MDI 2");
                end
            end
        elseif tonumber(tab) > 2 then --No G Code or MDI panel is displayed so Do Nothing
            mc.mcCntlSetLastError(inst, "Nothing to Start");
        else --Do CycleStart
            mc.mcCntlSetLastError(inst, "Do Cycle Start");
            mc.mcCntlCycleStart(inst);      
        end
    end
end

this works well and doesnt false start except when you press the third switch which is stop you can get a quick cycle start first then stop in the history i dont know if this is a problem or will be and it could be related to the diodes or i need to add a capacitor of .01 across my switches. i tried adjusting filtering but that didnt seem to help. i think the solution is in lua but i dont know enough lua. my next piece of code is for mpg jog X Y Z and A axis.

[mc.ISIG_INPUT4] = function (state)
    if (state == 1) then
        Mpg()
    end
end,
[mc.ISIG_INPUT5] = function (state)
    if (state == 1) then
        Mpg()
    end
end,
[mc.ISIG_INPUT6] = function (state)
    if (state == 1) then
        Mpg()
    end
---------------------------------------------------------------
--Mpg Axis Increment
---------------------------------------------------------------
function Mpg()
    local hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4)
    local Rotary1, rc = mc.mcSignalGetState(hsig)
    local hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5)
    local Rotary2, rc = mc.mcSignalGetState(hsig)
    local hsig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT6)
    local Rotary3, rc = mc.mcSignalGetState(hsig)
    --Mpg X
    if Rotary1 == 1 and Rotary2 == 0 and Rotary3 == 0 then --Mpg X
        mc.mcMpgSetAxis(inst,0,0)
        mc.mcCntlSetLastError(inst,"X Selected")
    elseif Rotary1 == 0 and Rotary2 == 1 and Rotary3 == 0 then --Mpg Y
        mc.mcMpgSetAxis(inst,0,1)
        mc.mcCntlSetLastError(inst,"Y Selected")
    elseif Rotary1 == 0 and Rotary2 == 0 and Rotary3 == 1 then --Mpg Z
        mc.mcMpgSetAxis(inst,0,2)
        mc.mcCntlSetLastError(inst,"Z Selected")
    elseif Rotary1 == 0 and Rotary2 == 1 and Rotary3 == 1 then --Mpg A
        mc.mcMpgSetAxis(inst,0,3)
        mc.mcCntlSetLastError(inst,"A Selected")
    elseif Rotary1 == 0 and Rotary2 == 0 and Rotary3 == 0 then --Mpg off
        mc.mcMpgSetAxis(inst,0,-1)
        mc.mcCntlSetLastError(inst,"No Axis Selected")
    end
end
i haven gotten to coding the last switch which is a rotary for increment x1 x10 x100. the mpg jog code works somewhat it will turn on X then Y then Z then A then go back as long as i dont go to fast. however it doesnt like to shut off mc.mcCntlSetLastError(inst,"No Axis Selected") i have only checked it with set last error so far my thought if it doesnt pass there how is it going to work. so i turn the switch to x then y then z then a then back fast slow ridiculous speed and is doesnt confuse to bad however it doenst like to shut off the last block of code i have done two ways as you see it and like this
else
        mc.mcMpgSetAxis(inst,0,-1)
        mc.mcCntlSetLastError(inst,"No Axis Selected")
    end
end
this was better in that i got "No Axis Selected" from the outer switches y z a if i moved quickly but when i was on X and turned it to off it stayed X axis selected or should i say it didnt change to no axis selected as X was just the last axis selected and the others could be slugish. i thought about using the PMC for ladder logic and for speed might solve my problem however after looking it over unless somebody helps me set up the first rung for one input on and two inputs off jogs mpg i havent the foggiest idea of how to do it. also there is probably a better way with screen load script or maybe i should be using plc and dont know it. if i /we can find a way to make this work i can have my full blown control with inputs for probe and spindle A B I encoder. and i am sure others can benefit from this solution. thank you
mark

Offline mark4

*
  •  167 167
    • View Profile
Re: A solution for more switches than inputs
« Reply #1 on: February 09, 2018, 11:22:59 PM »
capacitor size .1 microfarads typo

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: A solution for more switches than inputs
« Reply #2 on: February 10, 2018, 12:49:24 AM »
did you for a start try whats in the pokeys tot here http://blog.poscope.com/mach4-tutorial-custom-signal-mapping/

Offline mark4

*
  •  167 167
    • View Profile
Re: A solution for more switches than inputs
« Reply #3 on: February 10, 2018, 02:18:09 AM »
thanks for the reply and yes i tried that. my lua is something i am still learning. the signals were set up properly and working the problem was false triggering. as i was trouble shooting i took all extra wires off the pokeys completely the only ones i left were for cycle start and cycle stop push buttons. every time i pressed either button the history would show multiple presses. but thats not the worst after playing with it i stepped back and watched the history bar the machine cycled between cycle stop and cycle start all by itself. i tried resistors and capacitors i tried grounding the ps which was a small 5v power supply connected only to the pokeys board. one thing i didnt mention. i installed the pokeys board in my operator control cabinet. the only things in that cabinet are the computer,keyboard,mouse,monitor. two rotary switches one mpg adapter and one mpg. basically nothing that should bother the pokeys board. my drive cabinet houses everything else. i tried there tech support didnt much like the fact that i couldnt directly reply to the email had to go to there sight and log in tedius. at this point even if there is something more i can do with pokeys i would be very reluctant to do so. i am a machine rebuilder and i need to support my machines. a machine that can start itself with no input is just plain dangerous. i am sure there are people who make out well with the pokeys board but i didnt. the solution i came up with gives my machines
ac servo drive
four axis
index homing
spindle encoder
vfd
probe input
mpg
what more could you ask for
at this point it isnt about the pokeys its about coding to make the logic work for the switches
luck
mark 

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: A solution for more switches than inputs
« Reply #4 on: February 10, 2018, 02:45:53 AM »
To me this looks realy wrong

---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    ButtonEnable()
end,
[mc.ISIG_INPUT1] = function (state)
    if (state == 1) then
        Cycle()
     end
end,
[mc.ISIG_INPUT2] = function (state)
    if (state == 1) then
        Cycle()
    end
end,

its 2 inputs doing the same thing why not just have a cycle start and cycle stop then if they = one or the other do something else

Offline mark4

*
  •  167 167
    • View Profile
Re: A solution for more switches than inputs
« Reply #5 on: February 10, 2018, 08:05:15 PM »
Hello
its 2 inputs doing the same thing why not just have a cycle start and cycle stop then if they = one or the other do something else

its not wrong the pendants do it exactly the same. the function decides which button is pressed or which switch is active and that part isnt working right. if i were to have one input doing cycle start and one input doing cycle stop and another function ex feed hold then you would also cycle start or stop at the same time you tried to feed hold the diodes seperate that out. i am attaching a drawing i through together. you will note 3 positions of the rotaty switch position 1 output 1 position 2 output 2 position 3 output two and three at the same time which makes position 3 and the diodes dont let it feed back. problem i have is switch bounce and i believe 3 doesnt trigger the exact same so sometimes i get one of the other two before i get three. i am planning to add debounce to the switches and see if that helps. i dont know how to add a delay to lua script yet but i am working on it.

Offline mark4

*
  •  167 167
    • View Profile
Re: A solution for more switches than inputs
« Reply #6 on: February 13, 2018, 01:57:39 AM »
well so far i havent been able to make it work effectively it works as advertised but the coding is sluggish and not reliable. it might be the diodes arent fast enough or the switches need allot of debounce. so unless somebody comes up with some coding i havent tried i am going to add a multiplexer to my index pulses so i can gain 3 more inputs. that will get me the ones i need but truthfully i wanted to have a seperate input for each index.
mark

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: A solution for more switches than inputs
« Reply #7 on: February 13, 2018, 08:01:02 AM »
You should have a single function that checks the state of both inputs and performs one of the required three actions accordingly. Then call that function from both of the inputs signal script. And be aware that the function will be called twice if both inputs change state (another reason for checks mentioned later).

That should work but if your dealing with noise you will have to fix the noise issue first. No way to code around random.

But lua is fast so in your function check that the requested action hasn't already been performed before performing it. If the timing of the 2 inputs aren't perfect for what ever reason (response time of optos on BOB differs, this wire is longer than that wire, this capacitor takes a little longer to saturate, etc.) you may have issues without the checks.

Another way to do it would be to use a single analog input. Can add resistors with some careful planning then perform actions based on the value of the analog input.

Either of those methods aren't the most robust solution and will lend themselves to a whole host of issues over time and has the potential to be a real support nightmare. Particularly in a production environment. I think if I were doing this I would add a PLC for additional I/O and everything that could be 24 VDC would be. I might would try either solution on my own machines just for fun (hobby) but would likely do the PLC when I was finished playing with it. If it were a machine someone else would be running (even in my own shop) additional 24 VDC I/O is the only option I would consider, no doubt about it.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline mark4

*
  •  167 167
    • View Profile
Re: A solution for more switches than inputs
« Reply #8 on: February 13, 2018, 11:25:16 AM »
Hello thanks for the reply. I am looking at plc. I tried to do that with pokeys but that didn't work out. So can you recommend a plc I only have one Ethernet port. So for the pokeys I used a usb to Ethernet adapter and it seemed to work alright. Thank you
Mark

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: A solution for more switches than inputs
« Reply #9 on: February 13, 2018, 12:22:06 PM »
I can't make a recommendation on the PLC. Just find one that supports the I/O count and type you need, you like the tools they give you (or you have to buy) to program it and that fits your budget. The clicks from Automation Direct are used often with Mach and I have used them myself with good results.

AUD also offers a usb to serial adapter and the cable to use with it that goes to the PLC. The cable I used looked a lot like an ethernet cable but it wasn't. It was a serial cable that uses (I think) RJ11 connectors. But you can communicate with some PLCs over TCP Modbus and/or RS-485 serial and/or RS-232 serial. So...... you will need to decide what protocol is best for you and choose a PLC that matches.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!