Hello Guest it is December 07, 2019, 02:11:26 PM

Author Topic: Custom DRO script  (Read 3609 times)

0 Members and 1 Guest are viewing this topic.

Custom DRO script
« on: June 22, 2015, 04:46:59 PM »
Hi all,

I am looking for a way to create a custom output on a DRO. For instance, I have a bar puller that has two fixed drills attached to it, I would like to display the position of the bar puller (calling it the X Axis) and then on a separate DRO, display the position of the drill relative to the bar puller.

This should be a simple addition on each update: X Axis Position + Drill position relative to X axis 0 (which should never change so it can be hard-coded) but I am having trouble writing this value to the DRO. I was thinking it might be easier to make a few false axis' and do a mcGetAxisPos and then write it to the next axis (Y, Z and A that aren't being used) but I can't seem to get that to work either.

I am also assuming that this code would need to be placed in the DRO update script location, is this the correct place?

I have tried searching the forums and the API with no luck and I am still trying to get a handle on LUA script so any advice would be greatly appreciated!

Thanks!

- Adam

Re: Custom DRO script
« Reply #1 on: June 24, 2015, 11:44:58 PM »
create newDRO, have PLC update this newDRO with a local variable that 1. get axis position, 2. apply your offset formula and 3. use a screen set property call to write that value to your newDRO.

same concept as using a DRO to display mm conversions from your current DRO inch display as ya-nvr-no demonstrated is his posts about screen sets. if it is not working like you want just let me know and i'll also work on it with you.

--josh
« Last Edit: June 24, 2015, 11:46:44 PM by Screwie Louie »
Re: Custom DRO script
« Reply #2 on: June 25, 2015, 12:34:16 AM »
try this...

Operator -> Edit Screen -> insert new DRO -> label 'droXdrillOne', DRO code is blank, Editor = In Place, make any other personal formatting changes
                                   -> insert new DRO -> label 'droXdrillTwo', DRO code is blank, Editor = In Place, make any other personal formatting changes

Goto PLC script, try the following code. It's a start at least. mc.mcAxisGetMachinePos vs. mc.mcAxisGetPos = your preference of display

do
    local inst = mc.mcGetInstance()
    local Xpos = mc.mcAxisGetMachinePos (inst, 0)  

    local myOffset1 = ----enter your axis offset, drill 1----
    local myOffset2 = ----enter your axis offset, drill 2----

    local drillOneOffset = Xpos + myOffset1
    local drillTwoOffset = Xpos + myOffset2

    scr.SetProperty('droXdrillOne', 'Value', 'tostring(drillOneOffset))
    scr.SetProperty('droXdrillTwo', 'Value', 'tostring(drillTwoOffset))
end

There are many ways to accomplish what you would like to do. This is just one possible solution. Add, delete, modify, Play! :)

Re: Custom DRO script
« Reply #3 on: June 30, 2015, 11:03:33 AM »
It works! The ( ' ) before tostring had to be taken out but that's it. 

I need to learn the formatting for Lua and m4, your solution was too simple!

Thanks a lot josh!
Re: Custom DRO script
« Reply #4 on: June 30, 2015, 11:52:12 AM »
good catch!
Re: Custom DRO script
« Reply #5 on: July 02, 2015, 09:19:14 PM »
Well now that that is working... I have another question  :P

I have a macro that has some motion and does some stuff and at the end of it all, I want it to zero out the counter that was just made earlier in this thread.
I have a variable in the PLC script called boardZero which is in my scr.SetProperty to read out to a DRO so at the end of my new Macro script I tried to just put in boardZero = 0

I thought that since the PLC Script works in a loop it would just see that boardZero now is equal to 0 after the macro ran and update the DRO accordingly... but as usual, it doesn't seem to work that easy!
Any ideas?

Thanks!

Adam

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Custom DRO script
« Reply #6 on: July 02, 2015, 09:53:58 PM »
you need to zero the dro using it`s name and a if statement
Re: Custom DRO script
« Reply #7 on: July 03, 2015, 03:41:48 PM »
maybe try [ if boardZero == 0 then scr.SetProperty ('name of your DRO', 'Value', '0.0000') end ] in the PLC?

wait a sec...I had trouble using a macro call to change a global variable value and then have the PLC scan and execute a function based on that global variable's value. For me, I couldn't get the PLC to recognize the macro's global variable value change. I know I might of just confused you but I think I know what you are talking about...I don't think the above example would work but you can try. Hmmm, this is a puzzle. Because when you call the macro and start movement you will have to wait until the movement is complete until resetting the DRO to zero. If not, lua will reset the DRO to zero before the movement is complete if you use the scr.SetProperty call in the macro at the end. A possible solution would be to time your movement (say it takes 90 seconds to do what you want).

so, your macro would start by declaring the function, execute gCode, wx.wxSleep(90), scr.SetProperty ('name of your DRO', 'Value', '0.0000') end. This would put lua into a sleep state until the movement is complete (based on timing) then reset your DRO. All within your macro and proceed to execute the next block. Try that technique.

« Last Edit: July 03, 2015, 03:45:41 PM by Screwie Louie »

Offline dude1

*
  •  1,253 1,253
    • View Profile
Re: Custom DRO script
« Reply #8 on: July 03, 2015, 07:21:57 PM »
he will run in to the same problem I had SL with the laser zero while statement.

action, while, if, zero unless you can come up with a way around it I could not
Re: Custom DRO script
« Reply #9 on: July 05, 2015, 10:31:01 AM »
I wanted to use semaphore programming b/w macro calls and the PLC...I have to keep experimenting.

The weird thing is, I think I have to tell the PLC what gCode line to pull and if mCode = True then do something based off of a variable value or state condition (if req'd).

Am I wrong? Can user-defined macros make changes to global variable values which are defined in the Screen Load Up script -> then the PLC can observe and execute a function when those macros are running in gCode?

I think there is a conflict with m4's machState (i.e., File_Running vs Idle, etc.) to allow a function to execute. I believe this is a safety mechanism.