Hello Guest it is October 19, 2019, 09:57:53 PM

Author Topic: Mach 4 Teach File  (Read 1429 times)

0 Members and 1 Guest are viewing this topic.

Mach 4 Teach File
« on: November 01, 2017, 04:35:13 PM »
I am coming out of Mach 3 and wonder does mach 4 have anything close to the teach.tap.  I have some machines that I would Jog around and create point to point programs by hitting a button that would get the dros and write them to the teach file.  Has anyone come up with anything like this yet?  Thanks

Offline Chaoticone

*
  • *
  •  5,607 5,607
  • Precision Chaos
    • View Profile
Re: Mach 4 Teach File
« Reply #1 on: November 01, 2017, 04:46:32 PM »
Not that I know of but should be easy enough to do. How exactly should it work (not necessarily asking how the one in 3 works)? What does it do with the data points recorded? Stuff them in a csv file? Write Gcode using those points?
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Mach 4 Teach File
« Reply #2 on: November 01, 2017, 05:02:11 PM »
Yes I would jog to a point and I had two buttons one was for a rapid and another was for linear  movements and I would grab the speed for those out of two other dros.  It would create a g code program that I could run.  I just would use the append teach.tap and it would add each point to the bottom. 

Offline Chaoticone

*
  • *
  •  5,607 5,607
  • Precision Chaos
    • View Profile
Re: Mach 4 Teach File
« Reply #3 on: November 03, 2017, 05:19:06 PM »
This is a pretty good start I think. Put the function in the screen load script and call it with buttons whose clicked scripts are
GetTeachPoint("G1 ") --for a feed move
GetTeachPoint("G0 ") --for a rapid move

Will need a function to start a new file (which would include feed rate) and a function to finish the file or edit and rename the file manually. Not sure when I will get time to look at it again.

Code: [Select]
inst = mc.mcGetInstance()

function GetTeachPoint(mode) --"G1 " or "G0 "

local AxisTable = {
        [1] = 'X',
        [2] = 'Y',
        [3] = 'Z',
        [4] = 'A',
        [5] = 'B',
        [6] = 'C'}

local MyGcode = mode
for i,v in ipairs (AxisTable) do
local pos = tostring(mc.mcAxisGetPos(inst, (i - 1)))
MyGcode = MyGcode .. string.format(v .. "%0.4f ", pos)
end
MyGcode = MyGcode .. string.format("\n")

local Teach = wx.wxGetCwd() .. "\\GcodeFiles\\Teach.tap" --Define the file name and location
--file = io.open(Teach, "w+") --Open the file in update mode, all previous data is erased
file = io.open(Teach, "a+") --Append update mode, previous data is preserved, writing is only allowed at the end of file.
file:write (MyGcode) --Write the Gcode file
file:flush (Teach) --Save written data
file:close (Teach) --Close file
end
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Mach 4 Teach File
« Reply #4 on: November 04, 2017, 08:44:39 PM »
You're the man.  It does work!!!  I have a long ways to go but a great start.  Think you could point me in the right direction to where i could find out how to create a new file and end it.  Any kind of manual or post that is doing something similar.  Thanks you've been a huge help!!  If you'd like to do some work on the side let me know I would sure pay you for your work.  Thanks again
Re: Mach 4 Teach File
« Reply #5 on: November 05, 2017, 02:13:17 AM »
Hi Kenny,
wxWidgets is a bunch of functions that do a lot of things like text boxes, data input boxes, file browse panels and more.....lots more. I personally
have found wxWidgets much harder to understand than Lua or Machs API. I have found while I can code Lua and API calls from scratch I need something
to copy and modify for wxWidgets code.

If you want a file browse box try m401  in Mach4Hobby/LuaExamples/ProbeToFile.

Craig
My wife left with my best friend...
     and I miss him!
Re: Mach 4 Teach File
« Reply #6 on: November 05, 2017, 11:46:23 AM »
Thanks Craig....I've been able to kind of copy and paste and make a few things work for me...Right now i'm trying to configure a few buttons...one is a new file I have it figured out how to erase all the data and start a new teach.tap but i'm trying to add GO and G1 Feedrates ...I would like those to be in their own DRO's where when I push New teach file it grabs theme out of there writes them to teach.tap and Loads the file. 

I have my G0 and G1 buttons where they are writing to the file and loading but every time it loads it starts back at the top.  Id like to have the code in there where every time I hit those buttons it would get the current line and set the next like +1.

So Technically my goal is to everytime you teach a point is always on the very last line and then i'm wanting to add forward and backwards buttons where you could step though the taught program to verify.

Sorry to be a pain but as it turns out Lua is much more complex than the old Mach 3.  I have all this in mach 3 but I know it's not nearly as expandable as Mach 4 is.  Thanks for all the help it is greatly appreciated!!!

Offline Chaoticone

*
  • *
  •  5,607 5,607
  • Precision Chaos
    • View Profile
Re: Mach 4 Teach File
« Reply #7 on: November 17, 2017, 09:01:48 PM »
This will create a new file and pop up a message box where you enter the desired feed rate.

Just add the function to screen load script and call the function from a button.

Code: [Select]
function CreateNewTeach()

local MyNum = wx.wxGetNumberFromUser("Select or enter a feed rate", "Feed Rate:", "Teach Feed Rate", 50, 1, 1500) --Default, min, max
local MyGcode = string.format("(File created using CreateNewTeach function)\nF%0.4f", MyNum)
local Teach = wx.wxGetCwd() .. "\\GcodeFiles\\Teach.tap" --Define the file name and location
file = io.open(Teach, "w+") --Open the file in update mode, all previous data is erased
--file = io.open(Teach, "a+") --Append update mode, previous data is preserved, writing is only allowed at the end of file.
file:write (MyGcode) --Write the Gcode file
file:flush (Teach) --Save written data
file:close (Teach) --Close file
end
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!