506,621 active members
3,807 visitors online
Register for free
Page 1 of 2 12
Results 1 to 12 of 22
  1. #1
    Join Date
    Mar 2004

    parametric programming

    I'm rewritng a very old Gcode program to run on a Camsoft Pro control... FWIW, need more softjaws on a lathe that does not have reversible jaws, have to cut the teeth.

    Anyway, my last two controls allowed versions of IFTHEN and GOTO to loop sections of code over and over (until condition is met) within the Gcode program. I'm not finding a way to do this in Camsoft Pro.

    I'll get this part made by using M98, to get me by, today. I can see M98 just runs the GOSUB command. A clever person could find a way to implement loops and conditional logic within Gcodes using this, somehow.

    Anyway, my question. Can I do loops (GOTO) and conditional branching (IFTHEN) within a Gcode prgram? How?


    P.S. This is the code I'm reworking:

    ;set second jaw back 0.100", third back 0.200"

    (*BLEC'*',CMST';',CNDL3,CNDR4,ZRSP0,PDOF0.05,FDOV0 *)

    %LAPPER = 0
    %ZDEPTH = 0.5000

    %COUNTER = 0
    %LAPPER = %LAPPER + 1

    G92 X 0.00 Y 0.00 Z %ZDEPTH
    G00 X 0.000 Y -0.250 Z 0.00


    G42 T 02
    G01 X 0.008 Y 0.000 F 3.0
    G01 X 0.122 Y 0.000
    G03 X 0.096 Y 0.750 I -1.304 J 0.330
    G01 X 0.000 Y 0.750
    G02 X 0.008 Y 0.000 I -3.986 J -0.420
    G01 X 0.008 Y -0.125
    G01 G 40 X 0.2857 Y -0.25
    G92 X 0.000 Y -0.25 Z 0.00


    G00 X 0.00 Y 0.00 Z 0.00


  2. #2
    Join Date
    Nov 2004
    Ok. I dont know bleep about G Codes but if your interface is anything like mine, this might help you..

    In my interface program.. I can use a GOTO command to jump anywhere..
    But, when I write a program into a text file, I must use the JUMP command inplace of the GOTO command..

    IF THEN still works fine..

    Did this help you? I dont have the pro version.. Mine is just Graphical OI.


  3. #3
    Join Date
    Mar 2004
    Yes, gave me something to look up. I got this nonsence program to show me that IFTHEN and JUMP don't work for me:

    N101 G0 X0
    N102 G0 X1
    JUMP N101

    Machine ended up at X=5. I couldn't get the JUMP command right. Check my syntax above, this should have put the control in an endless loop. Machine just moved to X0 then X1 then X2 then X5

    Next I changed < to >:

    N101 G0 X0
    N102 G0 X1
    JUMP N101

    Program ran the same,ended at X5, I wanted the IFTHEN to just drop through.

    Have I just got some stupid sytax errors???

  4. #4
    Join Date
    Mar 2004
    OK, found one syntax error. Got to pull the {} after the IF. What's wrong with JUMP?


  5. #5
    Join Date
    Nov 2004
    When I use the JUMP command, I make sure to put the line number on a line by itself.

    !IF Bla Bla THEN JUMP N101

    Try putting your line number on a seperate line..

    Sorry I can not give you better answers.. Your software is a bit different than mine is.
    Im not even sure if it must be on a line by itself.. Its just the way I do it..


  6. #6
    Join Date
    Mar 2004
    I tried every syntax variation I could think of with JUMP. No joy.

    I'll ask Camsoft on Monday.


  7. #7
    Join Date
    Nov 2004

    The code you wrote did not make sense to me..

    N101 G0 X0
    N102 G0 X1
    JUMP N101

    It would seem to me that the computer makes COUNTER=2 then the computer executes X0 then the computer executes X1 then the computer jumps to N101 and executes X0 again..
    From my perspective, it doesnt seem as though the program will every progress to the line GO X{COUNTER} because it is running into the JUMP N101 line..
    Am I mistaken?

    When I was doing mine, I was writing allot of 3 or 4 line programs that did nothing just so I could test code... Seems that's what your doing to in order to experiment. The solution has to be simple..

    What is COUNTER ?? Is this a user defined variable of some sort? Or a function within your software like the ESTOP command? The reason I ask that is because you have the COUNTER enclosed with {} which are math brackets in my software.
    If this is some type of command that is in your software, try removing the {} all together.. The math brackets {} as I understand, are only to be used when the computer must skip forward in the line and perform a math function in order to finish a math function as in:
    IF 5={4+1} THEN BLA BLA BLA.

    Where as, if I just want to compare two simple values the command would be
    IF 5=\12 then bla bla bla
    IF 5=A then bla bla bla..

    Any of this helping??


  8. #8
    Join Date
    Mar 2004
    This is just a junk program to test things. Makes no sence. No offence, but I can see you don't do G code.

    The Pro manual talks about different syntax for Gcode fiiles. In the control, a variable is: \## and you'd write stuff like \99=1. In Gcode, variables can have names, ie COUNTER, and assigining values must be in curlies {COUNTER=1}.

    G0 is the standard gcode for rapid to point defined in cartesion X Y Z values.

    You're right about the JUMP, the program is ignoring this command. That's what I was testing here.


  9. #9
    Join Date
    May 2005
    I did not know that g-code supported jump without modification.

    We have a fanuc robot at work that we use those commands on but we use "jmp" instead of "jump"
    It might be a long shot, but you can see if that makes any difference.

    Our code looks like this:

    blah blah blah
    JMP LBL[515];

  10. #10
    Join Date
    Nov 2004
    Sorry I can't help you more Karl,,

    Your right about one thing.. I dont know bleep about Gcodes!!! LOL.. My CNC control has nothing to do with a normal CNC machining center..

    I have gotten pretty good at using my version of Graphical OI so I thought I would step in and try.. It was a good try .. LOL

    I hope you solve your problem..


  11. #11
    Registered camsoft's Avatar
    Join Date
    Apr 2003
    Variables, Math, Marcos, Jumps and G code usage.

    There are numerous sections of the manuals that cover these topics.

    Usage and Syntax does change between the Graphical OI, CNC Lite, Plus and Professional versions. All of the commands are the same syntax between each package, but the degree of access and power changes. For example a subset of FANUC variables and Macros are only available in the CNC Professional, while CamSoft variables and macros are available in all versions. The JUMP command is available in all versions and the syntax in the same. See below for instructions and examples for proper usage.

    The documentation is lengthy, so we are only providing a limited answer below. The best way to find answers is to electronically search using the Search for Solutions button on CNCsetup.exe or Setup.exe. You can search for answers using key words like a web-browser.

    QUESTION 121
    Can I use variables and/or do math in my G Code Program?

    The controller does have the ability to store unlimited variable names. A legal variable name is a name that begins with any letter of the alphabet. To save a value to a variable in a G Code program, enclose the math and the variable name followed by an equal sign (=) inside curly braces {}. For example, to store 5.5 to the variable

    KEEPME: {KEEPME=5.5}

    For example, to do math to an existing X axis coordinate in a G Code line where X needs to have .75 added to its value, write the G Code line like this: N100 G01 X{5.5+.75} Y6.2 F30

    For example, to add the value of a variable to an existing X axis coordinate in a G Code line, enter: N100 G01 X{5.5+KEEPME} Y6.2 F30

    For example, pre-store the values of variables at the top of the program.

    At the top of the program:

    For example, to add the variable FIRSTX to the X axis coordinate in your G Code program, enter: N100 G01 X{5.5+FIRSTX} Y5

    QUESTION 197
    What are the limitations of subprograms and variables within the G code program?

    You should first be aware that we allow two formats to be used to assign variables, call macros and do math within the G code program.

    Curly Braces { } or Fanuc Style Square Brackets [ ] may be used in macros or to perform math equations. Named variables can be replaced by FANUC style # numbered variables.

    Example #1

    Same as:

    Example #2

    #9 same as MYNAME
    #151 same as MYVARB
    [ ] same as { } or ( )

    These variables, in either named or numbered formats, are public/global throughout the entire time the computer remains on even between different G code programs. They will only be erased when you exit the CNC or overwrite them.

    There are three types of variables: LOCAL, USER and SYSTEM variables. LOCAL variables: These are variables that are only available locally within each subprogram. If you call a subprogram with M98, the variables in the main program are not seen by the subprogram. They are not shared. Variables automatically become local when they are placed inside a subprogram.

    USER variables: Are seen by all G code programs since the computer has been turned on. They are known as public or global and can be shared.

    SYSTEM variables: Are for the installer's internal use only in logic routines. All variables in the G code program are also kept totally separate from the SYSTEM variables that the installer used within the internal system logic. The user cannot change the SYSTEM variable values; however, the installer does have access to the USER variables and can internally read and set the USER variables within the G code program.

    Subprograms called using M98 or the command GOSUB must be complete enough to be able to run on their own, by themselves, including the use of user variables in G code, G41, G42, SmartPath or the 3-5 axes tool comp features.

    To access a SYSTEM variable from a G code program:

    Whereas in logic a SYSTEM variable gets assigned like this:

    To make a SYSTEM variable such as \100 accessible to a G code program, reassign it to a named USER variable:

    From within the G code program you would write this:
    G00 X{SIZE}

    Other Examples

    When using names as variables for math functions, note where we are using the {} and () characters because the placement of these are important for it to work correctly. LDANG is a named variable that can be used in a G code program and read into logic for calculation or directly used in the G code program. Note that the \112 variable is not valid in a G code program, only in logic files. Refer to the “Pre-Programmed G & M Programming Codes” section in this manual for examples on Fanuc style macro named variables that can be used with trig functions.


    See the 2 pages Titled "Example of macro variables used in G code program."

    How do I write logic to use a value entered by the user in a text box on the screen?

    QUESTION 237
    How can we ask the user a question so that the answer can be used in a G code program?

    This command enables the user to jump or switch the execution of the G code program to a specific G code line that contains a match for the parameter after the JUMP command. The parameter may be a line number, an axis position, a certain feed rate or spindle speed or just about any identical match that can be found in a G code line. The object you are jumping to must appear first in the line of G code. When found, the program will start executing at the line where the match was found. It is important that there is a space following the search item in the G code program.

    Tech Support
    CamSoft Corp.
    (Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)

  12. #12
    Join Date
    Mar 2003
    I search all over to the point the lettering on F3 is wearing off.

    In CNCLite I tried a simple back and forth motion:

    N1 G10 Y20.0 F50.
    N2 G10 Y0.0
    N3 G10 Y20.0
    N4 G10 Y0.0
    N5 G10 Y20.0
    JUMP N2
    N6 G10 Y0.0

    (G10 isn't modal.)

    !JUMP N2


    Added WAITUNTIL STOP on a prior line.

    Still nuthin.

    In the "Line" box, I will see "2" after the jump line is read, but then the screen flickers just a little and then N10 is run.

    REWIND doesn't.

    Neither does GOTO

    If anyone knows how to use these commands, please step forward.
    In another controller, I just place GOTO Nxx and it does. Without being admonished to read the manual.

Page 1 of 2 12

Similar Threads

  1. Programming PLC on Fanuc 0M
    By MetLHead in forum Fanuc
    Replies: 21
    Last Post: 02-18-2019, 06:36 AM
  2. Gsoft Online CNC Programming Tool
    By tslawnyk in forum News Announcements
    Replies: 5
    Last Post: 12-07-2007, 02:18 PM
  3. Mazak C axis programming
    By dpinson in forum Uncategorised MetalWorking Machines
    Replies: 1
    Last Post: 07-02-2005, 09:06 PM
  4. API Programming Anyone
    By Al_The_Man in forum Computers / Networking
    Replies: 3
    Last Post: 02-15-2005, 03:31 AM
  5. Conversational CNC Programming
    By BlueChip in forum News Announcements
    Replies: 0
    Last Post: 07-24-2004, 07:37 PM

Posting Permissions

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