Manufacturing Information Solutions Forum Index Manufacturing Information Solutions
Your Place for Support and Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Macro Example

 
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> G-Code Programming
View previous topic :: View next topic  
Author Message
BillyB
Frequent Poster


Joined: 27 Jul 2005
Posts: 60
Location: Lexington, KY, USA

PostPosted: Fri Jul 29, 2005 5:39 pm    Post subject: Macro Example Reply with quote

I thought that I would shair this with you:

User Macro is a very powerful option that lets you write your own canned cycles, make moves based on internal calculations, do "conditinal jumps" with a GOTO command, perform loops with a "WHILE[xxxx]DO" command, read signals from switches and turn relays on & off, print data to the serial port, and just plain make trouble in a variety of ways.

With the User Macro option, you can mix regular G-code statements with Macro statements in your part program. You can also write macros that execute automatically with any G-code or M-code that you want to use in your main program. Kind of like calling a sub-program with M98, only much more powerful because your main program can pass data to the macro (like a canned cycle would).

Years ago, we wrote a bunch of macros that used a Renishaw touch-probe to digitize 3D surfaces and 2D cams on a VMC. The Macro function let us digitize any surface area with a single G-code command. That G-code statement let us define an area to be digitized and the increment between rows and points. We used the WHILE[xxxx]DO statements in our macro to make rows and columns of digitized points. Each time we moved the probe to an X-Y point, we touched the part in -Z using the G31 skip cutting command, calulated the servo's following error, then transmitted the X-Y-Z coordinate of the probe stylus to a computer with the DPRNT statement.

It's powerful stuff, but you've got a lot of learning to do. It also takes quite a bit of time to "debug" your macros and make them work the way you want. It's a little like writing programs in the old interpreter BASIC language on PCs, only the syntax is different.

If your control has the "Custom Macro" option, you'll be able to display a page called "Macro Val" or "Macro Variable". On some controls, this is done by pressing the "OFFSET" button twice. On CNCs with soft-function keys, you should see a key for Macro variables. Also, if you type a macro statement into your program (like: DPRNT ) the controls with the User Macro option will display it correctly. If you DON'T have the User Macro option, the control won't recognize the command, and will space out the letters, like so: D P R N T
==============================================

Do you have a machining function that you do quite often and possibly at different locations? If so you can define a sub program/ custom macro to do a specific function.

O6000(DRILL MACRO)
#100 = #1 (DEPTH)
#101 = #2 (CLEAR)
#102 = -[#1+#2]
N100 G91
N110 G1 Z[#102] F1111
N120 G0 Z[#100 + #101]
N130 G90
N140 M99

N... G0 X.. Y..
G65 P6000 A154. B5.0 (CALL ONE TIME)
N.. X
***** MODAL FORM *******
N... G0 X.. Y... Z...
G66 P6000 A100. B5.
N.. Y..
N.. X..
N.. X.. Y..
N.. G67

==============================================

Condition loops are fairly simple to achieve
Dont take these codes as gospel as I have'nt got my Fanuc manual handy
To loop something say roughing down a profile in 2mm steps
G65 H1 P#101 Q2. (Depth of first cut)
N100 (start of the profiling op)
N110 G1 Z-#101 F1000 (Z axis to 1 cut depth)
N120 ---
-----
N250 ----- The actual profile
N260 G65 H2 P#101 Q#101 R2. (add depth of cut)
N270 G65 H81 P100 Q#101 R22.
N280 G0 Z25. M5 (end of tool use)

Ok here we go with an explaination of line 270
G65 H81 is the equals loop condition (I think, not got my manual handy)
If Q is not equal to R, then goto Line held by P, if Q and R are equal, then goto the next line.

So what line 270 says if the depth of cut is not equal to 22 then loop back to line 100
why 22 deep, because line 260 will add another 2 onto the depth of cut before the values are tested

There are lots more commands available like SIN and SQR, and lots more loop condition codes for less than, more than you'll need to consult a fanuc yellow book for details (in the macro A section I think)
Back to top
View user's profile Send private message Send e-mail
JoeM
Master Poster


Joined: 09 Jul 2004
Posts: 122
Location: Jackson Hole, Wyoming USA

PostPosted: Fri Jul 29, 2005 5:46 pm    Post subject: Reply with quote

To drill a hole:
O1000(DRILL PROGRAM)
#101 = 20.5 (DEPTH MM)
#102 = 4. (CLEAR)
#103 = 1200 (MMPM FEED)
G91
G1 Z[-1*[#101+#102]] F[#103]
G0 Z[#101+#102]
G90 M99
(MAIN PROGRAM)
N100 G90 G0 G80 M5
M6 T1
S3000 M3
G0 X254. Y300. Z200. M8
M98 P1000 (NO PARAMETER PASSED SELF CONTAINED)
X300.
M98 P1000
G91 G30 X0 Y0 Z0
M2
_________________
Thanks.
===================
I would rather by Fly Fishing!
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Manufacturing Information Solutions Forum Index -> G-Code Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group