Need Help! Need help getting IF/THEN/ELSE & GOTO or JUMP to work in CNC-Lite v7.8


Results 1 to 6 of 6

Thread: Need help getting IF/THEN/ELSE & GOTO or JUMP to work in CNC-Lite v7.8

  1. #1
    Member
    Join Date
    Jan 2008
    Location
    usa
    Posts
    78
    Downloads
    0
    Uploads
    0

    Default Need help getting IF/THEN/ELSE & GOTO or JUMP to work in CNC-Lite v7.8

    I'm using CNC-Lite v7.8 & would like to be able to set/change/evaluate variables & JUMP/GOTO (ALL IN GCODE) as the tests indicate. I've been able to create & change variables OK, as shown in the code snippet below. Initial move is to X0 Y0, then to X1, then to Y2. All of that works as desired.

    Code:
    N1 {BEGINROW=0}
    N2 {CURNTROW=0}
    N3 {MAXROW=13}
    N4 GOO X0.0 Y0.0
    N5 {CURNTROW=CURNTROW+1}
    N6 X{CURNTROW}
    N7 {CURNTROW=CURNTROW+1}
    N8 Y{CURNTROW}
    N9 M02
    What I would like to do is test a variable, and then jump to some other N num in the program. The below prog should move to X5 & Y5, then M02 to end program, but just blows thru the N6 'if' statement & goes directly to M02 end program.



    Code:
    N1 {BEGINROW=0}
    N2 {CURNTROW=0}
    N3 {MAXROW=13}
    N4 GOO  X{CURNTROW} Y{CURNTROW}
    N5 {CURNTROW=CURNTROW+1}
    N6 IF{CURNTROW<5}THEN GOTO N4
    N7 M02
    Help will be appreciated.

    Steve

    Similar Threads:


  2. #2
    Member Karl_T's Avatar
    Join Date
    Mar 2004
    Location
    Dassel.MN
    Posts
    1542
    Downloads
    2
    Uploads
    0

    Default Re: Need help getting IF/THEN/ELSE & GOTO or JUMP to work in CNC-Lite v7.8

    Camsoft does not support parametric programming in the Gcode in this manner.

    Put your logic in an Mcode and then call the code in your Gcode program. Your imagination is the limit here.

    Here's my M96 that loops the number of times set in the counter variable.
    the M97 that jumps to any line label
    the M98 that calls a subroutine.



    IF \140=1 THEN MESSAGE 'if \400 set to 1 then its in learners mode to display extra help
    IF \140=1 THEN MESSAGE To use M96 put statement
    IF \140=1 THEN MESSAGE {LOOPM96=5} <on its own line>
    IF \140=1 THEN MESSAGE N400 <space after this and on its own line>
    IF \140=1 THEN MESSAGE <lines of code>
    IF \140=1 THEN MESSAGE M96 N100
    IF \140=1 THEN MESSAGE the 5 can be any number
    IF \140=1 THEN MESSAGE the 400 can be any number
    IF \140=1 THEN MESSAGE
    \93=1
    LOADING \55:IF\55=0THENEXIT
    {LOOPM96=LOOPM96-1}
    IF{LOOPM96}>0THENJUMP Nn
    -----M96

    JUMP Nn 'to use write M97 N100 to goto N100, BEWARE OF AN ENDLESS LOOP!!
    -----M97

    GOSUB Np;l
    -----M98


    SPECIAL NOTE:

    PUT ANY GOTO LINE LABELS ON THIER OWN LINE WITH A SPACE AFTER THE LABEL.

    example
    M97 N100
    ...code...

    N100 'I use a quote mark to ensure the space.



  3. #3
    Member Karl_T's Avatar
    Join Date
    Mar 2004
    Location
    Dassel.MN
    Posts
    1542
    Downloads
    2
    Uploads
    0

    Default Re: Need help getting IF/THEN/ELSE & GOTO or JUMP to work in CNC-Lite v7.8

    You know, I could use a generic less than and a generic greater than.

    Outline of approach:
    first value in P
    second value in Q
    goto location in N

    less than in M93
    greater than in M94

    So this line IF{CURNTROW<5}THEN GOTO N4
    becomes M93 P{CURNTROW} Q5 N4


    I will let you figure the code in M93 and M94

    The main line in M93 will be: IF p<q THEN JUMP Nn



  4. #4
    Member
    Join Date
    Jan 2008
    Location
    usa
    Posts
    78
    Downloads
    0
    Uploads
    0

    Default Re: Need help getting IF/THEN/ELSE & GOTO or JUMP to work in CNC-Lite v7.8

    Karl,
    Yesterday before quitting I found an old post of yours, concerning this subject.

    Code:
    You found,IMHO, the greatest weakness in Camsoft. It doesn't do parametric programming. I wrote a number of special M codes as a work around for looping in Gcode. Here's a clip, the message statements explain how to set up your Gcode to loop.
    
    
    MESSAGE
    MESSAGE To use M93 put statement
    MESSAGE {LOOPM93=5} <on its own line>
    MESSAGE N100 <space after this and on its own line>
    MESSAGE <lines of code>
    MESSAGE M93 N100
    MESSAGE the 5 can be any number
    MESSAGE the 100 can be any number
    MESSAGE
    \93=1
    LOADING \55:IF\55=0THENEXIT
    {LOOPM93=LOOPM93-1}
    IF{LOOPM93}>0THENJUMP Nn
    -----M93
    
    MESSAGE
    MESSAGE To use M94 put statement
    MESSAGE {LOOPM94=5} <on its own line>
    MESSAGE N200 <space after this and on its own line>
    MESSAGE <lines of code>
    MESSAGE M94 N200
    MESSAGE the 5 can be any number
    MESSAGE the 200 can be any number
    MESSAGE
    \93=1
    LOADING \55:IF\55=0THENEXIT
    {LOOPM94=LOOPM94-1}
    IF{LOOPM94}>0THENJUMP Nn
    -----M94
    
    MESSAGE
    MESSAGE To use M95 put statement
    MESSAGE {LOOPM95=5} <on its own line>
    MESSAGE N300 <space after this and on its own line>
    MESSAGE <lines of code>
    MESSAGE M95 N300
    MESSAGE the 5 can be any number
    MESSAGE the 300 can be any number
    MESSAGE
    \93=1
    LOADING \55:IF\55=0THENEXIT
    {LOOPM95=LOOPM95-1}
    IF{LOOPM95}>0THENJUMP Nn
    -----M95
    
    MESSAGE
    MESSAGE To use M96 put statement
    MESSAGE {LOOPM96=5} <on its own line>
    MESSAGE N400 <space after this and on its own line>
    MESSAGE <lines of code>
    MESSAGE M96 N100
    MESSAGE the 5 can be any number
    MESSAGE the 400 can be any number
    MESSAGE
    \93=1
    LOADING \55:IF\55=0THENEXIT
    {LOOPM96=LOOPM96-1}
    IF{LOOPM96}>0THENJUMP Nn
    -----M96
    
    JUMP Nn 'to use write M98 N100 to goto N100, ENDLESS LOOP!!
    -----M97
    I entered it in my MCODE file, saved, backed-up, etc, restarted, and still could not make it work. I'm at work now, so I cannot post the exact code I tried. I will do that this evening, along with my modified MCODE file. Hopefully you might see what I have missed.
    Steve



  5. #5
    Moderator
    Join Date
    Apr 2003
    Location
    United States
    Posts
    332
    Downloads
    0
    Uploads
    0

    Default Re: Need help getting IF/THEN/ELSE & GOTO or JUMP to work in CNC-Lite v7.8

    CamSoft has two methods to do parametric programming.

    In G code we use the traditional math functions and user defined variables along with a set of M codes to do IF THEN , > Greater Than and < Less Than functions to simplify parametric programming for novice programmers without needing to write advanced code. These M codes accomplish the same parametric functions in a simpler format. If you're willing to learn the CamSoft logic commands then you'll have the ultimate power of parametric programming which is much like Microsoft Basic with the addition of axis motion and digital I/O Control. These functions are standard features in the CNC professional version and can be added to CNC Lite or CNC plus upon request in version 7.9. Call technical support for these M codes and further help if you need it.

    Below is your program that was posted over the weekend with our M95 example:
    ---------
    N1 {BEGINROW=0}
    N2 {CURNTROW=0}
    N3 {MAXROW=13}
    N4 G00 X{CURNTROW} Y{CURNTROW}
    N5 {CURNTROW=CURNTROW+1}
    N6 M95 R{CURNTROW} Q5 P4
    N7 M02
    ---------

    BTW you had a mistake in N4 using the letter O instead of the number zero.


    Here are some M code examples to do IF THEN, > Greater Than, < Less Than Then and Jump to / GOTO line



    JUMP to N100 using P if Q is Equal to R
    Example:
    M91 Q3 R3 P100


    JUMP to N100 using P if Q does not Equal R
    Example:
    M92 Q2 R3 P100



    JUMP to N100 using P if Q is equal to or greater than R
    Example:
    M93 Q3 R2 P100



    JUMP to N100 using P if Q is equal to or less than R
    Example:
    M94 Q2 R3 P100



    JUMP to N4 using P if the Variable {CURNTROW} is less than Q
    See Page 8-59 for Example of Macro Variables Used in a G code program
    Example:
    M95 R{CURNTROW} Q5 P4



    JUMP to N100 using P based on the word GOTO in G code
    Example:
    M96 GOTO100


    JUMP to N100 using P in the G code program
    Example:
    M97 P100


    Go to SUB Program starting with N100 line using P as program number. L repeat Nth number of times
    Example:
    M98 P100 L3


    Return to the next line after M98 in the G code program when the Sub Program is finished
    Example:
    M99

    Tech Support
    CamSoft Corp.
    support@camsoftcorp.com
    PH 951-674-8100
    Fax 951-674-3110
    CNC Controller, PC Based CNC Controls



  6. #6
    Member
    Join Date
    Jan 2008
    Location
    usa
    Posts
    78
    Downloads
    0
    Uploads
    0

    Default Re: Need help getting IF/THEN/ELSE & GOTO or JUMP to work in CNC-Lite v7.8

    OK Guys,

    I think I've got it. I was able to make the following changes to the MCODE file, & got this GCode prog to work as expected.

    Thanks to all who contributed.


    The working GCode prog:

    Code:
    (Jump/Loop Test)
    {LOOPM93=5}
    N100 
    G00 X2.5 Y2.5
    G00 X0.0 Y0.0
    M93 N100
    G00 X5.0 Y5.0
    M02
    The working MCODE:

    Code:
    -----M92
    !MESSAGE
    !MESSAGE To use M93 put statement
    !MESSAGE {LOOPM93=5} <on its own line>
    !MESSAGE N100 <space after this and on its own line>
    !MESSAGE <lines of code>
    !MESSAGE M93 N100
    !MESSAGE the 5 can be any number
    !MESSAGE the 100 can be any number
    !MESSAGE
    !\93=1
    !LOADING \55:IF\55=0THENEXIT
    !{LOOPM93=LOOPM93-1}
    !IF{LOOPM93}>0THENJUMP Nn
    -----M93
    Cheers,
    Steve



Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

Need help getting IF/THEN/ELSE &amp; GOTO or JUMP to work in CNC-Lite v7.8

Need help getting IF/THEN/ELSE &amp; GOTO or JUMP to work in CNC-Lite v7.8