Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: jevs on August 04, 2019, 01:41:33 PM

Title: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 01:41:33 PM
I am watching a video on youtube and he is hovering over things and getting values in the editor. This does not seem to work in the current editor?
Is there a way to see this?
I can right click stuff and select "Evaluate in console", but all i ever get is nil.
I am not really sure how your supposed to test your code to see if it is working without getting it all done and seeing if it runs in Mach4 or not. It would be nice if you could run it and get some idea of what you have written so far is working.
Keep in mind I am not a computer programmer.
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: joeaverage on August 04, 2019, 01:55:45 PM
Hi,
hovering over the variable works......if it shows nil then the variable has no defined value.

Craig
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 02:08:54 PM
I must be doing something wrong because I get nil for everything.
Code: [Select]
function m6()

local inst = mc.mcGetInstance()
local selectedTool = mc.mcToolGetSelected(inst) --Gets selected tool
selectedTool = math.tointeger(selectedTool) --Converts selected tool to integer
local currentTool = mc.mcToolGetCurrent(inst) --Gets currently loaded tool
currentTool = math.tointeger(currentTool) --Converts currenlty loaded tool to integer

Shouldn't I be able to get a value at least for the current tool? It has a current tool on the screen. Somehow I think the editor and mach are not in communication at this point.
I never get any values by hovering over anything in the screen load script or anywhere else either and selecting evaluate in console give nil on everything.
So, I am not sure what I have wrong.

About from the editor:
ZeroBrane Studio (devel; MobDebug 0.702)
Copyright © 2011-2017 ZeroBrane LLC
Paul Kulchenko
Licensed under the MIT License.
Based on Estrela Editor
Copyright © 2008-2011 Luxinia DevTeam
Christoph Kubisch, Eike Decker
Licensed under the MIT License.

Based on wxLua editor
Copyright © 2002-2005 Lomtick Software
J. Winwood, John Labenski
Licensed under wxWindows Library License, v3.
Built with wxWidgets 3.1.1, wxLua 2.8.12.3
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: joeaverage on August 04, 2019, 02:11:58 PM
Hi,
you will get a value once the line has been executed.....until it has the variable is undefined.

Craig
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: joeaverage on August 04, 2019, 02:24:54 PM
Hi,
you only get live data when you are in a de-bug session.....you do have the debugger running when trying
to get live values?

Craig
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 02:50:48 PM
I think I am starting to figure this out....I wish there was a video tutorial though.
I cannot get the debugger to run on my stuff. I just get an error.

However, I loaded up a lua example from the mach4 directory to try to figure out how it works.
I guess I need to put a red ball everywhere I want the debugger to stop and then F5 moves it to the next red ball. Then I can hover over things and get a value.

If you start the debugger (green arrow) then it ends up putting a green arrow next to the first line that is not a comment. Nothing in there has a value. If you hit the green arrow again, it just seems to exit the debugger. So, I assume you have to put a red ball on the lines to make it stop without exiting? It will not stop on every line though, so I guess it can only stop at certain places in the code depending on what the code is.

Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 02:58:09 PM
I still get nil where I think there should be a value....not sure. I am learning a little here by trial and error though (which is not the fastest way) :)

I commented out my bad code that was stopping the debugger from loading and running. I wish they would give the exact way to do things in the API help instead of giving you a basic idea that you have to figure out what to add or change to make it work....

Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: joeaverage on August 04, 2019, 02:58:51 PM
Hi,

Quote
If you start the debugger (green arrow) then it ends up putting a green arrow next to the first line that is not a comment. Nothing in there has a value.

The green arrow shows that this is the next instruction to be executed, it has not been executed yet and so the variable may well
be undefined. What you need to do is single-step through the code, that is DON'T push the green arrow again but F11.
Once the line has been executed then hover on the variable.

Craig
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 03:01:42 PM
Hi,

Quote
If you start the debugger (green arrow) then it ends up putting a green arrow next to the first line that is not a comment. Nothing in there has a value.

The green arrow shows that this is the next instruction to be executed, it has not been executed yet and so the variable may well
be undefined. What you need to do is single-step through the code, that is DON'T push the green arrow again but F11.
Once the line has been executed then hover on the variable.

Craig

Ahh, that helps. I figured there should be a way to step through one line at a time without adding a bunch of red balls which still skips stuff.....thanks.
You can see where a tutorial video would help someone that knows so little :)

Do you know where I might find an M6 for an ATC with a tool height touch plate? If I could see some code rather than trying to reinvent it from scratch it would be much faster. I am doing stuff now that I do not know if it is even needed. Just trying to mimic my old VB script from Mach3, but I did not have a touch plate to set tool heights then. Part of why I am switching to mach4 is so I can have more than one probe input (3D and tool height) without trying to put them in series on the same input. This is not as nice because then you have to short the input jack on the 3d probe or the touch plate won't work when it is detached (NC probes).
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 03:11:13 PM
This is already a big help! Now I got one thing working. Using the debugger is so much faster...
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: joeaverage on August 04, 2019, 04:55:35 PM
Hi,
there are:

https://www.machsupport.com/forum/index.php?topic=37369.0 (https://www.machsupport.com/forum/index.php?topic=37369.0)
https://www.machsupport.com/forum/index.php?topic=37783.0 (https://www.machsupport.com/forum/index.php?topic=37783.0)

Craig
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 05:09:08 PM
Great! I will watch those now before moving forward. Thanks.

However, I think I kinda have the hang of it now. It has been working for me. Part of my problem is just not knowing how to format the code correctly from the miserable API help. It has the info you need, just not the exact syntax to know how to use it. I am sure this is clear to people that already know...but tough for a new person that is not a programmer.
My code was hanging the debugger as part of my problem, It could not compile...now I just comment out anything new when it does not work to see if that is what is doing it...

I am just stuck on how to use the code information I can find in the API help now...flooding the board with questions, but I am not sure how else to get through this. No way I am going to be as far as I had hoped after working on this for a weeks worth of free time, even giving up on sleeping :(

It is getting there though....thanks for the help.

I am surprised there is hardly any scripts to be found on the internet being shared. I am yet to find a single M6 script for an ATC.....this would help a lot. I am just trying to make it up from scratch.
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 05:37:20 PM
Based on that second video, should I be putting this at the beginning of everything I work on?

Code: [Select]
if mc.mcInEditor() == 1 then
   dofile("ScreenScript.lua")
end
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: joeaverage on August 04, 2019, 05:37:45 PM
Hi,

Quote
It has the info you need, just not the exact syntax to know how to use it. I am sure this is clear to people that already know...but tough for a new person that is not a programmer.

Tough luck.....this has afflicted all of us, I was not a Lua programmer when I started either.....and by most measures still not!
Mach4, with its modular structure and Lua scripting language offers a great deal more flexibilty and performance over Mach3 but
it comes at a cost, namely learning curve.

Second issue that you are observing is that the documentation of Mach4 often lags its current state. NFS is a very small company that does not
have the resources to employ a document writer and consequently the documentation has fallen behind. Before you jump up and down just,
weigh the fact that NFS is still releasing new functionality, including script based THC, mcSurface Wizard, Zero Brane editor and mcTouch Off wizard
in the last 12 months alone, verses up-to-date documentation......NFS doesn't have the resources to do both WITHOUT charging a lot more for its
software or some sort of annual subscription.

Craig
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: DazTheGas on August 04, 2019, 05:39:50 PM
Quote
I am yet to find a single M6 script for an ATC

The whole idea of the m6 video a while back was to try and explain how you go about setting up your "Own" custom m6 step by step, and nearly everyone has a different way of how they want it to work.

A nice way of seeing your values is to open the watch window from the view menu, right click on the variable you want to watch and add it to watch expression, this will save you having to hover over the script.

DazTheGas
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 05:46:47 PM
Hi,

Quote
It has the info you need, just not the exact syntax to know how to use it. I am sure this is clear to people that already know...but tough for a new person that is not a programmer.

Tough luck.....this has afflicted all of us, I was not a Lua programmer when I started either.....and by most measures still not!
Mach4, with its modular structure and Lua scripting language offers a great deal more flexibilty and performance over Mach3 but
it comes at a cost, namely learning curve.

Second issue that you are observing is that the documentation of Mach4 often lags its current state. NFS is a very small company that does not
have the resources to employ a document writer and consequently the documentation has fallen behind. Before you jump up and down just,
weigh the fact that NFS is still releasing new functionality, including script based THC, mcSurface Wizard, Zero Brane editor and mcTouch Off wizard
in the last 12 months alone, verses up-to-date documentation......NFS doesn't have the resources to do both WITHOUT charging a lot more for its
software or some sort of annual subscription.

Craig

They will get my $200 when it works.....so, I guess they will be waiting awhile.....
Like many others I am sure... I am not a programmer and you have to be a programmer to make it work.
I would be willing to bet there are many other people that are not as persistent or computer literate as myself that just walk away, which is ashame.
I would certainly be further along if I could get one line of code to just work without spending hours on how to make it work.
My VB script to do what I am trying to do now seem so much easier.
I am determined to get this done though, so expect a lot more dumb questions to come :) 
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: joeaverage on August 04, 2019, 05:48:17 PM
Hi,

Quote
Based on that second video, should I be putting this at the beginning of everything I work on?

That depends on the macro or code that you are working on.

For instance if you have a macro running in the debugger, that macro alone is the 'Lua Chunk', other Lua code in other
scripts or macros are unavailble to it. Thus if you call say mcState, a global variable, in your macro the your debug session will
fail because the debugger is running your macro alone as its entire Lua chunk.

If you require the wider context of the entire Lua chunk then yes you are correct to use the dofile() command.
Be aware now that when you single step through the code you will now have to single step through the wider code
chunk, thousands of lines.

For this reason you may well need to define certain variables or functions within your macro just for debug purposes
so you don't have to debug the entire Lua chunk.

Craig
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 05:50:27 PM
Quote
I am yet to find a single M6 script for an ATC

The whole idea of the m6 video a while back was to try and explain how you go about setting up your "Own" custom m6 step by step, and nearly everyone has a different way of how they want it to work.

A nice way of seeing your values is to open the watch window from the view menu, right click on the variable you want to watch and add it to watch expression, this will save you having to hover over the script.

DazTheGas
I have been watching your videos and those are much appreciated! However I am stuck on a couple things right now. I cannot even make the spindle motor stop. I think I know which code to use, just not how to type it in so it works. I need it to stop the spindle if it is running (which I hope includes the decel time), then start making moves.
I have learned a lot this weekend for sure, but I am nowhere close to getting this done....
I did learn more from that first video too. Docking the watch and stack up top there seems handy.
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: joeaverage on August 04, 2019, 05:53:19 PM
Hi,

Quote
Like many others I am sure... I am not a programmer and you have to be a programmer to make it work.

Remember I cautioned you that learning Mach/Lua was quite a challenge and that there are procedures that do not require much,
if any, Lua coding and that I commended them to you to save the grief you are now experiencing.

Quote
They will get my $200 when it works.....so, I guess they will be waiting awhile.....

It works....whether you believe it or not.

Craig
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 06:01:15 PM
"Remember I cautioned you that learning Mach/Lua was quite a challenge and that there are procedures that do not require much,
if any, Lua coding and that I commended them to you to save the grief you are now experiencing."

I am confused. How do I make my tool changer work without using Lua coding?
I don't think I really need to keep getting the warnings. Really, just the answers to questions is what eases the pain most and makes it move faster. I think the secret of it being a pain in the behind is out of the bag LOL. I have accepted that and just doing what has to be done now...

I do believe Mach4 will work. I have it mostly working. I am down to to a few tasks. I just need the tool change to work and then get the pokeys55 replaced with the 57e and setup.....then I should be done other than tweaking as needed when I start using it to make parts.

I will have to figure out probing and auto tool height setting also, but I never had that stuff installed to try with Mach3 either.

Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: joeaverage on August 04, 2019, 07:12:03 PM
Hi,

Quote
I don't think I really need to keep getting the warnings.

My apologies.


Quote
I am confused. How do I make my tool changer work without using Lua coding?

Have you even looked at the toolchanger scripts that come as examples? Most people find that a couple of tweaks
to one of the examples is enough, no 'real' coding required.

Craig
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 04, 2019, 07:22:27 PM
Yes, many times and watched all the videos many times. I don't just have a little router off ebay that I need to move over to a spot and manually pull out a tool.
I need to shut the spindle off, make sure it is off, record the positions, move to z0, move to x, y positions, then move Z up past home to Z5.800 and back down to z3.8 how many ever times it takes to get to the called for tool, go over and measure the tool, then go back to where it all started Etc.
It is a simple tool changer, but not as simple as the example scripts. I made this work with the VB script in much less time, but that was still a learning experience also. Trust me, I have a lot of hours in this changeover already and an overload of info.

Basically this thread we are talking on now is solved though. I got a pretty good handle on the editor at this point. It is not the stall point anymore. 

I have the example scripts for the tool change working, it is just adding what I need in there is the challenge.
I need to duplicate this, but also some things seem to be different with Mach4 and I need to add in the tool measure at some point....
https://www.youtube.com/watch?v=W-0q5uM8jbU

Code: [Select]
'Tool change macro for 7 tool turret
Sub Main()
'Sets variable OldTool to what is currently loaded
OldTool=GetCurrentTool()

'Sets Variable MaxToolNum to the max number of tools possible
MaxToolNum=7

'Sets variable Newtool to the one being selected with M6 T#
NewTool=GetSelectedTool()

'Get positions before moving to do tool change
x = GetToolChangeStart( 0 )
y = GetToolChangeStart( 1 )
z = GetToolChangeStart( 2 )
a = GetToolChangeStart( 3 )
b = GetToolChangeStart( 4 )
c = GetToolChangeStart( 5 )

'If the current tool loaded is 0 or greater than 7 then tool has been lost
'so need to ask what tool is currently loaded
While OldTool=0 Or OldTool>7
OldTool=Question ("Current tool unknown, enter tool in spindle 1 to " & MaxToolNum)
Wend

'Sets CurrentTool to Oldtool in case it was lost and entered above
SetCurrentTool(OldTool)

'When the tool asked for is invalid then this makes you select a valid tool
While NewTool > MaxToolNum Or NewTool <1
NewTool = Question ("Invalid tool chosen, enter tool number 1 to " & MaxToolNum)
Wend

        'If the tool asked for is the same one that is already loaded then exit macro
If NewTool=OldTool Then
Message "Tool already loaded or tool not specified with T# (ex:M6 T4)"
Exit Sub
End If

'Turn off soft limits if they are on
If GetOEMLED(23) Then
DoOEMButton(119)
End If

'Moves To Z home from where ever it is
code "G53G0Z0"
While IsMoving()
Wend

'Sets ChangeNums to 0 for safety in case it is not at 0
ChangeNums=0

'Makes the magic happen and moves the proper number of times if new tool is higher than old
If NewTool>OldTool Then
For ChangeNums=1 To NewTool-OldTool

'Moves Z axis to the top of tool change
code "G53 G1 F70 Z5.800"
While IsMoving()
Wend

'Moves back to bottom of tool change area
code "G53 G1 F70 Z3.8"
While IsMoving()
Wend

Next

'Makes the magic happen and moves the proper number of times if new tool is lower than old
Else
For ChangeNums=(OldTool-NewTool) To 6

'Moves Z axis to the top of tool change
code "G53 G1 F70 Z5.800"
While IsMoving()
Wend

'Moves back to bottom of tool change area
code "G53 G1 F70 Z3.8"
While IsMoving()
Wend

Next
End If

'Move Back to Z Home
code "G53 G1 F70 Z0"
While IsMoving()
Wend

'Should be a succesful tool change at this point so this sets the NewTool as the current tool
SetCurrentTool(NewTool)

'Turn back on soft limits
DoOEMButton(119)
End Sub           

Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: joeaverage on August 05, 2019, 07:36:38 AM
Hi,

Quote
Yes, many times and watched all the videos many times

I was not talking about videos......what about the example scripts?

Mach4Hobby/LuaExamples/ToolChanger.......there are four scripts that might give you some ideas.

Craig
Title: Re: How to show the value of a variable in the ZeroBrane Editor?
Post by: jevs on August 05, 2019, 08:50:16 AM
Unfortunately those tool change examples do not exist in the latest download that I have. I only get the one stripped out M6 that is in the profile macros folder. I did notice in one of the Artsoft videos I saw that they had this folder you mention in their examples, but she did not go into it to see what is in there. After I noticed that, I double checked mine and it is no longer included I guess.
I would love to have some examples of something more for an ATC that has the code for shutting off the spindle and waiting for it to slow down before moving etc. 
I did send them an email to ask them for the code or an example late last night. I am back to work today, so may not get to do much with this today. Maybe tonight if nothing else comes up I will work on it more. Maybe I will get something in the email by then.
I was thinking adding the frequency feedback might open some options for monitoring the speed for some added code abilities. Like I said that got shut down also unless I reduce the signal voltage from the VFD or add an encoder. I am still looking into doing that. I already have the wire ran to send it over to the BoB.
However, you should not really need that to do this. Mach3 didn't need it. I am sure there is a correct code to do it. I just need more time to figure it out or someone else may give me the answer by then. I am sure this has been done many times by people by now surely. It is a pretty basic need for a tool changer I would think.