Hello Guest it is June 04, 2024, 11:16:58 PM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SwiftyJ

Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 »
201
Hi, I think have replicated the control in Mach4 using buttons with your inputs etc. I've done it in a way that can easily be modified, there is a lot more to add to the signal library, but is simpler.
There are four new functions as well to add to the screen load script. I used input 50 as Jog- and 51 as Jog+, not sure if this is correct for your settings.

I have also attached the screen set I modified. There is a tab called 'External Jog' next to MDI/Gcode tab. All the code is in the screen load script right under the signal library. The only thing I don't know is what will happen on startup - if mach will run the signal library code if it see's an input is active on startup

Save what you have, then try this, see if its any help

Signal Library
Code: [Select]
[mc.ISIG_INPUT19] = function (state) -- Increment Selection 1
    if(state == 1) then
setJogInc(1)
end
end,
[mc.ISIG_INPUT20] = function (state) -- Increment Selection 2
    if(state == 1) then
setJogInc(0.1)
end
end,
[mc.ISIG_INPUT21] = function (state) -- Increment Selection 3
    if(state == 1) then
setJogInc(0.01)
end
end,
[mc.ISIG_INPUT22] = function (state) -- Increment Selection 4
    if(state == 1) then
setJogInc(0.001)
end
end,
[mc.ISIG_INPUT23] = function (state) -- Increment Selection 5
    if(state == 1) then
setJogInc(0.0001)
end
end,
[mc.ISIG_INPUT24] = function (state) -- Jog Rate Selection 1
    if(state == 1) then
setJogRate(2)
end
end,
[mc.ISIG_INPUT25] = function (state) -- Jog Rate Selection 2
    if(state == 1) then
setJogRate(5)
end
end,
[mc.ISIG_INPUT26] = function (state) -- Jog Rate Selection 3
    if(state == 1) then
setJogRate(10)
end
end,
[mc.ISIG_INPUT27] = function (state) -- Jog Rate Selection 4
    if(state == 1) then
setJogRate(25)
end
end,
[mc.ISIG_INPUT28] = function (state) -- Jog Rate Selection 5
    if(state == 1) then
setJogRate(50)
end
end,
[mc.ISIG_INPUT29] = function (state) -- Jog Rate Selection 6
    if(state == 1) then
setJogRate(75)
end
end,
[mc.ISIG_INPUT30] = function (state) -- Jog Rate Selection 7
    if(state == 1) then
setJogRate(100)
end
end,

[mc.ISIG_INPUT50] = function (state) -- Jog- Input
local axisNum = getAxisToJog()
    if(state == 1) then
jogAxis(axisNum, mc.MC_JOG_NEG)
else
jogAxis(axisNum, mc.MC_JOG_STOP)
end
end,

[mc.ISIG_INPUT51] = function (state) -- Jog+ Input
local axisNum = getAxisToJog()
    if(state == 1) then
jogAxis(axisNum, mc.MC_JOG_POS)
else
jogAxis(axisNum, mc.MC_JOG_STOP)
end
end,

4 new functions
Code: [Select]
function setJogInc(inc)
local rc, axisNum
local inst = mc.mcGetInstance()
--For each axis set the incremental value and jog type to inc
for axisNum=0,5,1 do -- X = 0, Y = 1, Z = 2
rc = mc.mcJogSetInc(inst, axisNum, inc)
rc = mc.mcJogSetType(inst, axisNum, mc.MC_JOG_TYPE_INC)
end
end

function setJogRate(rate)
local rc, axisNum
local inst = mc.mcGetInstance()
--For each axis set the jog rate value and jog type to cont
for axisNum=0,5,1 do -- X = 0, Y = 1, Z = 2
rc = mc.mcJogSetRate(inst, axisNum, rate)
rc = mc.mcJogSetType(inst, axisNum, mc.MC_JOG_TYPE_VEL)
end
end

function jogAxis(axis, dir)
-- Get states of Inc and Cont outputs
local inst = mc.mcGetInstance()
local rc
-- Below is a work around as there is no mc.mcJogGetType API call
local axisLetters = {[0] = "X", [1] = "Y", [2] = "Z", [3] = "A", [4] = "B", [5] = "C"}
local hReg = mc.mcRegGetHandle(inst, string.format("core/inst/JogType%s", axisLetters[axis]))
local jogType = mc.mcRegGetValue(hReg)
--
if (jogType == mc.MC_JOG_TYPE_INC) and dir ~= mc.MC_JOG_STOP then --If incremental jog
local incVal = mc.mcJogGetInc(inst, axis) --Get increment value for the axis
rc = mc.mcJogIncStart(inst, axis, (incVal*dir)) --Start the inc jog
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error starting incremental jog")
end
elseif (jogType == mc.MC_JOG_TYPE_VEL) and dir ~= mc.MC_JOG_STOP then --If continuous and not stopping
rc = mc.mcJogVelocityStart(inst, axis, dir)
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error starting continuous jog")
end
elseif (jogType == mc.MC_JOG_TYPE_VEL) and dir == mc.MC_JOG_STOP then
mc.mcJogVelocityStop(inst, axis)
end
end

function getAxisToJog() --This function looks at the inputs for the axis selector and returns the axis number for the one that is selected
local inst = mc.mcGetInstance()
local axisToJog, k, v
--Create table for axis input signals
local axesTbl = {[0] = mc.ISIG_INPUT44, [1] = mc.ISIG_INPUT45, [2] = mc.ISIG_INPUT46, [3] = mc.ISIG_INPUT47, [4] = mc.ISIG_INPUT48, [5] = mc.ISIG_INPUT49}
-- Find the input that is active and return the axis number
for k,v in pairs(axesTbl) do
local hSig = mc.mcSignalGetHandle(inst, v)
if (mc.mcSignalGetState(hSig) == mc.MC_ON) then
axisToJog = k
break
end
end
return axisToJog
end

202
Can you post a picture of the controls you are trying to set up or describe what you want everything to do? There may be a way to condense the code you have written and make it bit more user friendly / easier to edit in the future

203
Do you not just need a conditional statement to prevent mc.mcJogVelocityStop from running when jog mode is in incremental?

204
Mach4 General Discussion / Re: Switching tabs
« on: April 28, 2019, 06:53:02 AM »
If you want something to happen when the state of an output or input changes, the Signal Library is the place to do it. The signal library already exists in the default Mach4 Screen Load Script.

Code: [Select]
---------------------------------------------------------------
-- Signal Library
---------------------------------------------------------------
SigLib = { --<Start of signal library

[mc.ISIG_INPUT0] = function (state)
--Code here executes when Input 0 changes state, either high to low, or low to high
--We can check the state of the input/output by using the 'state' variable that is passed into the function.
if (state == 1) then
--Do something when Input 0 is active
end
end, -- Don't forget to put a comma here.

} --<End of signal library

Any Mach4 inputs or outputs can be added to the signal library in the same format as above, just change the input/output name in the square brackets.

For changing the properties of screen controls there is the scr.SetProperty API call. The tab control has a 'Current Tab' property which we can use to change the tab that is shown.

First we get the name of the control from the Screen Tree Manager, in this case it's "nbGCodeMDI1". See the attachment for info on where to get this.
Code: [Select]
scr.SetProperty("nbGCodeMDI1", )Then we enter the name of the property we want to change as a string
Code: [Select]
scr.SetProperty("nbGCodeMDI1", "Current Tab", )Finally, the value we want to change it to. For the Current Tab property, the value of the first tab is "0", second tab is "1" etc.
Code: [Select]
scr.SetProperty("nbGCodeMDI1", "Current Tab", "1" )
Now combine the two things above,

Code: [Select]

[mc.ISIG_INPUT0] = function (state)
if (state == 1) then
--Change to MDI tab when Input 0 is high.
scr.SetProperty("nbGCodeMDI1", "Current Tab", "1" )
else
--Change to GCode tab when Input 0 is low.
scr.SetProperty("nbGCodeMDI1", "Current Tab", "0" )
end
end,

205
Mach4 General Discussion / Re: edit Cyclestop in screen
« on: April 25, 2019, 07:20:52 AM »
Remove CycleStop() from your button script so it just says:

Code: [Select]
--Create a coroutine called 'wait'
wait = coroutine.create(CycleStop)
--Start the coroutine
coroutine.resume(wait)

206
Are you not able to select the Register from the properties menu for the gauge control? (see attachment)

If you have not yet created a register, with mach disabled go to Configure>Plugins>Regfile and then add a new instance register and then restart mach. This will appear within the iRegs0 menu when you go to Diagnostics>Regfile. This will also appear in the Register property dropdown for the gauge control. You will need to write a value to the register for the gauge to update.

Alternatively you can use the scr.SetProperty which is used for modifying GUI controls
e.g.
Code: [Select]
scr.SetProperty('gau(1)', 'Value', '10')
Any control property can be edited using this, but it is always advisable to set values etc. using the proper methods.

You can also use wx.wxGauge, but this would required a lua panel if you want to embed it in the screen and gets a bit more confusing..

207
Mach4 General Discussion / Re: edit Cyclestop in screen
« on: April 25, 2019, 03:22:50 AM »
In your PLC script you should have the following code already if you're using the standard Mach4 screens. This bit of code monitors the state of mach, and when it is idle it will resume the coroutine from where it yielded.
Code: [Select]
-------------------------------------------------------
--  Coroutine resume
-------------------------------------------------------
if (wait ~= nil) and (machState == 0) then --wait exist and state == idle
local state = coroutine.status(wait)
    if state == "suspended" then --wait is suspended
        coroutine.resume(wait)
    end
end

The CycleStop() function will go in the screen load script. This will also turn off the COOLANT ON output, but you can change this to whatever output you have mapped for your coolant output.
Code: [Select]
function CycleStop()
local inst = mc.mcGetInstance()
local rc, hSig
mc.mcCntlCycleStop(inst)
mc.mcSpindleSetDirection(inst, 0)
hSig = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON)
if (hSig == mc.MERROR_NOERROR) then
mc.mcSignalSetState(hSig, mc.MC_OFF)
end
mc.mcCntlSetLastError(inst, "Cycle Stopped")
coroutine.yield() --This is where the function yields and the code in the PLC comes into play
rc = mc.mcCntlMdiExecute(inst, "G90 G53 Z0 Y0")
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Error moving to Z0 Y0")
end
end

This will go in the button script for your stop button
Code: [Select]
--Create a coroutine called 'wait'
wait = coroutine.create(CycleStop)
--Start the coroutine
coroutine.resume(wait)

This worked for me in the simulator, but always take caution when trying bits of code off the internet!

208
Mach4 General Discussion / Re: edit Cyclestop in screen
« on: April 24, 2019, 04:35:34 AM »
I'd say you need run the CycleStop() function as a coroutine using the wait coroutine in the PLC, yield the coroutine after mc.mcCycleStop(inst) so that it waits for mach state to be idle, and then use the GCodeExecute API when it resumes.

209
You could try monitoring the state of the control using mcCntlGetState for when it is probing. 102 is File:Run:Probe and 202 is MDI:Run:Probe. You can then activate the output when it is either of these states.

210
Are you trying to incremental jog using the keyboard or onscreen jog controls?

Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 »