Generating G Code from MDI history log

More
29 Mar 2012 11:12 #18846 by ArcEye
Hi,

If like me, you spent a long time using manual mills and lathes before going to CNC, your work practices probably reflect this.

I tend to make simple parts just using MDI. Commands replacing hand wheel movements.
This is often far more time effective than writing a program.

The effectiveness reduces when you have to repeat sequences.
For instance recently, when drilling and tapping a series of unequally spaced holes,
first using centre drill, then first diameter drill bit, then second diameter bit then finally tapping clearance bit.
This does not easily lend itself to a G81 cycle.

I wrote this script to generate a program for the successive drilling stages from the commands I had entered for the first stage. You could do the same cutting and pasting directly from the MDI history, but this saves a lot of time.

To use, prior to commencement clear the MDI history (Ctrl M)
Then just enter the commands necessary for the first run through.

Then in a terminal, $ mdi2ngc /path/filename.ngc which will produce a .ngc file

If necessary edit the file to change values
(For instance I changed all lines G01 Z-5 F12 for G01 Z-20 F12 after centre drilling, so that the drill now broke through)
Then load the file and continue.
#!/bin/bash

   if [ ! $# -ge 1 ]; then
      echo "Usage: mdi2ngc [output file]"
      exit 1
   fi
    #  edit this to reflect the header block you want to insert
    header="G80 G90 G94 G21 G17 G40 G8"
    
    #  edit this to reflect the footer block you want to insert
    footer="M5 M9 M2 M30"
    
    echo $header > $1

    for LINE in `cat ~/.axis_mdi_history`; do
        echo $LINE >> $1
    done        

    echo $footer >> $1
    
exit 0

Does not do anything new, just makes life easier, adapt and enjoy.

Please Log in or Create an account to join the conversation.

More
29 Mar 2012 12:54 #18847 by BigJohnT
ArcEye,

That's a pretty neat way to do that. It makes me wonder if a little code changing on my counterbore g code generator would be a slick way to generate multi operations on a series of holes that are not grid like.

wiki.linuxcnc.org/cgi-bin/wiki.pl?Simple...Counterbore_Software

John

Please Log in or Create an account to join the conversation.

More
29 Mar 2012 16:39 - 29 Mar 2012 16:40 #18851 by ArcEye
Hi John

Yeah it could be a good way of doing it.

This job was making a reinforcing plate for an existing part, with hole centres transfer punched through.
I had to visually align a 60 degree centre with each centre pop to get the co-ordinates exact.

If there had not been so many holes, I could have just 'touched off' each hole in a different co-ordinate system as I have done in the past, which makes things ridiculously easy to code eg.
G54 G0 X0 YO
DRILL
G55 G0 X0 Y0
DRILL
G56 G0 X0 Y0
DRILL
..etc etc

I like 'one offs' , but they are real time consumers.

regards
Last edit: 29 Mar 2012 16:40 by ArcEye.

Please Log in or Create an account to join the conversation.

More
29 Mar 2012 18:44 #18856 by BigJohnT
Yea, about all I do is one offs. So if you had a way to jog over to each position then store that into the table used by the counterbore program somehow then define the ops to do at each position... that would be cool.

John

Please Log in or Create an account to join the conversation.

More
30 Mar 2012 02:02 - 30 Mar 2012 02:37 #18863 by dgarrett
An example of how to do something similar with axis, ngcgui, and a simple subroutine:

0) specify a subroutine in the ini file or load it from a "Custom"
tab (example attached for position.ngc)

1) Navigate to the position subroutine tab page and
enter "howmany" positions, and other routine entry values

2) Jog to the first position (having a pendant is useful)

3) On the "position" tab page:
put keyboard cursor in the x1 entry box
type "x" (enters current x position)
tab to y1 entry box
type ":y" (enters current y position)

(note: typing x,y,z,a,b,c,d enters the current coordinate value,
d means 2*x=current_diameter (eg for a lathe))

repeat 2) and 3) for remaining positions x2,y2, etc.

4) "Create Feature"

5) repeat 2-4 for additional features if needed

6a) "Finalize"
run the generated program

OR

6b) type Ctrl-a (toggle autosend)
"MakeFile"
save file with a unique name in a location of your choice to run later

The generated program will move to each position and pause (m0) I use this with a quill to manually drill holes at the positions.

With simple modifications, you could modify the subroutine to do anything else instead of pausing, like calling another subroutine.

File Attachment:

File Name: position.ngc
File Size:2 KB
Attachments:
Last edit: 30 Mar 2012 02:37 by dgarrett. Reason: see next post for correct position.ngc file

Please Log in or Create an account to join the conversation.

More
30 Mar 2012 02:36 #18864 by dgarrett
oops, attached is the correct file for position.ngc

Notes, as written:
1) requires linuxcnc2.5
2) uses nc_files/ngcgui_lib/utilitysubs/move.ngcjj
3) uses nc_files/ngcgui_lib/mfiles/M110
4) scaling and rotating the points about the origin are simple modifications

File Attachment:

File Name: position-8...c3bd.ngc
File Size:2 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
30 Mar 2012 09:09 #18869 by ArcEye
Nice one Dewey,

The #<x1> = #<_move:x> threw me at first until I realised that #<_move:x> was a global declared in move.ngc and not a referencing notation I was unaware of !!

I think you might have prompted a 'build a better mousetrap' competition.
I'll have to give this some serious thought.

regards

Please Log in or Create an account to join the conversation.

More
30 Mar 2012 10:50 #18871 by Rick G

An example of how to do something similar with axis, ngcgui, and a simple subroutine:

O.K. Dewey that is cool, everytime I turn around that ngcgui makes things faster and easier!
I will try that this weekend.
Thanks for sharing.

Rick G

Please Log in or Create an account to join the conversation.

More
30 Mar 2012 12:28 #18872 by BigJohnT
Dewey, That is Neat! I can't wait to get my BP converted to EMC...

John

Please Log in or Create an account to join the conversation.

More
30 Mar 2012 14:27 #18875 by dgarrett
"The #<x1> = #<_move:x> threw me at first until I realised that #<_move:x> was a global declared in move.ngc and not a referencing notation I was unaware of !!"

Yes, the general pattern for returning values from subroutines called by ngcgui subfiles is to return them as globals with a colon somewhere in the name. It is convenient to format the names as:

#<_nameofsubroutine:item_value>

as in:

#<_move:x>

It is good practice to immediately localize the return value, as in:
#<x1>=#<_move:x>

The only way to return multiple items from a subroutine is with globals. (I think the git-master version supports a return statement that can return a single item).

Using the colon in the name is important, it prevents ngcgui from interpreting the variable as a user input -- using globals as inputs to ngcgui is deprecated.

Please Log in or Create an account to join the conversation.

Time to create page: 0.194 seconds
Powered by Kunena Forum