Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Rimmel on July 02, 2024, 02:04:52 PM
-
Hi, has someone got a snippet of code that would allow me to set the Jog Rate % via the Lua linked to a button.
I can create button and link it to the button etc....
thanks in advance....
-
It is in 2 parts.
I put it all in the Mach Screen Load Script.
It does use some custom registers.
Part 1.
[mc.ISIG_INPUT11] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if(machEnabled==1) then
if (AltVal == 0) then
CutSpeedMinus()
elseif (AltVal == 1) then
CutSpeedPlus()
end
end
end
end,
Part 2
--------------------------------------
--cut speed plus function
---------------------------------------
function CutSpeedPlus()
local CutMax = 200
local CutNow = mc.mcCntlGetFRO(inst)
if (CutNow >= CutMax) then
CutNow = CutMax
else
CutNow = CutNow + 10
end
mc.mcCntlSetFRO(inst, CutNow)
end
--------------------------------------
--cut speed minus function
---------------------------------------
function CutSpeedMinus()
local CutMin = 10
local CutNow = mc.mcCntlGetFRO(inst)
if (CutNow <= CutMin) then
CutNow = CutMin
else
CutNow = CutNow - 10
end
mc.mcCntlSetFRO(inst, CutNow)
end
-
Sorry previous post was for cut speed
Here is what i have for jogging speed
Part 1
[mc.ISIG_INPUT19] = function (state)
local AltRegH = mc.mcRegGetHandle(inst, 'iRegs0/Alt')
local AltVal = mc.mcRegGetValue(AltRegH)
if (state == 1) then
if(machEnabled==1) then
if (AltVal == 0) then
JogSpeedMinus()
elseif (AltVal == 1) then
JogSpeedPlus()
end
end
end
end,
Part 2
--------------------------------------
--jog speed plus function
---------------------------------------
function JogSpeedPlus()
local JogMaxS = 100
local JogMax = tonumber(JogMaxS)
local JogNowS = scr.GetProperty('sliJogRate', 'Value')
local JogNow = tonumber(JogNowS)
if (JogNow >= JogMax) then
JogNow = JogMax
else
if (JogNow >= 5) then
JogNow = JogNow + 5
else
JogNow = 5
end
end
rc = scr.SetProperty('sliJogRate', 'Value', tostring(JogNow))
end
--------------------------------------
--jog speed minus function
---------------------------------------
function JogSpeedMinus()
local JogMinS = 1
local JogMin = tonumber(JogMinS)
local JogNowS = scr.GetProperty('sliJogRate', 'Value')
local JogNow = tonumber(JogNowS)
if (JogNow <= JogMin) then
JogNow = JogMin
else
if (JogNow >= 6) then
JogNow = JogNow - 5
else
JogNow = JogNow - 1
end
end
rc = scr.SetProperty('sliJogRate', 'Value', tostring(JogNow))
end
-
Thanks for the reply - a question if I may?
if (AltVal == 0) then
JogSpeedMinus()
elseif (AltVal == 1) then
JogSpeedPlus()
end
What does "AltVal" represent e.g. why are you checking if it's equal to 1 or 0?
Are you checking if the AltKey is pressed or not?
thanks again
-
On my handheld pendant every button can have 2 things it does.
When you hold down what I call the "Alt" button it does the second operation for the button.
AltVal is just a variable that lets me know what the register is set at so i know which function to do when the button is pressed.
-
Hi, mine was easier - I just wanted a few buttons on the screen with preset values attached to them.
All I needed was
Calling for 10% - "JogSpeedSet(10)" on the button script.
function JogSpeedSet(JogSpeed)
if(machEnabled==1) then
rc = scr.SetProperty('sliderJogRate', 'Value', tostring(JogSpeed))
end
end
I use a ShuttlePro and I am still trying to mimic the functions on that. I used to have a couple of macros I used to call to set Jog Speed on that.
You can't do that on the "Upgraded" Mach4...but you could on Mach3 ::) you can only seem to run Gcode.
Thanks again
-
Rimmel,
What exactly are you trying to do that can not be done in Mach4?
It is different but I found how to do everything plus a lot more.
-
I thought you were wanting a mechanical button.
If you just want a button in the software to change to a specific speed then yours is much easier.
I have mine set up so every push changes the speed by 5%.
-
Rimmel,
What exactly are you trying to do that can not be done in Mach4?
It is different but I found how to do everything plus a lot more.
Run the function I last quoted from a button on the Shuttlepro
It seems you cannot. You can only run pre-assigned functions or a line of gcode.
-
I know nothing about the Shuttle Pro other than it exists.
Is there a Plugin for it?
Can you use the buttons as an input into Mach4?
If you can then you can do something like part 1 of my earlier examples.
-
I know nothing about the Shuttle Pro other than it exists.
Is there a Plugin for it?
Can you use the buttons as an input into Mach4?
If you can then you can do something like part 1 of my earlier examples.
You can't in Mach4. But you could in Mach3...
-
I have found nothing you could do in Mach3 that you can not do in Mach4.
It is different and you have to do it a different way.
So it does have a plugin?
If it does have a plugin does it show inputs in the plugin?
-
The Plugin doesn't show inputs as such. You start the plugin and press a key and choose a predeterminded function.
In the Reg settings it also only shows GCode entries, no key-presses are registered.
https://www.youtube.com/watch?v=lQmi6Q_iOAU (https://www.youtube.com/watch?v=lQmi6Q_iOAU)
I don't even use the wheels on the Shuttle Pro, I only really need a pendant keyboard with 5 or 6 buttons on it. That I can program to accept Lua functions.
-
Make an m code that does what you want.
Then assign the key to do that m code.
-
Make an m code that does what you want.
Then assign the key to do that m code.
Hi Bill - already tried that, it doesn't work. The code won't even work in the MDI.
I think is it because the code is based on the screen thread e.g. "scr.SetProperty('sliderJogRate', 'Value', tostring(JogNow))"
Usually modern OS programming languages do not allow direct interaction between the GUI and the underlying core programming. You have to use some form of delegate.
It works on a screen button because that is also on the GUI thread.
I've been looking for a way to set the parameter in the core Mach4 programming - something like "mc.mcSetJogPercent".
Can't find much at present though. I have looked through the Mach4 Scripting Manual.pdf - but can't find a list of actually variables and their definitions for Mach4.
-
Try this in your m code.
#define VAL_SLOW_JOG_RATE 2032
mc.mcCntlSetParameter(2032, 10)
-
Try this in your m code.
#define VAL_SLOW_JOG_RATE 2032
mc.mcCntlSetParameter(2032, 10)
Will do - thanks
I'll report back.
-
Try this in your m code.
#define VAL_SLOW_JOG_RATE 2032
mc.mcCntlSetParameter(2032, 10)
Will do - thanks
I'll report back.
Hi - tried it. The macro compiles OK, but no effect of jogging rate when run in the MDI. I can't see the setting affected any other part of the system.
thanks again
-
I am sure there is a way to do this i just do not know how.
Hopefully some of the smart people can help.
-
I saw in the Mach4 Youtube video you posted earlier that there is an option to assign 'Jog Rate Set to X%" to a button on the ShuttlePro and it gives a few options of Jog percentage. Will this not work for you?