If, endif and Return in Subroutine

  • cnc_mill
  • Topic Author
  • New Member
  • New Member
More
12 years 5 months ago #47138 by cnc_mill
If, endif and Return in Subroutine was created by cnc_mill
Hello all Knowing Linuxcnc Users!

I am Trying to Use the if - endif with the subroutine Return in subroutines. I want to use it with Parameters and calculating that i must not user the repeat function.

I have already read the Limit of Boxes in Linuxcnc. But there i am not in the near of the Limit.


Here is the sample code witch i have written with the Documentation of Linuxcnc
Code:
O1102 sub T04 M6 G10 P4 L1 R1.49 #1 = -0 (Start First Cut) #2 = -1 (Cut Deep) #3 = -8 (End End-deep) N177 G0 X29.719 Y-9.779 N178 G0 Z5 N179 G1 Z0 F#3001 o1104 sub o1103 call (Contour written on the begin of the Program will be used from some other tools) #1 = [#1 + #2] (Calculate new Start-deep) o11 if [#3 GT #1] o1104 return o11 endif o1104 endsub o1104 call G0 Z10 o1102 endsub o1102 call

I Have tried multiple configurations of if and endif. When i Try o1104 Repeat and Endrepeat then the Contour will be done correctly multiple times.

I hope someone could help me to get this working.

Sorry for my bad english i try my best.

Thank you for Reading and have a nice day
Roland

Please Log in to join the conversation.

More
12 years 5 months ago #47152 by ArcEye
Hi

Very hard to be clear, because this sub does not actually do anything. (ie whatever it decides based upon the value of #3 is not acted upon, because that param is not passed to Z so it never plunges regardless of the value)

The main problem at present is the nesting of one sub declaration inside another and both subs calling themselves.

If all you want is to check the plunge depth and stop it at a certain point, this could be done inside a loop in the main program much more simply, or with a small and very simple sub.

Probably need some more info and the code using the sub to see what you want to achieve

regards

Please Log in to join the conversation.

More
12 years 5 months ago #47154 by andypugh
I think you probably want to use WHILE and ENDWHILE

Please Log in to join the conversation.

More
12 years 5 months ago #47166 by ArcEye

andypugh wrote: I think you probably want to use WHILE and ENDWHILE


Indeed,

This whole section of code, should never occur inside another sub
Code:
o1104 sub o1103 call (Contour written on the begin of the Program will be used from some other tools) #1 = [#1 + #2] (Calculate new Start-deep) o11 if [#3 GT #1] o1104 return o11 endif o1104 endsub o1104 call

and could simply be replaced by
Code:
o101 while[#3 GT #1] o1103 call (seems to be the only thing the sub did, so presume cutting happens there) #1 = [#1 + #2] o101 endwhile

although it is arguable that the only sub you need is 01103 and the whole thing could be in the main body of code

regards

Please Log in to join the conversation.

  • cnc_mill
  • Topic Author
  • New Member
  • New Member
More
12 years 5 months ago #47191 by cnc_mill
Replied by cnc_mill on topic If, endif and Return in Subroutine
Dear Arc and Andy! I am so happy that you understand my not Native English :blush:

Thank you Andy for your Inspiration!

Big Thanks to ArcEye for the Example for and NOOB as mine :)
I Try your code and modified it so it works perfectly for me.

Now my Programs are near to Heidenhain Parameter Programs.

*Whisper to ArcEye- next time i will make a new try to get you Pedant working on my Ho-made Machine. Is there a Easy way to get an Optical encoder on it for jog the axis?*

Thank you for your big help

if i could i want to give you 400 Karma:)

Please Log in to join the conversation.

Time to create page: 0.091 seconds
Powered by Kunena Forum