G-code

From EduTech Wiki
Jump to: navigation, search

1 Introduction

According to Wikipedia, “G-Code, or preparatory code or function, are functions in the Numerical control programming language. The G-codes are the codes that position the tool and do the actual work, as opposed to M-codes, that manages the machine; T for tool-related codes. S and F are tool-Speed and tool-Feed, and finally D-codes for tool compensation.”

See also

2 Arduino g-codes

  • See G-code page at RepRap wiki.

3 List of G-codes for the Rapman

This is a g-code page for the RapMan printer.

List of RapMan G-code (thanks to Bits from Bytes blog: RapMan special codes

Code Explanation Example
G0 Rapid Motion in X, Y, and Z axes. G0 X10.0 Y20.0 Z1.15
G1 Coordinated Motion in X, Y, and Z axes with speed F mm/minute. G1 X10.0 Y20.0 Z1.15 F960.0
G2 Arc – Clockwise (Not used by Skienforge)
G3 Arc - Counter (Clockwise Not used by Skienforge)
G4 Dwell Time G4 S20
G20 Inches as units used G20
G21 Millimetres as units used G21
G28 Go Home (far left) G28
G90 Absolute Positioning G90
G92 Set current as home G92
M101 Turn extruder on (forward/filament in). M101
M102 Turn extruder on Reverse (Still to add)
M103 Turn extruder off. M103
M104 Set target temperature to 245.0 C. M104 S245
M105 Custom code for temperature reading. Not used
M106 Turn fan on. M106
M107 Turn fan off. M107
M108 Set Extruder speed to S value/10 = 40rpm. M108 S400
M220 Turn off AUX V1.0.5 M220
M221 Turn on AUX V1.0.5 M221
M222 Set speed of fast XY moves M222
M223 Set speed of fast Z moves M223
M224 Enable extruder during fast moves M224
M225 Enable extruder during fast moves M225
M226 Pause RapMan as if pause button pressed M226

Typical file headers produced by the Skeinforge program

G21 millimeter system selection
G90 absolute distance mode
G28 Return to home position
M222 S800 Manually added to file. Set speed of fast XY moves. Default value 500 -V1.0.5
M223 S768 Manually added to file. Set speed of fast Z moves. Default value 500 -V1.0.5
M103 Turn extruder OFF.
M105 Custom code for temperature reading – not used by RapMan
M104 S247.0 Set temperature to 247.0 DegC.
G1 X0.0 Y0.0 Z0.0 F480.0 example of linear interpolation at speed 480
M101 Turn extruder ON.
Main code follows .....

4 Example code

Lines 1-12 from a Duplo-compatible block with a vertical hand on top (6.4cm X 6.4 cm x 13.5cm). The file has 79009 lines (!) and prints at medium speed/quality.

G90
G21
M103
M105
M113 S1.0
M104 S255.0
G1 X-8.64 Y-69.23 Z0.84 F60.0
M101
M108 S595.0
G1 X-8.64 Y5.87 Z0.84 F200.0
G1 X-4.32 Y5.87 Z0.84 F200.0
G1 X-4.32 Y-69.23 Z0.84 F200.0

Lines 1057 and forward

M103
M108 S350.0
G1 X0.36 Y-63.63 Z2.72 F960.0
M101
G1 X0.36 Y-63.64 Z2.72 F1200.0
G1 X63.64 Y-63.64 Z2.72 F1200.0
G1 X63.64 Y-0.36 Z2.72 F1200.0
G1 X0.36 Y-0.36 Z2.72 F1200.0
G1 X0.36 Y-62.91 Z2.72 F1200.0
M103
G1 X1.15 Y-62.86 Z2.72 F960.0
M101
G1 X1.14 Y-62.86 Z2.72 F1200.0
G1 X1.14 Y-56.39 Z2.72 F1200.0
G1 X2.64 Y-56.39 Z2.72 F1200.0
G1 X2.64 Y-55.61 Z2.72 F1200.0
G1 X1.14 Y-55.61 Z2.72 F1200.0
G1 X1.14 Y-40.39 Z2.72 F1200.0

5 Recovery from printing abortion

Printing stopped at line 299941 after 3 days of printing. I mean I had the printer on hold sometimes (ESC), but it was a 24 job. Anyhow, big low down, but I decided that I must recover from this without super glue, i.e. leave the object on the print bed and restart.

If you don't know where it crashed, e.g. if the board did reset: Run skeinforge again but make a change in the Analyze->Skeinview tool:

  • Change Mouse Mode to Display Line. You then can identify both the layer and the spot where it stops in this tool. Then click on a drawing it will display the g-code line...

Now if you were printing a tall object, the problem is that the rapman always expects to be able to home in order to find x,y,z = 0. If you have a "real" print it can't, since raising the print bed will destroy a 14cm high print for example.

Printing in progress, but crashed sometimes later :(/

I tried all sorts of things fiddling with G90 and G92 codes, but did not mange to restart g-code where the printer left.

G90
G92 X0 Y0 Z-142
or
G90
G92 X0 Y0 Z142

So I came up with a typical bricoleur solution :(

  • Fix the g-code to start at z=0
  • Fool the printer to believe that it is at z=0

Here are the two steps:

(1) Fixing the g-code file

Normally, you should write a script (argl for stupid end-user programmers) that replaces all the Z values. E.g. Z142.2 should become 0 or 0.2. In my case I was lucky since I just print vertically. So I decided to restart at 14cm and not 14.2cm (makes it higher, but that's fine).

GCode where it stopped:

G1 X-90.5 Y68.33 Z142.2 F960.0

So I went to start of the 140mm series and killed all the lines from beginning to there. Then I used three Regexps with a text editor (emacs) to change:

Z14\(.\)\(..\) by Z\1\2
Z15\(.\)\(..\) by Z1\1\2
Z16\(.\)\(..\) by Z2\1\2

Then of course, the g-code must have a header. Resulting g-code start:

G90
G21
M113 S1.0
M108 S380.0
M104 S210
M101
M103
M108 S380.0
M106
M103
G1 X40.96 Y-19.95 Z0.2 F869.59
M101
G1 X39.55 Y-18.93 Z0.2 F960.0
G1 X36.66 Y-17.64 Z0.2 F960.0

If your object is flat, you can stop here, else read on ....

(2) Fool the printer

a) Move the print head next to a top level point NEXT to home. Path toward -X (left) must be unobstructed. Then align it, i.e. make it touch the top.

b) Move it to the left a bit, and switch off.

c) Switch on. Then position the print head about 1mm below the point where you want to restart. This can be a bit less or more. You can see how much you go down on the control panel. I.e. press the Z+ button and move the print board up.

d) Switch off

e) Hold you finger on the Z switch (grey box which is usually touched by the long 6cm bolt. Run the file and release after 1-2 seconds, i.e. the print bed should move down again by 1mm.

f) Now the printer will move to Xmax/Ymin. If it barely scratches the print when it moves you are fine. If it is too high or too low, then repeat from (c). Took me about 4 attempts to get this right.

Remarks

I REALLY think that rapman firmware should include a control code to recover more easily e.g. Some g-code that says:

  • Home to X=0 and Y=0 (but leave Z ALONE)
  • Read from the G-code file the current Z-position (e.g. Z=142.2)
  • Then just print ....

There is a plan for future firmware to fix this. See this post by Ian - 22:22, 2 April 2010 (UTC).

I did manage to print this stronghold, see the Doblo factory article.

6 Links