Hello Guest it is June 04, 2024, 09:08:38 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 »
191
Mach4 General Discussion / Re: Mach 4 Exit button for touchscreen
« on: December 17, 2019, 08:11:19 AM »
Try using scr.Exit(true)

192
Mach4 General Discussion / Re: Switch one output with 2 different signals?
« on: December 04, 2019, 07:07:39 AM »
Assuming you are using a toggle button can you not just assign the 'Spindle On' output to the button at the bottom of the properties window in the screen editor?

193
Mach4 General Discussion / Re: MACH 4 screen contrast
« on: December 03, 2019, 04:48:49 AM »
You may not be increasing the widths by a big enough increment. I usually start at increasing by 50 each time and then fine tune from there

194
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

195
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

196
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.

197
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,

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

199
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

200
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

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