If, endif and Return in Subroutine

  • cnc_mill
  • cnc_mill's Avatar Topic Author
  • Visitor
  • Visitor
21 May 2014 13:20 - 21 May 2014 13:22 #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
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
Last edit: 21 May 2014 13:22 by cnc_mill.

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

More
21 May 2014 18:06 - 21 May 2014 18:09 #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
Last edit: 21 May 2014 18:09 by ArcEye.

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

More
21 May 2014 19:55 #47154 by andypugh
I think you probably want to use WHILE and ENDWHILE
The following user(s) said Thank You: cnc_mill

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

More
21 May 2014 22:11 - 21 May 2014 22:12 #47166 by ArcEye

I think you probably want to use WHILE and ENDWHILE


Indeed,

This whole section of code, should never occur inside another sub
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
	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
Last edit: 21 May 2014 22:12 by ArcEye.
The following user(s) said Thank You: cnc_mill

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

  • cnc_mill
  • cnc_mill's Avatar Topic Author
  • Visitor
  • Visitor
22 May 2014 17:11 #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 or Create an account to join the conversation.

Time to create page: 0.086 seconds
Powered by Kunena Forum