Hello Guest it is March 28, 2024, 11:07:59 AM

Author Topic: Using G-code files in Button Scripts  (Read 24895 times)

0 Members and 1 Guest are viewing this topic.

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Using G-code files in Button Scripts
« Reply #30 on: September 05, 2011, 07:14:13 PM »
HIYA J, There are many ways to do what I think you want. It depends on exacly what you need. MACH3 is VERY powerful in some respects.Here is an example of a simple 4 button function Gcode program that for the most part takes VB out of the equation for motion control yet allows you to use the VB functions to selct moduals to run in any order you choose.

Sample Gcode Program with all moduals included in the Base code. Note that each modual has a SUBProgram place marker  (o1,o2,o3,o4)



G90 G54 G80 (etc,etc)
G0X0Y0Z0
/M2

o1
G1 X1 Y0 F50
X1y1
X0y1
X0y0
/M2

o2
G1 X5 Y0 F50
X5y5
X0y5
X0y0
/M2

o3
G1 X10 Y0 F50
X10y10
X0y10
X0y0
/M2

o4
M30


VB Button scripts for buttons, one for each screen button

Code"m98 P1 L1"
DoButton(0)

Code"m98 P2 L1"
DoButton(0)

Code"m98 P3 L1"
DoButton(0)

Code"m98 P4 L1"
DoButton(0)


Load the master Program. IF you want Mach3 to check the code then press the block delete button and mach will preveiw all moduals and display what it can on the screen. To run turn OFF the block delete button.

Next select what modual you want to run and press the correct button.  It will MOVE to that modual and run the code . At the M2 line it will stop.

Next select the next modual you want to run and press the button . It will move to that modual and run the code. At the M2 line it will stop.

To end press the button for selection 4 and it will run the M30 ,end the program  and rewind back to the top.

IF you want to run the program end to end and in that order then turn ON the block delete and Mach will run it start to finish.

There are Many OTHER ways to do this as well. You could have a SINGLE intelligent button that ASKS you what modual you want to run next AND even be able to input #variable values into play.

Hope that helps, (;-) TP
« Last Edit: September 05, 2011, 07:22:19 PM by BR549 »
Re: Using G-code files in Button Scripts
« Reply #31 on: September 10, 2011, 03:28:07 PM »
Thanks for your input everyone.  I have been occupied with a few other things since last weekend but I will try out the suggestions and let you know how things have worked out.

There is one question I still have?  Why do G-Code files created using Teachfile run without any delays whereas those created manually as .txt files have to go through some sort of checking out process when loaded into Mach?  I know the latter are .tap files but when you change the file extention of some examples in the GCode folder to .txt and read them in Notepad they look just like manually created files.

J

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Using G-code files in Button Scripts
« Reply #32 on: September 10, 2011, 06:36:54 PM »
The teachfile/Run process bypasses the NORMAL load/verify process NOT a good thing.

(;-) TP
Re: Using G-code files in Button Scripts
« Reply #33 on: September 30, 2011, 09:42:22 PM »
I have been away for the last couple of weeks but have been been able to work on these button scripts from time to time.
Thanks to rrc1962 I have been able to make the TeachFile approach work and I can see its virtues in some instances.  However for what  am trying to do I think  the approach suggested by BR549 fits better.  The idea of writing individual subroutines that can be called from the buttons meets my objective of putting most of the code into a separate program and minimizes what is in the button script(s).

The standard Mach3Turn screens (I am working on a lathe at present) do not have a "block delete" button so I have added one. When testing changes to the code one can load the file using the normal "Load" button then as was pointed out, turning on block delete allows the code to be checked through for syntax errors. For normal operation, once the code has been checked, I then have a button to load the pre-tested program and carry out various preliminary steps. At the beginning of this button script are a couple of statements to turn block delete off.

A series of other buttons are then used for the actual tool setting and turning operations. In most cases these comprise some "if" statements to check that it is OK to carry out the operation then the subroutine call.

Overall the system is working very well but there are a couple of points where I have questions:

1. The subroutines (if that terminology is correct) begin with (e.g.) o1 and end with /M2 but I am also calling further subroutines from within these using M98 P10 (for example) to call o10. I have then ended those subroutines with M99 in the normal way. From an operating standpoint this all works OK but on checking through and also in operation one gets the message "Return called with no Sub in effect .... looping" when these further subroutines are called. The operation seems OK but I am concerned about seeing this error message.

Is there a better way of setting up and calling "sub-subroutines"?

2. Is there anywhere where these more advanced programing features are
 written up?

Again I am very grateful for all of the help that has been given I have now put together something that works as originally planned although I am sure there are more elegant approaches to the programing. I am sorry that I have not kept the dialogue flowing very well but time working on this has been limited

J

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Using G-code files in Button Scripts
« Reply #34 on: October 02, 2011, 11:57:45 PM »
YOU really need to post a copy of the file structure showing the full routine. Other than that I would just be guessing as to how you actually coded it.

Your request carried a bit beyond what you asked for(;-)originally.

There is really only 2 ways to setup and call subs. They are both covered in the manual. 

(;-) TP

(;-) TP

Re: Using G-code files in Button Scripts
« Reply #35 on: October 04, 2011, 05:37:17 PM »
The file structure I am using is based around having a subroutine that does what is required by a particular button and using a statement like Code"m98 P1 L1"  then DoButton(0) to call that subroutine. The system I have is along the following lines (suggested earlier.)

O1 (Subroutine to carry out actions for button 1)
..lines of code
M98 P10 Q4 (call further subroutine for operation that is repeated several times)
.. more code
/M2 (end of operation for this button)
%
O10 (subroutine for repeated operation)
... lines of code
M99 (subroutine return)

A similar approach is used for other buttons calling subroutines O2, O3 etc.

The approach works well but during the checking through process, when the subroutines like o10 are reached one gets the error message "Return Called with no Sub in effect ... looping." One can step further through the checking out process by hitting "Cycle start" each time and in practice the program seems to execute as intended. However I am always concerned with when an error message comes up in case something unanticipated may happen at some point.  The main question therefore is can one do what is outlined above in a neater way? It is possible to call everything from the button script; the first part of o1, o10 however many times it has to be repeated, then another subroutine with the second part of o1, but that makes things more complicated.

(Maybe I should just ignore the error messages and just get on with the machining!)

In the last reply "the manual" is referred to.  Which manual is this? I have looked through the Mach3 G & M code sections, I have Smid's book on CNC progaming, I have all the information handed out by Gerry at the last CNC workshop and tried to find everything that is applicable on the Mach3 website.  However I have not seen this approach with subroutines ending with /M2 and being called from a button using Code"m98 P1 L1". A reference would be appreciated.

Concerning the scope of all this:  When I started out I knew what I was trying to achieve but really did not know what was involved  in getting there. Now I have a much better understanding of all the issues and again I very much appreciate the help that has been given.

J

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Using G-code files in Button Scripts
« Reply #36 on: October 04, 2011, 07:08:32 PM »
OK IF you are calling SUBS from inside a SUB in Macro you are in UNCHARTED ground there is really no way to predict what will happen IF you run it.

The method I showed you is not really a SUB call it is a GOTO statement left over from the original Code that Mach3 was built on. It just happens to work reliably in a simple 1 time call to a sub without the need to return. Perfect for remote calls from a BUTTON or a goto piont in a GCODE program FROM a macro. It has MANY uses.

Very few people even know it exists . There are still  undocumented things in MACH3 (;-) but not as many as there once were. I am all the time plundering throught the original base code and LOOKING in mach3 to see IF any remants remain. (;-)

If you try it otherwise you may NOT have a return point  to go back to in the macro and it should error out or maybe something else who knows. Like I SAID uncharted GROUNDS.

USE WITH CAUTION,

(;-) TP

« Last Edit: October 04, 2011, 07:17:06 PM by BR549 »
Re: Using G-code files in Button Scripts
« Reply #37 on: October 05, 2011, 08:34:31 AM »
OK thanks for the clarification.  I did not realize that we are so far into uncharted teritory.

As I said, although I get the error message when checking through, the program does execute as one would hope/expect.  I guess I need to carry out some more extensive testing to get a measure of confidence that there are not some hidden issues.

Thanks again

J

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: Using G-code files in Button Scripts
« Reply #38 on: October 05, 2011, 12:15:00 PM »
IF you get it to do correctly please let us know I can add it to the unknown list(;-)

(;-) TP
Re: Using G-code files in Button Scripts
« Reply #39 on: October 05, 2011, 12:28:31 PM »
OK, most of the development has been "dry" running on my laptop but I have now started using the program to cut metal - I will let you know how it goes after I have made a few pieces.

J