Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: smav on January 27, 2019, 01:46:01 PM

Title: Configuring Keys In Key Board Inputs Configuration Table
Post by: smav on January 27, 2019, 01:46:01 PM
I have been attempting to assign the key board keys to certain functions under the Key Board configuration menu. I have been able to to assign the jog functions for each axis but I cannot create any for such things as e-stop, Jog rate %, spindle on/off and so on. The issue I have is in the function column on the Key Board configuration table does not have the functions like e-stop and the others listed so although I can fill in the other columns on the table as desired but the function column lacks, from what I see, most functions other than axis movement functions.
Is there a way to add functions to the column of that table so they can be assigned to a key?
Thanks for reading....
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: DazTheGas on January 27, 2019, 03:30:17 PM
You can see how its done from this video...

https://www.youtube.com/watch?v=jTzYotLTJkY

DazTheGas
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: smav on January 27, 2019, 04:45:31 PM
Thanks Daz for that tip.....I can and have mapped keys to inputs but my question is, how do you assign the input to a function. For example, I have the e-stop push button on my controller/vfd assigned to the emergency or e-stop input so that works as designed but how do I  assign the e-stop function to the keyboard key that I want to use also for the e-stop function?
Thanks again for the tip
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: smav on January 27, 2019, 04:48:36 PM
More specifically I assigned the ~ button to input 0. How do I give input 0 the function of e-stopping the machine when activated?
Thanks again for the help
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: DazTheGas on January 27, 2019, 05:03:35 PM
Use the sigLib script in the screen load script and activate the estop if input0 is pressed

Code: [Select]
[mc.ISIG_INPUT0] = function (state)
    if (state == 1) then   
        mc.mcCntlEStop(inst)
    end
end,

DazTheGas
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: smav on January 27, 2019, 06:16:08 PM
Thanks again for the help on that. I copied that code and noticed when I opened the screen load script that the first line was already there so all i had to do was add the other two lines with the end statement and the button initiates the e-stop now. :)
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: smav on January 28, 2019, 11:37:57 PM
Ok got the easy functions like e-stop and such figured out on how to map them to a key but I am a little lost on how you would map the keys to feed rate or jog rate. Is there a keyboard plugin that actually has all of the functions in mach 4 that you could just select from a drop? Basically I am lost on how you tell the input or write the a script to increase a DRO like Jog% to increase or decrease from button functions.
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: Cbyrdtopper on January 29, 2019, 09:06:56 AM
smav,
There aren't any more functions from a drop down other than jogging from the Keyboard Plugin Config.  You will have to add your inputs to the Signal Library just like you did with the E Stop.
The EStop was easy because there is already a call for E Stop; but you will have to write a script to do other functions like increasing Jog %.

I made a script to increase and decrease the Spindle Override with the (+) and (-) buttons.
I mapped the Buttons to Input 3 and Input 4.
In the screen load script; I made a function called SpindlePlus() to increase by 10% and SpindleMinus() to decrease by 10%
In the Signal Library, I put those functions in Input 3 and Input 4 respectively.



[mc.ISIG_INPUT3] = function (State)
    if (State == 1) then   
       SpindlePlus()
     end
end,

[mc.ISIG_INPUT4] = function (State)
    if (State == 1) then   
       SpindleMinus()
     end
end,

---------------------------------------------------------------
function SpindlePlus()
    local inst = mc.mcGetInstance()
    local SSO = mc.mcSpindleGetOverride(inst)--Returns:  0.5 - 1.5
    if SSO >= 1.5 then
       mc.mcCntlSetLastError(inst, "Can't increase SSO anymore.")
    else
       SSO = (SSO + 0.1)
       mc.mcSpindleSetOverride(inst, (SSO))
    end
end
---------------------------------------------------------------
function SpindleMinus()
    local inst = mc.mcGetInstance()
    local SSO = mc.mcSpindleGetOverride(inst)--Returns:  0.5 - 1.5
    if SSO <= 0.5 then
       mc.mcCntlSetLastError(inst, "Can't decrease SSO anymore.")
    else
       SSO = (SSO - 0.1)
       mc.mcSpindleSetOverride(inst, (SSO))
    end
end
---------------------------------------------------------------

Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: smav on January 29, 2019, 11:05:12 AM
Thanks for the info and help on that. I figured it would take a little bit of script in order to do that, wish I was a little handier at writing it. I think I can figure out from the example how to create the jog% function to input from a keyboard key.
Thanks again for the help and advice.
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: smav on January 31, 2019, 12:36:34 PM
Chad--I duplicated your example for spindle speed with the code in the screen load script and signal library and it works just as you describe. I then attempted to modify it to do the same, using inputs 1 and 2 to increase and decrease jog rate. There were only a few options such as JogRateAccel, JogRateVelocity and maybe another one that I thought should return a the value from the JogRate% DRO but I don't think any of those actually capture or read what is reflected in the Jog Rate % DRO value. I also attempted to see if I could create a register to capture the JogRate% DRO value and then get it from the register but that didn't work either. What I am trying to figure out is what is the right function call to get the current Jog Rate and the which is the correct one to call to increase or decrease it. I believe the slider and DRO represent the percentage of the motors 0 to full open feed rate. If you or anyone else has any suggestions or directions on which are the correct functions to call for the get and execute commands I would appreciate it. NOTE: Lua is new to me and my programming experience was in basic and VB.
Thanks for the advice and help. 
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: Cbyrdtopper on January 31, 2019, 04:43:39 PM
Using this macro, I can change the jog to whatever I want, notice I am changing the Jog% for each motor.  It won't update the display if you try and change it below 50%.  Not sure why, this is a question for someone who knows more than me.

--Set Jog Rate
function m324()
local inst = mc.mcGetInstance()
local JogRate = 72.3   --Jog %
mc.mcJogSetRate(inst, 0, JogRate)  --Motor 0
mc.mcJogSetRate(inst, 1, JogRate)  --Motor 1
mc.mcJogSetRate(inst, 2, JogRate)  --Motor 2
mc.mcJogSetRate(inst, 3, JogRate)  --Motor 3

end --m324

if (mc.mcInEditor() == 1) then
 m324()
end
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: smav on January 31, 2019, 05:10:44 PM
Thanks Chad, what i was reading last night kind of makes sense now. I was browsing the the manual for the various mach lua jog commands and from what I was reading, it appeared to me that when you wanted to change the jog rate it was axis dependent and not like a global command that would just apply to all four axis universally. So, I was looking for how they implemented the slider and dro function so that it controlled all four the same way but wasn't really finding anything. I will try this later today and let you know how it works. I am attempting to get the hand held controller that was configured for Mach 3 originally to work with mach 4 and being able to set the jog rate without having to walk back to the computer each time will make it much more user friendly.
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: smav on January 31, 2019, 10:38:34 PM
Chad--I was able figure out from your macro the script needed for the sig library and added an if statement to stop the jog rate increment at 1 and 100 when they were reached and used inputs 1 and 2 to trigger the jog + or - command from the screen load file. I also noticed what you saw with the DRO only decreasing say to 50 or whatever and found that it was actually only counting down to the point where the dro originally started from. So if the slider and DRO were showing say 65% then when you decreased the jog rate with the keyboard key and got to 65 the dro would stop counting until I came back up to it and started going above 65, the jog rate did actually continue to degrees as I tested it on the mill to see if was actually still decreasing even tho dro was not registering it. I found if I slid the slider to 1 then it would count the full range of 1 to 100 when I used the keyboard or my pendant buttons.

I figured the easiest fix would be to just have the jog rate reset to 1 in either the load or unload screen but although I was successful in getting the actual Jog Rate to reset to 1 using either method I was not able to get the DRO and slider to reset to 1 through either one. I  believe the dro is simply stored in a registry but I am not savvy enough to know where it is or how to manipulate it at this point. I appreciate all the advice and help. 
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: smav on February 02, 2019, 12:10:30 AM
Last Update--I figured out a script for the PLC so that it will run once at the beginning and will set the actual jog rate, Jog Rate% DRO  and Slider value to 1 on start up. Now the the keys and pendent buttons will scale up and down the jog rate since it is able to start out from 1. However, if you at any time adjust the slider with the mouse on the screen, then the slider and dro will only go back down to that value you set the slider to with the mouse, if you go back and use the keyboard or pendent after that. If you slide the slider back to 1 with the mouse it will then work as intended with the buttons or keyboard.
 
Again I really appreciate your suggestions and examples as those helped me figure out what I needed to do in regards the correct syntax as the manuals found in the help folder explain things in general but don't really have any exact examples.....
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: fritzzco on March 22, 2019, 11:43:12 PM
smav,
There aren't any more functions from a drop down other than jogging from the Keyboard Plugin Config.  You will have to add your inputs to the Signal Library just like you did with the E Stop.
The EStop was easy because there is already a call for E Stop; but you will have to write a script to do other functions like increasing Jog %.

I made a script to increase and decrease the Spindle Override with the (+) and (-) buttons.
I mapped the Buttons to Input 3 and Input 4.
In the screen load script; I made a function called SpindlePlus() to increase by 10% and SpindleMinus() to decrease by 10%
In the Signal Library, I put those functions in Input 3 and Input 4 respectively.



[mc.ISIG_INPUT3] = function (State)
    if (State == 1) then   
       SpindlePlus()
     end
end,

[mc.ISIG_INPUT4] = function (State)
    if (State == 1) then   
       SpindleMinus()
     end
end,

---------------------------------------------------------------
function SpindlePlus()
    local inst = mc.mcGetInstance()
    local SSO = mc.mcSpindleGetOverride(inst)--Returns:  0.5 - 1.5
    if SSO >= 1.5 then
       mc.mcCntlSetLastError(inst, "Can't increase SSO anymore.")
    else
       SSO = (SSO + 0.1)
       mc.mcSpindleSetOverride(inst, (SSO))
    end
end
---------------------------------------------------------------
function SpindleMinus()
    local inst = mc.mcGetInstance()
    local SSO = mc.mcSpindleGetOverride(inst)--Returns:  0.5 - 1.5
    if SSO <= 0.5 then
       mc.mcCntlSetLastError(inst, "Can't decrease SSO anymore.")
    else
       SSO = (SSO - 0.1)
       mc.mcSpindleSetOverride(inst, (SSO))
    end
end
---------------------------------------------------------------
Chad, Your posted script works well, I did it for also the FRO.   Thanks.   Can you show me how this would look for the JogRate?   I been trying for days now, no luck for some reason.   I just keep getting errors.  This is what I have for JogRate:
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: Cbyrdtopper on March 23, 2019, 02:30:37 PM
I can't see the code, the picture is too small.
Can you just copy the code into the thread?
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: fritzzco on March 23, 2019, 03:18:27 PM
Ok, try this, I don't know how to copy code into a thread, im dumb as hell on this stuff, sorry.

I put a + & - button by the jograte slider, they work good, but I cannot get to do that with the keyboard, :(

Thanks for your time,
Fritz
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: joeaverage on March 23, 2019, 03:47:00 PM
Hi,

Quote
I don't know how to copy code into a thread,

What you have done works but there is an even easier way.  You may have noted  a series of buttons
along the top of the text input panel, the one with the 'hash' icon will insert a code panel within your text.

There are many others, the quote and hyperlink insert buttons being commonly used ones.

They insert a matched pair of editing marks and all text within the marks is treated specially by your browser.

Craig
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: fritzzco on March 23, 2019, 04:03:02 PM
OK,  Thanks for that, always learning.

Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: fritzzco on March 24, 2019, 12:21:24 PM
Craig,  What am I doing wrong here?   I get errors no matter what I put in for a jog API.  I'm trying to map this to my keyboard F1 key.

SigLib = {
   
[mc.ISIG_INPUT22] = function (state)
    if (state == 1) then --
      local inst = mc.mcGetInstance()
        Feed2()
    end
end,


function Feed2()
    local inst = mc.mcGetInstance()
    local Feed2 = mc.mcJogGetRate(inst)
    if Feed2 == 100 then
       mc.mcCntlSetLastError(inst, "Can't increase JogRate anymore.")
    else
       local Feed2 = (Feed2 + 10)
       mc.mcJogSetRate(inst, Feed2)
    end
end
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: Cbyrdtopper on March 24, 2019, 12:45:32 PM
I think the jog functions need an axis.  So when you get and set the jog rate you need to set it for each axis.   I ran into this problem about a month ago.   
Mc.jog (inst, Axis#, jog rate)
I can't double-check this right now, I'm not at home, but I think that is what it is looking for.  You will need 3 lines to set it for X, Y, and Z.
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: fritzzco on March 24, 2019, 12:54:09 PM
Like this:?

-Set Jog Rate

function Feed2()
    local inst = mc.mcGetInstance()
    local Feed2 = mc.mcJogGetRate(inst)
   mc.mcJogSetRate(inst, 0, JogRate)  --Motor 0
   mc.mcJogSetRate(inst, 1, JogRate)  --Motor 1
   mc.mcJogSetRate(inst, 2, JogRate)  --Motor 2
   mc.mcJogSetRate(inst, 3, JogRate)  --Motor 3
    if Feed2 == 100 then
       mc.mcCntlSetLastError(inst, "Can't increase JogRate anymore.")
    else
       local Feed2 = (Feed2 + 10)
       mc.mcJogSetRate(inst, Feed2)
    end
end
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: fritzzco on March 24, 2019, 12:55:20 PM
Ok, tried it, don't work.  rats and more rats
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: fritzzco on March 24, 2019, 01:23:55 PM
I tried this, no work either   :-[

--Set Jog Rate

function Feed2()
    local inst = mc.mcGetInstance()
    local Feed2 = mc.mcJogGetRate(inst)
    if Feed2 == 100 then
       mc.mcCntlSetLastError(inst, "Can't increase JogRate anymore.")
    else
       local Feed2 = (Feed2 + 10)
      mc.mcJogSetRate(inst, mc.X_AXIS, SetRate) -- set set for axis
      mc.mcJogSetRate(inst, mc.Y_AXIS, SetRate) -- set set for axis
      mc.mcJogSetRate(inst, mc.Z_AXIS, SetRate) -- set set for axisMotor 3   
    end
   
end   
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: Cbyrdtopper on March 24, 2019, 03:12:11 PM
Once I get home to my laptop I will proof some code out and post it.   
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: fritzzco on March 24, 2019, 05:01:22 PM
Ok, Great, can't wait to see what you come up with.  Thank you.
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: Cbyrdtopper on March 24, 2019, 06:30:13 PM
Here is what I came up with; I made two buttons and put the code in the Clicked Script inside the button, you can make it a function if you like, but these work to increase and decrease the jog rate by 10%.  You can change that to whatever you like, or add another button to change the resolution of change.


--Jog Rate +10%
local inst = mc.mcGetInstance()
local CurrentRate = mc.mcJogGetRate(inst, 1)
local JogRate = (CurrentRate + 10)
if JogRate <= 100 then
    mc.mcJogSetRate(inst, 0, JogRate)
    mc.mcJogSetRate(inst, 1, JogRate)
    mc.mcJogSetRate(inst, 2, JogRate)
else if JogRate > 100 then
    mc.mcCntlSetLastError(inst, "Can't set Jog Rate higher")
end
end

--Jog Rate -10%
local inst = mc.mcGetInstance()
local CurrentRate = mc.mcJogGetRate(inst, 1)
local JogRate = (CurrentRate - 10)
if JogRate >= 10 then
    mc.mcJogSetRate(inst, 0, JogRate)
    mc.mcJogSetRate(inst, 1, JogRate)
    mc.mcJogSetRate(inst, 2, JogRate)
else if JogRate < 10 then
    mc.mcCntlSetLastError(inst, "Can't set Jog Rate Lower")
end
end

Also,
There is a little glitch; this occurred to someone else, I just remembered that they mentioned it happens so be aware of it.
It won't display correctly when you lower it below 50% unless you first change it to 0% and then you can freely raise and lower it from 0-100%.
I don't know why, that's the way it is.  So, when you start, just manually change the jog rate to 0% and you'll be good to go.

Also, looking at your code, maybe change the Axis to an integer instead of writing out the axis, your code may work just fine.
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: fritzzco on March 24, 2019, 06:59:46 PM
Well thank you, i'm going to do some plug and play to see how it works.   Let you know soon.......and thank you again for all your time on this. 
Fritz
Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: fritzzco on March 25, 2019, 02:55:56 PM
Hi,  Well, I didn't get your scripts to work, but I did figure it out using your parts, thanks to you!!   I got this working well in windows 7pro and 10pro.  The only thing is can't use the mouse on the slider or it will disrupt the DRO for some reason, but I don't use a mouse anyhow on any CNC machinery, I have touch screens.   Here is what I'm using and so grateful because of you.

Title: Re: Configuring Keys In Key Board Inputs Configuration Table
Post by: smav on January 06, 2020, 11:10:16 PM
Chad--I had the same issue with DRO not wanting to accurately record the jog rate when I used my pendant. I found that what it was doing was it would count down to what ever the initial value was set at when I started up mach4 and then count no lower. What I did to curb that issue was to set it to default to the value of 1 at start up so after I start march4 up I can use the mouse with slider,my pendant or keyboard interchangeably with no issues, the DRO value always tracks on as it should.