Hello Guest it is July 19, 2025, 08:26:27 AM

Author Topic: Lua set Jog% with a button  (Read 23995 times)

0 Members and 1 Guest are viewing this topic.

Offline Rimmel

*
  •  284 284
Lua set Jog% with a button
« 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....

Offline Bill_O

*
  •  601 601
Re: Lua set Jog% with a button
« Reply #1 on: July 02, 2024, 05:41:04 PM »
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

Offline Bill_O

*
  •  601 601
Re: Lua set Jog% with a button
« Reply #2 on: July 02, 2024, 05:44:34 PM »
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

Offline Rimmel

*
  •  284 284
Re: Lua set Jog% with a button
« Reply #3 on: July 03, 2024, 07:18:00 AM »
Thanks for the reply - a question if I may?

Code: [Select]
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
« Last Edit: July 03, 2024, 07:27:01 AM by Rimmel »

Offline Bill_O

*
  •  601 601
Re: Lua set Jog% with a button
« Reply #4 on: July 03, 2024, 09:01:24 AM »
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.

Offline Rimmel

*
  •  284 284
Re: Lua set Jog% with a button
« Reply #5 on: July 03, 2024, 02:12:28 PM »
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.

Code: [Select]
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
« Last Edit: July 03, 2024, 02:15:47 PM by Rimmel »

Offline Bill_O

*
  •  601 601
Re: Lua set Jog% with a button
« Reply #6 on: July 03, 2024, 04:33:37 PM »
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.

Offline Bill_O

*
  •  601 601
Re: Lua set Jog% with a button
« Reply #7 on: July 03, 2024, 04:36:45 PM »
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%.

Offline Rimmel

*
  •  284 284
Re: Lua set Jog% with a button
« Reply #8 on: July 03, 2024, 04:37:24 PM »
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.

Offline Bill_O

*
  •  601 601
Re: Lua set Jog% with a button
« Reply #9 on: July 03, 2024, 04:51:41 PM »
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.