Hello Guest it is April 28, 2024, 03:52:21 AM

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 »
191
What errors are you getting when you try to load mach4? If it’s an error with the screen set you may be able to directly edit the xml to resolve it

192
You can find more info on wxMessageBox here: https://docs.wxwidgets.org/3.1/group__group__funcmacro__dialog.html#ga193c64ed4802e379799cdb42de252647

wxMessageBox uses styles from wxMessageDialog which can be found at the top of the page here: https://docs.wxwidgets.org/3.1/classwx_message_dialog.html

The styles go where the '16' is in your example. So to show a message box with an 'Ok' button with an error symbol it would be the following
Code: [Select]
local rc = wx.wxMessageBox("This is my Message", "This is my Caption", wx.wxOK + wx.wxICON_ERROR)

In this case, if you selected the OK button, rc would be equal to 'wx.wxOK'.

Hope this helps

193
Mach4 General Discussion / Re: Load Image Programatically
« on: September 07, 2019, 04:36:55 AM »
Hi, to load an image into a wxStaticBitmap you have to use wxSetBitmap as below

Code: [Select]
wx.wxStaticBitmap:SetBitmap(wx.wxBitmap("imagelocation\\image.jpg", wx.wxBITMAP_TYPE_JPEG))



I tried this in the UI update event, but found that the image flickered. I think it would probably be better to monitor if a new g-code has been loaded in the Update UI event and then run a function once to read the file path from the g-code load the image.

194
Great!

I've seen your other thread about the feed rate switch.. It should be pretty easy to make it control the jog rate for the incremental moves as we've made it using the registers.
In the signal library for the FRO inputs, i'd just call mc.mcCntlSetFRO() API to set the feed rate, and then set the speed for the incremental moves using the function we made before cpSetJogRate(). If we check that the Jog Type is set to incremental it will prevent the FRO control changing the jog rate when the jog is set to continuous.

If you do this remove the setCpJogRate(100) I added for each of the incremental inputs in the signal library otherwise it will reset to 100 if you change increment value.

So you'd have something like this, I've not tested it but it should work...
Code: [Select]
[mc.ISIG_INPUT18] = function (state) -- Set FRO 100%
    if(state == 1) then
local inst = mc.mcGetInstance()
mc.mcCntlSetFRO(inst, 100) --Set FRO value 100%
local hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogType")
local jogType = mc.mcRegGetValue(hReg)
if (jogType == mc.MC_JOG_TYPE_INC) then --Check that Jog Type is incremental
setCpJogRate(100) --Set jog rate for incremental to 100%
end
end
end,

195
To jog incrementally using the keyboard hold down the Ctrl key. This even works when continuous mode is selected in Mach

196
I've rewritten it using registers which tidies some things up a bit more, and also helps with diagnostics as you can see through the register diagnostics what the jog values are currently set to. It also doesn't affect anything on the Mach screen.

I have added checks to the Jog+ and Jog- signals to check that Mach is enabled (this should prevent errors on startup) and check Mach is at idle (this should help prevent sending a jog command while it is jogging, and also prevent errors if a button is pressed when running g-code or something).  It also looks at input 43 to check that the control panel isn't set to 'Off'

I have added code to input 43 so that if Off is selected while it is jogging, the jogging will stop. You can remove this if you want..

For each of the increment inputs I have added setCpJogRate(100) to set jog rate to 100. You could change it so you have individual speeds for each increment.

There are a couple of functions added/removed and signal library has changed so best to delete what I sent before. You will also need to add the registers via Configure - Plugins - Regfile  (Mach may need to be restarted after)

Double check all the input numbers, I think have them correct

Images of the registers to add are attached

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

[mc.ISIG_INPUT43] = function (state) -- Off --This will stop all current jogging if off is selected
local axisNum
    if (state == 1) and (machEnabled == 1) then --Only runs if mach is enabled.
for axisNum=0,5,1 do
if mc.mcJogIsJogging(inst, axisNum) == 1 then --Check to see if the axis is jogging
mc.mcJogVelocityStop(inst, axisNum) --If it is then stop jogging
mc.mcCntlSetLastError(inst, "Jog stopped via Control Panel")
end
end
end
end,
[mc.ISIG_INPUT44] = function (state) -- Select X axis
    if(state == 1) then
setCpJogAxis(0)
end
end,
[mc.ISIG_INPUT45] = function (state) -- Select Y axis
    if(state == 1) then
setCpJogAxis(1)
end
end,
[mc.ISIG_INPUT46] = function (state) -- Select Z axis
    if(state == 1) then
setCpJogAxis(2)
end
end,
[mc.ISIG_INPUT47] = function (state) -- Select 4 axis
    if(state == 1) then
setCpJogAxis(3)
end
end,
[mc.ISIG_INPUT48] = function (state) -- Select 5 axis
    if(state == 1) then
setCpJogAxis(4)
end
end,
[mc.ISIG_INPUT49] = function (state) -- Select 6 axis
    if(state == 1) then
setCpJogAxis(5)
end
end,
[mc.ISIG_INPUT51] = function (state) -- Jog+ Input
local hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT43)
local cpJogEna = mc.mcSignalGetState(hSig) ~= 1 --If signal is not equal to 1, then cpJogEna == True
if (machEnabled == 1)  and cpJogEna then --If mach is enabled and cpJogEna == true
if(state == 1) and (machState == mc.MC_STATE_IDLE) then
cpJogAxis(mc.MC_JOG_POS)
else
cpJogAxis(mc.MC_JOG_STOP)
end
end
end,

[mc.ISIG_INPUT52] = function (state) -- Jog- Input
local hSig = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT43)
local cpJogEna = mc.mcSignalGetState(hSig) ~= 1 --If signal is not equal to 1, then cpJogEna == True
if (machEnabled == 1) and cpJogEna then
if (state == 1) and (machState == mc.MC_STATE_IDLE) then
cpJogAxis(mc.MC_JOG_NEG)
else
cpJogAxis(mc.MC_JOG_STOP)
end
end
end,

Screen load script functions
Code: [Select]
function setCpJogInc(inc) --Sets value of cpJogInc register
local inst = mc.mcGetInstance()
local hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogInc")
mc.mcRegSetValue(hReg, inc)
end

function setCpJogRate(rate) --Sets value of cpJogRate register
local inst = mc.mcGetInstance()
local hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogRate")
mc.mcRegSetValue(hReg, rate)
end

function setCpJogType(mode) --Sets value of cpJogType register
local inst = mc.mcGetInstance()
local hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogType")
mc.mcRegSetValue(hReg, mode)
end

function setCpJogAxis(axis) --Sets value of cpJogAxis register
local inst = mc.mcGetInstance()
local hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogAxis")
mc.mcRegSetValue(hReg, axis)
end

function cpJogAxis(dir) --This function starts the jogging
local inst, hReg
inst = mc.mcGetInstance()
--Retrieve values from registers
hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogAxis")
local jogAxis = mc.mcRegGetValue(hReg)
hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogRate")
local jogRate = mc.mcRegGetValue(hReg)
hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogInc")
local jogInc = mc.mcRegGetValue(hReg)
hReg = mc.mcRegGetHandle(inst, "iRegs0/cpJogType")
local jogType = mc.mcRegGetValue(hReg)
--Set Jog Rate
mc.mcJogSetRate(inst, jogAxis, jogRate)
--Jog Axis
if (jogType == mc.MC_JOG_TYPE_INC) and dir ~= mc.MC_JOG_STOP then --If incremental jog
rc = mc.mcJogIncStart(inst, jogAxis, (jogInc*dir)) --Start the inc jog
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, string.format("Error %.0f: Unable to start incremental jog", rc))
end
elseif (jogType == mc.MC_JOG_TYPE_VEL) and dir ~= mc.MC_JOG_STOP then --If continuous and not stopping
rc = mc.mcJogVelocityStart(inst, jogAxis, dir)
if (rc ~= mc.MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, string.format("Error %.0f: Unable to start continuous jog", rc))
end
elseif (jogType == mc.MC_JOG_TYPE_VEL) and dir == mc.MC_JOG_STOP then
mc.mcJogVelocityStop(inst, jogAxis)
end
end

197
If you want to stop the new code affecting the screen jog controls I can rewrite some of it using registers which would sort this out.

I think the reason you're getting the errors during start up is that Mach4 see's the input high and runs the jogAxis function. You can fix this by checking that the Mach is enabled in the Jog Plus and Jog Neg code in the signal library. There is a global variable that is set up at the top of the screen load screen 'machEnabled'. I believe you can use this e.g.
Code: [Select]
[mc.ISIG_INPUT50] = function (state) -- Jog- Input
if (machEnabled == 1) then
local axisNum = getAxisToJog()
if(state == 1) then
jogAxis(axisNum, mc.MC_JOG_NEG)
else
jogAxis(axisNum, mc.MC_JOG_STOP)
end
end
end,

Regarding the speed for incremental jog moves, Mach uses the current jog rate % when performing an incremental move. The feed rate control only affects g-code. You could set a different rate for each increment using the setJogRate() function

198
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

199
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

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

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