Lecture 11. G-codes part programming
The programming language of the mill is known as G-code. A G-code program is composed of one or more lines of code. Each line (called a block) may include commands to the machining system to do several different things. Blocks may be collected in a file to make a program.
A typical block consists of an optional line number at the beginning followed by one or more words. A word consists of a letter followed by a number (or strictly speaking, something that evaluates to a number). A word may either give a command or provide an argument to a command. For example, G01 X3 is a valid line of code with two words. G01 is a command meaning move in a straight line at the programmed feed rate, and X3 provides an argument value (the value of X should be 3 at the end of the move). Most commands start with either G (general) or M (miscellaneous). The words for these commands are called G-codes and M-codes.
The language has two commands (M02 or M30), execution of either of which ends a program. A program may end before the end of a file. Lines of a file that occur after the end of a program are not to be executed in the normal flow, so generally they’re parts of subroutines.
A block (or equivalently line) of code is a section of programming language elements that are grouped together into a single statement. A program consists of one or more blocks, each separated by a line break. Blocks in a program are executed sequentially from top to bottom or until an end command (M02 or M30) is encountered.
A real value may be an explicit number (such as 341 or -0.8807), a parameter value, an expression or a unary operation value. Definitions of these follow in the Word Initial Letters table.
Numbers are a subset of real values. Processing a real value to come up with a number is called evaluating. An explicit number evaluates to itself.
The following rules are used for explicit numbers. In these rules a digit is a single character between 0 and 9.
• A number consists of the following, in order: (1) an optional plus or minus sign, followed by (2) zero to many digits, followed, possibly, by (3) one decimal point, followed by (4) zero to many digits.
• There must be at least one digit somewhere in the number.
• There are two kinds of numbers: integers and decimals. An integer does not have a decimal point in it; a decimal does.
• Numbers may have any number of digits, subject to line length limitations.
• A non-zero number with no sign as the first character is assumed to be positive.
Initial zeros (before the decimal point and the first non-zero digit) and trailing zeros (after the decimal point and the last non-zero digit) are allowed but not required. A number written with initial or trailing zeros has the same value when it is read as if the extra zeros were not there.
Numbers used for specific purposes by the operating system are often restricted to some finite set of values or some to some range of values. In many uses, decimal numbers must be close enough to an integer to be accepted as input. A decimal number which is supposed to be close to an integer is considered close enough if it is within 0.0001 of an integer.
Дата добавления: 2017-05-02; просмотров: 1267;