View Single Post
  #11   Ban this user!
Old 05-23-2005, 10:00 AM
camsoft camsoft is offline
 
Join Date: Apr 2003
Location: United States
Posts: 279
camsoft is on a distinguished road

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:
{FIRSTX=3.489}
{SECONDY=-4.555}
{NUMOFPARTS=1}

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
{MYNAME=45*TAN(MYVARB)}

Same as:

Example #2
#9=45*TAN[#151]

Whereas:
#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:
\100={100+10}

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

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.

{LDANG=45.0}
\112={\110*COS(LDANG)/SIN(LDANG)}


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


QUESTION 49
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?


JUMP
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.
EXAMPLE: JUMP N350

Tech Support
CamSoft Corp.
951-674-8100
support@camsoftcorp.com
__________________
(Note: The opinions expressed in this post are my own and are not necessarily those of CNCzone and its management)
Reply With Quote

 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361