Hello Guest it is April 25, 2024, 01:17:24 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.


Topics - Screwie Louie

Pages: 1
1
This is in response to a request by Pedio. He would like to input a number value into a DRO and have the axis jog to that position instead of going to the MDI input page, writing the block and pressing Cycle Start. I believe his intent is to maximize time efficiency by jogging to a known position from his home page. ie "Enter value, press enter" => axis jogs to desired position. This example is simple without error checking or safety checking (ie. rc values, is axis homed, or is Z axis clear before movement, etc) To implement direct input into a DRO as a text box I will do my best to describe the instructions below. By the way, this was a great idea! Thanx Pedio (If you don't mind, I would like to add this feature to my Blackout Screenset --which is open code for everyone to use, edit, play, add their own features, repost, etc....) You guys are gonna be like "That's it?!?!?" Yep, gotta love m4! I demonstrate a mc.mcCntlMdiExecute function to jog to an absolute coordinate position (G90) and then using mc.mcJogIncStart function call instead of mc.mcCntlMdiExecute G91 command. Hope this helps!

Absolute Position:[/color]
1. Operator -> Edit Screen
2. Add DRO --to wherever you would like for this MDI input to be
3. DRO properties are: DRO Code = Blank, Editor = Keypad
4. On Modify Script =
           local inst = mc.mcGetInstance()
           local gCode = ""
           local Xmove = scr.GetProperty('droXMdiAbs', 'Value')

           Xmove = tonumber(Xmove)
           if Xmove == nil then Xmove = '0' end
           gCode = gCode ..string.format("G0 G90 X%.3f\n", Xmove)

           mc.mcCntlMdiExecute (inst, gCode)

Incremental Movement:[/color][/color]
1. Operator -> Edit Screen
2. Add DRO --to wherever you would like for this MDI input to be
3. DRO properties are: DRO Code = Blank, Editor = Keypad
4. On Modify Script =
           local inst = mc.mcGetInstance()
           local Xmove = scr.GetProperty('droXMdiInc', 'Value')

           Xmove = tonumber(Xmove)
           if Xmove == nil then Xmove = 0 end
           mc.mcJogIncStart (inst, 0, Xmove)

[/color]
That's it folks! I'll post some screen shots below in the next post to help you guys visualize the concept. It's pretty cool. Pedio had a great time-saving idea.

--josh
  

2
Hi Dan,Tim,Simpson36, can you load this up and try it out for me? Just need a another pair of eyeballs. Basically, I am using switches that will mirror my order of operations for a project. The screenset is designed for full screen viewing. The gCode can be viewd in gcedit (the last toggle...btw, some toggles will auto shut off, ie gcedit) It's not done yet. The 'open' toggles will be for probing and tool setting when I finish moving and get everything back together. It's all basic screen calls. Revamped the screen load up script and PLC. This was just done with m4's screen editor...--add, delete, modify, PLAY :)

--josh

3
Talk amongs't yourselfs...(that's my best Dana Carvey impression from Saturday Night Live)

I'm just the apprentice, but wow...the information in these threads is freakin great! Where has YaNvrNo been? Is he ok? I picked up a book on Fanuc macros to help me better understand gCode macros and such to integrate them with Lua; or vice versa. I'm talking from a teacher standpoint of course. Poppabear, Brett,  Terry, Brian, and the like. Hat's off to y'all.

Here's a conversation piece for y'all...

Is Lua to be integrated with Fanuc or vice versa?


peanut gallery comment: The ability to integrate both for automation and in a user defined gui environment has awesome potential. Top it off with today's microcontrollers; we will be controlling mills that make mills...that make tools accurately, reliably, and efficiently. Weapon system acquisition! Let's give Raytheon, Northrop Grumman, and Boeing some competition! ...hey, I can dream a little...

4
...Can't transition from "Idle" on event "Stop"....

how do we make mach 4 transition to Idle?

sequence:
1. start movement
2. input0 changed from low to high
3. mcCntlCycleStop() called
4. Gcode running changed from high to low
5. mach_state_stop
6. S_IDLE_on_entry
6. waiting on SetStill is Done!
7. attempt transition from "MDI running" on event "stop"
8. can't transistion from "idle" on event "stop"

then it repeats last cycle.... >:(

any advice?

--josh

5
Mach4 General Discussion / v2336 Keyboard Simulator plugin
« on: June 05, 2015, 01:17:25 PM »
...the working one

Attached is the keyboard simulator plugin from m4 ver. 2336.

Just delete the keyboard sim from your plugin folder and paste this one in. It works like a charm. I have 30 inputs mapped to functions.

Below is some sample code to put into your signal table/library in the screen load up script. You can map keys straight from m4 input tabs under configuration for jogging. You can really do a lot with it.

I would recommend when you map a key to have the Caps Lock on. This way when you type the keyboard sim doesn't interfere.

I can manipulate mach4 using the keyboard simulator with my Bluetooth keyboard away from the computer. It is also good to simulate probe inputs to test code with using the Mach4 Simulator plugin (as a motion controller sim).

--josh

Code: [Select]
--Keyboard Sim 'Return' w/Caps Lock on to enable Mach 4.
    sigLib[mc.ISIG_INPUT60] = function (state)
        local inst = mc.mcGetInstance ()
        local hSig = mc.mcSignalGetHandle (inst, mc.OSIG_MACHINE_ENABLED)
        local sigState = mc.mcSignalGetState (hSig)

        if state == 1 then
            if sigState == 0 then
            mc.mcSignalSetState (hSig, 1)
            elseif sigState == 1 then
            mc.mcSignalSetState (hSig, 0)
            end
        end
    end

    --Keyboard Sim 'C' w/Caps Lock on to center table.
    sigLib[mc.ISIG_INPUT61] = function (state)
        local inst = mc.mcGetInstance ()
        local gCode = ""
        if state == 1 then
            gCode = "G00 G90 X9.0 Y2.0 Z0.0 \n"
            mc.mcCntlMdiExecute (inst, gCode)
        end
    end

    --Keyboard Sim 'Esc' for Estop.
    sigLib[mc.ISIG_INPUT62] = function (state)
        local inst = mc.mcGetInstance ()
        local rc = 0
        mc.mcCntlEStop (inst, 1)
    end

    --Keyboard Sim 'H' w/Caps Lock on to home all axes.
    sigLib[mc.ISIG_INPUT63] = function (state)
        local inst = mc.mcGetInstance ()
        if state == 1 then
            mc.mcAxisHomeAll (inst)
        end

6
Just copy & paste in the mcLua editor and Run or use it in a button script. Couldn't get the .mcs file attached.

Demonstrates variable scoping, using 'for' loops, return codes, and 'goto' statement.

Run it first. Then deref your axis and run it again to see if the script picks up that your axes are not homed. Then read the code remarks.

The functions are only examples of what we can do. I just did this as a learning process.

--josh


--comments on--
Code: [Select]
--local variables are associated within this script only
--you can define global variables in the Screen Load Up script
--variables pass through all functions in this script
--Define local variables and initialize

local inst = mc.mcGetInstance ()                                                           
local rc = 0
local remark = ""

--using a 'for' loop to find what axes are enables
--this example is just written a different way, it is harder to read but faster to write

function countEnabledAxis ()
    local j = 0; for i=0, 11 do; if mc.mcAxisIsEnabled (inst, i) == 1 then j = j + 1; end; end
    wx.wxMessageBox ("You have " ..j.." axes enabled."); return j
end

--using a 'for' loop to make sure the axes are homed before executing movement
--the number of iterations or loops is equal to the number of enabled axes only
--we then check to see if the number of axes is homed is equal to number of axis enabled, kinda like a signal verification check

function safetyCheck1 ()
    local var = 0
    var = countEnabledAxis ()
    local j = 0
    for i=0, var do
        if mc.mcAxisIsHomed(inst,i) == 1 then
            j = j + 1
            wx.wxMessageBox ("Axis " ..j-1 .." is homed")
        end
    end
    wx.wxMessageBox (var .." axes enabled\n" ..j .." axes homed")
    if j ~= var then
        return "Not all Axes are homed.", false
    end 
end

--if applicable above functions can be loaded into the Screen Load Up script to return a value to your button script
--functions in the Screen Load Up script are accessible to all button scripts
--visualize function main(), call for your defined global safetyCheck function and then execute main function in your button

function main() 
    wx.wxMessageBox ("All is good to execute some screwie louie custom button script.")
end

--this is the point at which the script actuall starts
--the first thing is to start a safety check, this check can be anything you want it to be
--if the machine is not where you want it to be the safety check will return false

wx.wxMessageBox ("Being safety check.")
remark, rc = safetyCheck1 ()
local var = rc

--safety check returns a message 'remark' and a return code value
--just want to demonstrate what we can use return codes for and the 'goto' statement
--if the machine is not where we want it, skip executing the main function of our button script and goto finish line

if rc == false then wx.wxMessageBox (tostring(remark)) mc.mcCntlEnable (inst, 0) end goto finish
main ()


::finish::

--this let's use execute our current script in the editor enviroment for debugging puposes
if mc.mcInEditor () == 1 then main() end

--comments off--
Code: [Select]
local inst = mc.mcGetInstance ()                                                           
local rc = 0
local remark = ""

function countEnabledAxis ()
    local j = 0; for i=0, 11 do; if mc.mcAxisIsEnabled (inst, i) == 1 then j = j + 1; end; end
    wx.wxMessageBox ("You have " ..j.." axes enabled."); return j
end

function safetyCheck1 ()
    local var = 0
    var = countEnabledAxis ()
    local j = 0
    for i=0, var do
        if mc.mcAxisIsHomed(inst,i) == 1 then
            j = j + 1
            wx.wxMessageBox ("Axis " ..j-1 .." is homed")
        end
    end
    wx.wxMessageBox (var .." axes enabled\n" ..j .." axes homed")
    if j ~= var then
        return "Not all Axes are homed.", false
    end 
end

function main() 
    wx.wxMessageBox ("All is good to execute some screwie louie custom button script.")
end

wx.wxMessageBox ("Being safety check.")
remark, rc = safetyCheck1 ()
local var = rc
if rc == false then wx.wxMessageBox (tostring(remark)) mc.mcCntlEnable (inst, 0) end goto finish
main ()
::finish::

if mc.mcInEditor () == 1 then main() end

7
I keep forgetting to set my soft limits to on! PITA when I crash. So, here is some little Lua code that you can add to the RefAllHome button to automatically set your soft limits to on. 1. Operator->Edit screen->highlight RefHomeAll button, 2. on the left middle side of your screen, click on the notepad with the lightning bolt, 3. highlight where you see the code starting and click on the three dots box (side note: left down action vs. left up action vs left down script vs. left up script vs. click script are actions that are in relation to your mouse whereas when you press your left mouse button down it can call a script you have written, or call a predefined action written by NFS that you can choose from the pop up menu, etc. and then when you release the mouse button the left up action/script can do another call; the clicked script only executes a written script once -thank you simpson36 for sharing!) Hope this may help someone.

function softLimitsOn ()
    local inst = mc.mcGetInstance()
    local rc = 0
    local i = 0
    local j = 0

    for i=0,11 do                                                 --because there are 12 axes that can be mapped
        local val, rc = mc.mcAxisIsEnabled(inst,i)     --find which axes are enabled
        if val == 1 then                                         --if they are enabled, then
            j=j+1                                                   --start a counter
        end
    end

    j=j-1                                                            -- j=j-1 because of the whole '0' is actually the first instance in an arrays/stack,etc.

    for i=0,j do                                                   -- for how many axes are enabled; set the softlimit state to on
        mc.mcSoftLimitSetState (inst, i, 1)               -- found that mcSoftLimitSetState is more reliable than mcAxisSoftLimitEnable call function;
    end
end
softLimitsOn()                                                   --[[ call your softLimitsOn function and execute, I found that if you put this code in screenLoadScript
                                                                            that it may cancel your jogging capabilities whereas they will become greyed out. But hey,
                                                                            you never know unless you try!--]]

--josh

8
Hi folks,

I'm Josh...new around here. I've read a lot on this forum, built a machine, immediately jumped from Mach3 to Mach4 and have been working Lua a bit. Currently, I have a signal library built in the screen load script to watch for ISIG_INPUT0 events that will stop the axis from moving (Gcode cycles and jogging) from the basic if statement in the signal script. This works. Because G31 is not supported by my hardware yet I am trying to find a work around with programming the AutoToolSet button. The issue I am having is that the signal library is not recognizing the mc.mcCntlGcode...calls to stop the axis from moving when I code in Lua the button scripts. I think that screen scripts are different than mCode scripts from an interpreter standpoint that load into a different stack/buffer?.?.?... Anywho, any recommendations on how to say the signal library can recognize a call to mc.mcCntlGcodeExecute(inst, "G01 X...Y...Z..F.../n") and recognize an input signal mapped to mc.ISIG_INPUT0  in the signal library to stop the axis? Also, for kicks, if I call mc.mcCntLoadlGcode or string or file, how do I get that to execute? mc.mcCntlEnabled(inst, 1), mc.mcCntrlCycleStat(inst) doesn't execute the string (I've also tried incorporating input/output handle/get/set state function calls in the algorithm). I think I am missing something easy here...I am just asking for some direction and I can take Mach4 for a ride :o) I pretty much memorized the calls get/set/do from the down and dirty Lua pdf, scripting manual, pound variable list, signals list, the Spaced Out Lua reference (that was awesome!), Mach4 API, Lua Calls, etc. (yep, there is a reason why I am divorced :o) I can't remember "her" birthday but sure as ********* can remember programming function calls! Hope to hear from y'all and promise to share any code that may be relevant to new users coming from Mach3. After all, Mach 4 Hobby users are the beta testers for NFS. Great business strategy btw...crowd source beta testing...at a little cost. But, I've learned so much that it's okay with me and am glad to become apart of the community. Now...if I can cut my first part before I am 100 yrs. old...reliability, repeatability, and accuracy; it is computer numerical control for a reason, lol. Yes, I've learned Gcode sequences too, but the beauty of Mach4 is combining Lua and Gcode to execute a block. The potential capabilities are pretty darn good. I just need a strip map to let screen calls and mCode macro calls communicate with global function / reference tables and the signal script. My two cent...ok, may three cents...

-josh

Pages: 1