Author Topic: nesting sub programs  (Read 4264 times)

0 Members and 1 Guest are viewing this topic.

Offline SDConcepts

  • Active Member
  • Posts: 66
    • View Profile
nesting sub programs
« on: January 11, 2009, 10:11:09 AM »
can mach 3 nest sub programs?  basically i want to run one sub within another sub to give me two rows of parts.  ideally i would like to make one hex, then move over complete nine more. then move up a row and repeat the pattern of 10.  i'm thinking that i would want the center of each hex to be zero then use and incremental move code to do the hex.  does this make sense?  the code i've posted below will allow me to do one hex but won't step over to do any others.  i'm thinking that i have something wrong in my coding.  yes i realize i can do this in lazy cam but i don't want to be dependent on that, plus i want to use the wear offsets available in cutter comp.

here is what i have so far...

%o0001
G90 G94 G17 G50 G80
G54
T01 M06
G43 H1 D1
G0 X0 Y0
m98 P2 L2
G90
G28 X y z
M5 M9
M30


O2
m98 P1 L10
G91 Y1.5
M99

o1
g91
g1 X-1.0 Y-1.0 f10
Z1.0
G41
G1 X.5
Y1.289
X.5 Y.289
X.5 Y-.289
Y-.577
X-.5 Y-.289
X-.5 Y.289
Y1.0
G0 Z 3.5
g90
X0 Y0
M99

vmax549

  • Guest
Re: nesting sub programs
« Reply #1 on: January 11, 2009, 10:57:00 AM »
Attaboy(;-) SD,  It never hurts to learn a new trick. Just for the record Lcam does tool comp also(;-).

First off Yes SUBS can nest SUbs, the exception is NOT to nest itself.

Problem #1  You have confused MACH by having 2 subs called o1 (;-), After you fix the sub for the last line you will see mach endlessly loops in itself because it gores to the first o1 in the line and reruns the whole program again(endless loop) Your main program name is the same as the sub name(o0001,o1).  To name the program use a ;0001  or  (0001) that way you will see the name on file load.

Problem #2  In the sub o1 did you end it with a line return?? or did you mean to use the % Mach needs a line after the last line cal weither it be an empty line or the %charector. Without the empty line MACH will not see the last M99 so it stops there.  A good habit is to start and end a program with %,,,,,,,,,,,,,,,,,,,,,% that way you never forget the empty line. 

Problem#3  On your tool change when you called the G43 H1 D1. You do not used the Dword  just G43 H1, the H1 calls the height data from T1.

Problem#4  On your G41  A good habit is to call the D1  as G41 D1. MACH will use the last tool called But a good habit is to call it anyway.

Problem #4   Check your geometry on the lines(;-)  your are close but not perfect.  Also it is VERY easy to get lost when switching back and forth between ABS and INC programing especially with subs in a sub. We call it getting LOST in Hyperspace, you never know where you will pop out.



Hope that helps, (;-) TP

« Last Edit: January 11, 2009, 11:08:29 AM by vmax549 »

Offline SDConcepts

  • Active Member
  • Posts: 66
    • View Profile
Re: nesting sub programs
« Reply #2 on: January 11, 2009, 11:07:10 AM »
So based on the corrections listed...ultimately i'm not worried about the geometry corrections of the hex.  i just want the rest of it to work. 

%o0001
G90 G94 G17 G50 G80
G54
T01 M06
G43 H1
G0 X0 Y0
m98 P2 L2
G90
G28 X y z
M5 M9
M30
%

O2
m98 P3 L10
G91 Y1.5
M99

o3
g91
g1 X-1.0 Y-1.0 f10
Z1.0
G41 D1
G1 X.5
Y1.289
X.5 Y.289
X.5 Y-.289
Y-.577
X-.5 Y-.289
X-.5 Y.289
Y1.0
G0 Z 3.5
g90
X0 Y0
M99

vmax549

  • Guest
Re: nesting sub programs
« Reply #3 on: January 11, 2009, 11:17:56 AM »
SD you should not use the program name in that way.

%o0001 is a NONO  Mach sees it as a sub name, BAD habit to get into. IT will work in this instance but still a bad habit.

Use % (0001)    or % ; 0001

Also the last line of your  o3 sub needs the % or an empty line after the M99. A % is a good habit .

M99
%           

Offline HimyKabibble

  • V4 Screen Contributor
  • Posts: 1,687
    • View Profile
Re: nesting sub programs
« Reply #4 on: January 11, 2009, 11:36:08 AM »
On a semi-related note - What are the legal ways of entering comments in G-code?

Regards,
Ray L.
Regards,
Ray L.

vmax549

  • Guest
Re: nesting sub programs
« Reply #5 on: January 11, 2009, 12:07:29 PM »
SD, one last note(;-)


IF you start a G41, you will need to end the COMP move with a G40 before leaving the sub enviroment for another loop( I think)



o3
g91
g1 X-1.0 Y-1.0 f10
Z1.0
G41 D1
G1 X.5
Y1.289
X.5 Y.289
X.5 Y-.289
Y-.577
X-.5 Y-.289
X-.5 Y.289
Y1.0
G40  y.5     *********    DOes a leadout move to clear the comp move before leaving the sub
G0 Z 3.5
g90
X0 Y0
M99



THe g28 x y z      will error out like that. YOu need to either use

G28 X1.111 Y1.111 Z1.111    the XYZ calls for a midpoint move before going home

Or

G28        just goes home.


HIYA RAY, Page 10-12 in the manual (;-)

%(notes)
// notes

(notes)

(msg,notes)


Just a thought, (;-)TP
« Last Edit: January 11, 2009, 12:14:50 PM by vmax549 »