G-code to engrave numbers on cylinders

More
02 Nov 2013 01:27 - 30 Aug 2018 20:48 #40497 by andypugh
[edit 30/8/18: I added tick marks, see forum.linuxcnc.org/20-g-code/27169-g-cod...ders?start=10#116888 ]

I wrote this G-code to engrave angles on a lathe part. It might be handy for other things. It uses a sub for each digit, then computed-calls to call the right one.



;Attempt to engrave scale rings
;Engraving is done in the XA plane and in the postive direction from X =0

#<_dia> = 50 ; scale diamter
#<_depth> = 0.2 ; engraving depth
#<_height> = 2 ; character height
#<_scale> = 1 ; unit conversion
#<_inc> = 10 ; angle between marks
#<_feed> = 20

G21

F #<_feed>

#41 = [180 / [#<_dia> * 3.14159] * #<_height>]
#42 = #<_height>
(debug, #41 #42)
 O0 sub
 G92 A0 X0
 G0 A0 X0 Z[#<_dia> / 2 + 1]
 G1 Z[#<_dia> / 2 - #<_depth>]
 A[0.2357 * #41] X[0.0976 * #42]
 A[0.3333 * #41] X[0.3333 * #42]
 A[0.3333 * #41] X[0.6667 * #42]
 A[0.2357 * #41] X[0.9024 * #42]
 A[0.0000 * #41] X[1.0000 * #42]
 A[-0.2357 * #41] X[0.9024 * #42]
 A[-0.3333 * #41] X[0.6667 * #42] 
 A[-0.3333 * #41] X[0.3333 * #42]
 A[0.0000* #41] X[0.0000 * #42]
 G0 Z[#<_dia> / 2 + 1]
 G92.1
 O0 endsub
 
 O1 sub
 G92 A0 X0
 G1 Z[#<_dia> / 2 - #<_depth>]
 A[0.0000 * #41] X[1.0000 * #42]
 G0 Z[#<_dia> / 2 + 1]
 G92.1
 O1 endsub
 
 O2 sub
 G92 A0 X0
 G0 A[0.3333 * #41] X[0.000 * #42] Z[#<_dia> / 2 + 1]
 G1 Z[#<_dia>/2 - #<_depth>]
 A[-.3333 * #41] X[0.0000 * #42]
 A[0.0000 * #41] X[0.3333 * #42]
 A[0.2357 * #41] X[0.4310 * #42]
 A[0.3333 * #41] X[0.6666 * #42]
 A[0.2357 * #41] X[0.9024 * #42]
 A[0.0000 * #41] X[1.0000 * #42]
 A[-.2357 * #41] X[0.9024 * #42] 
 A[-.3333 * #41] X[0.6667 * #42]
 G0 Z[#<_dia> / 2 + 1]
 G92.1
 O2 endsub
 
 O3 sub
 G92 A0 X0
 G0 A[-.3333 * #41] X[0.3333 * #42] Z[#<_dia> / 2 + 1]
 G1 Z[#<_dia>/2 - #<_depth>]
 A[-.2357 * #41] X[0.0976 * #42]
 A[0.0000 * #41] X[0.0000 * #42]
 A[0.2357 * #41] X[0.0976 * #42]
 A[0.3333 * #41] X[0.3333 * #42]
 A[0.2357 * #41] X[0.5690 * #42]
 A[0.0000 * #41] X[0.6667 * #42]
 A[0.3333 * #41] X[1.0000 * #42] 
 A[-.3333 * #41] X[1.0000 * #42]
 G0 Z[#<_dia> / 2 + 1]
 G92.1
 O3 endsub
 
 O4 sub
 G92 A0 X0
 G0 A[0.2357 * #41] X[0.000 * #42] Z[#<_dia> / 2 + 1]
 G1 Z[#<_dia>/2 - #<_depth>]
 A[0.2357 * #41] X[1.0000 * #42]
 A[-.3333 * #41] X[0.3333 * #42]
 A[0.3333 * #41] X[0.3333 * #42]
 G0 Z[#<_dia> / 2 + 1]
 G92.1
 O4 endsub
 
 O5 sub
 G92 A0 X0
 G0 A[-.3333 * #41] X[0.3333 * #42] Z[#<_dia> / 2 + 1]
 G1 Z[#<_dia>/2 - #<_depth>]
 A[-.2357 * #41] X[0.0976 * #42]
 A[0.0000 * #41] X[0.0000 * #42]
 A[0.2357 * #41] X[0.0976 * #42]
 A[0.3333 * #41] X[0.3333 * #42]
 A[0.2357 * #41] X[0.5690 * #42]
 A[0.0000 * #41] X[0.6667 * #42]
 A[-.3333 * #41] X[0.6667 * #42]
 A[-.3333 * #41] X[1.0000 * #42] 
 A[0.3333 * #41] X[1.0000 * #42]
 G0 Z[#<_dia> / 2 + 1]
 G92.1
 O5 endsub
 
 O6 sub
 G92 A0 X0
 G0 A[-.3333 * #41] X[0.0333 * #42] Z[#<_dia> / 2 + 1]
 G1 Z[#<_dia> / 2 - #<_depth>]
 A[-.2357 * #41] X[0.5690 * #42]
 A[0.0000 * #41] X[0.6667 * #42]
 A[0.2357 * #41] X[0.5690 * #42]
 A[0.3333 * #41] X[0.3333 * #42]
 A[0.2357 * #41] X[0.0976 * #42]
 A[0.0000 * #41] X[0.0000 * #42]
 A[-.2357 * #41] X[0.0967 * #42] 
 A[-.3333 * #41] X[0.3333 * #42]
 A[-.2357 * #41] X[0.9024 * #42]
 A[0.0000 * #41] X[1.0000 * #42]
 A[0.2357 * #41] X[0.9024 * #42]
 G0Z [#<_dia> / 2 + 1]
 G92.1
 O6 endsub
 
 O7 sub
 G92 A0 X0
 G0 A[-.2357 * #41] X[0.0000 * #42] Z[#<_dia> / 2 + 1]
 G1 Z[#<_dia>/2 - #<_depth>]
 A[0.3333 * #41] X[1.0000 * #42]
 A[-.3333 * #41] X[1.0000 * #42]
 G0 Z[#<_dia> / 2 + 1]
 G92.1
 O7 endsub
 
 O8 sub
 G92 A0 X0
 G0 A[0.2357 * #41] X[0.5690 * #42] Z[#<_dia> / 2 + 1]
 G1 Z[#<_dia> / 2 - #<_depth>]
 A[-.2357 * #41] X[0.5690 * #42]
 A[-.3333 * #41] X[0.3333 * #42]
 A[-.2357 * #41] X[0.0976 * #42]
 A[0.0000 * #41] X[0.0000 * #42]
 A[0.2357 * #41] X[0.0976 * #42]
 A[0.3333 * #41] X[0.3333 * #42]
 A[0.2357 * #41] X[0.5690 * #42] 
 A[0.3333 * #41] X[0.6667 * #42]
 A[0.2357 * #41] X[0.9024 * #42]
 A[0.0000 * #41] X[1.0000 * #42]
 A[-.2357 * #41] X[0.9024 * #42]
 A[-.3333 * #41] X[0.6667 * #42]
 A[-.2357 * #41] X[0.5690 * #42]
 G0 Z[#<_dia> / 2 + 1]
 G92.1
 O8 endsub
 
 O9 sub
 G92 A0 X0
 G0 A[-.3333 * #41] X[0.3333 * #42] Z[#<_dia> / 2 + 1]
 G1 Z[#<_dia>/2 - #<_depth>]
 A[-.2357 * #41] X[0.0976 * #42]
 A[0.0000 * #41] X[0.0000 * #42]
 A[0.2357 * #41] X[0.0976 * #42]
 A[0.3333 * #41] X[0.3333 * #42]
 A[0.3333 * #41] X[0.6667 * #42]
 A[0.2367 * #41] X[0.9024 * #42]
 A[0.0000 * #41] X[1.0000 * #42] 
 A[-.2357 * #41] X[0.9024 * #42]
 A[-.3333 * #41] X[0.6667 * #42]
 A[-.2357 * #41] X[0.4310 * #42]
 A[0.0000 * #41] X[0.3333 * #42]
 A[0.2357 * #41] X[0.4310 * #42]
 A[0.3333 * #41] X[0.6667 * #42]
 G0 Z[#<_dia> / 2 + 1]
 G92.1
 O9 endsub
 
 ; Start Engraving
 
 G92.1
 #3 = 0
 O100 while [#3 LT 360]
 #4 = [#3 * #<_scale>]
(DEBUG, #4)
 O101 if [#4 LT 10]
	G0 A#3 X0 Z[#<_dia> / 2 + 1]
	O[FIX[#4]] call
 O101 else if [#4 LT 100]
	G0 A[#3 - #42 * 0.5] X0 Z[#<_dia> / 2 + 1]
	O[FIX[#4 / 10]] call
	G0 A[#3 + #42 * 0.5] X0
	O[FIX[#4 mod 10]] call
 O101 else if [#4 LT 1000]
 	G0 A[#3 - #42 ] X0 Z[#<_dia> / 2 + 1]
	O[FIX[#4 / 100]] call
	G0 A#3 X0
	O[FIX[[#4/10] mod 10]] call
 	G0 A[#3 + #42 ] X0
	O[FIX[#4 mod 10]] call
 O101 endif
 
 #3 = [#3 + #<_inc>]
 O100 endwhile
 
 M2
Attachments:
Last edit: 30 Aug 2018 20:48 by andypugh.
The following user(s) said Thank You: BigJohnT, Dimitrios, biqut2, RotarySMP, jo_key, fhs1954, clunc, Boltonbrass

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

More
02 Nov 2013 18:27 #40509 by BigJohnT
That's pretty slick Andy.

JT

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

More
23 Nov 2013 23:51 - 23 Nov 2013 23:53 #41130 by andypugh
The fonts are based on two octagons, and straight lines, but the results don't show it.

Attachments:
Last edit: 23 Nov 2013 23:53 by andypugh.
The following user(s) said Thank You: jtc, cts1085

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

More
30 Jan 2015 00:56 #55453 by Kirk_Wallace
Andy, thank you for replying to my IRC query. My setup -- 10.04, 2.5, stock sim_axis9 and stock sim.ini and your g-code above --- produces a tool that only moves in X and Z. It appears that the DROs change appropriately, but not the display. If it is convenient, could you let me know if you there are any configuration or other changes I should look at?

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

More
30 Jan 2015 02:30 #55458 by andypugh

If it is convenient, could you let me know if you there are any configuration or other changes I should look at?


I just tried it in the stock sim/axis-9-axis config and it was as you describe.

I changed GEOMETRY to ABCXYZYVW and then on restart the display looked as-shown in the picture above.

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

More
30 Jan 2015 02:51 #55460 by Kirk_Wallace
Crud, I tried:
[TRAJ]

AXES = 9
COORDINATES = A B C X Y Z U V W
HOME = 0 0 0 0 0 0 0 0 0
LINEAR_UNITS = inch
ANGULAR_UNITS = degree
CYCLE_TIME = 0.010
DEFAULT_VELOCITY = 1.0
DEFAULT_ANGULAR_VELOCITY = 45.0
POSITION_FILE = position9.txt
MAX_LINEAR_VELOCITY = 1.2
MAX_ANGULAR_VELOCITY = 90.0

No joy. (using LinuxCNC 2.6.5 on Wheezy)

Attachments:

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

More
30 Jan 2015 02:56 #55461 by andypugh

Crud, I tried:
[TRAJ]

AXES = 9
COORDINATES = A B C X Y Z U V W


[DISPLAY] GEOMETRY not [TRAJ] COORDINATES

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

More
30 Jan 2015 03:05 #55462 by Kirk_Wallace
UUUUUGGGGHHHH, It's working now. Sorry about that.

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

More
29 Sep 2017 17:44 #99634 by Smokeys
Has anyone expanded this to include letters as well as numbers. Seem like this could be a cool generic program to engrave serial numbers or other information on pens and such.

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

More
29 Sep 2017 18:52 #99638 by andypugh
I think it would be difficult to modify this code to handle alphabetical characters as it relies on calculating and calling computed subroutines.
I guess it might be possible have subs for each ASCII code, but I don't know how one would pass the strings to the G-code.

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

Time to create page: 0.257 seconds
Powered by Kunena Forum