G-koodi

Kohteesta Helsinki Hacklabin wiki
Loikkaa: valikkoon, hakuun

G-Code

G-koodisyntaksia noudattava CNC-ohjelma koostuu matalan tason toiminnoista joita kutsutaan lauseiksi (block). Lauseet puolestaan rakentuvat sanoista (code). Sanat ovat joko "valmistelevia" G-koodeja tai "sekalaisia" M-koodeja.
G-koodisyntaksi on lähes rakenteeton sillä mitään ohjelmakontrollin ohjausrakenteita kieleen ei kuulu. Aliohjelmakutsu käyttäen M-koodisanoja on olemassa mutta ei juuri muuta.
G-koodi on tulkattua koodia siinä mielessä, että kooditulkki jäsentää aina yhden kokonaisen lauseen kerrallaan ja optimoi sisällön suorituksen ennen sen käynnistämistä. Lotan Fanuc-ohjain toimii siten, että lauseessa mahdollisesti olevista ristiriitaisista käskysanoista viimeksi kirjoitettu jää voimaan ja toteutetaan.
On erityisesti syytä tiedostaa, lähes kaikki G-koodisanat ovat modaalisia eli ne jäävät voimaan kunnes samaan modaaliryhmään kuuluva toinen koodi astuu niiden tilalle. Samoin lauseesta puuttuva argumentti saa sen arvon joka sillä on viimeksi ollut jossain aikaisemmassa lauseessa. Näin ollen muuttumatonta argumenttia ei tarvitse toistaa lause lauseelta.

A CNC program that follows G-code syntax consists of low-level functions called blocks. Sentences, in turn, are built from words (code). The words are either "preparatory" G-codes or "Miscellaneous" M-codes.
The G-code syntax is almost unstructured because no program control controls are included in the language. A subroutine call using M codewords exists but little else.
G-code is interpreted code in the sense that the code interpreter always parses one whole sentence at a time and optimizes the execution of the content before it is launched. Lotta's Fanuc controller works in such a way that the last of the conflicting command words in a sentence remains valid and executed.
In particular, it should be noted that almost all G codewords are "modal", meaning that they remain in effect until another code belonging to the same modal group replaces them. Similarly, an argument that is missing from a sentence gets the value it last had in an earlier sentence. Therefore, the unchanged argument does not need to be repeated sentence by sentence.

Esimerkki yksinkertaisesta NC-lauseesta:
N001 G01 X500.000 Y60.000 Z0.000 M03
Rivinumero 001; koordinoitu liike työstönopeudella koordinaatteihin XYZ samalla käynnistäen kara pyörimään myötäpäivään

Esimerkki modaalisesta NC-lauseesta:
G01 X500. Y60. Z0. M03
X510.
X520.
Koordinoitu liike työstönopeudella koordinaatteihin 500/60/0, sen jälkeen 510/60/0 ja 520/60/0 koska G01 on modaalinen.

Example of a simple NC block:
N001 G01 X500.000 Y60.000 Z0.000 M03
Line number 001; coordinated movement at machining speed to XYZ coordinates while starting the spindle to rotate clockwise

Example of a modal NC block:
G01 X500. Y60. Z0. M03
X510.
X520.
Coordinated movement at machining speed to coordinates 500/60/0, then 510/60/0 and 520/60/0 because G01 is modal.

Lotan tunnistamat G-koodisanat

Useimmat G-koodilauseet muodostuvat valmistelevasta G-koodista, sekä siihen liittyvistä yhdestä tai useammasta argumentista. Lauseissa käytetään myös "sekalaisia" M-koodisanoja ohjaamaan koneen toimintoja päälle ja pois.
Koska useimmat G-koodisanat ovat modaalisia, usein riittää pelkkä argumenttien mainitseminen läskylauseessa, jolloin voimassa oleva modaalinen käsky toistetaan kyseisillä argumenteilla. Tästä edellä yksinkertainen esimerkki.

G-koodisanojen argumentit

Argumentti Ohjaa koodeja Toiminto
P_ --- Lyhennetty asemakoordinaatin esitystapa. Sama kuin X_ Y_ Z_ missä _ tarkoittaa koordinaatin numeroarvoa. Myös vaihtoehtoiset koordinaatit kuten IJK, UVW jne.
X, Y, Z Modaali 01 koodit Paikkakoordinaatit liikettä varten
A, B, C Modaali 01 koodit Kulmakoordinaatit X, Y, Z-akselien ympäri tapahtuvaa kiertoa varten (4. akseli)
I, J, K G02, G03 Suhteelliset paikkakoordinaatit ympyränkaaren keskipisteen sijoitamiseksi
U, V, W Modaali 01 koodit X, Y, Z-akselien suuntaiset suhteelliset paikkakoordinaatit liikettä varten
S M03, M04 Karan kierosluvun ohjearvo
F Modaali 01 koodit Syöttöliikkeen nopeus mm/min
H Modaali 01 koodit Työkalun pituus- ja sädekompensointi
T --- Työkalun valinta
R modaali 09 koodit

G02, G03

Liikkeen paluutaso katkoporauksessa ja vastaavissa

Säteen määrittely ympyräinterpolaatiossa

Q Modaali 09 koodit Porauksen askelsyvyys katkoporauksessa tms
P G04 Taukoaika ms
N --- Lauseen rivinumero (ei pakollinen)

G-code words recognized by Lotta

Most G-code statements consist of a preparatory G-code, and one or more arguments associated with it. The sentences also use "Miscellaneous" M-code words to control the machine functions on and off.
Since most G codewords are modal, it is often sufficient to simply mention the arguments in the statement statement, in which case the valid modal statement is repeated with those arguments. A simple example of this above.

G codeword arguments

Argument Control codes Function
P_ --- Abbreviated position coordinate format. Same as X_ Y_ Z_ where _ is the numeric value of the coordinate. Also alternative coordinates such as IJK, UVW, etc.
X, Y, Z Modal 01 codes Position coordinates for motion
A, B, C Modal 01 codes Angular coordinates for rotation about the X, Y, Z axes (4th axis)
I, J, K G02, G03 Relative position coordinates to position the center of the arc
U, V, W Modal 01 codes Relative position coordinates along the X, Y, Z axes for motion
S M03, M04 Spindle speed setpoint
F Modal 01 codes Feed speed mm / min
H Modal 01 codes Tool length and radius compensation
T --- Tool selection
R modal 09 codes

G02, G03

The return level of the movement in break drilling and the like

Radius definition in circular interpolation

Q Modal 09 codes Drilling step depth in break drilling, etc.
P G04 Pause time ms
N --- Sentence line number (optional)

Varsinaiset G-koodisanat

G-koodi Modaaliryhmä Toiminto
G00 01 Pikaliike annettuihin koordinaatteihin
G01 01 Koordinoitu liike työstönopeudella annettuihin koordinaatteihin
G02 01 Ympyräinterpolaatio myötäpäivään
G03 01 Ympyräinterpolaatio vastapäivään
G04 00 Tauko
G05 00 Suurnopeussyklillä koneistus
G09 00 Täsmällinen paikoitus
G15 17 Polaarikoordinaattimoodin peruutus
G16 17 Polaarikoordinaatimoodin asetus
G17 02 XY-tason asetus ympyräinterpolaatioon
G18 02 ZX-tason asetus ympyräinterpolaatioon
G19 02 YZ-tason asetus ympyräinterpolaatioon
G20 06 Mittayksiköt tuumina
G21 06 Mittayksiköt milleinä
G22 00 Esimerkki
G23 00 Esimerkki
G27 00 Kotiasemaan ajon tarkistus
G28 00 Ajo kotiasemaan
G29 00 Paluu kotiasemasta
G30 00 Paluu 2. kotiasemaan
G31 00 Toiminnon ohitus
G33 01 Kierteitys
G39 00 Nurkan kierto ympyräinterpolaation avulla
G40 07 Työkalun säteen kompensoinnin peruutus
G41 07 Työkalun säteen kompensointi vasemmalle
G42 07 Työkalun säteen kompensointi oikealle
G43 08 Työkalun pituuskompensointi summaten (+ suuntaan)
G44 08 Työkalun pituuskompensointi vähentäen (- suuntaan)
G45 00 Työkaluoffsetin kasvatus
G46 00 Työkaluoffsetin vähennys
G47 00 Työkaluoffsetin 2x kasvatus
G48 00 Työkaluoffsetin 2x vähennys
G49 08 Työkalun pituuskompensoinnin peruutus
G50 11 Skaalauksen peruutus
G51 11 Skaalauksen asetus
G52 00 Työkoordinaatiston siirto
G53 00 Liikkeen referointi konekoordinaatteihin
G54 14 Työkoordinaatiston 1 valinta
G55 14 Työkoordinaatiston 2 valinta
G56 14 Työkoordinaatiston 3 valinta
G57 14 Työkoordinaatiston 4 valinta
G58 14 Työkoordinaatiston 5 valinta
G59 14 Työkoordinaatiston 6 valinta
G60 00 Yksisuuntainen paikoitus
G61 15 Tarkka pysäytystila
G62 15 Automaattinen nurkan ohitustila
G63 15 Kierteitystila
G64 15 Leikkuutyöstötila
G65 12 Makrokäsky, makrokutsu
G66 12 Kustom-makron modaalinen kutsu
G67 12 Kustom-makron modalisen kutsun peruutus
G68 16 Koordinaatiston kierto
G69 16 Koordinaatiston kieron peruutus
G73 09 Katkoporaus-työkierto 1
G74 09 Vastakierteitys-työkierto
G76 09 Tarkkuusavarrus
G80 09 Työkierron peruutus
G81 09 Pisteporaus-työkierto
G82 09 Vastaporaus-työkierto
G83 09 Katkoporaus-työkierto 2
G84 09 Kierteitys-työkierto
G85 09 Avarrustyökierto
G86 09 Avarrustyökierto
G87 09 Vasta-avarrustyökierto
G88 09 Avarrustyökierto
G89 09 Avarrustyökierto
G90 03 Absoluuttikoordinaattien valinta
G91 03 Suhteellisten koordinaattien valinta
G92 00 Absoluuttikoordinaatiston origon asetus
G94 05 Syöttö yks/minuutti
G95 05 Syöttö yks/karan kierros
G96 13 Vakio-pintanopeussäätö päälle
G97 13 Vakio-pintanopeussäätö pois päältä
G98 10 Työkierrossa välipaluu alkupisteen tasalle
G99 10 Työkierrossa välipaluu R-koordinaatin tasalle

Actual G codewords

G code Modal group Function
G00 01 Fast motion to the given coordinates
G01 01 Coordinated motion at the machining speed to the given coordinates
G02 01 Circular interpolation clockwise
G03 01 Circular interpolation counterclockwise
G04 00 Break
G05 00 Machining with high speed cycle
G09 00 Accurate positioning
G15 17 Canceling the polar coordinate mode
G16 17 Polar coordinate mode setting
G17 02 XY plane setting for circular interpolation
G18 02 ZX plane setting for circular interpolation
G19 02 YZ level setting for circular interpolation
G20 06 Units of measurement in inches
G21 06 Units of measurement in millis
G22 00 Example
G23 00 Example
G27 00 Home drive check
G28 00 Driving to your home station
G29 00 Return from home station
G30 00 Return to 2nd home station
G31 00 Bypass function
G33 01 Threading
G39 00 Angle rotation by circular interpolation
G40 07 Cancel tool radius compensation
G41 07 Tool radius compensation to the left
G42 07 Tool radius compensation to the right
G43 08 Tool length compensation by summing (+ direction)
G44 08 Tool length compensation decreasing (- direction)
G45 00 Tool offset breeding
G46 00 Tool offset reduction
G47 00 2x increase in tool offset
G48 00 2x reduction of tool offset
G49 08 Cancel tool length compensation
G50 11 Cancel scaling
G51 11 Scaling setting
G52 00 Transfer of work coordinate system
G53 00 Reference of motion to machine coordinates
G54 14 Selection of work coordinate system 1
G55 14 Selection of work coordinate system 2
G56 14 Selection of work coordinate system 3
G57 14 Selection of work coordinate system 4
G58 14 Selection of work coordinate system 5
G59 14 Selection of work coordinate system 6
G60 00 One-way parking
G61 15 Exact stop mode
G62 15 Automatic corner bypass mode
G63 15 Threading mode
G64 15 Cutting machine mode
G65 12 Macro instruction, macro call
G66 12 Modal call to the custom macro
G67 12 Cancel a modal call to a custom macro
G68 16 Coordinate system rotation
G69 16 Canceling the coordinate system rotation
G73 09 Intermittent drilling cycle 1
G74 09 Counter-threading cycle
G76 09 Precision armature
G80 09 Cycle cancellation
G81 09 Spot drilling cycle
G82 09 Counter-drilling cycle
G83 09 Intermittent drilling cycle 2
G84 09 Threading cycle
G85 09 Boring cycle
G86 09 Boring cycle
G87 09 Counter-reaming cycle
G88 09 Boring cycle
G89 09 Boring cycle
G90 03 Selection of absolute coordinates
G91 03 Selection of relative coordinates
G92 00 Setting the origin of the absolute coordinate system
G94 05 Input one / minute
G95 05 Feed one / spindle revolution
G96 13 Constant surface speed control on
G97 13 Constant surface speed control off
G98 10 In the cycle, a snippet returns to the starting point
G99 10 In the cycle, return to the R coordinate

Lotan tunnistamat M-koodisanat

M-koodi Toiminto
M00 Pakollinen tauko. Ohjelma pysähtyy tähän kunnes käyttäjä painaa [CYCLE START] jolloin ohjelma jatkaa
M01 Ehdollinen tauko. Sama kuin edellä, mutta vain mikäli paneelin [OPT STOP] on painettuna aktiiviseksi
M02 Ohjelman lopetus. Suoritus päättyy ja ohjelma kuitataan ajetuksi.
M03 Kara liikkeelle myötäpäivään. Kara lähtee pyörimään nopeudella joka on aiemmin asetettu argumentilla S
M04 Kara liikkeelle vastapäivään.
M05 Kara seis.
M06 Työkalun vaihto - suorituskäsky. Edeltävä valinta käyttäen käskysanaa T toteutetaan tällä toiminnolla.
M08 Leikkuuneste päälle. Edellytää, että paneelissa on valittu (COOLANT) [CLNT AUTO] aktiiviseksi
M09 Leikkuuneste pois
M19 Karan orientointi. Kiertää karan asentoon jossa työkalun vaihto tapahtuu. Samaa asentoa käytetään mm. vasta-avarruksessa jne
M29 Jäykkä kierteitystila päälle
M30 Ohjelman lopetus ja paluu alkuun
M40 4. akselin lukitus
M41 4. akselin vapautus
M94 Akselin peilauksen peruutus
M95 X-akselin peilaus
M96 Y-akselin peilaus
M98 Aliohjelman kutsu
M99 Aliohjelmasta paluu

M-code words recognized by Lotta

M code Function
M00 Mandatory break. The program stops here until the user presses [CYCLE START] at which point the program continues
M01 Conditional break. Same as above, but only if panel [OPT STOP] is pressed active
M02 End of the program. Execution ends and the program is acknowledged as run.
M03 Spindle moved clockwise. The spindle starts rotating at the speed previously set by argument S.
M04 Spindle moved counterclockwise.
M05 Kara stand.
M06 Tool change - execution command. The pre-selection using the command word T is performed with this function.
M08 Cutting fluid on. Requires (COOLANT) [CLNT AUTO] to be selected as active on the panel
M09 Cutting fluid off
M19 Spindle orientation. Rotates the spindle to the position where the tool is changed. The same position is used e.g. counter-reaming, etc.
M29 Rigid threading mode on
M30 Ending the program and returning to the beginning
M40 4th axle lock
M41 4th shaft release
M94 Axis mirroring cancellation
M95 X-axis mirroring
M96 Y-axis mirroring
M98 Subroutine call
M99 Return from the subroutine



Ylös