Subroutine hangs Finalizing

More
04 Dec 2015 08:47 #66360 by prm_ex
Hello to forum - i'm new, this is my first post.

I have met a problem to load my subroutine via ngcgui.
Settings should be fine while an example sub from the web is working.
I have written my own sub for my need.
I can open it, create feature but Finalizing starts to load it (blue bar on the window bottom) and hangs in the middle and is not going into axis..
Whole the linuxcnc window is blocked. Nothing works but the window can be closed by clicking X.
I was trying to investigate a mistake letter or sign. But cannot find the reason.
Would You please be so kind and advise what can be wrong?
My code is short:
(2015-12-01 sub do blablabla)               

(info: mojsub)

o<anie> sub
#<przesuwX> = #1 (=1194)
#<przesuwZ> = #2 (=400)
#<obsuwZ> = #3 (=6.28)
#<liczba_przejazdow> = #4 (=30)
#<aktualny_Z> = 0
#<licznik> = 0

o100  while [#<licznik> LT #<liczba_przejazdow>]
#<aktualny_Z> = [#<aktualny_Z> + #<przesuwZ>]
G0 x#<przesuwX> z#<aktualny_Z>
#<aktualny_Z> = [#<aktualny_Z> + 60]
G0 z#<aktualny_Z>
#<aktualny_Z> = [#<aktualny_Z> + #<przesuwZ>]
G0 x0 z#<aktualny_Z>
o101 while [[#<aktualny_Z> MOD 60 ] NE 0]
#<aktualny_Z> = [#<aktualny_Z> + 1]
o101 endwhile
#<aktualny_Z> = [#<aktualny_Z> + 60 + #<obsuwZ>]
G0 z#<aktualny_Z>
#<licznik>=[#<licznik> + 1]
o100 endwhile
o<anie> endsub 
Of course name of ngc file is proper (as sub name)
Thanks in advance for any help
greetings

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

More
04 Dec 2015 10:42 #66365 by verticalperformance
It's not the fact that it's a subroutine or a problem with NGCGUI, removing the sub and making it a stand alone piece of g-code will also not load, with it hanging up when opening the file.

The centre while loop (o101) seems to be an infinite loop. If you comment out both o101 it will load.
I suspect the #<aktualny_Z> MOD 60 never equals zero for some reason.

I'm not sure what the o101 loop is trying to do as there are no moves inside it - as far as I can see it just keeps adding 1 to the value until it gets to 60 and the MOD function is supposed to return 0. You could just add 60 to begin with :)

Stand alone code.....
G21
#<przesuwX> = 1194
#<przesuwZ> = 400
#<obsuwZ> = 6.28
#<liczba_przejazdow> = 30
#<aktualny_Z> = 0
#<licznik> = 0

o100  while [#<licznik> LT #<liczba_przejazdow>]
    #<aktualny_Z> = [#<aktualny_Z> + #<przesuwZ>]
    G0 x#<przesuwX> z#<aktualny_Z>
    #<aktualny_Z> = [#<aktualny_Z> + 60]
    G0 z#<aktualny_Z>
    #<aktualny_Z> = [#<aktualny_Z> + #<przesuwZ>]
    G0 x0 z#<aktualny_Z>
    o101 while [[#<aktualny_Z> MOD 60 ] NE 0]
        #<aktualny_Z> = [#<aktualny_Z> + 1]
    o101 endwhile
    #<aktualny_Z> = [#<aktualny_Z> + 60 + #<obsuwZ>]
    G0 z#<aktualny_Z>
    #<licznik>=[#<licznik> + 1]
o100 endwhile
M30
The following user(s) said Thank You: prm_ex

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

More
04 Dec 2015 12:16 #66371 by prm_ex
Replied by prm_ex on topic Subroutine hangs Finalizing
Thank You for the answer.
In deed I have not check without loops but the loop should not be infinitive while it is max 59 loops needed to jump out of it
There is not any move inside the loop 'cos it is not necessary to do move of 1mm i.e. 59 times.
Counter increases and after loop completes the required move is only one.
Are You guys sure that operator MOD is working and beeing interpreted properly?

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

More
04 Dec 2015 13:13 #66378 by jepler
Replied by jepler on topic Subroutine hangs Finalizing
To the program posted by verticalperformance, I added a (debug) line.
o101 while [[#<aktualny_Z> MOD 60 ] NE 0]
        (debug,#<aktualny_Z> #<debug1> #<debug2>)
        #<aktualny_Z> = [#<aktualny_Z> + 1]
    o101 endwhile
and then I ran it in a terminal in the "stand alone interpreter" program, rs274:
rs274 -g prm_ex.ngc
(using the rs274 program in this way is probably not documented anywhere, unfortunately)

With the debug message, I was able to see that the value of #<aktualny_Z> eventually had a value like 1826.280000. This value MOD 60 is 26.28. By adding 1 to the value each time, it will *NEVER* become equal to a multiple of 60.

If the goal is to round #<aktualny_Z> up to the next multiple of 60, then you can do that without a while loop using the "FUP" (floating point round up) function:
    #<aktualny_Z> = [60 * FUP[#<aktualny_Z>/60]]
This divides aktualny_Z by 60, rounds up to the next whole number, and the multiplies by 60 again. So for instance, any number above 0 and not above 60 will become 60, any number above 60 but not above 120 will become 120, and so on. In computer programs, this is a common way to round one number up to a multiple of another number.
The following user(s) said Thank You: prm_ex

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

More
04 Dec 2015 16:30 #66394 by prm_ex
Replied by prm_ex on topic Subroutine hangs Finalizing
Of course! You are completely right! :woohoo:
Thank You (clicked).
#aktualny_Z only in the beginning is integer. After adding a space (#obsuw_Z) that is USUALLY float (i missed that :blush: ) then result becomes float as well.
As You say a solution is to round up the variable to an integer and then use MOD to rotate the axis to the start angle position.
Once again thank You very much
greetings

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

Time to create page: 0.085 seconds
Powered by Kunena Forum