Hello Guest it is April 24, 2024, 12:15:46 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 - TTalma

Pages: 1 2 3 4 5 6 7 8 »
1
In my tool changer script I need to make sure that the bottom of the spindle is above the top of the tool holders before moving to load a tool. I don't want to raise to machine coords z=0 (Z axis highest position) each time I change tools since it is 3.5" above the top of the tool holders, and this up and down movement wastes a lot of time. Most of the time this is not an issue since I will move to a safe height after dropping off a tool but there are a few situations where I manually unload the spindle and I want to ensure it's at a safe height. So I added some code to check, if it's below safe height, it should raise to a safe height.

so I use the following line to get the current position in machine coordinates:
Code: [Select]
local currentZ = mc.mcAxisGetMachinePos(inst, mc.Z_AXIS)
but about 75% of the time this call returns 0, while the dro (set to machine coords) displays a non zero number, and the dro is always correct. I can't read the DRO because most of the time it will be displaying work coords.

So is there a reliable way to read machine coordinates?

2
I like the format of the tool table, but I hate that it's a popup.  I would like to use it as is in a new tab I create. Do I need to recreate it or is it possible to just use it on a new screen?

3
I have made a module file 'PocketPositions.Lua' with a bunch of functions.

In the screen load script I added the following:
Code: [Select]
-- Pocket Positions
package.loaded.PocketPositions = nil
PocketPositions = require "PocketPositions"

From a tab On enter script I have:
Code: [Select]
local pocketNums = PocketPositions.GetUsedPocketNumbers()
if pocketNums[1] ~= nil then
wx.wxMessageBox("pocketNums[1] ="..tostring(pocketNums[1]))
table.sort(pocketNums)
local pocketStr = ""
for i=1, #pocketNums do
pocketStr = pocketStr .. pocketNums[i] .. "|"
end
wx.wxMessageBox("pocketStr="..pocketStr)
scr.SetProperty("GROUPBOX_CurrentToolPocket", "Strings", pocketStr)
else
wx.wxMessageBox("pocketStr=nil")
end

the function 'PocketPositions.GetUsedPocketNumbers()' looks like:
Code: [Select]
-- Gets a table of the pocket numbers that are configured
function PocketPositions.GetUsedPocketNumbers()
local PocketNums={}
local n=0

-- make sure the pockets have been loaded
if PocketDetails == nil or PocketDetails[0] == nil then
PocketPositions.ReadPocketData()
end

for k,v in pairs(PocketDetails) do
  n=n+1
  PocketNums[n]=k
end

return PocketNums
end

When it calls the function 'PocketPositions.ReadPocketData()' (which is also in the  'PocketPositions.Lua' file) I get an error that 'PocketPositions' is null.

If I step through 'PocketPositions.ReadPocketData()' in the script editor it works fine.

Any idea what's happening and how I fix it?


4
I messed around with it a lot and still couldn't figure out why it wasn't working. As a test I made a new profile with no edits, added the M500 from above and it worked fine.

I ended up copying my screen set in to this new profile and it worked, I can't figure out what I did to break it, It must be one of the files I was editing i made some odd mistake. But I'm moving along now.

5
I only have the m500 file in the Macros folder.

I tried upper and lower case with no difference.

I did notice something weird though with the button, When I press it it's starts the cycle and hangs like when running it in the MDI window. When I press the button again is when it executes.

The code is in the 'Button clicked' event and looks like:
Code: [Select]
local inst=mc.mcGetInstance()
mc.mcCntlGcodeExecute(inst, "m500\n")

6
I created a new m code, m500 and put it in the folder 'C:\Mach4Hobby\Profiles\AXYZ\Macros'.

The contents of the file are:
Code: [Select]
function m500()
wx.wxMessageBox("Works")
end

if (mc.mcInEditor() == 1) then
m500()
end
I'm running the profile in AXYZ and have confirmed this.

When I type 'M500' in the MDI window, or put it in a gcode file it does not execute. It just sits on the line and the cycle time counter goes up. I don't get any errors, it doesn't do anything.

I tried making a simple gcode file that looked like:
Code: [Select]
X0 Y0
m500
X1 Y1

The machine moves to 0,0 then just sits on the m500 line.

I tried calling the command from a button and it works fine

I stepped through the function and the message box pops up correctly.

What am I doing wrong?



7
Thank you the /e option worked!

Other than my M code files and other files I've created which file s should I back up?

8
I was editing a screen and added a button. I set the click script to call macro 'm500', and typed it in that way. It should be 'm500()'. But now when I load the screen it gives the error:
Lua: Script error during pre compilation
c:\mach4hobby\Screenscript.Lua:861'Syntex error near 'end'

I tried removing the line from Screenscript.lua, (I did remove the read-only status). Saved the file and and verified my change was saved. But when I restart Mach 4 I get the same error, and when I check Screenscript.lua the line with the error is back.

How do I fix this error?

9
Thank you so much for your explanation! It was nice and clear! And worked exactly like I needed it to.

10
Like the title states I'm trying to call a function that I have placed in a module from a button I've added to a screen.

I plan to add several functions and but even though I've copied examples that I've found they do not work. So far my code is really simple it looks like:

Button: (Clicked Script event)
Code: [Select]
PrintVal("123")
In folder C:\Mach4Hobby\Profiles\AXYZ\Macros
I added File: Load_Modules.mcs, all of the code looks like:
Code: [Select]
package.path = wx.wxGetCwd() .. "\\Profiles\\AXYZ\\Modules\\Test.lua"

package.loaded.Test = nil
require "Test"

In Folder C:\Mach4Hobby\Profiles\AXYZ\Modules
I added File: Test.lua, all of the code looks like:
Code: [Select]
function PrintVal(val)
wx.wxMessageBox("Current val="..tostring(val))
end

When I press the button I get the error:
Lua: Error while running chunk
c:\Mach4Hobby\ScreenScript.lua:854: attempt to call a nil value (global 'PrintVal')
stack traceback:
c:\Mach4Hobby\ScreenScript.lua:854: in function 'BUTTON_Test_Clicked_Script'


Can anyone tell me what I am doing wrong?
All of the files compile. The best I can figure out is that the screenscript.lua doesn't know anything about the modules, but according to the documentation my Load_modules.mcs file should load this.

I have made sure to delete the Load_Modules.mcc file and restart mach to recompile it after making changes to that file.

Pages: 1 2 3 4 5 6 7 8 »