GcodeG代码详解
GcodeG代码详解
GcodeG代码详解G代码是数控程序中的指令。
一般都称为G指令。
代码功能G代码代码名称-功能简述G00------快速定位G01------直线插补G02------顺时针方向圆弧插补G03------逆时针方向圆弧插补G04------定时暂停G05------通过中间点圆弧插补G06------抛物线插补G07------Z 样条曲线插补G08------进给加速G09------进给减速G10------数据设置G16------极坐标编程G17------加工XY平面G18------加工XZ平面G19------加工YZ平面G20------子程序调用G22------半径尺寸编程方式G220-----系统操作界面上使用G23------直径尺寸编程方式G230-----系统操作界面上使用G24------子程序结束G25------跳转加工G26------循环加工G30------倍率注销G31------倍率定义G32------等螺距螺纹切削,英制G33------等螺距螺纹切削,公制G34------增螺距螺纹切削G35------减螺距螺纹切削G40------刀具补偿/刀具偏置注销G41------刀具补偿——左G42------刀具补偿——右G43------刀具偏置——正G44------刀具偏置——负G45------刀具偏置+/+G46------刀具偏置+/-G47------刀具偏置-/-G48------刀具偏置-/+G49------刀具偏置0/+G50------刀具偏置0/-G51------刀具偏置+/0G52------刀具偏置-/0G53------直线偏移,注销G54------直线偏移xG55------直线偏移yG56------直线偏移zG57------直线偏移xyG58------直线偏移xzG59------直线偏移yzG60------准确路径方式(精)G61------准确路径方式(中)G62------准确路径方式(粗)G63------攻螺纹G68------刀具偏置,内角G69------刀具偏置,外角G70------英制尺寸寸G71------公制尺寸毫米G74------回参考点(机床零点) G75------返回编程坐标零点G76------车螺纹复合循环G80------固定循环注销G81------外圆固定循环G331-----螺纹固定循环G90------绝对尺寸G91------相对尺寸G92------预制坐标G93------时间倒数,进给率G94------进给率,每分钟进给G95------进给率,每转进给G96------恒线速度控制G97------取消恒线速度控制功能详解G00—快速定位格式:G00 X(U)__Z(W)__说明:(1)该指令使刀具按照点位控制方式快速移动到指定位置。
G-Code详解
G-Code详解基础运动既然G-code是计算机指挥3D打印机干活用的一套语言,那么其中最重要的就是运动类的指令。
G0/G1 直线移动虽然从名字上看,G0叫做“快速直线移动”,而G1叫做“直线移动”,但实际上在Repetier-firmware里面,G0和G1指令是完全等价的,没有任何区别。
移动是否快速,完全是靠参数F来决定的(下面会详细介绍)。
这条指令的作用也很简单,就是将挤出头线性移动到一个特定的位置。
这条指令带有不少参数,完整的形式是这样的:G0 Xnnn Ynnn Znnn Ennn Fnnn Snnn或者G1 Xnnn Ynnn Znnn Ennn Fnnn Snnn使用时,不需要所有的参数全部存在,但至少要有一个参数。
其中,•Xnnn表示X轴的移动位置;•Ynnn表示Y轴的移动位置;•Znnn表示Z轴的移动位置;•Ennn表示E轴(挤出头步进电机)的移动位置;•Fnnn表示速度,单位是毫米/每分钟;•Snnn表示是否检查限位开关,S0不检查,S1检查,缺省值是S0;举例来说,G1 F1500G1 X50 Y25.3 E22.4这样两行G-code,表示了首先将速度设置为1500mm/min,也就是25mm/s,然后将挤出头移动至x=50mm, y=25.3mm的位置上,z轴高度不变,并且将挤出头步进电机移动至22.4mm的位置上。
这里,速度、xyz位置都比较好理解,但挤出头步进电机的位置怎么理解呢?移动至22.4mm处,代表着挤出了多少耗材呢?实际上,这里挤出头的具体动作,要根据之前挤出头步进电机所在的状态(也就是位置)而定。
比如在这两条语句之前,挤出头步进电机已经处于20mm 的位置处,那么这里挤出头步进电机只要再前进2.4mm就可以了。
仔细想想,其实挤出头步进电机的工作方式,与xyz轴完全一样。
xyz轴之所以比较好理解,是因为我们清楚的知道原点(0, 0, 0)的位置在哪里。
而对于e轴来说原点的位置也会在打印开始处被初始化到0的位置。
Gcode G代码详解
reprap wiki上面的Gcode说明G-codeFrom RepRapWiki(Redirected from Gcode)Jump to: navigation, searchContents [hide]1 Introduction2 RepRap G Code Fields3 Comments4 Individual commands4.1 Checking4.1.1 N and *4.2 Buffered G Commands4.2.1 G0: Rapid move4.2.2 G1: Controlled move4.2.3 G28: Move to Origin4.3 Unbuffered G commands4.3.1 G4: Dwell4.3.2 G20: Set Units to Inches4.3.3 G21: Set Units to Millimeters4.3.4 G90: Set to Absolute Positioning4.3.5 G91: Set to Relative Positioning4.3.6 G92: Set Position4.4 Unbuffered M and T commands4.4.1 M0: Stop4.4.2 M17: Enable/Power all stepper motors 4.4.3 M18: Disable all stepper motors4.4.4 M20: List SD card4.4.5 M21: Initialise SD card4.4.6 M22: Release SD card4.4.7 M23: Select SD file4.4.8 M24: Start/resume SD print4.4.9 M25: Pause SD print4.4.10 M26: Set SD position4.4.11 M27: Report SD print status4.4.12 M28: Begin write to SD card4.4.13 M29: Stop writing to SD card4.4.14 M40: Eject4.4.15 M41: Loop4.4.16 M42: Stop on material exhausted 4.4.17 M43: Stand by on material exhausted 4.4.18 M80: ATX Power On4.4.19 M81: ATX Power Off4.4.20 M84: Stop idle hold4.4.21 M92: Set axis_steps_per_unit4.4.22 M101 Turn extruder 1 on Forward4.4.23 M102 Turn extruder 1 on Reverse4.4.24 M103 Turn all extruders off4.4.25 M104: Set Extruder Temperature (Fast)4.4.26 M105: Get Extruder Temperature4.4.27 M106: Fan On4.4.28 M107: Fan Off4.4.29 M108: Set Extruder Speed4.4.30 M109: Set Extruder Temperature4.4.31 M110: Set Current Line Number4.4.32 M111: Set Debug Level4.4.33 M112: Emergency Stop4.4.34 M113: Set Extruder PWM4.4.35 M114: Get Current Position4.4.36 M115: Get Firmware Version and Capabilities4.4.37 M116: Wait4.4.38 M117: Get Zero Position4.4.39 M118: Negotiate Features4.4.40 M119: Get Endstop Status4.4.41 M126: Open Valve4.4.42 M127: Close Valve4.4.43 M128: Extruder Pressure PWM4.4.44 M129: Extruder pressure off4.4.45 M140: Bed Temperature (Fast)4.4.46 M141: Chamber Temperature (Fast)4.4.47 M142: Holding Pressure4.4.48 M143: Maximum hot-end temperature4.4.49 M160: Number of mixed materials4.4.50 M203: Record Z adjustment4.4.51 M226: Gcode Initiated Pause4.4.52 M227: Enable Automatic Reverse and Prime4.4.53 M228: Disable Automatic Reverse and Prime4.4.54 M229: Enable Automatic Reverse and Prime4.4.55 M230: Disable / Enable Wait for Temperature Change 4.4.56 M240: Start conveyor belt motor4.4.57 M241: Stop conveyor belt motor4.4.58 M245: Start cooler4.4.59 M246: Stop cooler4.4.60 M300: Play beep sound4.4.61 T: Select Tool5 Proposed EEPROM configuration codes6 Replies from the RepRap machine to the host computer7 Proposal for sending multiple lines of G-code7.1 Problem to solveIntroductionThis page describes the G Codes that the RepRap firmware uses and how they work.The list of what can be done is extensible. But check this page first, and add your extension here first before you implement it.A typical piece of GCode as sent to a RepRap machine might look like this:N3 T0*57N4 G92 E0*67N5 G28*22N6 G1 F1500.0*82N7 G1 X2.0 Y2.0 F3000.0*85N8 G1 X3.0 Y3.0*33The meaning of all those symbols and numbers (and more) is explained below.TO find out which specific gcode/s are implemented in any given firmware, please see the Firmware_features page.(For the technically minded, the end of line is marked by both a <nl> and a <cr>. If you want to manually enter GCodes in your reprap using the Arduino Serial interface, make sure to select "Both NL & CR" on the bottom of the screen.)This isn't accurate, firmware accepts single <nl> as well as single <cr>, or combinations thereof. Hosts should accepts all four combinations as well. --Traumflug 09:34, 20 April 2011 (UTC)RepRap G Code FieldsThis section explains the letter-preceded fields. The numbers in the fields are represented by nnn. Numbers can be integers, or can contain a decimal point, depending on context. For example an X coordinate can be integer (X175) or fractional (X17.62), whereas trying to select extruder number 2.76 would make no sense.Letter MeaningGnnn Standard GCode command, such as move to a pointMnnn RepRap-defined command, such as turn on a cooling fanTnnn Select tool nnn. In RepRap, tools are extrudersSnnn Command parameter, such as the voltage to send to a motorPnnn Command parameter, such as a time in millisecondsXnnn An X coordinate, usually to move toYnnn A Y coordinate, usually to move toZnnn A Z coordinate, usually to move toInnn Parameter - not currently usedJnnn Parameter - not currently usedFnnn Feedrate in mm per minute. (Speed of print head movement)Rnnn Parameter - not currently usedQnnn Parameter - not currently usedEnnn Length of extrudate in mm. This is exactly like X, Y and Z, but for the length of filament to extrude. It is common for newer stepper based systems to interpret ... Better: Skeinforge 40 and up interprets this as the absolute length of input filament to consume, rather than the length of the extruded output.Nnnn Line number. Used to request repeat transmission in the case of communications errors. *nnn Checksum. Used to check for communications errors.CommentsG Code comments:N3 T0*57 ;This is a commentN4 G92 E0*67; So is thisN5 G28*22Will be ignored by RepRap, as will blank lines. But it's better to strip these out in the host computer before the lines are sent. This saves bandwidth.Individual commandsCheckingN and *Example: N123 [...G Code in here...] *71These are the line number and the checksum. The RepRap firmware checks the checksum against a locally-computed value and, if they differ, requests a repeat transmission of the line of the given number.You can leave both of these out - RepRap will still work, but it won't do checking. You have to have both or neither though.The checksum "cs" for a GCode string "cmd" (including its line number) is computed by exor-ing the bytes in the string up to and not including the * character as follows:int cs = 0;for(i = 0; cmd[i] != '*' && cmd[i] != NULL; i++)cs = cs ^ cmd[i];cs &= 0xff; // Defensive programming...and the value is appended as a decimal integer to the command after the * character.The RepRap firmware expects line numbers to increase by 1 each line, and if that doesn't happen it is flagged as an error. But you can reset the count using M110 (see below).Buffered G CommandsThe RepRap firmware stores these commands in a ring buffer internally for execution. This means that there is no (appreciable) delay while a command is acknowledged and the next transmitted. In turn, this means that sequences of line segments can be plotted without a dwell between one and the next. As soon as one of these buffered commands is received it is acknowledged and stored locally. If the local buffer is full, then the acknowledgment is delayed until space for storage in the buffer is available. This is how flow control is achieved.G0: Rapid moveExample: G0 X12In this case move rapidly to X = 12 mm. In fact, the RepRap firmware uses exactly the same code for rapid as it uses for controlled moves (see G1 below), as - for the RepRap machine - this is just as efficient as not doing so. (The distinction comes from some old machine tools that used to move faster if the axes were not driven in a straight line. For them G0 allowed any movement in space to get to the destination as fast as possible.)G1: Controlled moveExample: G1 X90.6 Y13.8 E22.4Go in a straight line from the current (X, Y) point to the point (90.6, 13.8), extruding material as the move happens from the current extruded length to a length of 22.4 mm.RepRap does subtle things with feedrates. Thus:G1 F1500G1 X90.6 Y13.8 E22.4Will set a feedrate of 1500 mm/minute, then do the move described above at that feedrate. ButG1 F1500G1 X90.6 Y13.8 E22.4 F3000Will set a feedrate of 1500 mm/minute, then do the move described above accelerating to a feedrate of 3000 mm/minute as it does so. The extrusion will accelerate along with the X, Y movement so everything stays synchronized.RepRap thus treats feedrate as simply another variable (like X, Y, Z, and E) to be linearly interpolated. This gives complete control over accelerations and decelerations in a way that ensures that everything moves together and the right volume of material is extruded at all points.The first example shows how to get a constant-speed movement. The second how to accelerate or decelerate. ThusG1 F1500G1 X90.6 Y13.8 E22.4 F3000G1 X80 Y20 E36 F1500Will do the first movement accelerating as before, and the second decelerating from 3000 mm/minute back to 1500 mm/minute.To reverse the extruder by a given amount (for example to reduce its internal pressure while it does an in-air movement so that it doesn't dribble) simply use G1 to send an E value that is less than the currently extruded length.G28: Move to OriginExample: G28This causes the RepRap machine to move back to its X, Y and Z zero endstops, a process known as "homing". It does so accelerating, so as to get there fast. But when it arrives it backs off by 1 mm in each direction slowly, then moves back slowly to the stop. This ensures more accurate positioning.If you add coordinates, then just the axes with coordinates specified will be zeroed. ThusG28 X0 Y72.3will zero the X and Y axes, but not Z. The actual coordinate values are ignored.Unbuffered G commandsThe following commands are not buffered. When one is received it is stored, but it is not acknowledged to the host until the buffer is exhausted and then the command has been executed. Thus the host will pause at one of these commands until it has been done. Short pauses between these commands and any that might follow them do not affect the performance of the machine.G4: DwellExample: G4 P200In this case sit still doing nothing for 200 milliseconds. During delays the state of the machine (for example the temperatures of its extruders) will still be preserved and controlled.G20: Set Units to InchesExample: G20Units from now on are in inches.G21: Set Units to MillimetersExample: G21Units from now on are in millimeters. (This is the RepRap default.)G90: Set to Absolute PositioningExample: G90All coordinates from now on are absolute relative to the origin of the machine. (This is the RepRap default.)G91: Set to Relative PositioningExample: G91All coordinates from now on are relative to the last position.G92: Set PositionExample: G92 X10 E90Allows programming of absolute zero point, by reseting the current position to the values specified. This would set the machine's X coordinate to 10, and the extrude coordinate to 90. No physical motion will occur.Unbuffered M and T commandsM0: StopExample: M0The RepRap machine finishes any moves left in its buffer, then shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M112.M17: Enable/Power all stepper motorsExample: M17M18: Disable all stepper motorsExample: M18Disables stepper motors and allows axis to move 'freely.'M20: List SD cardExample: M20All files in the root folder of the SD card are listed to the serial port. This results in a line like:ok Files: {SQUARE.G,SQCOM.G,}The trailing comma is optional. Note that file names are returned in upper case, but - when sent to the M23 command (below) they must be in lower case. This seems to be a function of the SD software. Go figure...M21: Initialise SD cardExample: M21The SD card is initialised. If an SD card is loaded when the machine is switched on, this will happen by default. SD card must be initialised for the other SD functions to work.M22: Release SD cardExample: M22SD card is released and can be physically removed.M23: Select SD fileExample: M23 filename.gcoThe file specified as filename.gco (8.3 naming convention is supported) is selected ready for printing.M24: Start/resume SD printExample: M24The machine prints from the file selected with the M23 command.M25: Pause SD printExample: M25The machine pause printing at the current position within the file selected with the M23 command.M26: Set SD positionExample: M26Set SD position in bytes (M26 S12345).M27: Report SD print statusExample: M27Report SD print status.M28: Begin write to SD cardExample: M28 filename.gcoFile specified by filename.gco is created (or overwritten if it exists) on the SD card and all subsequent commands sent to the machine are written to that file.M29: Stop writing to SD cardExample: M29 filename.gcoFile opened by M28 command is closed, and all subsequent commands sent to the machine are executed as normal.M40: EjectIf your RepRap machine can eject the parts it has built off the bed, this command executes the eject cycle. This usually involves cooling the bed and then performing a sequence of movements that remove the printed parts from it. The X, Y and Z position of the machine at the end of this cycle are undefined (though they can be found out using the M114 command, q.v.).See also M240 and M241 below.M41: LoopExample: M41If the RepRap machine was building a file from its own memory such as a local SD card (as opposed to a file being transmitted to it from a host computer) this goes back to the beginning of the file and runs it again. So, for example, if your RepRap is capable of ejecting parts from its build bed then you can set it printing in a loop and it will run and run. Use with caution - the only things that will stop it are:1.When you press the reset button,2.When the build material runs out (if your RepRap is set up to detect this), and3.When there's an error (such as a heater failure).M42: Stop on material exhaustedExample: M42If your RepRap can detect when its material runs out, this decides the behaviour when that happens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off. You have to press reset to reactivate the machine. In other words, it parks itself and then executes an M0 command (q.v.).M43: Stand by on material exhaustedExample: M43If your RepRap can detect when its material runs out, this decides the behaviour when thathappens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off except the heated bed, the temperature of which is maintained. The machine will still respond to G and M code commands in this state.M80: ATX Power OnExample: M80Turns on the ATX power supply from standby mode to fully operational mode. No-op on electronics without standby mode.Note: some firmwares, like Teacup, handle power on/off automatically, so this is redundant there.M81: ATX Power OffExample: M81Turns off the ATX power supply. Counterpart to M80.M84: Stop idle holdExample: M84Stop the idle hold on all axis and extruder. In some cases the idle hold causes annoying noises, which can be stopped by disabling the hold. Be aware that by disabling idle hold during printing, you will get quality issues. This is recommended only in between or after printjobs.M92: Set axis_steps_per_unitExample: M92 X<newsteps> Sprinter and MarlinAllows programming of steps per unit of axis till the electronics are reset for the specified axis. Very useful for calibration.M101 Turn extruder 1 on ForwardDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM102 Turn extruder 1 on ReverseDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM103 Turn all extruders offDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM104: Set Extruder Temperature (Fast)Example: M104 S190Set the temperature of the current extruder to 190oC and return control to the host immediately (i.e. before that temperature has been reached by the extruder). See also M109.M105: Get Extruder TemperatureExample: M105Request the temperature of the current extruder and the build base in degrees Celsius. The temperatures are returned to the host computer. For example, the line sent to the host in response to this command looks likeok T:201 B:117M106: Fan OnExample: M106 S127Turn on the cooling fan at half speed. Optional parameter 'S' declares the PWM value (0-255)M107: Fan OffExample: M107Turn off the cooling fan (if any).M108: Set Extruder SpeedSets speed of extruder motor. (Deprecated in current firmware, see M113)M109: Set Extruder TemperatureExample: M109 S190Set the temperature of the current extruder to 190oC and wait for it to reach that value before sending an acknowledgment to the host. In fact the RepRap firmware waits a while after the temperature has been reached for the extruder to stabilise - typically about 40 seconds. This can be changed by a parameter in the firmware configuration file when the firmware is compiled. See also M104 and M116.M110: Set Current Line NumberExample: N123 M110Set the current line number to 123. Thus the expected next line after this command will be 124.M111: Set Debug LevelExample: M111 S6Set the level of debugging information transmitted back to the host to level 6. The level is the OR of three bits:#define DEBUG_ECHO (1<<0)#define DEBUG_INFO (1<<1)#define DEBUG_ERRORS (1<<2)Thus 6 means send information and errors, but don't echo commands. (This is the RepRap default.)M112: Emergency StopExample: M112Any moves in progress are immediately terminated, then RepRap shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M0.M113: Set Extruder PWMExample: M113Set the PWM for the currently-selected extruder. On its own this command sets RepRap to use the on-board potentiometer on the extruder controller board to set the PWM for the currently-selected extruder's stepper power. With an S field:M113 S0.7it causes the PWM to be set to the S value (70% in this instance). M113 S0 turns the extruder off, until an M113 command other than M113 S0 is sent.M114: Get Current PositionExample: M114This causes the RepRap machine to report its current X, Y, Z and E coordinates to the host.For example, the machine returns a string such as:ok C: X:0.00 Y:0.00 Z:0.00 E:0.00M115: Get Firmware Version and CapabilitiesExample: M115Request the Firmware Version and Capabilities of the current microcontroller The details are returned to the host computer as key:value pairs separated by spaces and terminated with alinefeed.sample data from firmware:ok PROTOCOL_VERSION:0.1 FIRMWARE_NAME:FiveD FIRMWARE_URL:http%3A// MACHINE_TYPE:Mendel EXTRUDER_COUNT:1This M115 code is inconsistently implemented, and should not be relied upon to exist, or output correctly in all cases. An initial implementation was committed to svn for the FiveD Reprap firmware on 11 Oct 2010. Work to more formally define protocol versions is currently (October 2010) being discussed. See M115_Keywords for one draft set of keywords and their meanings.M116: WaitExample: M116Wait for all temperatures and other slowly-changing variables to arrive at their set values. See also M109.M117: Get Zero PositionExample: M117This causes the RepRap machine to report the X, Y, Z and E coordinates in steps not mm to the host that it found when it last hit the zero stops for those axes. That is to say, when you zero X, the x coordinate of the machine when it hits the X endstop is recorded. This value should be 0, of course. But if the machine has drifted (for example by dropping steps) then it won't be. This command allows you to measure and to diagnose such problems. (E is included for completeness. It doesn't normally have an endstop.)M118: Negotiate FeaturesExample: M118 P42This M-code is for future proofing. NO firmware or hostware supports this at the moment. It is used in conjunction with M115's FEATURES keyword.See Protocol_Feature_Negotiation for more info.M119: Get Endstop StatusExample: M119Returns the current state of the configured X,Y,Z endstops. Should take into account any 'inverted endstop' settings, so one can confirm that the machine is interpreting the endstops correctly.M126: Open ValveExample: M126 P500Open the extruder's valve (if it has one) and wait 500 milliseconds for it to do so.M127: Close ValveExample: M127 P400Close the extruder's valve (if it has one) and wait 400 milliseconds for it to do so.M128: Extruder Pressure PWMExample: M128 S255PWM value to control internal extruder pressure. S255 is full pressure.M129: Extruder pressure offExample: M129 P100In addition to setting Extruder pressure to 0, you can turn the pressure off entirely. P400 will wait 100ms to do so.M140: Bed Temperature (Fast)Example: M140 S55Set the temperature of the build bed to 55oC and return control to the host immediately (i.e. before that temperature has been reached by the bed).M141: Chamber Temperature (Fast)Example: M141 S30Set the temperature of the chamber to 30oC and return control to the host immediately (i.e. before that temperature has been reached by the chamber).M142: Holding PressureExample: M142 S1Set the holding pressure of the bed to 1 bar.The holding pressure is in bar. For hardware which only has on/off holding, when the holding pressure is zero, turn off holding, when the holding pressure is greater than zero, turn on holding.M143: Maximum hot-end temperatureExample: M143 S275Set the maximum temperature of the hot-end to 275CWhen temperature of the hot-end exceeds this value, take countermeasures, for instance anemergency stop. This is to prevent hot-end damage.M160: Number of mixed materialsExample: M160 S4Set the number of materials, N, that the current extruder can handle to the number specified. The default is 1.When N >= 2, then the E field that controls extrusion requires N+1 values separated by spaces after it like this:M160 S4G1 X90.6 Y13.8 E22.4 0.1 0.1 0.1 0.7G1 X70.6 E42.4 0.0 0.0 0.0 1.0G1 E42.4 1.0 0.0 0.0 0.0The second line moves straight to the point (90.6, 13.8) extruding 22.4mm of filament. The mix ratio at the end of the move is 0.1:0.1:0.1:0.7.The third line moves back 20mm in X extruding 20mm of filament. The mix varies linearly from 0.1:0.1:0.1:0.7 to 0:0:0:1 as the move is made.The fourth line has no physical effect, but sets the mix proportions for the start of the next move to 1:0:0:0.M203: Record Z adjustmentExample: M203 Z-0.75This records a Z offset in non-volatile memory in RepRap's microcontroller where it remains active until next set, even when the power is turned off and on again. If the first layer is too close to the bed, you need to effectively move the bed down, so the Z value will be negative. If the nozzle is too far from the bed during the first layer, the Z value should be positive to raise the bed. The maximum adjustment is +/-1.27mm.M226: Gcode Initiated PauseExample: M226Initiates a pause in the same way as if the pause button is pressed.M227: Enable Automatic Reverse and PrimeExample: M227 P1600 S1600P and S are steps.M228: Disable Automatic Reverse and PrimeExample: M228M229: Enable Automatic Reverse and PrimeExample: M229 P1.0 S1.0P and S are extruder screw rotations.M230: Disable / Enable Wait for Temperature ChangeExample: M230 S1S1 Disable wait for temperature change S0 Enable wait for temperature changeM240: Start conveyor belt motorExample: M240The conveyor belt allows to start mass production of a part with a reprapM241: Stop conveyor belt motorExample: M241M245: Start coolerExample: M245used to cool parts/heated-bed down after printing for easy remove of the parts after printM246: Stop coolerExample: M246M300: Play beep soundUsage: M300 S<frequency Hz> P<duration ms>Example: M300 S300 P1000Play beep sound, use to notify important events like the end of printing. See working example on R2C2 electronics.T: Select ToolExample: T1Select extruder number 1 to build with. Extruder numbering starts at 0.Proposed EEPROM configuration codesBRIEFLY: each RepRap has a number of physical parameters that should be persistent, but easily configurable, such as extrusion steps/mm, various max values, etc. Those parameters are currently hardcoded in the firmware, so that a user has to modify, recompile and re-flash the firmware for any adjustments. These configs can be stored in MCU's EEPROM and modified via some M-codes. Please see the detailed proposal at M-codes for EEPROM config. (This is proposed by --AlexRa on 11-March-2011. There is currently no working implementation of the proposed commands).Replies from the RepRap machine to the host computerAll communication is in printable ASCII characters. Messages sent back to the host computer are terminated by a newline and look like this:xx [line number to resend] [T:93.2 B:22.9] [C: X:9.2 Y:125.4 Z:3.7 E:1902.5] [Some debugging or other information may be here]xx can be one of:okrs!!ok means that no error has been detected.rs means resend, and is followed by the line number to resend.!! means that a hardware fault has been detected. The RepRap machine will shut down immediately after it has sent this message.The T: and B: values are the temperature of the currently-selected extruder and the bed respectively, and are only sent in response to M105. If such temperatures don't exist (for example for an extruder that works at room temperature and doesn't have a sensor) then a value below absolute zero (-273oC) is returned.C: means that coordinates follow. Those are the X: Y: etc values. These are only sent in response to M114 and M117.The RepRap machine may also send lines that look like this:// This is some debugging or other information on a line on its own. It may be sent at any time.Such lines will always be preceded by //.The most common response is simply:okWhen the machine boots up it sends the stringstartonce to the host before sending anything else. This should not be replaced or augmented by version numbers and the like. M115 (see above) requests those.All this means that every line sent by RepRap to the host computer except the start line has a two-character prefix (one of ok, rs, !! or //). The machine should never send a line without such a prefix.。
Gcode G代码详解备课讲稿
G c o d e G代码详解reprap wiki上面的Gcode说明G-codeFrom RepRapWiki(Redirected from Gcode)Jump to: navigation, searchContents [hide]1 Introduction2 RepRap G Code Fields3 Comments4 Individual commands4.1 Checking4.1.1 N and *4.2 Buffered G Commands4.2.1 G0: Rapid move4.2.2 G1: Controlled move4.2.3 G28: Move to Origin4.3 Unbuffered G commands4.3.1 G4: Dwell4.3.2 G20: Set Units to Inches4.3.3 G21: Set Units to Millimeters4.3.4 G90: Set to Absolute Positioning4.3.5 G91: Set to Relative Positioning4.3.6 G92: Set Position4.4 Unbuffered M and T commands4.4.1 M0: Stop4.4.2 M17: Enable/Power all stepper motors 4.4.3 M18: Disable all stepper motors4.4.4 M20: List SD card4.4.5 M21: Initialise SD card4.4.6 M22: Release SD card4.4.7 M23: Select SD file4.4.8 M24: Start/resume SD print4.4.9 M25: Pause SD print4.4.10 M26: Set SD position4.4.11 M27: Report SD print status4.4.12 M28: Begin write to SD card4.4.13 M29: Stop writing to SD card4.4.14 M40: Eject4.4.15 M41: Loop4.4.16 M42: Stop on material exhausted 4.4.17 M43: Stand by on material exhausted 4.4.18 M80: ATX Power On4.4.19 M81: ATX Power Off4.4.20 M84: Stop idle hold4.4.21 M92: Set axis_steps_per_unit4.4.22 M101 Turn extruder 1 on Forward4.4.23 M102 Turn extruder 1 on Reverse4.4.24 M103 Turn all extruders off4.4.25 M104: Set Extruder Temperature (Fast)4.4.26 M105: Get Extruder Temperature4.4.27 M106: Fan On4.4.28 M107: Fan Off4.4.29 M108: Set Extruder Speed4.4.30 M109: Set Extruder Temperature4.4.31 M110: Set Current Line Number4.4.32 M111: Set Debug Level4.4.33 M112: Emergency Stop4.4.34 M113: Set Extruder PWM4.4.35 M114: Get Current Position4.4.36 M115: Get Firmware Version and Capabilities4.4.37 M116: Wait4.4.38 M117: Get Zero Position4.4.39 M118: Negotiate Features4.4.40 M119: Get Endstop Status4.4.41 M126: Open Valve4.4.42 M127: Close Valve4.4.43 M128: Extruder Pressure PWM4.4.44 M129: Extruder pressure off4.4.45 M140: Bed Temperature (Fast)4.4.46 M141: Chamber Temperature (Fast)4.4.47 M142: Holding Pressure4.4.48 M143: Maximum hot-end temperature4.4.49 M160: Number of mixed materials4.4.50 M203: Record Z adjustment4.4.51 M226: Gcode Initiated Pause4.4.52 M227: Enable Automatic Reverse and Prime4.4.53 M228: Disable Automatic Reverse and Prime4.4.54 M229: Enable Automatic Reverse and Prime4.4.55 M230: Disable / Enable Wait for Temperature Change 4.4.56 M240: Start conveyor belt motor4.4.57 M241: Stop conveyor belt motor4.4.58 M245: Start cooler4.4.59 M246: Stop cooler4.4.60 M300: Play beep sound4.4.61 T: Select Tool5 Proposed EEPROM configuration codes6 Replies from the RepRap machine to the host computer7 Proposal for sending multiple lines of G-code7.1 Problem to solveIntroductionThis page describes the G Codes that the RepRap firmware uses and how they work. The list of what can be done is extensible. But check this page first, and add your extension here first before you implement it.A typical piece of GCode as sent to a RepRap machine might look like this:N3 T0*57N4 G92 E0*67N5 G28*22N6 G1 F1500.0*82N7 G1 X2.0 Y2.0 F3000.0*85N8 G1 X3.0 Y3.0*33The meaning of all those symbols and numbers (and more) is explained below.TO find out which specific gcode/s are implemented in any given firmware, please see the Firmware_features page.(For the technically minded, the end of line is marked by both a <nl> and a <cr>. If you want to manually enter GCodes in your reprap using the Arduino Serial interface, make sure to select "Both NL & CR" on the bottom of the screen.)This isn't accurate, firmware accepts single <nl> as well as single <cr>, or combinations thereof. Hosts should accepts all four combinations as well. --Traumflug 09:34, 20 April 2011 (UTC)RepRap G Code FieldsThis section explains the letter-preceded fields. The numbers in the fields are represented by nnn. Numbers can be integers, or can contain a decimal point, depending on context. For example an X coordinate can be integer (X175) or fractional (X17.62), whereas trying to select extruder number 2.76 would make no sense.Letter MeaningGnnn Standard GCode command, such as move to a pointMnnn RepRap-defined command, such as turn on a cooling fanTnnn Select tool nnn. In RepRap, tools are extrudersSnnn Command parameter, such as the voltage to send to a motorPnnn Command parameter, such as a time in millisecondsXnnn An X coordinate, usually to move toYnnn A Y coordinate, usually to move toZnnn A Z coordinate, usually to move toInnn Parameter - not currently usedJnnn Parameter - not currently usedFnnn Feedrate in mm per minute. (Speed of print head movement)Rnnn Parameter - not currently usedQnnn Parameter - not currently usedEnnn Length of extrudate in mm. This is exactly like X, Y and Z, but for the length of filament to extrude. It is common for newer stepper based systems to interpret ... Better: Skeinforge 40 and up interprets this as the absolute length of input filament to consume, rather than the length of the extruded output.Nnnn Line number. Used to request repeat transmission in the case of communications errors.*nnn Checksum. Used to check for communications errors.CommentsG Code comments:N3 T0*57 ;This is a commentN4 G92 E0*67; So is thisN5 G28*22Will be ignored by RepRap, as will blank lines. But it's better to strip these out in the host computer before the lines are sent. This saves bandwidth.Individual commandsCheckingN and *Example: N123 [...G Code in here...] *71These are the line number and the checksum. The RepRap firmware checks the checksum against a locally-computed value and, if they differ, requests a repeat transmission of the line of the given number.You can leave both of these out - RepRap will still work, but it won't do checking. You have to have both or neither though.The checksum "cs" for a GCode string "cmd" (including its line number) is computed by exor-ing the bytes in the string up to and not including the * character as follows: int cs = 0;for(i = 0; cmd[i] != '*' && cmd[i] != NULL; i++)cs = cs ^ cmd[i];cs &= 0xff; // Defensive programming...and the value is appended as a decimal integer to the command after the * character.The RepRap firmware expects line numbers to increase by 1 each line, and if that doesn't happen it is flagged as an error. But you can reset the count using M110 (see below).Buffered G CommandsThe RepRap firmware stores these commands in a ring buffer internally for execution. This means that there is no (appreciable) delay while a command is acknowledgedand the next transmitted. In turn, this means that sequences of line segments can be plotted without a dwell between one and the next. As soon as one of these buffered commands is received it is acknowledged and stored locally. If the local buffer is full, then the acknowledgment is delayed until space for storage in the buffer is available. This is how flow control is achieved.G0: Rapid moveExample: G0 X12In this case move rapidly to X = 12 mm. In fact, the RepRap firmware uses exactlythe same code for rapid as it uses for controlled moves (see G1 below), as - for the RepRap machine - this is just as efficient as not doing so. (The distinction comes from some old machine tools that used to move faster if the axes were not driven in a straight line. For them G0 allowed any movement in space to get to the destination as fast as possible.)G1: Controlled moveExample: G1 X90.6 Y13.8 E22.4Go in a straight line from the current (X, Y) point to the point (90.6, 13.8), extruding material as the move happens from the current extruded length to a length of 22.4 mm. RepRap does subtle things with feedrates. Thus:G1 F1500G1 X90.6 Y13.8 E22.4Will set a feedrate of 1500 mm/minute, then do the move described above at that feedrate. ButG1 F1500G1 X90.6 Y13.8 E22.4 F3000Will set a feedrate of 1500 mm/minute, then do the move described above accelerating to a feedrate of 3000 mm/minute as it does so. The extrusion will accelerate along with the X, Y movement so everything stays synchronized.RepRap thus treats feedrate as simply another variable (like X, Y, Z, and E) to be linearly interpolated. This gives complete control over accelerations and decelerations in a way that ensures that everything moves together and the right volume of material is extruded at all points.The first example shows how to get a constant-speed movement. The second how to accelerate or decelerate. ThusG1 F1500G1 X90.6 Y13.8 E22.4 F3000G1 X80 Y20 E36 F1500Will do the first movement accelerating as before, and the second decelerating from 3000 mm/minute back to 1500 mm/minute.To reverse the extruder by a given amount (for example to reduce its internal pressure while it does an in-air movement so that it doesn't dribble) simply use G1 to send an E value that is less than the currently extruded length.G28: Move to OriginExample: G28This causes the RepRap machine to move back to its X, Y and Z zero endstops, a process known as "homing". It does so accelerating, so as to get there fast. But when it arrives it backs off by 1 mm in each direction slowly, then moves back slowly to the stop. This ensures more accurate positioning.If you add coordinates, then just the axes with coordinates specified will be zeroed. ThusG28 X0 Y72.3will zero the X and Y axes, but not Z. The actual coordinate values are ignored. Unbuffered G commandsThe following commands are not buffered. When one is received it is stored, but it is not acknowledged to the host until the buffer is exhausted and then the command has been executed. Thus the host will pause at one of these commands until it has been done. Short pauses between these commands and any that might follow them do not affect the performance of the machine.G4: DwellExample: G4 P200In this case sit still doing nothing for 200 milliseconds. During delays the state of the machine (for example the temperatures of its extruders) will still be preserved and controlled.G20: Set Units to InchesExample: G20Units from now on are in inches.G21: Set Units to MillimetersExample: G21Units from now on are in millimeters. (This is the RepRap default.)G90: Set to Absolute PositioningExample: G90All coordinates from now on are absolute relative to the origin of the machine. (This is the RepRap default.)G91: Set to Relative PositioningExample: G91All coordinates from now on are relative to the last position.G92: Set PositionExample: G92 X10 E90Allows programming of absolute zero point, by reseting the current position to the values specified. This would set the machine's X coordinate to 10, and the extrude coordinate to 90. No physical motion will occur.Unbuffered M and T commandsM0: StopExample: M0The RepRap machine finishes any moves left in its buffer, then shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M112.M17: Enable/Power all stepper motorsExample: M17M18: Disable all stepper motorsExample: M18Disables stepper motors and allows axis to move 'freely.'M20: List SD cardExample: M20All files in the root folder of the SD card are listed to the serial port. This results in a line like:ok Files: {SQUARE.G,SQCOM.G,}The trailing comma is optional. Note that file names are returned in upper case, but - when sent to the M23 command (below) they must be in lower case. This seems to be a function of the SD software. Go figure...M21: Initialise SD cardExample: M21The SD card is initialised. If an SD card is loaded when the machine is switched on, this will happen by default. SD card must be initialised for the other SD functions to work.M22: Release SD cardExample: M22SD card is released and can be physically removed.M23: Select SD fileExample: M23 filename.gcoThe file specified as filename.gco (8.3 naming convention is supported) is selected ready for printing.M24: Start/resume SD printExample: M24The machine prints from the file selected with the M23 command.M25: Pause SD printExample: M25The machine pause printing at the current position within the file selected with theM23 command.M26: Set SD positionExample: M26Set SD position in bytes (M26 S12345).M27: Report SD print statusExample: M27Report SD print status.M28: Begin write to SD cardExample: M28 filename.gcoFile specified by filename.gco is created (or overwritten if it exists) on the SD card and all subsequent commands sent to the machine are written to that file.M29: Stop writing to SD cardExample: M29 filename.gcoFile opened by M28 command is closed, and all subsequent commands sent to the machine are executed as normal.M40: EjectIf your RepRap machine can eject the parts it has built off the bed, this command executes the eject cycle. This usually involves cooling the bed and then performing a sequence of movements that remove the printed parts from it. The X, Y and Z position of the machine at the end of this cycle are undefined (though they can be found out using the M114 command, q.v.).See also M240 and M241 below.M41: LoopExample: M41If the RepRap machine was building a file from its own memory such as a local SD card (as opposed to a file being transmitted to it from a host computer) this goes back to the beginning of the file and runs it again. So, for example, if your RepRap is capable of ejecting parts from its build bed then you can set it printing in a loop and it will run and run. Use with caution - the only things that will stop it are:1.When you press the reset button,2.When the build material runs out (if your RepRap is set up to detect this), and3.When there's an error (such as a heater failure).M42: Stop on material exhaustedExample: M42If your RepRap can detect when its material runs out, this decides the behaviour when that happens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off. You have to press reset to reactivate the machine. In other words, it parks itself and then executes an M0 command (q.v.).M43: Stand by on material exhaustedExample: M43If your RepRap can detect when its material runs out, this decides the behaviour when that happens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off except the heated bed, the temperature of which is maintained. The machine will still respond to G and M code commands in this state.M80: ATX Power OnExample: M80Turns on the ATX power supply from standby mode to fully operational mode. No-op on electronics without standby mode.Note: some firmwares, like Teacup, handle power on/off automatically, so this is redundant there.M81: ATX Power OffExample: M81Turns off the ATX power supply. Counterpart to M80.M84: Stop idle holdExample: M84Stop the idle hold on all axis and extruder. In some cases the idle hold causes annoying noises, which can be stopped by disabling the hold. Be aware that by disabling idle hold during printing, you will get quality issues. This is recommended only in between or after printjobs.M92: Set axis_steps_per_unitExample: M92 X<newsteps> Sprinter and MarlinAllows programming of steps per unit of axis till the electronics are reset for the specified axis. Very useful for calibration.M101 Turn extruder 1 on ForwardDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM102 Turn extruder 1 on ReverseDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM103 Turn all extruders offDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM104: Set Extruder Temperature (Fast)Example: M104 S190Set the temperature of the current extruder to 190oC and return control to the host immediately (i.e. before that temperature has been reached by the extruder). See also M109.M105: Get Extruder TemperatureExample: M105Request the temperature of the current extruder and the build base in degrees Celsius. The temperatures are returned to the host computer. For example, the line sent to the host in response to this command looks likeok T:201 B:117M106: Fan OnExample: M106 S127Turn on the cooling fan at half speed. Optional parameter 'S' declares the PWM value (0-255)M107: Fan OffExample: M107Turn off the cooling fan (if any).M108: Set Extruder SpeedSets speed of extruder motor. (Deprecated in current firmware, see M113)M109: Set Extruder TemperatureExample: M109 S190Set the temperature of the current extruder to 190oC and wait for it to reach that value before sending an acknowledgment to the host. In fact the RepRap firmware waits a while after the temperature has been reached for the extruder to stabilise - typically about 40 seconds. This can be changed by a parameter in the firmware configuration file when the firmware is compiled. See also M104 and M116.M110: Set Current Line NumberExample: N123 M110Set the current line number to 123. Thus the expected next line after this command will be 124.M111: Set Debug LevelExample: M111 S6Set the level of debugging information transmitted back to the host to level 6. The level is the OR of three bits:#define DEBUG_ECHO (1<<0)#define DEBUG_INFO (1<<1)#define DEBUG_ERRORS (1<<2)Thus 6 means send information and errors, but don't echo commands. (This is the RepRap default.)M112: Emergency StopExample: M112Any moves in progress are immediately terminated, then RepRap shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M0.M113: Set Extruder PWMExample: M113Set the PWM for the currently-selected extruder. On its own this command sets RepRap to use the on-board potentiometer on the extruder controller board to set the PWM for the currently-selected extruder's stepper power. With an S field:M113 S0.7it causes the PWM to be set to the S value (70% in this instance). M113 S0 turns the extruder off, until an M113 command other than M113 S0 is sent.M114: Get Current PositionExample: M114This causes the RepRap machine to report its current X, Y, Z and E coordinates to the host.For example, the machine returns a string such as:ok C: X:0.00 Y:0.00 Z:0.00 E:0.00M115: Get Firmware Version and CapabilitiesExample: M115Request the Firmware Version and Capabilities of the current microcontroller The details are returned to the host computer as key:value pairs separated by spaces and terminated with a linefeed.sample data from firmware:ok PROTOCOL_VERSION:0.1 FIRMWARE_NAME:FiveDFIRMWARE_URL:http%3A// MACHINE_TYPE:MendelEXTRUDER_COUNT:1This M115 code is inconsistently implemented, and should not be relied upon to exist, or output correctly in all cases. An initial implementation was committed to svn for the FiveD Reprap firmware on 11 Oct 2010. Work to more formally define protocol versions is currently (October 2010) being discussed. See M115_Keywords for one draft set of keywords and their meanings.M116: WaitExample: M116Wait for all temperatures and other slowly-changing variables to arrive at their set values. See also M109.M117: Get Zero PositionExample: M117This causes the RepRap machine to report the X, Y, Z and E coordinates in steps not mm to the host that it found when it last hit the zero stops for those axes. That is to say, when you zero X, the x coordinate of the machine when it hits the X endstop is recorded. This value should be 0, of course. But if the machine has drifted (for example by dropping steps) then it won't be. This command allows you to measure and to diagnose such problems. (E is included for completeness. It doesn't normally have an endstop.)M118: Negotiate FeaturesExample: M118 P42This M-code is for future proofing. NO firmware or hostware supports this at the moment. It is used in conjunction with M115's FEATURES keyword.See Protocol_Feature_Negotiation for more info.M119: Get Endstop StatusExample: M119Returns the current state of the configured X,Y,Z endstops. Should take into account any 'inverted endstop' settings, so one can confirm that the machine is interpreting the endstops correctly.M126: Open ValveExample: M126 P500Open the extruder's valve (if it has one) and wait 500 milliseconds for it to do so.M127: Close ValveExample: M127 P400Close the extruder's valve (if it has one) and wait 400 milliseconds for it to do so.M128: Extruder Pressure PWMExample: M128 S255PWM value to control internal extruder pressure. S255 is full pressure.M129: Extruder pressure offExample: M129 P100In addition to setting Extruder pressure to 0, you can turn the pressure off entirely.P400 will wait 100ms to do so.M140: Bed Temperature (Fast)Example: M140 S55Set the temperature of the build bed to 55oC and return control to the host immediately (i.e. before that temperature has been reached by the bed).M141: Chamber Temperature (Fast)Example: M141 S30Set the temperature of the chamber to 30oC and return control to the host immediately (i.e. before that temperature has been reached by the chamber).M142: Holding PressureExample: M142 S1Set the holding pressure of the bed to 1 bar.The holding pressure is in bar. For hardware which only has on/off holding, when the holding pressure is zero, turn off holding, when the holding pressure is greater than zero, turn on holding.M143: Maximum hot-end temperatureExample: M143 S275Set the maximum temperature of the hot-end to 275CWhen temperature of the hot-end exceeds this value, take countermeasures, for instance an emergency stop. This is to prevent hot-end damage.M160: Number of mixed materialsExample: M160 S4Set the number of materials, N, that the current extruder can handle to the number specified. The default is 1.When N >= 2, then the E field that controls extrusion requires N+1 values separated by spaces after it like this:M160 S4G1 X90.6 Y13.8 E22.4 0.1 0.1 0.1 0.7G1 X70.6 E42.4 0.0 0.0 0.0 1.0G1 E42.4 1.0 0.0 0.0 0.0The second line moves straight to the point (90.6, 13.8) extruding 22.4mm of filament. The mix ratio at the end of the move is 0.1:0.1:0.1:0.7.The third line moves back 20mm in X extruding 20mm of filament. The mix varies linearly from 0.1:0.1:0.1:0.7 to 0:0:0:1 as the move is made.The fourth line has no physical effect, but sets the mix proportions for the start of the next move to 1:0:0:0.M203: Record Z adjustmentExample: M203 Z-0.75This records a Z offset in non-volatile memory in RepRap's microcontroller where it remains active until next set, even when the power is turned off and on again. If the first layer is too close to the bed, you need to effectively move the bed down, so the Z value will be negative. If the nozzle is too far from the bed during the first layer, the Z value should be positive to raise the bed. The maximum adjustment is +/-1.27mm.M226: Gcode Initiated PauseExample: M226Initiates a pause in the same way as if the pause button is pressed.M227: Enable Automatic Reverse and PrimeExample: M227 P1600 S1600P and S are steps.M228: Disable Automatic Reverse and PrimeExample: M228M229: Enable Automatic Reverse and PrimeExample: M229 P1.0 S1.0P and S are extruder screw rotations.M230: Disable / Enable Wait for Temperature ChangeExample: M230 S1S1 Disable wait for temperature change S0 Enable wait for temperature changeM240: Start conveyor belt motorExample: M240The conveyor belt allows to start mass production of a part with a reprapM241: Stop conveyor belt motorExample: M241M245: Start coolerExample: M245used to cool parts/heated-bed down after printing for easy remove of the parts after printM246: Stop coolerExample: M246M300: Play beep soundUsage: M300 S<frequency Hz> P<duration ms>Example: M300 S300 P1000Play beep sound, use to notify important events like the end of printing. See working example on R2C2 electronics.T: Select ToolExample: T1Select extruder number 1 to build with. Extruder numbering starts at 0.Proposed EEPROM configuration codesBRIEFLY: each RepRap has a number of physical parameters that should be persistent, but easily configurable, such as extrusion steps/mm, various max values, etc. Those parameters are currently hardcoded in the firmware, so that a user has to modify, recompile and re-flash the firmware for any adjustments. These configs can be stored in MCU's EEPROM and modified via some M-codes. Please see the detailed proposal at M-codes for EEPROM config. (This is proposed by --AlexRa on 11-March-2011. There is currently no working implementation of the proposed commands).Replies from the RepRap machine to the host computerAll communication is in printable ASCII characters. Messages sent back to the host computer are terminated by a newline and look like this:xx [line number to resend] [T:93.2 B:22.9] [C: X:9.2 Y:125.4 Z:3.7 E:1902.5] [Some debugging or other information may be here]xx can be one of:okrs!!ok means that no error has been detected.rs means resend, and is followed by the line number to resend.!! means that a hardware fault has been detected. The RepRap machine will shut down immediately after it has sent this message.The T: and B: values are the temperature of the currently-selected extruder and the bed respectively, and are only sent in response to M105. If such temperatures don't exist (for example for an extruder that works at room temperature and doesn't have a sensor) then a value below absolute zero (-273oC) is returned.C: means that coordinates follow. Those are the X: Y: etc values. These are only sent in response to M114 and M117.The RepRap machine may also send lines that look like this:// This is some debugging or other information on a line on its own. It may be sent at any time.Such lines will always be preceded by //.The most common response is simply:okWhen the machine boots up it sends the stringstartonce to the host before sending anything else. This should not be replaced or augmented by version numbers and the like. M115 (see above) requests those.All this means that every line sent by RepRap to the host computer except the start line has a two-character prefix (one of ok, rs, !! or //). The machine should never send a line without such a prefix.。
g代码原理
g代码原理
G代码(也称为G-code)是一种在计算机数控(CNC)加工中广泛使用的编程语言。
它被用于控制自动化机器,如数控机床、3D打印机、CNC雕刻机等,以进行精确的制造和加工。
G代码的原理基于一系列预定义的命令,这些命令告诉机器应该如何移动、切割或制造材料。
每个命令都以“G”开头,后面跟着一个数字,用以指示命令的类型。
例如,“G0”表示快速定位,机器会以最快的速度移动到指定的位置,而“G1”表示线性插补,机器会以给定的速度移动到指定位置。
G代码编程的一个关键概念是“笛卡尔坐标系”。
这个坐标系将机器的工作空间划分为X、Y和Z三个轴。
通过使用G代码,可以指定每个轴上的移动距离和速度。
除了移动指令外,G代码还可以控制工具的选择、旋转速度、冷却液的开启和关闭等。
所有这些信息都包含在G代码程序中,该程序在运行时由机器的控制器解释并执行。
G代码编程需要一定的技能和经验,因为它直接关系到机器的操作和制造结果。
一个好的G代码程序可以大大提高制造效率和质量。
gcode 加工整圆方法
在GCODE 编程中,加工整圆主要通过G2 和G3 命令来实现。
以下是详细步骤:1. 准备工具和坐标系:首先,确定加工整圆所需的工具,如刀具或激光头。
同时,确保机床坐标系正确设置。
2. 编写GCODE 程序:在编写GCODE 程序时,需要使用G2 或G3 命令来绘制圆弧。
以下是一个简单的GCODE 示例,用于加工整圆:```gcodeG90 G54 G17 G40 G49G28 G91 Z0G90G00 X0 Y0G43 H1G94M06 T1G01 Z-100G01 X100 Y100G02 X100 Y150 I50 J0G03 X150 Y150 I0 J0G01 X150 Y100G02 X100 Y100 I50 J0G03 X100 Y150 I0 J0G01 X100 Y100G00 Z0G28 G91 Z0G90```3. 解析GCODE 程序:- G90:设定绝对编程模式。
- G54:设定机床坐标系。
- G17:设定XY 平面。
- G40、G49:关闭刀具补偿。
- G28、G91:返回参考点。
- G90:切换回绝对编程模式。
- G00、G01:快速移动到起点。
- G2、G3:绘制圆弧。
- M06:换刀。
- G01、G02、G03:绘制整圆。
- G00:回到初始位置。
- G28、G91:返回参考点。
4. 模拟加工:在实际加工之前,可以使用仿真软件或机床自带的模拟功能,对GCODE 程序进行模拟加工,以确保程序的正确性。
5. 执行加工:将编写好的GCODE 程序上传到机床,进行实机加工。
在加工过程中,注意监控刀具位置、加工速度和机床运行状态,确保加工安全、顺利进行。
GcodeG代码详解
reprap wiki上面的Gcode说明G-codeFrom RepRapWiki(Redirected from Gcode)Jump to: navigation, searchContents [hide]1 Introduction2 RepRap G Code Fields3 Comments4 Individual commands4.1 Checking4.1.1 N and *4.2 Buffered G Commands4.2.1 G0: Rapid move4.2.2 G1: Controlled move4.2.3 G28: Move to Origin4.3 Unbuffered G commands4.3.1 G4: Dwell4.3.2 G20: Set Units to Inches4.3.3 G21: Set Units to Millimeters4.3.4 G90: Set to Absolute Positioning4.3.5 G91: Set to Relative Positioning4.3.6 G92: Set Position4.4 Unbuffered M and T commands4.4.1 M0: Stop4.4.2 M17: Enable/Power all stepper motors 4.4.3 M18: Disable all stepper motors4.4.4 M20: List SD card4.4.5 M21: Initialise SD card4.4.6 M22: Release SD card4.4.7 M23: Select SD file4.4.8 M24: Start/resume SD print4.4.9 M25: Pause SD print4.4.10 M26: Set SD position4.4.11 M27: Report SD print status4.4.12 M28: Begin write to SD card4.4.13 M29: Stop writing to SD card4.4.14 M40: Eject4.4.15 M41: Loop4.4.16 M42: Stop on material exhausted 4.4.17 M43: Stand by on material exhausted 4.4.18 M80: ATX Power On4.4.19 M81: ATX Power Off4.4.20 M84: Stop idle hold4.4.21 M92: Set axis_steps_per_unit4.4.22 M101 Turn extruder 1 on Forward4.4.23 M102 Turn extruder 1 on Reverse4.4.24 M103 Turn all extruders off4.4.25 M104: Set Extruder Temperature (Fast)4.4.26 M105: Get Extruder Temperature4.4.27 M106: Fan On4.4.28 M107: Fan Off4.4.29 M108: Set Extruder Speed4.4.30 M109: Set Extruder Temperature4.4.31 M110: Set Current Line Number4.4.32 M111: Set Debug Level4.4.33 M112: Emergency Stop4.4.34 M113: Set Extruder PWM4.4.35 M114: Get Current Position4.4.36 M115: Get Firmware Version and Capabilities4.4.37 M116: Wait4.4.38 M117: Get Zero Position4.4.39 M118: Negotiate Features4.4.40 M119: Get Endstop Status4.4.41 M126: Open Valve4.4.42 M127: Close Valve4.4.43 M128: Extruder Pressure PWM4.4.44 M129: Extruder pressure off4.4.45 M140: Bed Temperature (Fast)4.4.46 M141: Chamber Temperature (Fast)4.4.47 M142: Holding Pressure4.4.48 M143: Maximum hot-end temperature4.4.49 M160: Number of mixed materials4.4.50 M203: Record Z adjustment4.4.51 M226: Gcode Initiated Pause4.4.52 M227: Enable Automatic Reverse and Prime4.4.53 M228: Disable Automatic Reverse and Prime4.4.54 M229: Enable Automatic Reverse and Prime4.4.55 M230: Disable / Enable Wait for Temperature Change 4.4.56 M240: Start conveyor belt motor4.4.57 M241: Stop conveyor belt motor4.4.58 M245: Start cooler4.4.59 M246: Stop cooler4.4.60 M300: Play beep sound4.4.61 T: Select Tool5 Proposed EEPROM configuration codes6 Replies from the RepRap machine to the host computer7 Proposal for sending multiple lines of G-code7.1 Problem to solveIntroductionThis page describes the G Codes that the RepRap firmware uses and how they work.The list of what can be done is extensible. But check this page first, and add your extension here first before you implement it.A typical piece of GCode as sent to a RepRap machine might look like this:N3 T0*57N4 G92 E0*67N5 G28*22N6 G1 F1500.0*82N7 G1 X2.0 Y2.0 F3000.0*85N8 G1 X3.0 Y3.0*33The meaning of all those symbols and numbers (and more) is explained below.TO find out which specific gcode/s are implemented in any given firmware, please see the Firmware_features page.(For the technically minded, the end of line is marked by both a <nl> and a <cr>. If you want to manually enter GCodes in your reprap using the Arduino Serial interface, make sure to select "Both NL & CR" on the bottom of the screen.)This isn't accurate, firmware accepts single <nl> as well as single <cr>, or combinations thereof. Hosts should accepts all four combinations as well. --Traumflug 09:34, 20 April 2011 (UTC)RepRap G Code FieldsThis section explains the letter-preceded fields. The numbers in the fields are represented by nnn. Numbers can be integers, or can contain a decimal point, depending on context. For example an X coordinate can be integer (X175) or fractional (X17.62), whereas trying to select extruder number 2.76 would make no sense.Letter MeaningGnnn Standard GCode command, such as move to a pointMnnn RepRap-defined command, such as turn on a cooling fanTnnn Select tool nnn. In RepRap, tools are extrudersSnnn Command parameter, such as the voltage to send to a motorPnnn Command parameter, such as a time in millisecondsXnnn An X coordinate, usually to move toYnnn A Y coordinate, usually to move toZnnn A Z coordinate, usually to move toInnn Parameter - not currently usedJnnn Parameter - not currently usedFnnn Feedrate in mm per minute. (Speed of print head movement)Rnnn Parameter - not currently usedQnnn Parameter - not currently usedEnnn Length of extrudate in mm. This is exactly like X, Y and Z, but for the length of filament to extrude. It is common for newer stepper based systems to interpret ... Better: Skeinforge 40 and up interprets this as the absolute length of input filament to consume, rather than the length of the extruded output.Nnnn Line number. Used to request repeat transmission in the case of communications errors. *nnn Checksum. Used to check for communications errors.CommentsG Code comments:N3 T0*57 ;This is a commentN4 G92 E0*67; So is thisN5 G28*22Will be ignored by RepRap, as will blank lines. But it's better to strip these out in the host computer before the lines are sent. This saves bandwidth.Individual commandsCheckingN and *Example: N123 [...G Code in here...] *71These are the line number and the checksum. The RepRap firmware checks the checksum against a locally-computed value and, if they differ, requests a repeat transmission of the line of the given number.You can leave both of these out - RepRap will still work, but it won't do checking. You have to have both or neither though.The checksum "cs" for a GCode string "cmd" (including its line number) is computed by exor-ing the bytes in the string up to and not including the * character as follows:int cs = 0;for(i = 0; cmd[i] != '*' && cmd[i] != NULL; i++)cs = cs ^ cmd[i];cs &= 0xff; // Defensive programming...and the value is appended as a decimal integer to the command after the * character.The RepRap firmware expects line numbers to increase by 1 each line, and if that doesn't happen it is flagged as an error. But you can reset the count using M110 (see below).Buffered G CommandsThe RepRap firmware stores these commands in a ring buffer internally for execution. This means that there is no (appreciable) delay while a command is acknowledged and the next transmitted. In turn, this means that sequences of line segments can be plotted without a dwell between one and the next. As soon as one of these buffered commands is received it is acknowledged and stored locally. If the local buffer is full, then the acknowledgment is delayed until space for storage in the buffer is available. This is how flow control is achieved.G0: Rapid moveExample: G0 X12In this case move rapidly to X = 12 mm. In fact, the RepRap firmware uses exactly the same code for rapid as it uses for controlled moves (see G1 below), as - for the RepRap machine - this is just as efficient as not doing so. (The distinction comes from some old machine tools that used to move faster if the axes were not driven in a straight line. For them G0 allowed any movement in space to get to the destination as fast as possible.)G1: Controlled moveExample: G1 X90.6 Y13.8 E22.4Go in a straight line from the current (X, Y) point to the point (90.6, 13.8), extruding material as the move happens from the current extruded length to a length of 22.4 mm.RepRap does subtle things with feedrates. Thus:G1 F1500G1 X90.6 Y13.8 E22.4Will set a feedrate of 1500 mm/minute, then do the move described above at that feedrate. ButG1 F1500G1 X90.6 Y13.8 E22.4 F3000Will set a feedrate of 1500 mm/minute, then do the move described above accelerating to a feedrate of 3000 mm/minute as it does so. The extrusion will accelerate along with the X, Y movement so everything stays synchronized.RepRap thus treats feedrate as simply another variable (like X, Y, Z, and E) to be linearly interpolated. This gives complete control over accelerations and decelerations in a way that ensures that everything moves together and the right volume of material is extruded at all points.The first example shows how to get a constant-speed movement. The second how to accelerate or decelerate. ThusG1 F1500G1 X90.6 Y13.8 E22.4 F3000G1 X80 Y20 E36 F1500Will do the first movement accelerating as before, and the second decelerating from 3000 mm/minute back to 1500 mm/minute.To reverse the extruder by a given amount (for example to reduce its internal pressure while it does an in-air movement so that it doesn't dribble) simply use G1 to send an E value that is less than the currently extruded length.G28: Move to OriginExample: G28This causes the RepRap machine to move back to its X, Y and Z zero endstops, a process known as "homing". It does so accelerating, so as to get there fast. But when it arrives it backs off by 1 mm in each direction slowly, then moves back slowly to the stop. This ensures more accurate positioning.If you add coordinates, then just the axes with coordinates specified will be zeroed. ThusG28 X0 Y72.3will zero the X and Y axes, but not Z. The actual coordinate values are ignored.Unbuffered G commandsThe following commands are not buffered. When one is received it is stored, but it is not acknowledged to the host until the buffer is exhausted and then the command has been executed. Thus the host will pause at one of these commands until it has been done. Short pauses between these commands and any that might follow them do not affect the performance of the machine.G4: DwellExample: G4 P200In this case sit still doing nothing for 200 milliseconds. During delays the state of the machine (for example the temperatures of its extruders) will still be preserved and controlled.G20: Set Units to InchesExample: G20Units from now on are in inches.G21: Set Units to MillimetersExample: G21Units from now on are in millimeters. (This is the RepRap default.)G90: Set to Absolute PositioningExample: G90All coordinates from now on are absolute relative to the origin of the machine. (This is the RepRap default.)G91: Set to Relative PositioningExample: G91All coordinates from now on are relative to the last position.G92: Set PositionExample: G92 X10 E90Allows programming of absolute zero point, by reseting the current position to the values specified. This would set the machine's X coordinate to 10, and the extrude coordinate to 90. No physical motion will occur.Unbuffered M and T commandsM0: StopExample: M0The RepRap machine finishes any moves left in its buffer, then shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M112.M17: Enable/Power all stepper motorsExample: M17M18: Disable all stepper motorsExample: M18Disables stepper motors and allows axis to move 'freely.'M20: List SD cardExample: M20All files in the root folder of the SD card are listed to the serial port. This results in a line like:ok Files: {SQUARE.G,SQCOM.G,}The trailing comma is optional. Note that file names are returned in upper case, but - when sent to the M23 command (below) they must be in lower case. This seems to be a function of the SD software. Go figure...M21: Initialise SD cardExample: M21The SD card is initialised. If an SD card is loaded when the machine is switched on, this will happen by default. SD card must be initialised for the other SD functions to work.M22: Release SD cardExample: M22SD card is released and can be physically removed.M23: Select SD fileExample: M23 filename.gcoThe file specified as filename.gco (8.3 naming convention is supported) is selected ready for printing.M24: Start/resume SD printExample: M24The machine prints from the file selected with the M23 command.M25: Pause SD printExample: M25The machine pause printing at the current position within the file selected with the M23 command.M26: Set SD positionExample: M26Set SD position in bytes (M26 S12345).M27: Report SD print statusExample: M27Report SD print status.M28: Begin write to SD cardExample: M28 filename.gcoFile specified by filename.gco is created (or overwritten if it exists) on the SD card and all subsequent commands sent to the machine are written to that file.M29: Stop writing to SD cardExample: M29 filename.gcoFile opened by M28 command is closed, and all subsequent commands sent to the machine are executed as normal.M40: EjectIf your RepRap machine can eject the parts it has built off the bed, this command executes the eject cycle. This usually involves cooling the bed and then performing a sequence of movements that remove the printed parts from it. The X, Y and Z position of the machine at the end of this cycle are undefined (though they can be found out using the M114 command, q.v.).See also M240 and M241 below.M41: LoopExample: M41If the RepRap machine was building a file from its own memory such as a local SD card (as opposed to a file being transmitted to it from a host computer) this goes back to the beginning of the file and runs it again. So, for example, if your RepRap is capable of ejecting parts from its build bed then you can set it printing in a loop and it will run and run. Use with caution - the only things that will stop it are:1.When you press the reset button,2.When the build material runs out (if your RepRap is set up to detect this), and3.When there's an error (such as a heater failure).M42: Stop on material exhaustedExample: M42If your RepRap can detect when its material runs out, this decides the behaviour when that happens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off. You have to press reset to reactivate the machine. In other words, it parks itself and then executes an M0 command (q.v.).M43: Stand by on material exhaustedExample: M43If your RepRap can detect when its material runs out, this decides the behaviour when thathappens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off except the heated bed, the temperature of which is maintained. The machine will still respond to G and M code commands in this state.M80: ATX Power OnExample: M80Turns on the ATX power supply from standby mode to fully operational mode. No-op on electronics without standby mode.Note: some firmwares, like Teacup, handle power on/off automatically, so this is redundant there.M81: ATX Power OffExample: M81Turns off the ATX power supply. Counterpart to M80.M84: Stop idle holdExample: M84Stop the idle hold on all axis and extruder. In some cases the idle hold causes annoying noises, which can be stopped by disabling the hold. Be aware that by disabling idle hold during printing, you will get quality issues. This is recommended only in between or after printjobs.M92: Set axis_steps_per_unitExample: M92 X<newsteps> Sprinter and MarlinAllows programming of steps per unit of axis till the electronics are reset for the specified axis. Very useful for calibration.M101 Turn extruder 1 on ForwardDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM102 Turn extruder 1 on ReverseDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM103 Turn all extruders offDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM104: Set Extruder Temperature (Fast)Example: M104 S190Set the temperature of the current extruder to 190oC and return control to the host immediately (i.e. before that temperature has been reached by the extruder). See also M109.M105: Get Extruder TemperatureExample: M105Request the temperature of the current extruder and the build base in degrees Celsius. The temperatures are returned to the host computer. For example, the line sent to the host in response to this command looks likeok T:201 B:117M106: Fan OnExample: M106 S127Turn on the cooling fan at half speed. Optional parameter 'S' declares the PWM value (0-255)M107: Fan OffExample: M107Turn off the cooling fan (if any).M108: Set Extruder SpeedSets speed of extruder motor. (Deprecated in current firmware, see M113)M109: Set Extruder TemperatureExample: M109 S190Set the temperature of the current extruder to 190oC and wait for it to reach that value before sending an acknowledgment to the host. In fact the RepRap firmware waits a while after the temperature has been reached for the extruder to stabilise - typically about 40 seconds. This can be changed by a parameter in the firmware configuration file when the firmware is compiled. See also M104 and M116.M110: Set Current Line NumberExample: N123 M110Set the current line number to 123. Thus the expected next line after this command will be 124.M111: Set Debug LevelExample: M111 S6Set the level of debugging information transmitted back to the host to level 6. The level is the OR of three bits:#define DEBUG_ECHO (1<<0)#define DEBUG_INFO (1<<1)#define DEBUG_ERRORS (1<<2)Thus 6 means send information and errors, but don't echo commands. (This is the RepRap default.)M112: Emergency StopExample: M112Any moves in progress are immediately terminated, then RepRap shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M0.M113: Set Extruder PWMExample: M113Set the PWM for the currently-selected extruder. On its own this command sets RepRap to use the on-board potentiometer on the extruder controller board to set the PWM for the currently-selected extruder's stepper power. With an S field:M113 S0.7it causes the PWM to be set to the S value (70% in this instance). M113 S0 turns the extruder off, until an M113 command other than M113 S0 is sent.M114: Get Current PositionExample: M114This causes the RepRap machine to report its current X, Y, Z and E coordinates to the host.For example, the machine returns a string such as:ok C: X:0.00 Y:0.00 Z:0.00 E:0.00M115: Get Firmware Version and CapabilitiesExample: M115Request the Firmware Version and Capabilities of the current microcontroller The details are returned to the host computer as key:value pairs separated by spaces and terminated with alinefeed.sample data from firmware:ok PROTOCOL_VERSION:0.1 FIRMWARE_NAME:FiveD FIRMWARE_URL:http%3A// MACHINE_TYPE:Mendel EXTRUDER_COUNT:1This M115 code is inconsistently implemented, and should not be relied upon to exist, or output correctly in all cases. An initial implementation was committed to svn for the FiveD Reprap firmware on 11 Oct 2010. Work to more formally define protocol versions is currently (October 2010) being discussed. See M115_Keywords for one draft set of keywords and their meanings.M116: WaitExample: M116Wait for all temperatures and other slowly-changing variables to arrive at their set values. See also M109.M117: Get Zero PositionExample: M117This causes the RepRap machine to report the X, Y, Z and E coordinates in steps not mm to the host that it found when it last hit the zero stops for those axes. That is to say, when you zero X, the x coordinate of the machine when it hits the X endstop is recorded. This value should be 0, of course. But if the machine has drifted (for example by dropping steps) then it won't be. This command allows you to measure and to diagnose such problems. (E is included for completeness. It doesn't normally have an endstop.)M118: Negotiate FeaturesExample: M118 P42This M-code is for future proofing. NO firmware or hostware supports this at the moment. It is used in conjunction with M115's FEATURES keyword.See Protocol_Feature_Negotiation for more info.M119: Get Endstop StatusExample: M119Returns the current state of the configured X,Y,Z endstops. Should take into account any 'inverted endstop' settings, so one can confirm that the machine is interpreting the endstops correctly.M126: Open ValveExample: M126 P500Open the extruder's valve (if it has one) and wait 500 milliseconds for it to do so.M127: Close ValveExample: M127 P400Close the extruder's valve (if it has one) and wait 400 milliseconds for it to do so.M128: Extruder Pressure PWMExample: M128 S255PWM value to control internal extruder pressure. S255 is full pressure.M129: Extruder pressure offExample: M129 P100In addition to setting Extruder pressure to 0, you can turn the pressure off entirely. P400 will wait 100ms to do so.M140: Bed Temperature (Fast)Example: M140 S55Set the temperature of the build bed to 55oC and return control to the host immediately (i.e. before that temperature has been reached by the bed).M141: Chamber Temperature (Fast)Example: M141 S30Set the temperature of the chamber to 30oC and return control to the host immediately (i.e. before that temperature has been reached by the chamber).M142: Holding PressureExample: M142 S1Set the holding pressure of the bed to 1 bar.The holding pressure is in bar. For hardware which only has on/off holding, when the holding pressure is zero, turn off holding, when the holding pressure is greater than zero, turn on holding.M143: Maximum hot-end temperatureExample: M143 S275Set the maximum temperature of the hot-end to 275CWhen temperature of the hot-end exceeds this value, take countermeasures, for instance anemergency stop. This is to prevent hot-end damage.M160: Number of mixed materialsExample: M160 S4Set the number of materials, N, that the current extruder can handle to the number specified. The default is 1.When N >= 2, then the E field that controls extrusion requires N+1 values separated by spaces after it like this:M160 S4G1 X90.6 Y13.8 E22.4 0.1 0.1 0.1 0.7G1 X70.6 E42.4 0.0 0.0 0.0 1.0G1 E42.4 1.0 0.0 0.0 0.0The second line moves straight to the point (90.6, 13.8) extruding 22.4mm of filament. The mix ratio at the end of the move is 0.1:0.1:0.1:0.7.The third line moves back 20mm in X extruding 20mm of filament. The mix varies linearly from 0.1:0.1:0.1:0.7 to 0:0:0:1 as the move is made.The fourth line has no physical effect, but sets the mix proportions for the start of the next move to 1:0:0:0.M203: Record Z adjustmentExample: M203 Z-0.75This records a Z offset in non-volatile memory in RepRap's microcontroller where it remains active until next set, even when the power is turned off and on again. If the first layer is too close to the bed, you need to effectively move the bed down, so the Z value will be negative. If the nozzle is too far from the bed during the first layer, the Z value should be positive to raise the bed. The maximum adjustment is +/-1.27mm.M226: Gcode Initiated PauseExample: M226Initiates a pause in the same way as if the pause button is pressed.M227: Enable Automatic Reverse and PrimeExample: M227 P1600 S1600P and S are steps.M228: Disable Automatic Reverse and PrimeExample: M228M229: Enable Automatic Reverse and PrimeExample: M229 P1.0 S1.0P and S are extruder screw rotations.M230: Disable / Enable Wait for Temperature ChangeExample: M230 S1S1 Disable wait for temperature change S0 Enable wait for temperature changeM240: Start conveyor belt motorExample: M240The conveyor belt allows to start mass production of a part with a reprapM241: Stop conveyor belt motorExample: M241M245: Start coolerExample: M245used to cool parts/heated-bed down after printing for easy remove of the parts after printM246: Stop coolerExample: M246M300: Play beep soundUsage: M300 S<frequency Hz> P<duration ms>Example: M300 S300 P1000Play beep sound, use to notify important events like the end of printing. See working example on R2C2 electronics.T: Select ToolExample: T1Select extruder number 1 to build with. Extruder numbering starts at 0.Proposed EEPROM configuration codesBRIEFLY: each RepRap has a number of physical parameters that should be persistent, but easily configurable, such as extrusion steps/mm, various max values, etc. Those parameters are currently hardcoded in the firmware, so that a user has to modify, recompile and re-flash the firmware for any adjustments. These configs can be stored in MCU's EEPROM and modified via some M-codes. Please see the detailed proposal at M-codes for EEPROM config. (This is proposed by --AlexRa on 11-March-2011. There is currently no working implementation of the proposed commands).Replies from the RepRap machine to the host computerAll communication is in printable ASCII characters. Messages sent back to the host computer are terminated by a newline and look like this:xx [line number to resend] [T:93.2 B:22.9] [C: X:9.2 Y:125.4 Z:3.7 E:1902.5] [Some debugging or other information may be here]xx can be one of:okrs!!ok means that no error has been detected.rs means resend, and is followed by the line number to resend.!! means that a hardware fault has been detected. The RepRap machine will shut down immediately after it has sent this message.The T: and B: values are the temperature of the currently-selected extruder and the bed respectively, and are only sent in response to M105. If such temperatures don't exist (for example for an extruder that works at room temperature and doesn't have a sensor) then a value below absolute zero (-273oC) is returned.C: means that coordinates follow. Those are the X: Y: etc values. These are only sent in response to M114 and M117.The RepRap machine may also send lines that look like this:// This is some debugging or other information on a line on its own. It may be sent at any time.Such lines will always be preceded by //.The most common response is simply:okWhen the machine boots up it sends the stringstartonce to the host before sending anything else. This should not be replaced or augmented by version numbers and the like. M115 (see above) requests those.All this means that every line sent by RepRap to the host computer except the start line has a two-character prefix (one of ok, rs, !! or //). The machine should never send a line without such a prefix.。
github gcode解析
github gcode解析G代码解析在 GitHub 上的实践G代码是一种用于控制数控机床(CNC)的计算机语言。
它由一系列代码组成,这些代码指定机器的移动、速度和输出。
G代码解析是将 G 代码转换成机器可执行指令的过程。
GitHub 中的 G 代码解析项目GitHub 是一个托管代码库的平台,其中包含大量与 G 代码解析相关的项目。
这些项目为各种用例提供了解决方案,包括:G 代码查看器:用于查看和编辑 G 代码文件的工具。
G 代码模拟器:在虚拟环境中模拟 G 代码程序,以识别错误并可视化机器运动。
G 代码后处理器:将 G 代码转换为特定 CNC 机床兼容的格式。
G 代码优化器:优化 G 代码程序的效率和性能。
G 代码生成器:从 CAD 模型或其他输入生成 G 代码程序。
GitHub 上 G 代码解析项目的特点GitHub 上的 G 代码解析项目具有以下特点:开源:大多数项目都是开源的,允许用户查看、修改和分发代码。
跨平台:许多项目可在多个操作系统上运行。
社区支持:项目通常由活跃的社区提供支持,提供帮助、文档和持续改进。
各种语言:G 代码解析项目使用多种编程语言编写,包括Python、C++ 和 Java。
文档齐全:大多数项目都有详细的文档,帮助用户了解其功能和用法。
选择 GitHub 上的 G 代码解析项目选择 GitHub 上的 G 代码解析项目时,请考虑以下因素:功能:确定项目是否具有您需要的特定功能。
可用性:考虑兼容性、平台支持和易用性。
社区支持:活跃的社区通常会提供有价值的帮助和反馈。
许可证:了解项目的许可证条款,确保它们符合您的使用情况。
文档:查看项目文档,以了解其功能、用法和限制。
通过仔细考虑这些因素,您可以从 GitHub 上广泛的项目中选择最适合您需求的 G 代码解析解决方案。
倒锥螺纹编程实例
倒锥螺纹编程实例在数控编程中,倒锥螺纹的编程需要特别注意。
倒锥螺纹指的是螺距随着深度增加而逐渐增大的螺纹,也称为锥形螺纹或斜角螺纹。
以下是一个简单的倒锥螺纹编程实例,以常见的G代码编程为例:1. 定义倒锥螺纹参数:螺纹类型:锥形螺纹直径范围:外径为100mm,内径为80mm螺距:外端为5mm,内端为10mm深度:20mm2. G代码编程:```gcodeG92 X90 Z-20 I5 J0 F100G92 X85 Z-20 I10 J0 F100````G92` 是固定循环指令,用于螺纹切削。
`X` 和 `Z` 是坐标轴的移动距离。
`I` 和 `J` 是螺旋线生成的半径增量,分别控制半径在X和Y轴上的变化。
`F` 是进给速度。
注意,这是一个简化的例子,实际生产中可能需要更复杂的计算和调整。
3. 说明:第一行指令从X=90开始,以I=5, J=0进行螺旋切削,到Z=−20深度,F=100是进给速度。
第二行指令从X=85开始,以I=10, J=0进行螺旋切削,到Z=−20深度,F=100是进给速度。
这样,从外到内,螺距逐渐增大,形成倒锥螺纹。
4. 注意事项:确保您的数控机床支持所需的G代码。
不同的机床和控制器可能有不同的G代码集或功能。
在编程前,最好先验证G代码以确保它符合您的机器规格和要求。
考虑工件的材料、刀具的类型和规格、切削参数等因素,确保安全有效地进行加工。
5. 验证:在编程后,务必在机床上进行试切,检查刀具路径和切削效果是否符合预期。
如有问题,需及时调整G代码或参数。
6. 优化:实际生产中可能需要进一步优化切削参数、刀具路径等,以提高生产效率、减少刀具磨损或达到其他特定要求。
c语言 gcode 解析
c语言 gcode 解析Gcode是一种用于数控机床操作的指令语言。
它可以控制机床运动、加工速度、刀具选择以及其他相关参数。
在本文中,我们将介绍如何使用c语言解析gcode文件,并将其转换为机床可以执行的指令。
一、Gcode的基本结构在Gcode中,每个指令都以字母开头,后跟一个或多个数字。
例如,G01指令表示线性插补,X、Y和Z指令表示轴的位置,F指令表示进给速度。
下面是一个简单的Gcode文件示例:G01 X10 Y20 Z30 F100G02 X30 Y20 I10 J0 F200G03 X30 Y40 I0 J20 F300二、解析Gcode文件我们可以使用c语言编写程序来解析Gcode文件。
首先,我们需要打开Gcode文件,并逐行读取它。
然后,我们可以使用字符串操作函数来提取每个指令的字母和数字参数。
最后,我们可以根据指令类型和参数生成机床可以执行的指令。
以下是一个简单的c语言程序,它可以解析上面的示例Gcode文件并将其转换为机床指令:#include <stdio.h>#include <string.h>int main(){char line[256];FILE* file = fopen("example.gcode", "r");if (file == NULL) {printf("Failed to open file\n");return 1;}while (fgets(line, sizeof(line), file)) {char letter = line[0];float value = 0;char* ptr = line + 1;while (*ptr) {if (*ptr >= '0' && *ptr <= '9') {value = value * 10 + (*ptr - '0');} else if (*ptr == '.') {float fraction = 0.1;ptr++;while (*ptr >= '0' && *ptr <= '9') { value += (*ptr - '0') * fraction;fraction /= 10;ptr++;}break;}ptr++;}switch (letter) {case 'G':switch ((int)value) {case 0:printf("Move\n");break;case 1:printf("Linear interpolation\n");break;case 2:printf("Clockwise circular interpolation\n");break;case 3:printf("Counterclockwise circularinterpolation\n");break;}break;case 'X':printf("X position: %f\n", value); break;case 'Y':printf("Y position: %f\n", value); break;case 'Z':printf("Z position: %f\n", value); break;case 'F':printf("Feed rate: %f\n", value); break;}}fclose(file);return 0;}三、总结在本文中,我们介绍了Gcode的基本结构和如何使用c语言解析Gcode文件。
广数G代码(Gcode)
广数G代码(G code)G code. TXT - you are two boats and you are really beautiful. - everyone who says they don't want to be in love has an impossible person in their heart. I love every unhappy but still smiling child. If there is one person, I am invisible and know that I am waiting for someoneNumerical control lathes can be divided into simple numerical control lathe (economical numerical control lathe),multi-function CNC lathe and CNC turning center according to the function and mechanical composition of numerical control system.(1) simple CNC lathe (economical nc lathe) is a low grade of numerical control lathe, is often done with a single machine or single chip microcomputer control, mechanical part is designed on the basis of the ordinary lathe to improve.(2) the multi-function CNC lathe is also called the all-purpose CNC lathe, which is controlled by a special numerical control system and has the characteristics of nc lathe.(3) the CNC turning center increases the additional coordinate axes on the basis of CNC lathe.Main technical specifications of CNC lathe (CJK6153).The diameter of rotary diameter: phi 530mm. Rotary diameter of the maximum workpiece of the skateboard: 2280mm, the machine tool with the maximum distance of 1000mm, the maximum X direction of the tool frame: 260mm, the maximum z-direction ofthe tool holder: 1000mm. Manual 4 frequency conversion speed control 25 ~ 2000 RPM.4.1.6 numerical control lathe (CJK6153) lubrication and coolingThe lubrication of the machine tool and the lubrication of other parts are two parts. Have the headstock gear adopt oil lubrication, forced by cycloid pump lubrication, cycloidal pump oil absorption, first by the refined filter, and then into a magnetic filter, and then sent to each component of the spindle bearing or effects of oil lubrication and all other moving parts to forced lubrication and oil lubrication. Machine tools in other parts of lubrication, such as tail frame, guide rails and the screw nut adopt oil lubrication, the interval lubrication pump is adopted to X axis and Z axis of the guide surface and the ball screw nut lubrication, tail sleeve cylindrical parts such as automatic intermittent lubrication. In the transparent state tank, with a liquid alarm switch, the machine will lubricate the alarm when the oil in the box is below the regulation value. The machine cooling system adopts pump cooling. The daily maintenance of the cooling unit is mainly the replacement of the cooling water and the cleaning of the filter. It is strictly forbidden to start the cooling pump before the cooling liquid is poured in the cooling box to avoid burning the cooling pump. When cooling water is reduced, supply should be timely. The cooling water should be replaced when the pollution is bad. The cooling liquid should be selected to prevent rust.4.2 programming method of CNC latheIn order to learn the programming of CNC lathe, we must understand the operation point of nc lathe. Most of the existing textbooks do not use CNC lathe operation and programming as a whole.4.2.1 machine coordinate system for CNC latheThe machine tool coordinate system is the inherent coordinate system of the machine tool, it is the foundation for making and adjusting the machine tool, and also the basis of setting the workpiece coordinate system. The machine tool coordinate system has been adjusted before the factory, generally not allowed to change arbitrarily. Reference point is also a fixed limit point on the machine tool, and its position is determined by mechanical block or stroke switch. The machine coordinate system is confirmed by returning the machine zero. Before the machine is turned on, CNC lathe should be familiar with the panel of CNC lathe. The form of the panel is closely related to the numerical control system. It is easy to turn on the CNC lathe. The lathe of the distribution system. When the power is turned on, it is easy to turn on the power supply. After the machine is turned on, the table is returned to the point of origin (or reference point, which has a fixed distance to the origin of the machine tool). The return zero (reference point) step of the CNC lathe is: the switch is in the "back zero" position. Press the manual axis in the direction key + X, + Z to zero indicator light. If the work is not done, the error compensation and backgap compensation will not be realized. Setting the machine tool origin is directly related to the G54 instruction in programming.4.2.Set the workpiece coordinate system of CNC latheThe workpiece coordinate system is the coordinate system used in programming, also called the programming coordinate system, which is artificially set. The establishment of workpiece coordinate system is an indispensable step in nc lathe machining. Different systems have different approaches.1. Establishment method of Siemens 802S system workpiece coordinate system(1) turn the knife to the base knife (e.g. 1 knife).(2) in the MDA state, input T1D0 to make the knife fill 0.(3) machine tool return reference point.(4) use the test method to determine the coordinate origin of the workpiece. The end face of the cutting test. Z doesn't move. If the point is the origin of Z direction, then the zero point of the parameter is placed in the G54 of the directory, and the Z of the point is the negative value of A, that is, Z = -a. If Z goes to the left of the end, then enter Z = - (A +) in G54, return the car. And I'm going to do the same thing with the outer circle. The Z direction is back, and the machine tool coordinates of X direction are recorded, the diameter of the machine is measured, and the radius R is obtained. In the G54 X, input X = -(A + R), return the car.2. The establishment method of the workpiece coordinate system of the GSK980T system(1) use manual method to test the end surface.(2) when the Z axis does not move, the axis is withdrawn along the X-axis and the spindle rotation is stopped. 3. Measuring the distance between the end plane and the zero point of the workpiece coordinate system. Then enter G50 Z in the input method and run the sentence. 4. In the same way, a manual way outside circle, in the case of the X axis fixed return along the Z axis, and stop the spindle rotation, measuring the workpiece diameter X, the entry mode input G50X, run the other can.3. The establishment method of GSK928TC workpiece coordinate system(1) the outer circle of the car, along the z-direction, measured the diameter, enter the diameter value by InputX, enter the car.(2) the end face of the vehicle, along the X direction, the distance between the end and the origin of the work piece, input the distance value by InputZ, and then enter the vehicle.4.2.3 determines the position of the base knife in the work coordinate systemAfter the workpiece coordinate system is determined, the position of the knife (reference knife) in the workpiececoordinate system can be determined by the G50 instruction.4.2.4 determines the location of other knives in the artifact coordinate systemProcessing a parts often need to several different cutting tools, due to the deviation of the tool setting and tool itself every knife to the cutting position, the position of the tip is not coincidence, as users don't need to consider when programming tool, the deviation between need to determine the position of other knife in the workpiece coordinate system, it needs to be through to the knife. Different systems have different approaches to dao.1. Method of Siemens 802S system(1) select a knife as the base knife, press the parameter key and the tool compensation button, then press the new tool button, input the reference knife number and the edge (complement). If the base knife is 1, choose 1 edge (complement), then the cutter is T1D1.(2) call to the knife window, use the base knife car outside circle, Z to return the knife, in the X axis zero deviation of the knife window (because it is the base knife), press the calculation key to confirm.(3) call each other cutter, determine the number of the knife and the edge of the knife, enter the diameter of the outside circle and the end of the car. Enter negative values for the depth of the steps. Calculate and determine.The wide range GSK980T system for the dao(1) use the benchmark tool to test the workpiece, and set the reference frame: test the end face X to return the knife, enter the input mode, press the program button. Enter G50 Z0, which is to use the end face as the z-base level. Then press the set key, set the offset number (the benchmark knife + 100), enter Z = 0, try to cut out the outer circle, Z to the back knife, measure the outer circle diameter, enter the input mode, press the program button. Enter G50X, then press the setting key, setting the partial number, the base knife offset number + 100, X =.(2) call each other cutter, outside circle, Z to return knife. If the diameter of the outer circle is measured, the measured value is set to the one offset, which is the value of the knife number + 100, such as the knife number 2, and the offset number is 202, where X =. Similarly, the steps of the car, X to the back of the knife, the depth of the steps, the input Z = - in the offset sign.3.The wide GSK928TC system for the dao method(1) use the base knife to try to cut the workpiece, use the input to establish the frame of the knife, the Z of the coordinate system is at the origin, generally located at the right end of the workpiece, which is the end of the test cut as Z to the zero.(2) call other knives, such as knife 2, to make a T20 call, then try to cut the outer circle Z to the back of the knife, measure the diameter, and then press the I key. The input. Cut the steps, X to the back, measure the depth of the steps, then press the K key, input - the knife patch is set.4.2.5 axis directionThe direction of the center of the center of the center to the center of the center is the positive direction. The axis perpendicular to the spindle axis in the horizontal plane is the X-axis, and the direction of the rotation center of the spindle is in the positive direction.4.2.6 diameter or radius programmingThe radial dimensions of the processed parts are indicated in the diameter of the drawing and the measurement of processing, so it is more convenient to use diameter size programming.4.2.7 general programming methods1. Determine the location of the first knifeThe g50x Z directive determines the position of the first knife, which requires the first blade to be moved to the position of X Z.2. Return reference pointsG26 (G28) : the X Z axis also returns the reference point, G27:the X axis returns reference point, G29: the z-axis returns reference points.3. Quick positioningG00 X Z quickly locates to the specified point.4. Linear interpolationG01 X Z F is used for outer circle and end surface. F is the feed rate, whose unit is mm/min (specified in G94 or G98) or mm/r (specified in G95 or G99).5. Arc interpolationG02 (03) X Z I K F is used for the car to be rounded or reversed. X Z is the endpoint of the arc, I K is the coordinate of the center relative to the starting point, F is the feed velocity.6. Screw cuttingG33 (32) X Z P (E) I K this instruction for thread cutting, X, Z for threaded end point coordinates, P for metric screw thread (0.25-100 - mm), E for inch screw thread (100-4 teeth per inch), for the refund of the I K. The spindle speed cannot be too high when the thread is cutting, generally N by P is less than 3000, N is the spindle speed (RPM), P is the metric thread guide (mm).7. Delay or pauseG04 X, X is the number of seconds to pause, which is generallyused to cut the slot and keep the bottom smooth.8. Spindle speed settingM03 (04) S is used for the main axis clockwise or counterclockwise, the spindle speed is S, and its unit is m/min (specified by G96) or r/min (specified by G97). The M05 indicates that the spindle stops.9. End of programM02 (end at this point) or M30 (return program first sentence after the end).4.2.8 cycleBecause of the commonly used bar materials and forging materials, the machining margin is larger, which is a simplified programming. The CNC lathe often has different forms of fixed cycle, which can be used for many cyclic cutting.1. Outer diameter and inner diameter cycleG90x Z R F is used for simple turning cycle of external diameter and internal diameter, X Z is the cyclic endpoint coordinates, and R represents the circular cone surface circulation. The value of the cone is the difference of the diameter of the cone, the starting point of the circle is determined by the previous procedure, and F is the feed speed.2. Threading cycle of threadG92 X Z P (E) I K R L, the instruction is used for thread cutting cycle, X, Z for threaded end point coordinates, P for metric screw thread (0.25-100 - mm), E for inch screw thread (100-4 teeth per inch), I K for the refund of, R represents the diameter of the thread starting point and end point (for processing taper thread), L said thread, starting point is determined by the other programs on thread cutting cycle. G92 instructions differ from G33 instructions to G92 multiple automatic cutting threads.Face turning cycleThe G94 X Z R F is used for the simple turning cycle of the end face, X Z is the cyclic endpoint coordinates, and R represents the cone loop. Its value is the size of the cone (Z deviation), and the starting point is determined by the previous program, F is the feed speed.4. Grooving cycleThe G75 X Z I K E F is used to cut the slot loop, X Z is the cyclic endpoint coordinates, and I is the input value per X axis,K is the number of retreats per X axis, E is the offset of Z axis, F is the speed of feed, and the Z is cut off.5. Circular coarse vehicle complex cycleThe G71 X I K L F is used for the outer round coarse vehiclecomplex cycle, which is to write out the shape of the outer circle when the program is programmed. The system starts from the blank to automatically take out the circular shape of the outer circle. The loop cutting, parallel to the Z axis X for circulation coordinates, I for each X amount of feed, K for each X amount of return, L to determine the number of processing procedure in the shape of the cylindrical, F feed speed, G71 instruction period immediately decided to cylindrical shape processing procedures section.6. The end face coarse vehicle complex cycleG72 Z I K L F is used for the end surface rough vehicle complex cycle, which is to write the end surface processing shape when programming, and the system starts automatically out of the end loop shape from the blank. The loop cutting, parallel to the X axis Z for circulation coordinates, I for each Z axis feed quantity, K for the amount of return for each of the Z axis, L to determine the number of end face processing in the shape of a program, F feed speed, G72 instruction period immediately decided to end processing procedures section shape.4.2.9 tool compensationWhen programming, think turning point is a point, but in fact in order to improve the tool life and workpiece surface quality and tool tip into a circular arc radius is often, in order to improve the machining precision of workpiece, round head dao program, need for the tool radius compensation. Most CNC lathes have the automatic tool radius compensation function (G41, G42). This kind of CNC lathe can be programmed directly according tothe contour dimension of the workpiece.4.2.10 absolute coordinates and incremental coordinatesX and Z are absolute coordinates, U and W are relative coordinates.4.2.11 public system and inch size settingThe system size sets the instruction G21, the British system size sets the G20, the machine is in the G21 state after the power is on the system.4.2.12 circular arc to reverse the judgmentThe CNC lathe is a machine tool with two coordinate axes. Only the X and Z axes should be considered by the right hand rule. The positive direction of the Y-axis is pointed to itself in the judgment, (i.e. the negative direction along the Y-axis), and the circular arc of the x-z plane can be correctly judged by standing in such position.CNC lathe programming of typical parts。
广数g代码(WidenumberGcode)
广数g代码(Wide number G code)G code.Txt - you pedal two boats, you row really beautiful. Every man who says he doesn't want to be in love has an impossible man in his heart. I love every unhappy but still laughing child. (there is no one, see through me, invisible, know I'm waiting for someone). Classification of 4.1.4 CNC lathesCNC lathes vary in variety, according to CNC system functions and mechanical composition, can be divided into simple CNC lathe (economic CNC lathe), multi-function CNC lathe and CNC turning center.(1) simple numerical control lathe (economical CNC lathe) isa low grade CNC lathe. It is controlled by single board machine or single chip microcomputer. The mechanical part is improved on the basis of ordinary lathe.(2) multi function CNC lathe, also known as fully functional CNC lathe, is controlled by a special CNC system, and has various structural characteristics of CNC lathes.(3) CNC turning centers add additional coordinate axes on the basis of NC lathes.Main technical specifications of 4.1.5 CNC lathe (CJK6153).The maximum diameter: 530mm diameter rotary tool. Skateboard maximum workpiece diameter rotary: 280mm diameter, top machine from 1000mm, X to the maximum knife stroke: 260mm, maximum Z to knife stroke: 1000mm. Manual 4 stage variable frequencyspeed regulation, 25~2000 turn / minute.Lubrication and cooling of 4.1.6 numerical control lathe (CJK6153)The two part lubrication of the machine into the headstock rengar and other parts. The gear changing headstock is oil lubricated, forced lubrication by the cycloidal pump, and through the refining filter, when the cycloidal pump pumps oil,Then enter the magnetic filter, and then sent to the lubrication parts, or through the oil distributor on the spindle bearings and all other running parts forced lubrication and fuel injection lubrication. Other parts of the machine tool lubrication, such as tailstock, rail and screw nut are lubricated by oil, the use of intermittent lubrication pump automatic intermittent lubrication of X axis and Z axis of the guide rail and ball screw nut, lubricating the surface of tailstock sleeve and other parts of the outer circle. In the transparent tank, there is a liquid level alarm switch. When the oil in the tank is below the specified value, the machine will issue a lubrication alarm. The cooling system of the machine adopts pump cooling. The daily maintenance of cooling equipment is mainly cooling water supply, replacement and filter cleaning. The cooling pump is not allowed to start before the coolant is inserted into the cooling box, so as not to cause the cooling pump to burn out. When cooling water is reduced, supplies should be made in time. When cooling water is polluted, it should be replaced completely. The cooling liquid should be chosen to prevent rust.4.2 programming method of NC latheIn order to master the programming of NC lathe, it is necessary to understand the operation points of NC lathe. Most of the existing teaching materials do not regard the operation and programming of NC lathe as a whole.4.2.1 sets the machine tool coordinate system of NC latheThe coordinate system of machine tools is the inherent coordinate system of machine tools. It is the basis of manufacturing and adjusting machine tools, and also the basis of setting up the coordinate system of workpieces. The machine tool coordinate system has been adjusted before leaving the factory and is not allowed to change at will. The reference point is also a fixed limit point on the machine tool. Its position is determined by a mechanical block or a travel switch. Confirm the machine coordinate system by returning the machine zero.Back to the machine before the start of zero, CNC lathe boot before you should be familiar with CNC lathe panels. The form of panel is closely related to CNC system. CNC lathe boot difficult and easy?. For the production system of the lathe with pictures. Most of the boot is relatively simple, generally open the power supply, directly start the CNC system can be. After starting the machine, by returning zero, the worktable is returned to the original point of the machine (or reference point, which is a fixed point from the origin of the machine tool). The step of zero return of NC lathe is that the switch is placed back to zero. Press the manual shaft feed key +X, +Zto zero, the indicator light. After starting the machine, you must first return the zero (back to the test center), and if you do not do this work, then the pitch error compensation, backlash compensation and other functions will not be achieved. Setting the machine machine origin is directly related to the G54 instructions in the program.4.2.2 setting the workpiece coordinate system of NC latheThe workpiece coordinate system is the coordinate system used in programming, also known as the programming coordinate system. The coordinate system is artificially set. Setting up the workpiece coordinate system is an essential step before NC lathe machining. Different systems have different methods.1. establishment method of workpiece coordinate system of SIEMENS 802S system(1) turn the tool holder to the reference knife (such as cutter No. 1).(2) in the MDA state, enter T1D0, so that the knife complement is 0.(3) machine tool back reference point.(4) determine the origin of workpiece coordinates by trial cutting. The end face of the cutting specimen. Z the direction is still. If the point is the origin of the Z direction, the zero point under the parameter is offset in the G54 of the directory, and the Z of the point is input to the negative valueof the mechanical coordinate value A, or Z=-A.If Z is to the origin at the left end of the end, enter Z=- (A+) in the G54 and enter the carriage. Similarly, try cutting the outer circle and the X direction is not moving. Z direction retract, write down the machine coordinate A in X direction, measure the diameter, get the radius R, enter X=- (A+R) in the G54 of X, and return the car.Construction method of workpiece coordinate system of 2. wide number GSK980T system(1) test the end face by hand.(2) when the Z axis is not moving, return the knife along the X axis and stop the spindle rotation. 3. measuring the distance between the end face and the zero of the workpiece coordinate system Z. Then enter G50 Z in the input mode and run the sentence.4., the same way, manually use the car outside the circle, in the X axis is not moving, along the Z axis back, and stop spindle rotation, measuring workpiece diameter X, in the input mode input G50X, run the sentence can.Construction method of 3. wide number GSK928TC workpiece coordinate system(1) the outside of the car, along the Z to return the knife, measured diameter, press InputX enter diameter value, enter the car can.(2) the end of the car, along the X to return the knife,measuring the end of the workpiece coordinates and the origin of the distance between, and press InputZ enter the distance value, enter the car can.4.2.3 determines the position of the reference tool in the workpiece coordinate systemAfter the workpiece coordinate system has been determined, the position of the first cutter (reference knife) in the workpiece coordinate system can be determined by using the G50 instruction.4.2.4 determines where other knives are located in the workpiece coordinate systemA parts processing often requires several different cutting tools, cutting tool installation and the deviation of the tool itself, each knife to the cutting position, its tip position does not coincide, for users in programming without considering the deviation between the tool,The location of other knives in the workpiece coordinate system must be determined, which needs to be achieved by tool setting. Different systems have different tool setting methods.1., SIEMENS 802S system tool setting method(1) select a knife as the reference knife, press the parameter key and the tool compensation button, then press the new tool button, enter the reference knife's knife number and the knife edge (repair) number. For example, the standard knife is No.1, and the No. 1 knife edge is used (cutter), and the cutter is T1D1.(2) call the tool setting window, use the reference cutter, the outer circle and the Z to retract the knife, and enter 0 at the zero offset of the X axis of the tool window (because it is a reference knife), then press the calculation key to confirm it.(3) call each other tool, determine the cutter number and edge (patch) number, the input diameter of the outer circle and the end face of the vehicle. Enter the negative value of the step depth. Calculate and confirm.Tool setting method of 2. wide number GSK980T system(1) cutting the workpiece with the reference knife, setting the reference coordinate system: cutting the end face X, returning the knife, entering the input mode, pressing the program button. Enter G50 Z0, that is, the end face as Z to the base plane. Then press the settings button, set the offset number (reference knife +100), enter Z=0, try cutting the outer circle, Z to the knife, measure the diameter of the outer circle, enter the entry mode, press the program button. Enter G50X, and then press the settings button to set the offset number, the reference knife offset number +100, X=.(2) call each other tool, the outer circle of the car and the Z to return the knife. Measure the diameter of the outer circle and set the measured value to an offset number. The offset is +100. If the number is 2, the offset number is 202. Enter X= here. In the same way, the step of the car and the X retractthe knife to measure the depth of the step,Enter Z=- at the offset number.Tool setting method of 3. wide number GSK928TC system(1) cutting the workpiece with the reference cutter, and setting up the cutter coordinate system with input. The coordinate system is Z to the origin, which is usually located at the right end of the workpiece, that is to say, the cut end face is taken as Z zero.(2) call other knives, such as 2 knives, call with T20, and then try to cut the outer circle, Z, retract the knife, measure the diameter, and press the I key. Input. Try cutting the steps, X to the knife, measuring the depth of the step, and then press the K key, input -, the knife is set up.The direction of the 4.2.5 coordinate axisEither coordinate system specifies that the axis parallel to the spindle axis of the lathe is the Z axis, and the center of the center from the center of the chuck to the tailstock is in the positive direction. In the horizontal plane, the direction perpendicular to the axis of the lathe spindle is X axis, and the direction of the rotation center away from the main shaft is in the positive direction.4.2.6 diameter or radius dimensions are programmedThe radial dimension of the machined part is usually indicatedby the diameter value in the process of drawing and processing. Therefore, it is more convenient to program with diameter.4.2.7 general programming method1. make sure the location of the first knifeG50 X Z, this command determines the position of the first knife, at which point the first knife is moved to the workpiece coordinates of X Z.2. returns the reference pointG26 (G28): the X Z axis returns the reference point at the same time, the G27:X axis returns the reference point, and the G29:Z axis returns the reference point.3. fast positioningG00 X Z, quick to locate the specified point.4. linear interpolationG01 X Z F, this instruction is used for the outer circle and end face of car. F is the feed rate,其单位为mm / min (用g94或g98指定) 或mm / r (用g95或g99指定).5.圆弧插补g02 (03) x z in k f 该指令用于车顺圆或逆圆周.x z为圆弧终点坐标, in k为圆心相对于起点的坐标, f为进给速度.6.螺纹切削g33 (32) x z p (e) in k 该指令用于螺纹切削, x z为螺纹终点坐标, p为公制螺纹导程 (0.25-100mm), e为英制螺纹导程 (100 - 4牙 / 英寸), in k为退尾数据.螺纹切削时主轴转速不能太高, 一般n×p≤3000, n为主轴转速 (rpm), p为公制螺纹导程 (mm).7. 延时或暂停g04 x, x为暂停秒数, 该指令一般用于切槽, 可保持槽底光滑.8.主轴转速设定m03 (04) 该指令用于主轴顺时针或逆时针转, 主轴转速为s, 其单位为m / min (用g96指定) 或r / min (用g97指定).m05表示主轴停止.9.程序结束m02 (在此处结束) 或m30 (结束后返回程序首句).4.2.8 循环由于车削加工常用棒料和锻料作为毛坯, 加工余量较大, 为简化编程, 数控车床常具备不同形式的固定循环, 可进行多次循环切削.1. 外径、内径循环g90 x z r f 该指令用于外径、内径的简单车削循环, x z为循环终点坐标, r表示圆锥面循环.其值为圆锥体大小端差 (直径差), 循环起点由上句程序决定,F is the feed rate.2. thread turning cycleG92 X Z P (E) I K R L the instructions for thread turning cycle, X Z P as the end point coordinate thread, metric thread lead (0.25-100mm), E (100-4 inch thread lead tooth / inch) K, I back tail data, R said the starting point and end point thread diameter difference (used for machining taper thread), L said the thread number, thread turning cycle starting point determined by the procedure. The difference between the G92 instruction and the G33 instruction is that the G92 can automatically cut threads many times.3. end turning cycleG94 X Z R F. This instruction is used for the simple turning cycle of the end face. The X Z is the loop end point coordinate, and the R represents the cone cycle. Its value is the size of the cone, the end difference (Z to the difference), the starting point of the cycle is determined by the previous sentence procedure, and the F is the feed rate.4. groove cycleG75 X Z I K E F the instructions for cutting cycle, X Z cycle end point coordinates, I for the amount of feed each X axis,K axis X knife back every time, every time the E for the Z axis offset, F feed rate, Z said cut off.5., outer circle, rough car, compound cycleG71 X I K L F this instruction is used in the outer circle rough vehicle compound cycle, namely when programming writes the excircle processing shape, the system starts from the semifinished material to go out automatically the outer circle shape. The loop is parallel to the Z axis cutting, X circular end point coordinates, I for the amount of feed each X axis, K axis X knife back every time, L decided to program process of cylindrical shape quantity, F velocity, G71 program instruction segment immediately after the decision process of cylindrical shape of the ground.6. end rough vehicle combined cycleG72 Z I K L F this instruction is used in the end face rough vehicle compound cycle, namely when programming writes the end surface processing shape, the system starts from the semifinished material to go out automatically the end face cycle shape. The loop is parallel to the X axis cutting, Z circular end point coordinates, I for the amount of feed each Z axis, K axis Z knife back every time, L decided to end processing program segment shape quantity, F velocity, G72 program instruction segment immediately after the decisions end processing shape.4.2.9 tool compensationWhen programming, that the turning point is a point, but in fact in order to improve tool life and surface quality of the workpiece, tool nose often ground into a small circular arc radius, in order to improve the machining precision of the workpiece, preparation of round knife program, need to compensate for the tool radius. Most CNC lathes have automatic tool radius compensation (G41, G42), which can be programmed directly according to the outline dimensions of the workpiece.4.2.10 absolute coordinates and incremental coordinatesX and Z represent absolute coordinates, and U and W represent relative coordinates.4.2.11 metric and inch size settingThe metric size setting instruction G21, the grandfather size setting instruction G20, and the system is powered on, the machine is in the G21 state.The judgement of the arc of 4.2.12CNC lathe is a two coordinate machine tool, only the X axis and Z axis, the right hand rule should be based on the Y axis is also added to consider. When judging, let the positive direction of the Y axis point to itself, that is, to look in the negative direction of the Y axis. Standing in such a position, the clockwise and counterclockwise clockwise of the arc on the X-Z plane can be correctly judged.4.3. typical parts NC lathe programming example。
使用 gcode 坐标
G代码是数控编程中常用的一种语言,用于指导机床进行加工操作。
在G代码中,可以使用不同的坐标系来表示工件和刀具的位置。
在G代码中,常用的坐标系有绝对坐标系和相对坐标系。
绝对坐标系以机床原点为参考,表示工件或刀具在机床坐标系中的绝对位置。
相对坐标系则以当前位置为参考,表示工件或刀具相对于当前位置的偏移量。
在G代码中,可以使用G90和G91指令来设置坐标系的类型。
G90指令表示使用绝对坐标系,而G91指令表示使用相对坐标系。
例如,如果要让刀具从当前位置移动到工件上的某个绝对位置,可以使用类似下面的G代码指令:
gcode
G90 G0 X10 Y20 Z5
上面的指令中,G90表示使用绝对坐标系,G0表示进行快速移动,X10 Y20 Z5则表示目标位置的坐标值。
如果要让刀具从当前位置相对移动一段距离,可以使用类似下面的G代码指令:
gcode
G91 G0 X5 Y10 Z2
上面的指令中,G91表示使用相对坐标系,G0表示进行快速移动,X5 Y10 Z2则表示相对于当前位置的偏移量。
需要注意的是,在使用G代码进行数控编程时,应该根据具体的机床型号和控制系统来确定支持的坐标系类型和指令格式。
Gcode G代码详解
reprap wiki上面的Gcode说明G-codeFrom RepRapWiki(Redirected from Gcode)Jump to: navigation, searchContents [hide]1 Introduction2 RepRap G Code Fields3 Comments4 Individual commands4.1 Checking4.1.1 N and *4.2 Buffered G Commands4.2.1 G0: Rapid move4.2.2 G1: Controlled move4.2.3 G28: Move to Origin4.3 Unbuffered G commands4.3.1 G4: Dwell4.3.2 G20: Set Units to Inches4.3.3 G21: Set Units to Millimeters4.3.4 G90: Set to Absolute Positioning4.3.5 G91: Set to Relative Positioning4.3.6 G92: Set Position4.4 Unbuffered M and T commands4.4.1 M0: Stop4.4.2 M17: Enable/Power all stepper motors 4.4.3 M18: Disable all stepper motors4.4.4 M20: List SD card4.4.5 M21: Initialise SD card4.4.6 M22: Release SD card4.4.7 M23: Select SD file4.4.8 M24: Start/resume SD print4.4.9 M25: Pause SD print4.4.10 M26: Set SD position4.4.11 M27: Report SD print status4.4.12 M28: Begin write to SD card4.4.13 M29: Stop writing to SD card4.4.14 M40: Eject4.4.15 M41: Loop4.4.16 M42: Stop on material exhausted 4.4.17 M43: Stand by on material exhausted 4.4.18 M80: ATX Power On4.4.19 M81: ATX Power Off4.4.20 M84: Stop idle hold4.4.21 M92: Set axis_steps_per_unit4.4.22 M101 Turn extruder 1 on Forward4.4.23 M102 Turn extruder 1 on Reverse4.4.24 M103 Turn all extruders off4.4.25 M104: Set Extruder Temperature (Fast)4.4.26 M105: Get Extruder Temperature4.4.27 M106: Fan On4.4.28 M107: Fan Off4.4.29 M108: Set Extruder Speed4.4.30 M109: Set Extruder Temperature4.4.31 M110: Set Current Line Number4.4.32 M111: Set Debug Level4.4.33 M112: Emergency Stop4.4.34 M113: Set Extruder PWM4.4.35 M114: Get Current Position4.4.36 M115: Get Firmware Version and Capabilities4.4.37 M116: Wait4.4.38 M117: Get Zero Position4.4.39 M118: Negotiate Features4.4.40 M119: Get Endstop Status4.4.41 M126: Open Valve4.4.42 M127: Close Valve4.4.43 M128: Extruder Pressure PWM4.4.44 M129: Extruder pressure off4.4.45 M140: Bed Temperature (Fast)4.4.46 M141: Chamber Temperature (Fast)4.4.47 M142: Holding Pressure4.4.48 M143: Maximum hot-end temperature4.4.49 M160: Number of mixed materials4.4.50 M203: Record Z adjustment4.4.51 M226: Gcode Initiated Pause4.4.52 M227: Enable Automatic Reverse and Prime4.4.53 M228: Disable Automatic Reverse and Prime4.4.54 M229: Enable Automatic Reverse and Prime4.4.55 M230: Disable / Enable Wait for Temperature Change 4.4.56 M240: Start conveyor belt motor4.4.57 M241: Stop conveyor belt motor4.4.58 M245: Start cooler4.4.59 M246: Stop cooler4.4.60 M300: Play beep sound4.4.61 T: Select Tool5 Proposed EEPROM configuration codes6 Replies from the RepRap machine to the host computer7 Proposal for sending multiple lines of G-code7.1 Problem to solveIntroductionThis page describes the G Codes that the RepRap firmware uses and how they work.The list of what can be done is extensible. But check this page first, and add your extension here first before you implement it.A typical piece of GCode as sent to a RepRap machine might look like this:N3 T0*57N4 G92 E0*67N5 G28*22N6 G1 F1500.0*82N7 G1 X2.0 Y2.0 F3000.0*85N8 G1 X3.0 Y3.0*33The meaning of all those symbols and numbers (and more) is explained below.TO find out which specific gcode/s are implemented in any given firmware, please see the Firmware_features page.(For the technically minded, the end of line is marked by both a <nl> and a <cr>. If you want to manually enter GCodes in your reprap using the Arduino Serial interface, make sure to select "Both NL & CR" on the bottom of the screen.)This isn't accurate, firmware accepts single <nl> as well as single <cr>, or combinations thereof. Hosts should accepts all four combinations as well. --Traumflug 09:34, 20 April 2011 (UTC)RepRap G Code FieldsThis section explains the letter-preceded fields. The numbers in the fields are represented by nnn. Numbers can be integers, or can contain a decimal point, depending on context. For example an X coordinate can be integer (X175) or fractional (X17.62), whereas trying to select extruder number 2.76 would make no sense.Letter MeaningGnnn Standard GCode command, such as move to a pointMnnn RepRap-defined command, such as turn on a cooling fanTnnn Select tool nnn. In RepRap, tools are extrudersSnnn Command parameter, such as the voltage to send to a motorPnnn Command parameter, such as a time in millisecondsXnnn An X coordinate, usually to move toYnnn A Y coordinate, usually to move toZnnn A Z coordinate, usually to move toInnn Parameter - not currently usedJnnn Parameter - not currently usedFnnn Feedrate in mm per minute. (Speed of print head movement)Rnnn Parameter - not currently usedQnnn Parameter - not currently usedEnnn Length of extrudate in mm. This is exactly like X, Y and Z, but for the length of filament to extrude. It is common for newer stepper based systems to interpret ... Better: Skeinforge 40 and up interprets this as the absolute length of input filament to consume, rather than the length of the extruded output.Nnnn Line number. Used to request repeat transmission in the case of communications errors. *nnn Checksum. Used to check for communications errors.CommentsG Code comments:N3 T0*57 ;This is a commentN4 G92 E0*67; So is thisN5 G28*22Will be ignored by RepRap, as will blank lines. But it's better to strip these out in the host computer before the lines are sent. This saves bandwidth.Individual commandsCheckingN and *Example: N123 [...G Code in here...] *71These are the line number and the checksum. The RepRap firmware checks the checksum against a locally-computed value and, if they differ, requests a repeat transmission of the line of the given number.You can leave both of these out - RepRap will still work, but it won't do checking. You have to have both or neither though.The checksum "cs" for a GCode string "cmd" (including its line number) is computed by exor-ing the bytes in the string up to and not including the * character as follows:int cs = 0;for(i = 0; cmd[i] != '*' && cmd[i] != NULL; i++)cs = cs ^ cmd[i];cs &= 0xff; // Defensive programming...and the value is appended as a decimal integer to the command after the * character.The RepRap firmware expects line numbers to increase by 1 each line, and if that doesn't happen it is flagged as an error. But you can reset the count using M110 (see below).Buffered G CommandsThe RepRap firmware stores these commands in a ring buffer internally for execution. This means that there is no (appreciable) delay while a command is acknowledged and the next transmitted. In turn, this means that sequences of line segments can be plotted without a dwell between one and the next. As soon as one of these buffered commands is received it is acknowledged and stored locally. If the local buffer is full, then the acknowledgment is delayed until space for storage in the buffer is available. This is how flow control is achieved.G0: Rapid moveExample: G0 X12In this case move rapidly to X = 12 mm. In fact, the RepRap firmware uses exactly the same code for rapid as it uses for controlled moves (see G1 below), as - for the RepRap machine - this is just as efficient as not doing so. (The distinction comes from some old machine tools that used to move faster if the axes were not driven in a straight line. For them G0 allowed any movement in space to get to the destination as fast as possible.)G1: Controlled moveExample: G1 X90.6 Y13.8 E22.4Go in a straight line from the current (X, Y) point to the point (90.6, 13.8), extruding material as the move happens from the current extruded length to a length of 22.4 mm.RepRap does subtle things with feedrates. Thus:G1 F1500G1 X90.6 Y13.8 E22.4Will set a feedrate of 1500 mm/minute, then do the move described above at that feedrate. ButG1 F1500G1 X90.6 Y13.8 E22.4 F3000Will set a feedrate of 1500 mm/minute, then do the move described above accelerating to a feedrate of 3000 mm/minute as it does so. The extrusion will accelerate along with the X, Y movement so everything stays synchronized.RepRap thus treats feedrate as simply another variable (like X, Y, Z, and E) to be linearly interpolated. This gives complete control over accelerations and decelerations in a way that ensures that everything moves together and the right volume of material is extruded at all points.The first example shows how to get a constant-speed movement. The second how to accelerate or decelerate. ThusG1 F1500G1 X90.6 Y13.8 E22.4 F3000G1 X80 Y20 E36 F1500Will do the first movement accelerating as before, and the second decelerating from 3000 mm/minute back to 1500 mm/minute.To reverse the extruder by a given amount (for example to reduce its internal pressure while it does an in-air movement so that it doesn't dribble) simply use G1 to send an E value that is less than the currently extruded length.G28: Move to OriginExample: G28This causes the RepRap machine to move back to its X, Y and Z zero endstops, a process known as "homing". It does so accelerating, so as to get there fast. But when it arrives it backs off by 1 mm in each direction slowly, then moves back slowly to the stop. This ensures more accurate positioning.If you add coordinates, then just the axes with coordinates specified will be zeroed. ThusG28 X0 Y72.3will zero the X and Y axes, but not Z. The actual coordinate values are ignored.Unbuffered G commandsThe following commands are not buffered. When one is received it is stored, but it is not acknowledged to the host until the buffer is exhausted and then the command has been executed. Thus the host will pause at one of these commands until it has been done. Short pauses between these commands and any that might follow them do not affect the performance of the machine.G4: DwellExample: G4 P200In this case sit still doing nothing for 200 milliseconds. During delays the state of the machine (for example the temperatures of its extruders) will still be preserved and controlled.G20: Set Units to InchesExample: G20Units from now on are in inches.G21: Set Units to MillimetersExample: G21Units from now on are in millimeters. (This is the RepRap default.)G90: Set to Absolute PositioningExample: G90All coordinates from now on are absolute relative to the origin of the machine. (This is the RepRap default.)G91: Set to Relative PositioningExample: G91All coordinates from now on are relative to the last position.G92: Set PositionExample: G92 X10 E90Allows programming of absolute zero point, by reseting the current position to the values specified. This would set the machine's X coordinate to 10, and the extrude coordinate to 90. No physical motion will occur.Unbuffered M and T commandsM0: StopExample: M0The RepRap machine finishes any moves left in its buffer, then shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M112.M17: Enable/Power all stepper motorsExample: M17M18: Disable all stepper motorsExample: M18Disables stepper motors and allows axis to move 'freely.'M20: List SD cardExample: M20All files in the root folder of the SD card are listed to the serial port. This results in a line like:ok Files: {SQUARE.G,SQCOM.G,}The trailing comma is optional. Note that file names are returned in upper case, but - when sent to the M23 command (below) they must be in lower case. This seems to be a function of the SD software. Go figure...M21: Initialise SD cardExample: M21The SD card is initialised. If an SD card is loaded when the machine is switched on, this will happen by default. SD card must be initialised for the other SD functions to work.M22: Release SD cardExample: M22SD card is released and can be physically removed.M23: Select SD fileExample: M23 filename.gcoThe file specified as filename.gco (8.3 naming convention is supported) is selected ready for printing.M24: Start/resume SD printExample: M24The machine prints from the file selected with the M23 command.M25: Pause SD printExample: M25The machine pause printing at the current position within the file selected with the M23 command.M26: Set SD positionExample: M26Set SD position in bytes (M26 S12345).M27: Report SD print statusExample: M27Report SD print status.M28: Begin write to SD cardExample: M28 filename.gcoFile specified by filename.gco is created (or overwritten if it exists) on the SD card and all subsequent commands sent to the machine are written to that file.M29: Stop writing to SD cardExample: M29 filename.gcoFile opened by M28 command is closed, and all subsequent commands sent to the machine are executed as normal.M40: EjectIf your RepRap machine can eject the parts it has built off the bed, this command executes the eject cycle. This usually involves cooling the bed and then performing a sequence of movements that remove the printed parts from it. The X, Y and Z position of the machine at the end of this cycle are undefined (though they can be found out using the M114 command, q.v.).See also M240 and M241 below.M41: LoopExample: M41If the RepRap machine was building a file from its own memory such as a local SD card (as opposed to a file being transmitted to it from a host computer) this goes back to the beginning of the file and runs it again. So, for example, if your RepRap is capable of ejecting parts from its build bed then you can set it printing in a loop and it will run and run. Use with caution - the only things that will stop it are:1.When you press the reset button,2.When the build material runs out (if your RepRap is set up to detect this), and3.When there's an error (such as a heater failure).M42: Stop on material exhaustedExample: M42If your RepRap can detect when its material runs out, this decides the behaviour when that happens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off. You have to press reset to reactivate the machine. In other words, it parks itself and then executes an M0 command (q.v.).M43: Stand by on material exhaustedExample: M43If your RepRap can detect when its material runs out, this decides the behaviour when thathappens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off except the heated bed, the temperature of which is maintained. The machine will still respond to G and M code commands in this state.M80: ATX Power OnExample: M80Turns on the ATX power supply from standby mode to fully operational mode. No-op on electronics without standby mode.Note: some firmwares, like Teacup, handle power on/off automatically, so this is redundant there.M81: ATX Power OffExample: M81Turns off the ATX power supply. Counterpart to M80.M84: Stop idle holdExample: M84Stop the idle hold on all axis and extruder. In some cases the idle hold causes annoying noises, which can be stopped by disabling the hold. Be aware that by disabling idle hold during printing, you will get quality issues. This is recommended only in between or after printjobs.M92: Set axis_steps_per_unitExample: M92 X<newsteps> Sprinter and MarlinAllows programming of steps per unit of axis till the electronics are reset for the specified axis. Very useful for calibration.M101 Turn extruder 1 on ForwardDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM102 Turn extruder 1 on ReverseDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM103 Turn all extruders offDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM104: Set Extruder Temperature (Fast)Example: M104 S190Set the temperature of the current extruder to 190oC and return control to the host immediately (i.e. before that temperature has been reached by the extruder). See also M109.M105: Get Extruder TemperatureExample: M105Request the temperature of the current extruder and the build base in degrees Celsius. The temperatures are returned to the host computer. For example, the line sent to the host in response to this command looks likeok T:201 B:117M106: Fan OnExample: M106 S127Turn on the cooling fan at half speed. Optional parameter 'S' declares the PWM value (0-255)M107: Fan OffExample: M107Turn off the cooling fan (if any).M108: Set Extruder SpeedSets speed of extruder motor. (Deprecated in current firmware, see M113)M109: Set Extruder TemperatureExample: M109 S190Set the temperature of the current extruder to 190oC and wait for it to reach that value before sending an acknowledgment to the host. In fact the RepRap firmware waits a while after the temperature has been reached for the extruder to stabilise - typically about 40 seconds. This can be changed by a parameter in the firmware configuration file when the firmware is compiled. See also M104 and M116.M110: Set Current Line NumberExample: N123 M110Set the current line number to 123. Thus the expected next line after this command will be 124.M111: Set Debug LevelExample: M111 S6Set the level of debugging information transmitted back to the host to level 6. The level is the OR of three bits:#define DEBUG_ECHO (1<<0)#define DEBUG_INFO (1<<1)#define DEBUG_ERRORS (1<<2)Thus 6 means send information and errors, but don't echo commands. (This is the RepRap default.)M112: Emergency StopExample: M112Any moves in progress are immediately terminated, then RepRap shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M0.M113: Set Extruder PWMExample: M113Set the PWM for the currently-selected extruder. On its own this command sets RepRap to use the on-board potentiometer on the extruder controller board to set the PWM for the currently-selected extruder's stepper power. With an S field:M113 S0.7it causes the PWM to be set to the S value (70% in this instance). M113 S0 turns the extruder off, until an M113 command other than M113 S0 is sent.M114: Get Current PositionExample: M114This causes the RepRap machine to report its current X, Y, Z and E coordinates to the host.For example, the machine returns a string such as:ok C: X:0.00 Y:0.00 Z:0.00 E:0.00M115: Get Firmware Version and CapabilitiesExample: M115Request the Firmware Version and Capabilities of the current microcontroller The details are returned to the host computer as key:value pairs separated by spaces and terminated with alinefeed.sample data from firmware:ok PROTOCOL_VERSION:0.1 FIRMWARE_NAME:FiveD FIRMWARE_URL:http%3A// MACHINE_TYPE:Mendel EXTRUDER_COUNT:1This M115 code is inconsistently implemented, and should not be relied upon to exist, or output correctly in all cases. An initial implementation was committed to svn for the FiveD Reprap firmware on 11 Oct 2010. Work to more formally define protocol versions is currently (October 2010) being discussed. See M115_Keywords for one draft set of keywords and their meanings.M116: WaitExample: M116Wait for all temperatures and other slowly-changing variables to arrive at their set values. See also M109.M117: Get Zero PositionExample: M117This causes the RepRap machine to report the X, Y, Z and E coordinates in steps not mm to the host that it found when it last hit the zero stops for those axes. That is to say, when you zero X, the x coordinate of the machine when it hits the X endstop is recorded. This value should be 0, of course. But if the machine has drifted (for example by dropping steps) then it won't be. This command allows you to measure and to diagnose such problems. (E is included for completeness. It doesn't normally have an endstop.)M118: Negotiate FeaturesExample: M118 P42This M-code is for future proofing. NO firmware or hostware supports this at the moment. It is used in conjunction with M115's FEATURES keyword.See Protocol_Feature_Negotiation for more info.M119: Get Endstop StatusExample: M119Returns the current state of the configured X,Y,Z endstops. Should take into account any 'inverted endstop' settings, so one can confirm that the machine is interpreting the endstops correctly.M126: Open ValveExample: M126 P500Open the extruder's valve (if it has one) and wait 500 milliseconds for it to do so.M127: Close ValveExample: M127 P400Close the extruder's valve (if it has one) and wait 400 milliseconds for it to do so.M128: Extruder Pressure PWMExample: M128 S255PWM value to control internal extruder pressure. S255 is full pressure.M129: Extruder pressure offExample: M129 P100In addition to setting Extruder pressure to 0, you can turn the pressure off entirely. P400 will wait 100ms to do so.M140: Bed Temperature (Fast)Example: M140 S55Set the temperature of the build bed to 55oC and return control to the host immediately (i.e. before that temperature has been reached by the bed).M141: Chamber Temperature (Fast)Example: M141 S30Set the temperature of the chamber to 30oC and return control to the host immediately (i.e. before that temperature has been reached by the chamber).M142: Holding PressureExample: M142 S1Set the holding pressure of the bed to 1 bar.The holding pressure is in bar. For hardware which only has on/off holding, when the holding pressure is zero, turn off holding, when the holding pressure is greater than zero, turn on holding.M143: Maximum hot-end temperatureExample: M143 S275Set the maximum temperature of the hot-end to 275CWhen temperature of the hot-end exceeds this value, take countermeasures, for instance anemergency stop. This is to prevent hot-end damage.M160: Number of mixed materialsExample: M160 S4Set the number of materials, N, that the current extruder can handle to the number specified. The default is 1.When N >= 2, then the E field that controls extrusion requires N+1 values separated by spaces after it like this:M160 S4G1 X90.6 Y13.8 E22.4 0.1 0.1 0.1 0.7G1 X70.6 E42.4 0.0 0.0 0.0 1.0G1 E42.4 1.0 0.0 0.0 0.0The second line moves straight to the point (90.6, 13.8) extruding 22.4mm of filament. The mix ratio at the end of the move is 0.1:0.1:0.1:0.7.The third line moves back 20mm in X extruding 20mm of filament. The mix varies linearly from 0.1:0.1:0.1:0.7 to 0:0:0:1 as the move is made.The fourth line has no physical effect, but sets the mix proportions for the start of the next move to 1:0:0:0.M203: Record Z adjustmentExample: M203 Z-0.75This records a Z offset in non-volatile memory in RepRap's microcontroller where it remains active until next set, even when the power is turned off and on again. If the first layer is too close to the bed, you need to effectively move the bed down, so the Z value will be negative. If the nozzle is too far from the bed during the first layer, the Z value should be positive to raise the bed. The maximum adjustment is +/-1.27mm.M226: Gcode Initiated PauseExample: M226Initiates a pause in the same way as if the pause button is pressed.M227: Enable Automatic Reverse and PrimeExample: M227 P1600 S1600P and S are steps.M228: Disable Automatic Reverse and PrimeExample: M228M229: Enable Automatic Reverse and PrimeExample: M229 P1.0 S1.0P and S are extruder screw rotations.M230: Disable / Enable Wait for Temperature ChangeExample: M230 S1S1 Disable wait for temperature change S0 Enable wait for temperature changeM240: Start conveyor belt motorExample: M240The conveyor belt allows to start mass production of a part with a reprapM241: Stop conveyor belt motorExample: M241M245: Start coolerExample: M245used to cool parts/heated-bed down after printing for easy remove of the parts after printM246: Stop coolerExample: M246M300: Play beep soundUsage: M300 S<frequency Hz> P<duration ms>Example: M300 S300 P1000Play beep sound, use to notify important events like the end of printing. See working example on R2C2 electronics.T: Select ToolExample: T1Select extruder number 1 to build with. Extruder numbering starts at 0.Proposed EEPROM configuration codesBRIEFLY: each RepRap has a number of physical parameters that should be persistent, but easily configurable, such as extrusion steps/mm, various max values, etc. Those parameters are currently hardcoded in the firmware, so that a user has to modify, recompile and re-flash the firmware for any adjustments. These configs can be stored in MCU's EEPROM and modified via some M-codes. Please see the detailed proposal at M-codes for EEPROM config. (This is proposed by --AlexRa on 11-March-2011. There is currently no working implementation of the proposed commands).Replies from the RepRap machine to the host computerAll communication is in printable ASCII characters. Messages sent back to the host computer are terminated by a newline and look like this:xx [line number to resend] [T:93.2 B:22.9] [C: X:9.2 Y:125.4 Z:3.7 E:1902.5] [Some debugging or other information may be here]xx can be one of:okrs!!ok means that no error has been detected.rs means resend, and is followed by the line number to resend.!! means that a hardware fault has been detected. The RepRap machine will shut down immediately after it has sent this message.The T: and B: values are the temperature of the currently-selected extruder and the bed respectively, and are only sent in response to M105. If such temperatures don't exist (for example for an extruder that works at room temperature and doesn't have a sensor) then a value below absolute zero (-273oC) is returned.C: means that coordinates follow. Those are the X: Y: etc values. These are only sent in response to M114 and M117.The RepRap machine may also send lines that look like this:// This is some debugging or other information on a line on its own. It may be sent at any time.Such lines will always be preceded by //.The most common response is simply:okWhen the machine boots up it sends the stringstartonce to the host before sending anything else. This should not be replaced or augmented by version numbers and the like. M115 (see above) requests those.All this means that every line sent by RepRap to the host computer except the start line has a two-character prefix (one of ok, rs, !! or //). The machine should never send a line without such a prefix.。
Gcode G代码详解
reprap wiki上面得Gcode说明G-codeFrom RepRapWiki(Redirected from Gcode)Jump to: navigation, searchContents [hide]1 Introduction2 RepRap G Code Fields3 ments4 Individual mands4、1 Checking4、1、1 N and *4、2 Buffered G mands4、2、1 G0: Rapid move4、2、2 G1: Controlled move4、2、3 G28: Move to Origin4、3 Unbuffered G mands4、3、1 G4: Dwell4、3、2 G20: Set Units to Inches4、3、3 G21: Set Units to Millimeters4、3、4 G90: Set to Absolute Positioning4、3、5 G91: Set to Relative Positioning4、3、6 G92: Set Position4、4 Unbuffered M and T mands4、4、1 M0: Stop4、4、2 M17: Enable/Power all stepper motors4、4、3 M18: Disable all stepper motors4、4、4 M20: List SD card4、4、5 M21: Initialise SD card4、4、6 M22: Release SD card4、4、7 M23: Select SD M24: Start/resume SD print 4、4、9 M25: Pause SD print4、4、10 M26: Set SD position4、4、11 M27: Report SD print status4、4、12 M28: Begin write to SD card4、4、13 M29: Stop writing to SD card4、4、14 M40: Eject4、4、15 M41: Loop4、4、16 M42: Stop on material exhausted4、4、17 M43: Stand by on material exhausted4、4、18 M80: ATX Power On4、4、19 M81: ATX Power Off4、4、20 M84: Stop idle hold4、4、21 M92: Set axis_steps_per_unit4、4、22 M101 Turn extruder 1 on Forward4、4、23 M102 Turn extruder 1 on Reverse4、4、24 M103 Turn all extruders off4、4、25 M104: Set Extruder Temperature (Fast)4、4、26 M105: Get Extruder Temperature4、4、27 M106: Fan On4、4、28 M107: Fan Off4、4、29 M108: Set Extruder Speed4、4、30 M109: Set Extruder Temperature4、4、31 M110: Set Current Line Number4、4、32 M111: Set Debug Level4、4、33 M112: Emergency Stop4、4、34 M113: Set Extruder PWM4、4、35 M114: Get Current Position4、4、36 M115: Get Firmware Version and Capabilities4、4、37 M116: Wait4、4、38 M117: Get Zero Position4、4、39 M118: Negotiate Features4、4、40 M119: Get Endstop Status4、4、41 M126: Open Valve4、4、42 M127: Close Valve4、4、43 M128: Extruder Pressure PWM4、4、44 M129: Extruder pressure off4、4、45 M140: Bed Temperature (Fast)4、4、46 M141: Chamber Temperature (Fast)4、4、47 M142: Holding Pressure4、4、48 M143: Maximum hot-end temperature4、4、49 M160: Number of mixed materials4、4、50 M203: Record Z adjustment4、4、51 M226: Gcode Initiated Pause4、4、52 M227: Enable Automatic Reverse and Prime4、4、53 M228: Disable Automatic Reverse and Prime4、4、54 M229: Enable Automatic Reverse and Prime4、4、55 M230: Disable / Enable Wait for Temperature Change 4、4、56 M240: Start conveyor belt motor4、4、57 M241: Stop conveyor belt motor4、4、58 M245: Start cooler4、4、59 M246: Stop cooler4、4、60 M300: Play beep sound4、4、61 T: Select Tool5 Proposed EEPROM configuration codes6 Replies from the RepRap machine to the host puter7 Proposal for sending multiple lines of G-code7、1 Problem to solveIntroductionThis page describes the G Codes that the RepRap firmware uses and how they work、The list of what can be done is extensible、But check this page first, and add your extension here first before you implement it、A typical piece of GCode as sent to a RepRap machine might look like this:N3 T0*57N4 G92 E0*67N5 G28*22N6 G1 F1500、0*82N7 G1 X2、0 Y2、0 F3000、0*85N8 G1 X3、0 Y3、0*33The meaning of all those symbols and numbers (and more) is explained below、TO find out which specific gcode/s are implemented in any given firmware, please see the Firmware_features page、(For the technically minded, the end of line is marked by both a <nl> and a <cr>、If you want to manually enter GCodes in your reprap using the Arduino Serial interface, make sure to select "Both NL & CR" on the bottom of the screen、)This isn't accurate, firmware accepts single <nl> as well as single <cr>, or binations thereof、Hosts should accepts all four binations as well、--Traumflug 09:34, 20 April 2011 (UTC) RepRap G Code FieldsThis section explains the letter-preceded fields、The numbers in the fields are represented by nnn、Numbers can be integers, or can contain a decimal point, depending on context、For example an X coordinate can be integer (X175) or fractional (X17、62), whereas trying to select extruder number 2、76 would make no sense、Letter MeaningGnnn Standard GCode mand, such as move to a pointMnnn RepRap-defined mand, such as turn on a cooling fanTnnn Select tool nnn、In RepRap, tools are extrudersSnnn mand parameter, such as the voltage to send to a motorPnnn mand parameter, such as a time in millisecondsXnnn An X coordinate, usually to move toYnnn A Y coordinate, usually to move toZnnn A Z coordinate, usually to move toInnn Parameter - not currently usedJnnn Parameter - not currently usedFnnn Feedrate in mm per minute、(Speed of print head movement)Rnnn Parameter - not currently usedQnnn Parameter - not currently usedEnnn Length of extrudate in mm、This is exactly like X, Y and Z, but for the length of filament to extrude、It is mon for newer stepper based systems to interpret 、、、Better: Skeinforge 40 and up interprets this as the absolute length of input filament to consume, rather than the length of the extruded output、Nnnn Line number、Used to request repeat transmission in the case of munications errors、*nnn Checksum、Used to check for munications errors、mentsG Code ments:N3 T0*57 ;This is a mentN4 G92 E0*67; So is thisN5 G28*22Will be ignored by RepRap, as will blank lines、But it's better to strip these out in the host puter before the lines are sent、This saves bandwidth、Individual mandsCheckingN and *Example: N123 [、、、G Code in here、、、] *71These are the line number and the checksum、The RepRap firmware checks the checksum against a locally-puted value and, if they differ, requests a repeat transmission of the line of the given number、You can leave both of these out - RepRap will still work, but it won't do checking、You have to have both or neither though、The checksum "cs" for a GCode string "cmd" (including its line number) is puted by exor-ing the bytes in the string up to and not including the * character as follows:int cs = 0;for(i = 0; cmd[i] != '*' && cmd[i] != NULL; i++)cs = cs ^ cmd[i];cs &= 0xff; // Defensive programming、、、and the value is appended as a decimal integer to the mand after the * character、The RepRap firmware expects line numbers to increase by 1 each line, and if that doesn't happen it is flagged as an error、But you can reset the count using M110 (see below)、Buffered G mandsThe RepRap firmware stores these mands in a ring buffer internally for execution、This means that there is no (appreciable) delay while a mand is acknowledged and the next transmitted、In turn, this means that sequences of line segments can be plotted without a dwell between one and the next、As soon as one of these buffered mands is received it is acknowledged and stored locally、If the local buffer is full, then the acknowledgment is delayed until space for storage in the buffer is available、This is how flow control is achieved、G0: Rapid moveExample: G0 X12In this case move rapidly to X = 12 mm、In fact, the RepRap firmware uses exactly the same code for rapid as it uses for controlled moves (see G1 below), as - for the RepRap machine - this is just as efficient as not doing so、(The distinction es from some old machine tools that used to move faster if the axes were not driven in a straight line、For them G0 allowed any movement in space to get to the destination as fast as possible、)G1: Controlled moveExample: G1 X90、6 Y13、8 E22、4Go in a straight line from the current (X, Y) point to the point (90、6, 13、8), extruding material as the move happens from the current extruded length to a length of 22、4 mm、RepRap does subtle things with feedrates、Thus:G1 F1500G1 X90、6 Y13、8 E22、4Will set a feedrate of 1500 mm/minute, then do the move described above at that feedrate、But G1 F1500G1 X90、6 Y13、8 E22、4 F3000Will set a feedrate of 1500 mm/minute, then do the move described above accelerating to a feedrate of 3000 mm/minute as it does so、The extrusion will accelerate along with the X, Y movement so everything stays synchronized、RepRap thus treats feedrate as simply another variable (like X, Y, Z, and E) to be linearly interpolated、This gives plete control over accelerations and decelerations in a way that ensures that everything moves together and the right volume of material is extruded at all points、The first example shows how to get a constant-speed movement、The second how to accelerate or decelerate、ThusG1 F1500G1 X90、6 Y13、8 E22、4 F3000G1 X80 Y20 E36 F1500Will do the first movement accelerating as before, and the second decelerating from 3000 mm/minute back to 1500 mm/minute、To reverse the extruder by a given amount (for example to reduce its internal pressure while it does an in-air movement so that it doesn't dribble) simply use G1 to send an E value that is less than the currently extruded length、G28: Move to OriginExample: G28This causes the RepRap machine to move back to its X, Y and Z zero endstops, a process known as "homing"、It does so accelerating, so as to get there fast、But when it arrives it backs off by 1 mm in each direction slowly, then moves back slowly to the stop、This ensures more accurate positioning、If you add coordinates, then just the axes with coordinates specified will be zeroed、ThusG28 X0 Y72、3will zero the X and Y axes, but not Z、The actual coordinate values are ignored、Unbuffered G mandsThe following mands are not buffered、When one is received it is stored, but it is not acknowledged to the host until the buffer is exhausted and then the mand has been executed、Thus the host will pause at one of these mands until it has been done、Short pauses between these mands and any that might follow them do not affect the performance of the machine、G4: DwellExample: G4 P200In this case sit still doing nothing for 200 milliseconds、During delays the state of the machine (for example the temperatures of its extruders) will still be preserved and controlled、G20: Set Units to InchesExample: G20Units from now on are in inches、G21: Set Units to MillimetersExample: G21Units from now on are in millimeters、(This is the RepRap default、)G90: Set to Absolute PositioningExample: G90All coordinates from now on are absolute relative to the origin of the machine、(This is the RepRap default、)G91: Set to Relative PositioningExample: G91All coordinates from now on are relative to the last position、G92: Set PositionExample: G92 X10 E90Allows programming of absolute zero point, by reseting the current position to the values specified、This would set the machine's X coordinate to 10, and the extrude coordinate to 90、No physical motion will occur、Unbuffered M and T mandsM0: StopExample: M0The RepRap machine finishes any moves left in its buffer, then shuts down、All motors and heaters are turned off、It can be started again by pressing the reset button on the master microcontroller、See also M112、M17: Enable/Power all stepper motorsExample: M17M18: Disable all stepper motorsExample: M18Disables stepper motors and allows axis to move 'freely、'M20: List SD cardExample: M20All files in the root folder of the SD card are listed to the serial port、This results in a line like: ok Files: {SQUARE、G,SQ、G,}The trailing ma is optional、Note that are returned in upper case, but - when sent to the M23 mand (below) they must be in lower case、This seems to be a function of the SD software、Go figure、、、M21: Initialise SD cardExample: M21The SD card is initialised、If an SD card is loaded when the machine is switched on, this will happen by default、SD card must be initialised for the other SD functions to work、M22: Release SD cardExample: M22SD card is released and can be physically removed、M23: Select SD fileExample: M23The as (8、3 naming convention is supported) is selected ready for printing、M24: Start/resume SD printExample: M24The machine prints from the with the M23 mand、M25: Pause SD printExample: M25The machine pause printing at the current position within the with the M23 mand、M26: Set SD positionExample: M26Set SD position in bytes (M26 S12345)、M27: Report SD print statusExample: M27Report SD print status、M28: Begin write to SD cardExample: M28by is created (or overwritten if it exists) on the SD card and all subsequent mands sent to the machine are written to that file、M29: Stop writing to SD cardExample: M29by M28 mand is closed, and all subsequent mands sent to the machine are executed as normal、M40: EjectIf your RepRap machine can eject the parts it has built off the bed, this mand executes the eject cycle、This usually involves cooling the bed and then performing a sequence of movements that remove the printed parts from it、The X, Y and Z position of the machine at the end of this cycle are undefined (though they can be found out using the M114 mand, q、v、)、See also M240 and M241 below、M41: LoopExample: M41If the RepRap machine was building a its own memory such as a local SD card (as opposed to a transmitted to it from a host puter) this goes back to the beginning of the runs it again、So, for example, if your RepRap is capable of ejecting parts from its build bed then you can set it printing in a loop and it will run and run、Use with caution - the only things that will stop it are:1、When you press the reset button,2、When the build material runs out (if your RepRap is set up to detect this), and3、When there's an error (such as a heater failure)、M42: Stop on material exhaustedExample: M42If your RepRap can detect when its material runs out, this decides the behaviour when that happens、The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off、You have to press reset to reactivate the machine、In other words, it parks itself and then executes an M0 mand (q、v、)、M43: Stand by on material exhaustedExample: M43If your RepRap can detect when its material runs out, this decides the behaviour when that happens、The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off except the heated bed, the temperature of which is maintained、The machine will still respond to G and M code mands in this state、M80: ATX Power OnExample: M80Turns on the ATX power supply from standby mode to fully operational mode、No-op on electronics without standby mode、Note: some firmwares, like Teacup, handle power on/off automatically, so this is redundant there、M81: ATX Power OffExample: M81Turns off the ATX power supply、Counterpart to M80、M84: Stop idle holdExample: M84Stop the idle hold on all axis and extruder、In some cases the idle hold causes annoying noises, which can be stopped by disabling the hold、Be aware that by disabling idle hold during printing, you will get quality issues、This is remended only in between or after printjobs、M92: Set axis_steps_per_unitExample: M92 X<newsteps> Sprinter and MarlinAllows programming of steps per unit of axis till the electronics are reset for the specified axis、Very useful for calibration、M101 Turn extruder 1 on ForwardDepreciated、see MCodeReference、Was used by older style DC extruders、See also Bits From BytesM102 Turn extruder 1 on ReverseDepreciated、see MCodeReference、Was used by older style DC extruders、See also Bits From BytesM103 Turn all extruders offDepreciated、see MCodeReference、Was used by older style DC extruders、See also Bits From BytesM104: Set Extruder Temperature (Fast)Example: M104 S190Set the temperature of the current extruder to 190oC and return control to the host immediately (i、e、before that temperature has been reached by the extruder)、See also M109、M105: Get Extruder TemperatureExample: M105Request the temperature of the current extruder and the build base in degrees Celsius、The temperatures are returned to the host puter、For example, the line sent to the host in response to this mand looks likeok T:201 B:117M106: Fan OnExample: M106 S127Turn on the cooling fan at half speed、Optional parameter 'S' declares the PWM value (0-255) M107: Fan OffExample: M107Turn off the cooling fan (if any)、M108: Set Extruder SpeedSets speed of extruder motor、(Deprecated in current firmware, see M113)M109: Set Extruder TemperatureExample: M109 S190Set the temperature of the current extruder to 190oC and wait for it to reach that value before sending an acknowledgment to the host、In fact the RepRap firmware waits a while after the temperature has been reached for the extruder to stabilise - typically about 40 seconds、This can be changed by a parameter in the firmware configuration the firmware is piled、See also M104 and M116、M110: Set Current Line NumberExample: N123 M110Set the current line number to 123、Thus the expected next line after this mand will be 124、M111: Set Debug LevelExample: M111 S6Set the level of debugging information transmitted back to the host to level 6、The level is the OR of three bits:#define DEBUG_ECHO (1<<0)#define DEBUG_INFO (1<<1)#define DEBUG_ERRORS (1<<2)Thus 6 means send information and errors, but don't echo mands、(This is the RepRap default、) M112: Emergency StopExample: M112Any moves in progress are immediately terminated, then RepRap shuts down、All motors and heaters are turned off、It can be started again by pressing the reset button on the master microcontroller、See also M0、M113: Set Extruder PWMExample: M113Set the PWM for the currently-selected extruder、On its own this mand sets RepRap to use the on-board potentiometer on the extruder controller board to set the PWM for the currently-selected extruder's stepper power、With an S field:M113 S0、7it causes the PWM to be set to the S value (70% in this instance)、M113 S0 turns the extruder off, until an M113 mand other than M113 S0 is sent、M114: Get Current PositionExample: M114This causes the RepRap machine to report its current X, Y, Z and E coordinates to the host、For example, the machine returns a string such as:ok C: X:0、00 Y:0、00 Z:0、00 E:0、00M115: Get Firmware Version and CapabilitiesExample: M115Request the Firmware Version and Capabilities of the current microcontroller The details are returned to the host puter as key:value pairs separated by spaces and terminated with a linefeed、sample data from firmware:ok PROTOCOL_VERSION:0、1 FIRMWARE_NAME:FiveD FIRMWARE_URL:%3A//reprap、org MACHINE_TYPE:Mendel EXTRUDER_COUNT:1This M115 code is inconsistently implemented, and should not be relied upon to exist, or output correctly in all cases、An initial implementation was mitted to svn for the FiveD Reprap firmware on 11 Oct 2010、Work to more formally define protocol versions is currently (October 2010) being discussed、See M115_Keywords for one draft set of keywords and their meanings、M116: WaitExample: M116Wait for all temperatures and other slowly-changing variables to arrive at their set values、See also M109、M117: Get Zero PositionExample: M117This causes the RepRap machine to report the X, Y, Z and E coordinates in steps not mm to the host that it found when it last hit the zero stops for those axes、That is to say, when you zero X, the x coordinate of the machine when it hits the X endstop is recorded、This value should be 0, of course、But if the machine has drifted (for example by dropping steps) then it won't be、This mand allows you to measure and to diagnose such problems、(E is included for pleteness、It doesn't normally have an endstop、)M118: Negotiate FeaturesExample: M118 P42This M-code is for future proofing、NO firmware or hostware supports this at the moment、It is used in conjunction with M115's FEATURES keyword、See Protocol_Feature_Negotiation for more info、M119: Get Endstop StatusExample: M119Returns the current state of the configured X,Y,Z endstops、Should take into account any 'inverted endstop' settings, so one can confirm that the machine is interpreting the endstops correctly、M126: Open ValveExample: M126 P500Open the extruder's valve (if it has one) and wait 500 milliseconds for it to do so、M127: Close ValveExample: M127 P400Close the extruder's valve (if it has one) and wait 400 milliseconds for it to do so、M128: Extruder Pressure PWMExample: M128 S255PWM value to control internal extruder pressure、S255 is full pressure、M129: Extruder pressure offExample: M129 P100In addition to setting Extruder pressure to 0, you can turn the pressure off entirely、P400 will wait 100ms to do so、M140: Bed Temperature (Fast)Example: M140 S55Set the temperature of the build bed to 55oC and return control to the host immediately (i、e、before that temperature has been reached by the bed)、M141: Chamber Temperature (Fast)Example: M141 S30Set the temperature of the chamber to 30oC and return control to the host immediately (i、e、before that temperature has been reached by the chamber)、M142: Holding PressureExample: M142 S1Set the holding pressure of the bed to 1 bar、The holding pressure is in bar、For hardware which only has on/off holding, when the holding pressure is zero, turn off holding, when the holding pressure is greater than zero, turn on holding、M143: Maximum hot-end temperatureExample: M143 S275Set the maximum temperature of the hot-end to 275CWhen temperature of the hot-end exceeds this value, take countermeasures, for instance an emergency stop、This is to prevent hot-end damage、M160: Number of mixed materialsExample: M160 S4Set the number of materials, N, that the current extruder can handle to the number specified、The default is 1、When N >= 2, then the E field that controls extrusion requires N+1 values separated by spaces after it like this:M160 S4G1 X90、6 Y13、8 E22、4 0、1 0、1 0、1 0、7G1 X70、6 E42、4 0、0 0、0 0、0 1、0G1 E42、4 1、0 0、0 0、0 0、0The second line moves straight to the point (90、6, 13、8) extruding 22、4mm of filament、The mix ratio at the end of the move is 0、1:0、1:0、1:0、7、The third line moves back 20mm in X extruding 20mm of filament、The mix varies linearly from 0、1:0、1:0、1:0、7 to 0:0:0:1 as the move is made、The fourth line has no physical effect, but sets the mix proportions for the start of the next move to 1:0:0:0、M203: Record Z adjustmentExample: M203 Z-0、75This records a Z offset in non-volatile memory in RepRap's microcontroller where it remains active until next set, even when the power is turned off and on again、If the first layer is too close to the bed, you need to effectively move the bed down, so the Z value will be negative、If the nozzle is too far from the bed during the first layer, the Z value should be positive to raise the bed、The maximum adjustment is +/-1、27mm、M226: Gcode Initiated PauseExample: M226Initiates a pause in the same way as if the pause button is pressed、M227: Enable Automatic Reverse and PrimeExample: M227 P1600 S1600P and S are steps、M228: Disable Automatic Reverse and PrimeExample: M228M229: Enable Automatic Reverse and PrimeExample: M229 P1、0 S1、0P and S are extruder screw rotations、M230: Disable / Enable Wait for Temperature ChangeExample: M230 S1S1 Disable wait for temperature change S0 Enable wait for temperature changeM240: Start conveyor belt motorExample: M240The conveyor belt allows to start mass production of a part with a reprapM241: Stop conveyor belt motorExample: M241M245: Start coolerExample: M245used to cool parts/heated-bed down after printing for easy remove of the parts after printM246: Stop coolerExample: M246M300: Play beep soundUsage: M300 S<frequency Hz> P<duration ms>Example: M300 S300 P1000Play beep sound, use to notify important events like the end of printing、See working example on R2C2 electronics、T: Select ToolExample: T1Select extruder number 1 to build with、Extruder numbering starts at 0、Proposed EEPROM configuration codesBRIEFLY: each RepRap has a number of physical parameters that should be persistent, but easily configurable, such as extrusion steps/mm, various max values, etc、Those parameters are currently hardcoded in the firmware, so that a user has to modify, repile and re-flash the firmware for any adjustments、These configs can be stored in MCU's EEPROM and modified via some M-codes、Please see the detailed proposal at M-codes for EEPROM config、(This is proposed by --AlexRa on 11-March-2011、There is currently no working implementation of the proposed mands)、Replies from the RepRap machine to the host puterAll munication is in printable ASCII characters、Messages sent back to the host puter are terminated by a newline and look like this:xx [line number to resend] [T:93、2 B:22、9] [C: X:9、2 Y:125、4 Z:3、7 E:1902、5] [Some debugging or other information may be here]xx can be one of:okrs!!ok means that no error has been detected、rs means resend, and is followed by the line number to resend、!! means that a hardware fault has been detected、The RepRap machine will shut down immediately after it has sent this message、The T: and B: values are the temperature of the currently-selected extruder and the bed respectively, and are only sent in response to M105、If such temperatures don't exist (for example for an extruder that works at room temperature and doesn't have a sensor) then a value below absolute zero (-273oC) is returned、C: means that coordinates follow、Those are the X: Y: etc values、These are only sent in response to M114 and M117、The RepRap machine may also send lines that look like this:// This is some debugging or other information on a line on its own、It may be sent at any time、Such lines will always be preceded by //、The most mon response is simply:okWhen the machine boots up it sends the stringstartonce to the host before sending anything else、This should not be replaced or augmented by version numbers and the like、M115 (see above) requests those、All this means that every line sent by RepRap to the host puter except the start line has a two-character prefix (one of ok, rs, !! or //)、The machine should never send a line without such a prefix、。
Gcode G代码详解(互联网+)
reprap wiki上面的Gcode说明G-codeFrom RepRapWiki(Redirected from Gcode)Jump to: navigation, searchContents [hide]1 Introduction2 RepRap G Code Fields3 Comments4 Individual commands4.1 Checking4.1.1 N and *4.2 Buffered G Commands4.2.1 G0: Rapid move4.2.2 G1: Controlled move4.2.3 G28: Move to Origin4.3 Unbuffered G commands4.3.1 G4: Dwell4.3.2 G20: Set Units to Inches4.3.3 G21: Set Units to Millimeters4.3.4 G90: Set to Absolute Positioning4.3.5 G91: Set to Relative Positioning4.3.6 G92: Set Position4.4 Unbuffered M and T commands4.4.1 M0: Stop4.4.2 M17: Enable/Power all stepper motors 4.4.3 M18: Disable all stepper motors4.4.4 M20: List SD card4.4.5 M21: Initialise SD card4.4.6 M22: Release SD card4.4.7 M23: Select SD file4.4.8 M24: Start/resume SD print4.4.9 M25: Pause SD print4.4.10 M26: Set SD position4.4.11 M27: Report SD print status4.4.12 M28: Begin write to SD card4.4.13 M29: Stop writing to SD card4.4.14 M40: Eject4.4.15 M41: Loop4.4.16 M42: Stop on material exhausted 4.4.17 M43: Stand by on material exhausted 4.4.18 M80: ATX Power On4.4.19 M81: ATX Power Off4.4.20 M84: Stop idle hold4.4.21 M92: Set axis_steps_per_unit4.4.22 M101 Turn extruder 1 on Forward4.4.23 M102 Turn extruder 1 on Reverse4.4.24 M103 Turn all extruders off4.4.25 M104: Set Extruder Temperature (Fast)4.4.26 M105: Get Extruder Temperature4.4.27 M106: Fan On4.4.28 M107: Fan Off4.4.29 M108: Set Extruder Speed4.4.30 M109: Set Extruder Temperature4.4.31 M110: Set Current Line Number4.4.32 M111: Set Debug Level4.4.33 M112: Emergency Stop4.4.34 M113: Set Extruder PWM4.4.35 M114: Get Current Position4.4.36 M115: Get Firmware Version and Capabilities4.4.37 M116: Wait4.4.38 M117: Get Zero Position4.4.39 M118: Negotiate Features4.4.40 M119: Get Endstop Status4.4.41 M126: Open Valve4.4.42 M127: Close Valve4.4.43 M128: Extruder Pressure PWM4.4.44 M129: Extruder pressure off4.4.45 M140: Bed Temperature (Fast)4.4.46 M141: Chamber Temperature (Fast)4.4.47 M142: Holding Pressure4.4.48 M143: Maximum hot-end temperature4.4.49 M160: Number of mixed materials4.4.50 M203: Record Z adjustment4.4.51 M226: Gcode Initiated Pause4.4.52 M227: Enable Automatic Reverse and Prime4.4.53 M228: Disable Automatic Reverse and Prime4.4.54 M229: Enable Automatic Reverse and Prime4.4.55 M230: Disable / Enable Wait for Temperature Change 4.4.56 M240: Start conveyor belt motor4.4.57 M241: Stop conveyor belt motor4.4.58 M245: Start cooler4.4.59 M246: Stop cooler4.4.60 M300: Play beep sound4.4.61 T: Select Tool5 Proposed EEPROM configuration codes6 Replies from the RepRap machine to the host computer7 Proposal for sending multiple lines of G-code7.1 Problem to solveIntroductionThis page describes the G Codes that the RepRap firmware uses and how they work.The list of what can be done is extensible. But check this page first, and add your extension here first before you implement it.A typical piece of GCode as sent to a RepRap machine might look like this:N3 T0*57N4 G92 E0*67N5 G28*22N6 G1 F1500.0*82N7 G1 X2.0 Y2.0 F3000.0*85N8 G1 X3.0 Y3.0*33The meaning of all those symbols and numbers (and more) is explained below.TO find out which specific gcode/s are implemented in any given firmware, please see the Firmware_features page.(For the technically minded, the end of line is marked by both a <nl> and a <cr>. If you want to manually enter GCodes in your reprap using the Arduino Serial interface, make sure to select "Both NL & CR" on the bottom of the screen.)This isn't accurate, firmware accepts single <nl> as well as single <cr>, or combinations thereof. Hosts should accepts all four combinations as well. --Traumflug 09:34, 20 April 2011 (UTC)RepRap G Code FieldsThis section explains the letter-preceded fields. The numbers in the fields are represented by nnn. Numbers can be integers, or can contain a decimal point, depending on context. For example an X coordinate can be integer (X175) or fractional (X17.62), whereas trying to select extruder number 2.76 would make no sense.Letter MeaningGnnn Standard GCode command, such as move to a pointMnnn RepRap-defined command, such as turn on a cooling fanTnnn Select tool nnn. In RepRap, tools are extrudersSnnn Command parameter, such as the voltage to send to a motorPnnn Command parameter, such as a time in millisecondsXnnn An X coordinate, usually to move toYnnn A Y coordinate, usually to move toZnnn A Z coordinate, usually to move toInnn Parameter - not currently usedJnnn Parameter - not currently usedFnnn Feedrate in mm per minute. (Speed of print head movement)Rnnn Parameter - not currently usedQnnn Parameter - not currently usedEnnn Length of extrudate in mm. This is exactly like X, Y and Z, but for the length of filament to extrude. It is common for newer stepper based systems to interpret ... Better: Skeinforge 40 and up interprets this as the absolute length of input filament to consume, rather than the length of the extruded output.Nnnn Line number. Used to request repeat transmission in the case of communications errors. *nnn Checksum. Used to check for communications errors.CommentsG Code comments:N3 T0*57 ;This is a commentN4 G92 E0*67; So is thisN5 G28*22Will be ignored by RepRap, as will blank lines. But it's better to strip these out in the host computer before the lines are sent. This saves bandwidth.Individual commandsCheckingN and *Example: N123 [...G Code in here...] *71These are the line number and the checksum. The RepRap firmware checks the checksum against a locally-computed value and, if they differ, requests a repeat transmission of the line of the given number.You can leave both of these out - RepRap will still work, but it won't do checking. You have to have both or neither though.The checksum "cs" for a GCode string "cmd" (including its line number) is computed by exor-ing the bytes in the string up to and not including the * character as follows:int cs = 0;for(i = 0; cmd[i] != '*' && cmd[i] != NULL; i++)cs = cs ^ cmd[i];cs &= 0xff; // Defensive programming...and the value is appended as a decimal integer to the command after the * character.The RepRap firmware expects line numbers to increase by 1 each line, and if that doesn't happen it is flagged as an error. But you can reset the count using M110 (see below).Buffered G CommandsThe RepRap firmware stores these commands in a ring buffer internally for execution. This means that there is no (appreciable) delay while a command is acknowledged and the next transmitted. In turn, this means that sequences of line segments can be plotted without a dwell between one and the next. As soon as one of these buffered commands is received it is acknowledged and stored locally. If the local buffer is full, then the acknowledgment is delayed until space for storage in the buffer is available. This is how flow control is achieved.G0: Rapid moveExample: G0 X12In this case move rapidly to X = 12 mm. In fact, the RepRap firmware uses exactly the same code for rapid as it uses for controlled moves (see G1 below), as - for the RepRap machine - this is just as efficient as not doing so. (The distinction comes from some old machine tools that used to move faster if the axes were not driven in a straight line. For them G0 allowed any movement in space to get to the destination as fast as possible.)G1: Controlled moveExample: G1 X90.6 Y13.8 E22.4Go in a straight line from the current (X, Y) point to the point (90.6, 13.8), extruding material as the move happens from the current extruded length to a length of 22.4 mm.RepRap does subtle things with feedrates. Thus:G1 F1500G1 X90.6 Y13.8 E22.4Will set a feedrate of 1500 mm/minute, then do the move described above at that feedrate. ButG1 F1500G1 X90.6 Y13.8 E22.4 F3000Will set a feedrate of 1500 mm/minute, then do the move described above accelerating to a feedrate of 3000 mm/minute as it does so. The extrusion will accelerate along with the X, Y movement so everything stays synchronized.RepRap thus treats feedrate as simply another variable (like X, Y, Z, and E) to be linearly interpolated. This gives complete control over accelerations and decelerations in a way that ensures that everything moves together and the right volume of material is extruded at all points.The first example shows how to get a constant-speed movement. The second how to accelerate or decelerate. ThusG1 F1500G1 X90.6 Y13.8 E22.4 F3000G1 X80 Y20 E36 F1500Will do the first movement accelerating as before, and the second decelerating from 3000 mm/minute back to 1500 mm/minute.To reverse the extruder by a given amount (for example to reduce its internal pressure while it does an in-air movement so that it doesn't dribble) simply use G1 to send an E value that is less than the currently extruded length.G28: Move to OriginExample: G28This causes the RepRap machine to move back to its X, Y and Z zero endstops, a process known as "homing". It does so accelerating, so as to get there fast. But when it arrives it backs off by 1 mm in each direction slowly, then moves back slowly to the stop. This ensures more accurate positioning.If you add coordinates, then just the axes with coordinates specified will be zeroed. ThusG28 X0 Y72.3will zero the X and Y axes, but not Z. The actual coordinate values are ignored.Unbuffered G commandsThe following commands are not buffered. When one is received it is stored, but it is not acknowledged to the host until the buffer is exhausted and then the command has been executed. Thus the host will pause at one of these commands until it has been done. Short pauses between these commands and any that might follow them do not affect the performance of the machine.G4: DwellExample: G4 P200In this case sit still doing nothing for 200 milliseconds. During delays the state of the machine (for example the temperatures of its extruders) will still be preserved and controlled.G20: Set Units to InchesExample: G20Units from now on are in inches.G21: Set Units to MillimetersExample: G21Units from now on are in millimeters. (This is the RepRap default.)G90: Set to Absolute PositioningExample: G90All coordinates from now on are absolute relative to the origin of the machine. (This is the RepRap default.)G91: Set to Relative PositioningExample: G91All coordinates from now on are relative to the last position.G92: Set PositionExample: G92 X10 E90Allows programming of absolute zero point, by reseting the current position to the values specified. This would set the machine's X coordinate to 10, and the extrude coordinate to 90. No physical motion will occur.Unbuffered M and T commandsM0: StopExample: M0The RepRap machine finishes any moves left in its buffer, then shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M112.M17: Enable/Power all stepper motorsExample: M17M18: Disable all stepper motorsExample: M18Disables stepper motors and allows axis to move 'freely.'M20: List SD cardExample: M20All files in the root folder of the SD card are listed to the serial port. This results in a line like:ok Files: {SQUARE.G,SQCOM.G,}The trailing comma is optional. Note that file names are returned in upper case, but - when sent to the M23 command (below) they must be in lower case. This seems to be a function of the SD software. Go figure...M21: Initialise SD cardExample: M21The SD card is initialised. If an SD card is loaded when the machine is switched on, this will happen by default. SD card must be initialised for the other SD functions to work.M22: Release SD cardExample: M22SD card is released and can be physically removed.M23: Select SD fileExample: M23 filename.gcoThe file specified as filename.gco (8.3 naming convention is supported) is selected ready for printing.M24: Start/resume SD printExample: M24The machine prints from the file selected with the M23 command.M25: Pause SD printExample: M25The machine pause printing at the current position within the file selected with the M23 command.M26: Set SD positionExample: M26Set SD position in bytes (M26 S12345).M27: Report SD print statusExample: M27Report SD print status.M28: Begin write to SD cardExample: M28 filename.gcoFile specified by filename.gco is created (or overwritten if it exists) on the SD card and all subsequent commands sent to the machine are written to that file.M29: Stop writing to SD cardExample: M29 filename.gcoFile opened by M28 command is closed, and all subsequent commands sent to the machine are executed as normal.M40: EjectIf your RepRap machine can eject the parts it has built off the bed, this command executes the eject cycle. This usually involves cooling the bed and then performing a sequence of movements that remove the printed parts from it. The X, Y and Z position of the machine at the end of this cycle are undefined (though they can be found out using the M114 command, q.v.).See also M240 and M241 below.M41: LoopExample: M41If the RepRap machine was building a file from its own memory such as a local SD card (as opposed to a file being transmitted to it from a host computer) this goes back to the beginning of the file and runs it again. So, for example, if your RepRap is capable of ejecting parts from its build bed then you can set it printing in a loop and it will run and run. Use with caution - the only things that will stop it are:1.When you press the reset button,2.When the build material runs out (if your RepRap is set up to detect this), and3.When there's an error (such as a heater failure).M42: Stop on material exhaustedExample: M42If your RepRap can detect when its material runs out, this decides the behaviour when that happens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off. You have to press reset to reactivate the machine. In other words, it parks itself and then executes an M0 command (q.v.).M43: Stand by on material exhaustedExample: M43If your RepRap can detect when its material runs out, this decides the behaviour when that happens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off except the heated bed, the temperature of which is maintained. The machine will still respond to G and M code commands in this state.M80: ATX Power OnExample: M80Turns on the ATX power supply from standby mode to fully operational mode. No-op on electronics without standby mode.Note: some firmwares, like Teacup, handle power on/off automatically, so this is redundant there.M81: ATX Power OffExample: M81Turns off the ATX power supply. Counterpart to M80.M84: Stop idle holdExample: M84Stop the idle hold on all axis and extruder. In some cases the idle hold causes annoying noises, which can be stopped by disabling the hold. Be aware that by disabling idle hold during printing, you will get quality issues. This is recommended only in between or after printjobs.M92: Set axis_steps_per_unitExample: M92 X<newsteps> Sprinter and MarlinAllows programming of steps per unit of axis till the electronics are reset for the specified axis. Very useful for calibration.M101 Turn extruder 1 on ForwardDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM102 Turn extruder 1 on ReverseDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM103 Turn all extruders offDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM104: Set Extruder Temperature (Fast)Example: M104 S190Set the temperature of the current extruder to 190oC and return control to the host immediately (i.e. before that temperature has been reached by the extruder). See also M109.M105: Get Extruder TemperatureExample: M105Request the temperature of the current extruder and the build base in degrees Celsius. The temperatures are returned to the host computer. For example, the line sent to the host in response to this command looks likeok T:201 B:117M106: Fan OnExample: M106 S127Turn on the cooling fan at half speed. Optional parameter 'S' declares the PWM value (0-255)M107: Fan OffExample: M107Turn off the cooling fan (if any).M108: Set Extruder SpeedSets speed of extruder motor. (Deprecated in current firmware, see M113)M109: Set Extruder TemperatureExample: M109 S190Set the temperature of the current extruder to 190oC and wait for it to reach that value beforesending an acknowledgment to the host. In fact the RepRap firmware waits a while after the temperature has been reached for the extruder to stabilise - typically about 40 seconds. This can be changed by a parameter in the firmware configuration file when the firmware is compiled. See also M104 and M116.M110: Set Current Line NumberExample: N123 M110Set the current line number to 123. Thus the expected next line after this command will be 124.M111: Set Debug LevelExample: M111 S6Set the level of debugging information transmitted back to the host to level 6. The level is the OR of three bits:#define DEBUG_ECHO (1<<0)#define DEBUG_INFO (1<<1)#define DEBUG_ERRORS (1<<2)Thus 6 means send information and errors, but don't echo commands. (This is the RepRap default.)M112: Emergency StopExample: M112Any moves in progress are immediately terminated, then RepRap shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M0.M113: Set Extruder PWMExample: M113Set the PWM for the currently-selected extruder. On its own this command sets RepRap to use the on-board potentiometer on the extruder controller board to set the PWM for the currently-selected extruder's stepper power. With an S field:M113 S0.7it causes the PWM to be set to the S value (70% in this instance). M113 S0 turns the extruder off, until an M113 command other than M113 S0 is sent.M114: Get Current PositionExample: M114This causes the RepRap machine to report its current X, Y, Z and E coordinates to the host.For example, the machine returns a string such as:ok C: X:0.00 Y:0.00 Z:0.00 E:0.00M115: Get Firmware Version and CapabilitiesExample: M115Request the Firmware Version and Capabilities of the current microcontroller The details are returned to the host computer as key:value pairs separated by spaces and terminated with a linefeed.sample data from firmware:ok PROTOCOL_VERSION:0.1 FIRMWARE_NAME:FiveD FIRMWARE_URL:http%3A// MACHINE_TYPE:Mendel EXTRUDER_COUNT:1This M115 code is inconsistently implemented, and should not be relied upon to exist, or output correctly in all cases. An initial implementation was committed to svn for the FiveD Reprap firmware on 11 Oct 2010. Work to more formally define protocol versions is currently (October 2010) being discussed. See M115_Keywords for one draft set of keywords and their meanings.M116: WaitExample: M116Wait for all temperatures and other slowly-changing variables to arrive at their set values. See also M109.M117: Get Zero PositionExample: M117This causes the RepRap machine to report the X, Y, Z and E coordinates in steps not mm to the host that it found when it last hit the zero stops for those axes. That is to say, when you zero X, the x coordinate of the machine when it hits the X endstop is recorded. This value should be 0, of course. But if the machine has drifted (for example by dropping steps) then it won't be. This command allows you to measure and to diagnose such problems. (E is included for completeness. It doesn't normally have an endstop.)M118: Negotiate FeaturesExample: M118 P42This M-code is for future proofing. NO firmware or hostware supports this at the moment. It isused in conjunction with M115's FEATURES keyword.See Protocol_Feature_Negotiation for more info.M119: Get Endstop StatusExample: M119Returns the current state of the configured X,Y,Z endstops. Should take into account any 'inverted endstop' settings, so one can confirm that the machine is interpreting the endstops correctly.M126: Open ValveExample: M126 P500Open the extruder's valve (if it has one) and wait 500 milliseconds for it to do so.M127: Close ValveExample: M127 P400Close the extruder's valve (if it has one) and wait 400 milliseconds for it to do so.M128: Extruder Pressure PWMExample: M128 S255PWM value to control internal extruder pressure. S255 is full pressure.M129: Extruder pressure offExample: M129 P100In addition to setting Extruder pressure to 0, you can turn the pressure off entirely. P400 will wait 100ms to do so.M140: Bed Temperature (Fast)Example: M140 S55Set the temperature of the build bed to 55oC and return control to the host immediately (i.e. before that temperature has been reached by the bed).M141: Chamber Temperature (Fast)Example: M141 S30Set the temperature of the chamber to 30oC and return control to the host immediately (i.e. before that temperature has been reached by the chamber).M142: Holding PressureExample: M142 S1Set the holding pressure of the bed to 1 bar.The holding pressure is in bar. For hardware which only has on/off holding, when the holding pressure is zero, turn off holding, when the holding pressure is greater than zero, turn on holding.M143: Maximum hot-end temperatureExample: M143 S275Set the maximum temperature of the hot-end to 275CWhen temperature of the hot-end exceeds this value, take countermeasures, for instance an emergency stop. This is to prevent hot-end damage.M160: Number of mixed materialsExample: M160 S4Set the number of materials, N, that the current extruder can handle to the number specified. The default is 1.When N >= 2, then the E field that controls extrusion requires N+1 values separated by spaces after it like this:M160 S4G1 X90.6 Y13.8 E22.4 0.1 0.1 0.1 0.7G1 X70.6 E42.4 0.0 0.0 0.0 1.0G1 E42.4 1.0 0.0 0.0 0.0The second line moves straight to the point (90.6, 13.8) extruding 22.4mm of filament. The mix ratio at the end of the move is 0.1:0.1:0.1:0.7.The third line moves back 20mm in X extruding 20mm of filament. The mix varies linearly from 0.1:0.1:0.1:0.7 to 0:0:0:1 as the move is made.The fourth line has no physical effect, but sets the mix proportions for the start of the next move to 1:0:0:0.M203: Record Z adjustmentExample: M203 Z-0.75This records a Z offset in non-volatile memory in RepRap's microcontroller where it remains active until next set, even when the power is turned off and on again. If the first layer is too closeto the bed, you need to effectively move the bed down, so the Z value will be negative. If the nozzle is too far from the bed during the first layer, the Z value should be positive to raise the bed. The maximum adjustment is +/-1.27mm.M226: Gcode Initiated PauseExample: M226Initiates a pause in the same way as if the pause button is pressed.M227: Enable Automatic Reverse and PrimeExample: M227 P1600 S1600P and S are steps.M228: Disable Automatic Reverse and PrimeExample: M228M229: Enable Automatic Reverse and PrimeExample: M229 P1.0 S1.0P and S are extruder screw rotations.M230: Disable / Enable Wait for Temperature ChangeExample: M230 S1S1 Disable wait for temperature change S0 Enable wait for temperature changeM240: Start conveyor belt motorExample: M240The conveyor belt allows to start mass production of a part with a reprapM241: Stop conveyor belt motorExample: M241M245: Start coolerExample: M245used to cool parts/heated-bed down after printing for easy remove of the parts after printM246: Stop coolerExample: M246M300: Play beep soundUsage: M300 S<frequency Hz> P<duration ms>Example: M300 S300 P1000Play beep sound, use to notify important events like the end of printing. See working example on R2C2 electronics.T: Select ToolExample: T1Select extruder number 1 to build with. Extruder numbering starts at 0.Proposed EEPROM configuration codesBRIEFLY: each RepRap has a number of physical parameters that should be persistent, but easily configurable, such as extrusion steps/mm, various max values, etc. Those parameters are currently hardcoded in the firmware, so that a user has to modify, recompile and re-flash the firmware for any adjustments. These configs can be stored in MCU's EEPROM and modified via some M-codes. Please see the detailed proposal at M-codes for EEPROM config. (This is proposed by --AlexRa on 11-March-2011. There is currently no working implementation of the proposed commands).Replies from the RepRap machine to the host computerAll communication is in printable ASCII characters. Messages sent back to the host computer are terminated by a newline and look like this:xx [line number to resend] [T:93.2 B:22.9] [C: X:9.2 Y:125.4 Z:3.7 E:1902.5] [Some debugging or other information may be here]xx can be one of:okrs!!ok means that no error has been detected.rs means resend, and is followed by the line number to resend.!! means that a hardware fault has been detected. The RepRap machine will shut down immediately after it has sent this message.The T: and B: values are the temperature of the currently-selected extruder and the bed respectively, and are only sent in response to M105. If such temperatures don't exist (for example for an extruder that works at room temperature and doesn't have a sensor) then a value below absolute zero (-273oC) is returned.C: means that coordinates follow. Those are the X: Y: etc values. These are only sent in response to M114 and M117.The RepRap machine may also send lines that look like this:// This is some debugging or other information on a line on its own. It may be sent at any time.Such lines will always be preceded by //.The most common response is simply:okWhen the machine boots up it sends the stringstartonce to the host before sending anything else. This should not be replaced or augmented by version numbers and the like. M115 (see above) requests those.All this means that every line sent by RepRap to the host computer except the start line has a two-character prefix (one of ok, rs, !! or //). The machine should never send a line without such a prefix.。
G代码详解(Gcodedetails)
G代码详解(G code details)AC usage: (axis) =AC ({value}): the absolute size command used to activate the program segment (axis: the axis name of the axis to be run). Value: the absolute location of the axis to be runACP: is used to return instructions to the positive position. The rotating shaft runs in a negative direction (counterclockwise) to the programmed position.ACN: is used to return instructions to the negative position. The axis of revolution runs clockwise (clockwise) to the programmed position.AP: in polar coordinates, given the terminal position, the instruction pole angle.RP: the destination radius given in polar coordinates.DC: is used to return unknown instructions directly. The axis of rotation runs in a direct and shortest displacement to the programmed position. The rotary shaft runs at most 180 degrees.CFTCP: maintains a constant feed rate on the center of the cutter path.Constant feed rate is maintained on the CFC: profile (knife edge).CFIN: maintains only a constant feed rate along the edge of the concave contour, otherwise a constant feed rate is maintained on the center of the cutter path.CHF: contour angle, fillet, chamfer lengthCHR: bevel angle, chamfer, width of chamfer in original running directionRND: contour angle, fillet, park radiusRNDM: mode chamfer, rounded radiusFRC: rounding / chamfering feed rate, program segment validFRCM: reverse Park / chamfer feed rate, mode effectiveG00 positioningG01 linear cuttingG02 clockwise circular arc cuttingG03 counter clockwise arc cuttingG04 pause instructionG09 stopped testing correctlyG110: the position of the subsequent polar coordinates is based on the last return position.G111: so that the subsequent polar coordinates are based on the zero point of the current workpiece coordinate system.G112: the subsequent polar coordinates are based on the last valid pole.G10 correction settingsG12 clockwise circumferential cuttingG13 counter clockwise circumferential cuttingThe G15 polar coordinate system is cancelledG153:, like G53, also cancels the overall baseline frameworkG16 polar coordinate system settingG17XY plane settings, feed direction ZG18XZ plane settings, feed direction YG19YZ plane settings, feed direction XG20 English unit settingG21 metric unit settingsG22 software limit settingG23 software limit setting cancelledG25 spindle speed lower limitG26 spindle speed upper limitG27 mechanical origin reset detectionThe G28 automatically returns the mechanical origin through the intermediate pointThe G29 automatically returns from the reference pointG30 automatically revert to the second originG33 constant pitch thread cuttingG331 cutting internal threads without compensating clampsG332 without compensating clamps for cutting internal threads, returns, or return instructionsG40 cutter radius correction cancelledG41 tool radius offset left correctionG42 tool radius partial right correctionG43 tool length is corrected along the forward directionG44 tool length is corrected along the negative directionG49 tool length correction cancelledG45 tool position correction addedG46 tool position correction reducedG47 tool position correction increased two timesG48 tool position correction two times lessG50 scale function cancelled OFF,G500: closes the current set of zero offset, mode effective. G505--G599: calls first to ninety-ninth sets of zero offsets. G51 proportional function setting ONG52 returns to the basic coordinate systemG53 returns to the mechanical coordinate systemG54 calls the first set of zero offsetG55 calls second sets of zero offsetG56 calls third sets of zero offsetG57 calls fourth sets of zero offsetG58 fifth workpiece coordinate systemG59 sixth workpiece coordinate systemG60 external correctionG63: tapping with compensating clamps.G700: activates the imperial size system.G710: activated metric size systemG70 circle equal section cycle;Activate the imperial size system.G71 circumferential segment loops; activate metric size systems.G70, G71, G700 and G710 are effective only in itinerary information, arc programming (middle point coordinate{I1.J1.K1}, interpolation parameter {I.J.K}, circle radius CR), pitch G34/G35, programmable zero offset TRANS, and polar radius RP.G72 piecewise linear loopsG73 high speed beak drill cycleG74 left teeth cutting cycleG75: returns to the fixed point directlyG751: returns the fixed point FP: should return from the middlepointG76 fine boring cycleG77 reverse bore circulationG80 fixed loop cancelledG81 drilling cycleG82 countersunk head machining cycleG83 peck drill cycleG84 dextral teeth cutting cycleG85 boring cycleG86 boring cycleG87 boring cycleG88 boring cycleG89 boring cycleG90 absolute command modal effective coordinates setG91 increment instruction coordinates set (incremental activation size effective instruction mode: IC) to activate the program segment effective incremental size instruction.G92 absolute program zero settingG93 inverse time feed rate 1/minThe G94 feed per minute is set at mm/min, in/min, or (DEG) /minG95 each turn feed to set mm/rev with FZ: mode effective; FB: segment by paragraph effective feed rate.G96 selects constant speedG98 fixed cycle, the tool returns to the starting pointG99 fixed cycle, tool revert to R pointM04 spindle counter clockwise rotationM05 spindle stopM06 tool switchingM07 atomizing coolant opensM08 coolant opensM09 coolant closedM10 workbench (B axis) lockedM11 workbench (B axis) releaseM13 spindle clockwise rotation and add cutting fluidM14 spindle counterclockwise rotation and add cutting fluid M15 direct motionM16 negative directional motionM19 spindle positioningM30 program end memory regressionM90 program interrupt cancelledM91 program interrupt settingM92 multiple segment temporary cancellationM93 multi stage temporary settingM94 mirror projection worker can be canceledM95 mirror projection energy settingsM96 cutter adjustment arc rotation angle modeM97 tool angle angle correction modeM98 subroutine callThe M99 subroutine endsThe F: is involved in running the geometric axis feed rate (mm/min)Feed speed of FA: positioning shaftThe FL: synchronous axis / track axis speed limit is valid through the units set by the G94FGROUP: uses the F programming feed rate for all axes set under FGROUPFGREF: use FGREF to set the effective radius for each of the rotating shafts set under FGROUPFeed rate of positioning shaft set by FA:FXS (1 open function; 2 release function): used to activate and cancel the instructions to run to the fixed block function.FXST: is used to generate alternate instructions to clamp the torque to drive the largest% setting.FXSW: alternate commands for setting the width of the monitor block window.OVR: modifies the feed rate of the track feed F.OVRRAP: modifies the feed rate at fast running speeds.The OVRA: modifies the feed rate of the positioning feed FA or the spindle speed S.POS/POSA: run the alignment shaft to the set positionThe POSP: distribution operates from the positioning axis to the set end positionThe SPCON: activates position control operations, and the spindle is switched from speed control to position control. Valid for mode until SPCOF activation.SPCOF: cancels position control, and the main spindle is switched from position control to speed control.SPOS/SPOSA: position the spindle to the set angle.The SUPA:, like the G153, also cancels the handwheel offset (DRF), the overlay movement, the external zero offset, and the preset offset.WAITP: wait until the end of the alignment axis.WAITS: sets the synchronous instructions of the main shaft. When the following program is executed, the main axis of the setting and the main SPOSA programming block in the previous NC segment are reached at the end point (precise stop).WALIMON: activates the work area limit for all axesWALIMOF: cancels the work area limit for all axesShift instructionFirst, the outline of the workpiece can be made up of elements:1, straight line2, arc3, spiral (line and arc overlay).Two, running instructions (modal effective)1, fast running (G0)2, linear interpolation (G10)3, clockwise arc interpolation (G2)4, counterclockwise arc interpolation (G3)Linear interpolation (G1)Directive: G1 X... Y... Z... F...G1 AP=... RP... F...Of which: G1: linear interpolation (linear interpolation with feed rate).X... Y... Z: the end point given in Cartesian coordinates.AP: in polar coordinates, given the terminal position, the instruction pole angle.RP: the destination radius given in polar coordinates.F: units are mm / min feed rate.Arc interpolation (G2, G3,...)G2 clockwise circular arc cuttingG3 counter clockwise arc cutting(1) representing the center of the circle and the end point in absolute or relative size(2) coordinate the radius and end point in Cartesian coordinates(3) of the rectangular angle and the end point or the center of a given address(4) polar coordinates with polar angles, AP= and polar radii =.(5) intermediate point and terminal point.(6) the tangent direction at the end of the starting pointinstructionsG2/G3:X... Y... Z... I=AC (...) J=AC (...) K=AC (...). The center of the circle and the absolute value of the end points are based on the zero point of the workpiece.G2/G3:X... Y... Z... I... J... K... The center of the relative dimension is based on the arc starting point.G2/G3:X... Y... Z... CR=...... given the arc radius of CR=, in Cartesian coordinate system X... Y... Z... Given arc end point.G2/G3:X... Y... Z... AR=... AR=; to a given angle in Cartesian coordinate system X... Y... Z... Given arc end point.G2/G3:I... J... K... AR=... AR=; to a given angle in Cartesian coordinate system I... J... K... Given.G2/G3AP=... CP=... In polar coordinates, a polar radius is given by RP= through the given polar angle of the AP=.CIP:X... Y... Z... I1=AC (...) J1=AC (...) K1=AC (...); address I1=, J1=, K1=, given a middle point.CT:X... Y... Z... Through the arc of the starting and ending points, as well as the tangent direction at the starting point.Among them:G2: clockwise circular arc cuttingG3: counter clockwise arc cuttingCIP: the arc interpolation is done through the middle pointCT: defines a circle with a tangent transitionXYZ: the end point given in Cartesian coordinatesIJK: gives the center of the circle in Cartesian coordinates, the XYZ directionCR: arc radiusAR: angleAP: the end point, polar angle, given in polar coordinatesRP: the polar point given in polar coordinatesI1=J1=K1=: the middle point given in Cartesian coordinates, the XYZ directionSpecial shift instructionClass 1: approximate the coded processing positionCAC ([n]): returns to the encoding location of the position number n;CIC ([n]): starting from the current location number, forward (+n) or backward (-n), returns to the N positionCDC ([n]): returns the encoded location of the position number n with the shortest strokeCACP ([n]): in a positive direction to return to the position number n encoding position (only for rotary shaft)CACN ([n]): according to the negative direction to return to the position number n encoding position (only for rotary shaft)Second class: spline interpolationAdvantages: advantages: by using spline interpolation spline interpolation, compared with the use of an array of G1 number order, the contour of parts required for the program is reduced, the mechanical characteristics of curve trend in transition between the parts program is more smooth.ASPLINE: is used to activate the A spline interpolation instructionsA: 1, through the provision of the fulcrum of accurate to go. 2, always tangent to the curve trend, but non surface. 3, almost does not produce undesirable oscillations. 4, change the fulcrum of influence scope is local, that is the fulcrum of the change only in 6 following adjacent fulcrum effect.Applications: the A spline is first applied to curve interpolation with large increase in change.BSPLINE: instructions for activating B spline interpolationB splines: 1, go through the prescribed pivot, but only in the neighborhood. The pivot only constitutes a restricted polygon. The curve passes near the pivot point. Through the weight of the fulcrum and a coefficient, the curve line can be influenced in addition. 2, the curve trend is always tangent to the surface.3. does not produce undesired swings. 4, the fulcrum changes the scope of influence is partial, and the change of the fulcrum only acts on the following 6 adjacent pivots.Applications: B splines are primarily considered interfaces with CAD systems.CSPLINE: instructions for activating C spline interpolationC transect: 1, accurate to the specified pivot. 2, the curve trend is always tangent to the surface. 3, often produce undesired swings, especially in places with large increases in change. 4, the fulcrum changes the scope of influence is the overall situation. And the change of a fulcrum affects the whole curve.Application: when the fulcrum is on a known curve (garden, parabola, hyperbola), the C spline can be used very well.。
g代码计算偏移
g代码计算偏移
G代码是用于计算机数控(CNC)机床编程的语言。
它描述了刀具在空间中的
路径和速度,从而控制机床进行精确的制造。
偏移通常是指从一个点到另一个点的线性或圆弧路径。
如果你想要通过G代码计算偏移,你需要明确你想要做什么样的偏移。
例如,你可能想要沿着X轴或Y轴移动一段距离,或者你可能想要进行圆弧插补。
下面是一个简单的例子,说明如何使用G代码进行线性偏移:
gcode
G90 ; 设置到绝对模式
G01 X10 Y10 ; 移动到(10,10)
G01 X20 Y20 ; 从(10,10)偏移到(20,20)
在这个例子中,G01表示线性插补,X10 Y10表示起始点,X20 Y20表示目标点。
如果你需要进行圆弧插补,你可以使用G02或G03。
例如:
gcode
G90 ; 设置到绝对模式
G02 X20 Y20 I5 J0 ; 画一个半径为5的半圆弧,从当前点到(20,20)
在这个例子中,G02表示顺时针圆弧插补,I5 J0表示圆心的坐标。
需要注意的是,这只是一个非常基础的例子,实际的CNC编程可能需要更复杂的G
代码来处理各种情况,如不同的材料、刀具、切削参数等。
如果你有具体的需求或问题,欢迎进一步提问。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
reprap wiki上面的Gcode说明G-codeFrom RepRapWiki(Redirected from Gcode)Jump to: navigation, searchContents [hide]1 Introduction2 RepRap G Code Fields3 Comments4 Individual commands4.1 Checking4.1.1 N and *4.2 Buffered G Commands4.2.1 G0: Rapid move4.2.2 G1: Controlled move4.2.3 G28: Move to Origin4.3 Unbuffered G commands4.3.1 G4: Dwell4.3.2 G20: Set Units to Inches4.3.3 G21: Set Units to Millimeters4.3.4 G90: Set to Absolute Positioning4.3.5 G91: Set to Relative Positioning4.3.6 G92: Set Position4.4 Unbuffered M and T commands4.4.1 M0: Stop4.4.2 M17: Enable/Power all stepper motors 4.4.3 M18: Disable all stepper motors4.4.4 M20: List SD card4.4.5 M21: Initialise SD card4.4.6 M22: Release SD card4.4.7 M23: Select SD file4.4.8 M24: Start/resume SD print4.4.9 M25: Pause SD print4.4.10 M26: Set SD position4.4.11 M27: Report SD print status4.4.12 M28: Begin write to SD card4.4.13 M29: Stop writing to SD card4.4.14 M40: Eject4.4.15 M41: Loop4.4.16 M42: Stop on material exhausted 4.4.17 M43: Stand by on material exhausted 4.4.18 M80: ATX Power On4.4.19 M81: ATX Power Off4.4.20 M84: Stop idle hold4.4.21 M92: Set axis_steps_per_unit4.4.22 M101 Turn extruder 1 on Forward4.4.23 M102 Turn extruder 1 on Reverse4.4.24 M103 Turn all extruders off4.4.25 M104: Set Extruder Temperature (Fast)4.4.26 M105: Get Extruder Temperature4.4.27 M106: Fan On4.4.28 M107: Fan Off4.4.29 M108: Set Extruder Speed4.4.30 M109: Set Extruder Temperature4.4.31 M110: Set Current Line Number4.4.32 M111: Set Debug Level4.4.33 M112: Emergency Stop4.4.34 M113: Set Extruder PWM4.4.35 M114: Get Current Position4.4.36 M115: Get Firmware Version and Capabilities4.4.37 M116: Wait4.4.38 M117: Get Zero Position4.4.39 M118: Negotiate Features4.4.40 M119: Get Endstop Status4.4.41 M126: Open Valve4.4.42 M127: Close Valve4.4.43 M128: Extruder Pressure PWM4.4.44 M129: Extruder pressure off4.4.45 M140: Bed Temperature (Fast)4.4.46 M141: Chamber Temperature (Fast)4.4.47 M142: Holding Pressure4.4.48 M143: Maximum hot-end temperature4.4.49 M160: Number of mixed materials4.4.50 M203: Record Z adjustment4.4.51 M226: Gcode Initiated Pause4.4.52 M227: Enable Automatic Reverse and Prime4.4.53 M228: Disable Automatic Reverse and Prime4.4.54 M229: Enable Automatic Reverse and Prime4.4.55 M230: Disable / Enable Wait for Temperature Change 4.4.56 M240: Start conveyor belt motor4.4.57 M241: Stop conveyor belt motor4.4.58 M245: Start cooler4.4.59 M246: Stop cooler4.4.60 M300: Play beep sound4.4.61 T: Select Tool5 Proposed EEPROM configuration codes6 Replies from the RepRap machine to the host computer7 Proposal for sending multiple lines of G-code7.1 Problem to solveIntroductionThis page describes the G Codes that the RepRap firmware uses and how they work.The list of what can be done is extensible. But check this page first, and add your extension here first before you implement it.A typical piece of GCode as sent to a RepRap machine might look like this:N3 T0*57N4 G92 E0*67N5 G28*22N6 G1 F1500.0*82N7 G1 X2.0 Y2.0 F3000.0*85N8 G1 X3.0 Y3.0*33The meaning of all those symbols and numbers (and more) is explained below.TO find out which specific gcode/s are implemented in any given firmware, please see the Firmware_features page.(For the technically minded, the end of line is marked by both a <nl> and a <cr>. If you want to manually enter GCodes in your reprap using the Arduino Serial interface, make sure to select "Both NL & CR" on the bottom of the screen.)This isn't accurate, firmware accepts single <nl> as well as single <cr>, or combinations thereof. Hosts should accepts all four combinations as well. --Traumflug 09:34, 20 April 2011 (UTC)RepRap G Code FieldsThis section explains the letter-preceded fields. The numbers in the fields are represented by nnn. Numbers can be integers, or can contain a decimal point, depending on context. For example an X coordinate can be integer (X175) or fractional (X17.62), whereas trying to select extruder number 2.76 would make no sense.Letter MeaningGnnn Standard GCode command, such as move to a pointMnnn RepRap-defined command, such as turn on a cooling fanTnnn Select tool nnn. In RepRap, tools are extrudersSnnn Command parameter, such as the voltage to send to a motorPnnn Command parameter, such as a time in millisecondsXnnn An X coordinate, usually to move toYnnn A Y coordinate, usually to move toZnnn A Z coordinate, usually to move toInnn Parameter - not currently usedJnnn Parameter - not currently usedFnnn Feedrate in mm per minute. (Speed of print head movement)Rnnn Parameter - not currently usedQnnn Parameter - not currently usedEnnn Length of extrudate in mm. This is exactly like X, Y and Z, but for the length of filament to extrude. It is common for newer stepper based systems to interpret ... Better: Skeinforge 40 and up interprets this as the absolute length of input filament to consume, rather than the length of the extruded output.Nnnn Line number. Used to request repeat transmission in the case of communications errors. *nnn Checksum. Used to check for communications errors.CommentsG Code comments:N3 T0*57 ;This is a commentN4 G92 E0*67; So is thisN5 G28*22Will be ignored by RepRap, as will blank lines. But it's better to strip these out in the host computer before the lines are sent. This saves bandwidth.Individual commandsCheckingN and *Example: N123 [...G Code in here...] *71These are the line number and the checksum. The RepRap firmware checks the checksum against a locally-computed value and, if they differ, requests a repeat transmission of the line of the given number.You can leave both of these out - RepRap will still work, but it won't do checking. You have to have both or neither though.The checksum "cs" for a GCode string "cmd" (including its line number) is computed by exor-ing the bytes in the string up to and not including the * character as follows:int cs = 0;for(i = 0; cmd[i] != '*' && cmd[i] != NULL; i++)cs = cs ^ cmd[i];cs &= 0xff; // Defensive programming...and the value is appended as a decimal integer to the command after the * character.The RepRap firmware expects line numbers to increase by 1 each line, and if that doesn't happen it is flagged as an error. But you can reset the count using M110 (see below).Buffered G CommandsThe RepRap firmware stores these commands in a ring buffer internally for execution. This means that there is no (appreciable) delay while a command is acknowledged and the next transmitted. In turn, this means that sequences of line segments can be plotted without a dwell between one and the next. As soon as one of these buffered commands is received it is acknowledged and stored locally. If the local buffer is full, then the acknowledgment is delayed until space for storage in the buffer is available. This is how flow control is achieved.G0: Rapid moveExample: G0 X12In this case move rapidly to X = 12 mm. In fact, the RepRap firmware uses exactly the same code for rapid as it uses for controlled moves (see G1 below), as - for the RepRap machine - this is just as efficient as not doing so. (The distinction comes from some old machine tools that used to move faster if the axes were not driven in a straight line. For them G0 allowed any movement in space to get to the destination as fast as possible.)G1: Controlled moveExample: G1 X90.6 Y13.8 E22.4Go in a straight line from the current (X, Y) point to the point (90.6, 13.8), extruding material as the move happens from the current extruded length to a length of 22.4 mm.RepRap does subtle things with feedrates. Thus:G1 F1500G1 X90.6 Y13.8 E22.4Will set a feedrate of 1500 mm/minute, then do the move described above at that feedrate. ButG1 F1500G1 X90.6 Y13.8 E22.4 F3000Will set a feedrate of 1500 mm/minute, then do the move described above accelerating to a feedrate of 3000 mm/minute as it does so. The extrusion will accelerate along with the X, Y movement so everything stays synchronized.RepRap thus treats feedrate as simply another variable (like X, Y, Z, and E) to be linearly interpolated. This gives complete control over accelerations and decelerations in a way that ensures that everything moves together and the right volume of material is extruded at all points.The first example shows how to get a constant-speed movement. The second how to accelerate or decelerate. ThusG1 F1500G1 X90.6 Y13.8 E22.4 F3000G1 X80 Y20 E36 F1500Will do the first movement accelerating as before, and the second decelerating from 3000 mm/minute back to 1500 mm/minute.To reverse the extruder by a given amount (for example to reduce its internal pressure while it does an in-air movement so that it doesn't dribble) simply use G1 to send an E value that is less than the currently extruded length.G28: Move to OriginExample: G28This causes the RepRap machine to move back to its X, Y and Z zero endstops, a process known as "homing". It does so accelerating, so as to get there fast. But when it arrives it backs off by 1 mm in each direction slowly, then moves back slowly to the stop. This ensures more accurate positioning.If you add coordinates, then just the axes with coordinates specified will be zeroed. ThusG28 X0 Y72.3will zero the X and Y axes, but not Z. The actual coordinate values are ignored.Unbuffered G commandsThe following commands are not buffered. When one is received it is stored, but it is not acknowledged to the host until the buffer is exhausted and then the command has been executed. Thus the host will pause at one of these commands until it has been done. Short pauses between these commands and any that might follow them do not affect the performance of the machine.G4: DwellExample: G4 P200In this case sit still doing nothing for 200 milliseconds. During delays the state of the machine (for example the temperatures of its extruders) will still be preserved and controlled.G20: Set Units to InchesExample: G20Units from now on are in inches.G21: Set Units to MillimetersExample: G21Units from now on are in millimeters. (This is the RepRap default.)G90: Set to Absolute PositioningExample: G90All coordinates from now on are absolute relative to the origin of the machine. (This is the RepRap default.)G91: Set to Relative PositioningExample: G91All coordinates from now on are relative to the last position.G92: Set PositionExample: G92 X10 E90Allows programming of absolute zero point, by reseting the current position to the values specified. This would set the machine's X coordinate to 10, and the extrude coordinate to 90. No physical motion will occur.Unbuffered M and T commandsM0: StopExample: M0The RepRap machine finishes any moves left in its buffer, then shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M112.M17: Enable/Power all stepper motorsExample: M17M18: Disable all stepper motorsExample: M18Disables stepper motors and allows axis to move 'freely.'M20: List SD cardExample: M20All files in the root folder of the SD card are listed to the serial port. This results in a line like:ok Files: {SQUARE.G,SQCOM.G,}The trailing comma is optional. Note that file names are returned in upper case, but - when sent to the M23 command (below) they must be in lower case. This seems to be a function of the SD software. Go figure...M21: Initialise SD cardExample: M21The SD card is initialised. If an SD card is loaded when the machine is switched on, this will happen by default. SD card must be initialised for the other SD functions to work.M22: Release SD cardExample: M22SD card is released and can be physically removed.M23: Select SD fileExample: M23 filename.gcoThe file specified as filename.gco (8.3 naming convention is supported) is selected ready for printing.M24: Start/resume SD printExample: M24The machine prints from the file selected with the M23 command.M25: Pause SD printExample: M25The machine pause printing at the current position within the file selected with the M23 command.M26: Set SD positionExample: M26Set SD position in bytes (M26 S12345).M27: Report SD print statusExample: M27Report SD print status.M28: Begin write to SD cardExample: M28 filename.gcoFile specified by filename.gco is created (or overwritten if it exists) on the SD card and all subsequent commands sent to the machine are written to that file.M29: Stop writing to SD cardExample: M29 filename.gcoFile opened by M28 command is closed, and all subsequent commands sent to the machine are executed as normal.M40: EjectIf your RepRap machine can eject the parts it has built off the bed, this command executes the eject cycle. This usually involves cooling the bed and then performing a sequence of movements that remove the printed parts from it. The X, Y and Z position of the machine at the end of this cycle are undefined (though they can be found out using the M114 command, q.v.).See also M240 and M241 below.M41: LoopExample: M41If the RepRap machine was building a file from its own memory such as a local SD card (as opposed to a file being transmitted to it from a host computer) this goes back to the beginning of the file and runs it again. So, for example, if your RepRap is capable of ejecting parts from its build bed then you can set it printing in a loop and it will run and run. Use with caution - the only things that will stop it are:1.When you press the reset button,2.When the build material runs out (if your RepRap is set up to detect this), and3.When there's an error (such as a heater failure).M42: Stop on material exhaustedExample: M42If your RepRap can detect when its material runs out, this decides the behaviour when that happens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off. You have to press reset to reactivate the machine. In other words, it parks itself and then executes an M0 command (q.v.).M43: Stand by on material exhaustedExample: M43If your RepRap can detect when its material runs out, this decides the behaviour when thathappens. The X and Y axes are zeroed (but not Z), and then the machine shuts all motors and heaters off except the heated bed, the temperature of which is maintained. The machine will still respond to G and M code commands in this state.M80: ATX Power OnExample: M80Turns on the ATX power supply from standby mode to fully operational mode. No-op on electronics without standby mode.Note: some firmwares, like Teacup, handle power on/off automatically, so this is redundant there.M81: ATX Power OffExample: M81Turns off the ATX power supply. Counterpart to M80.M84: Stop idle holdExample: M84Stop the idle hold on all axis and extruder. In some cases the idle hold causes annoying noises, which can be stopped by disabling the hold. Be aware that by disabling idle hold during printing, you will get quality issues. This is recommended only in between or after printjobs.M92: Set axis_steps_per_unitExample: M92 X<newsteps> Sprinter and MarlinAllows programming of steps per unit of axis till the electronics are reset for the specified axis. Very useful for calibration.M101 Turn extruder 1 on ForwardDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM102 Turn extruder 1 on ReverseDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM103 Turn all extruders offDepreciated. see MCodeReference. Was used by older style DC extruders. See also Bits From BytesM104: Set Extruder Temperature (Fast)Example: M104 S190Set the temperature of the current extruder to 190oC and return control to the host immediately (i.e. before that temperature has been reached by the extruder). See also M109.M105: Get Extruder TemperatureExample: M105Request the temperature of the current extruder and the build base in degrees Celsius. The temperatures are returned to the host computer. For example, the line sent to the host in response to this command looks likeok T:201 B:117M106: Fan OnExample: M106 S127Turn on the cooling fan at half speed. Optional parameter 'S' declares the PWM value (0-255)M107: Fan OffExample: M107Turn off the cooling fan (if any).M108: Set Extruder SpeedSets speed of extruder motor. (Deprecated in current firmware, see M113)M109: Set Extruder TemperatureExample: M109 S190Set the temperature of the current extruder to 190oC and wait for it to reach that value before sending an acknowledgment to the host. In fact the RepRap firmware waits a while after the temperature has been reached for the extruder to stabilise - typically about 40 seconds. This can be changed by a parameter in the firmware configuration file when the firmware is compiled. See also M104 and M116.M110: Set Current Line NumberExample: N123 M110Set the current line number to 123. Thus the expected next line after this command will be 124.M111: Set Debug LevelExample: M111 S6Set the level of debugging information transmitted back to the host to level 6. The level is the OR of three bits:#define DEBUG_ECHO (1<<0)#define DEBUG_INFO (1<<1)#define DEBUG_ERRORS (1<<2)Thus 6 means send information and errors, but don't echo commands. (This is the RepRap default.)M112: Emergency StopExample: M112Any moves in progress are immediately terminated, then RepRap shuts down. All motors and heaters are turned off. It can be started again by pressing the reset button on the master microcontroller. See also M0.M113: Set Extruder PWMExample: M113Set the PWM for the currently-selected extruder. On its own this command sets RepRap to use the on-board potentiometer on the extruder controller board to set the PWM for the currently-selected extruder's stepper power. With an S field:M113 S0.7it causes the PWM to be set to the S value (70% in this instance). M113 S0 turns the extruder off, until an M113 command other than M113 S0 is sent.M114: Get Current PositionExample: M114This causes the RepRap machine to report its current X, Y, Z and E coordinates to the host.For example, the machine returns a string such as:ok C: X:0.00 Y:0.00 Z:0.00 E:0.00M115: Get Firmware Version and CapabilitiesExample: M115Request the Firmware Version and Capabilities of the current microcontroller The details are returned to the host computer as key:value pairs separated by spaces and terminated with alinefeed.sample data from firmware:ok PROTOCOL_VERSION:0.1 FIRMWARE_NAME:FiveD FIRMWARE_URL:http%3A// MACHINE_TYPE:Mendel EXTRUDER_COUNT:1This M115 code is inconsistently implemented, and should not be relied upon to exist, or output correctly in all cases. An initial implementation was committed to svn for the FiveD Reprap firmware on 11 Oct 2010. Work to more formally define protocol versions is currently (October 2010) being discussed. See M115_Keywords for one draft set of keywords and their meanings.M116: WaitExample: M116Wait for all temperatures and other slowly-changing variables to arrive at their set values. See also M109.M117: Get Zero PositionExample: M117This causes the RepRap machine to report the X, Y, Z and E coordinates in steps not mm to the host that it found when it last hit the zero stops for those axes. That is to say, when you zero X, the x coordinate of the machine when it hits the X endstop is recorded. This value should be 0, of course. But if the machine has drifted (for example by dropping steps) then it won't be. This command allows you to measure and to diagnose such problems. (E is included for completeness. It doesn't normally have an endstop.)M118: Negotiate FeaturesExample: M118 P42This M-code is for future proofing. NO firmware or hostware supports this at the moment. It is used in conjunction with M115's FEATURES keyword.See Protocol_Feature_Negotiation for more info.M119: Get Endstop StatusExample: M119Returns the current state of the configured X,Y,Z endstops. Should take into account any 'inverted endstop' settings, so one can confirm that the machine is interpreting the endstops correctly.M126: Open ValveExample: M126 P500Open the extruder's valve (if it has one) and wait 500 milliseconds for it to do so.M127: Close ValveExample: M127 P400Close the extruder's valve (if it has one) and wait 400 milliseconds for it to do so.M128: Extruder Pressure PWMExample: M128 S255PWM value to control internal extruder pressure. S255 is full pressure.M129: Extruder pressure offExample: M129 P100In addition to setting Extruder pressure to 0, you can turn the pressure off entirely. P400 will wait 100ms to do so.M140: Bed Temperature (Fast)Example: M140 S55Set the temperature of the build bed to 55oC and return control to the host immediately (i.e. before that temperature has been reached by the bed).M141: Chamber Temperature (Fast)Example: M141 S30Set the temperature of the chamber to 30oC and return control to the host immediately (i.e. before that temperature has been reached by the chamber).M142: Holding PressureExample: M142 S1Set the holding pressure of the bed to 1 bar.The holding pressure is in bar. For hardware which only has on/off holding, when the holding pressure is zero, turn off holding, when the holding pressure is greater than zero, turn on holding.M143: Maximum hot-end temperatureExample: M143 S275Set the maximum temperature of the hot-end to 275CWhen temperature of the hot-end exceeds this value, take countermeasures, for instance anemergency stop. This is to prevent hot-end damage.M160: Number of mixed materialsExample: M160 S4Set the number of materials, N, that the current extruder can handle to the number specified. The default is 1.When N >= 2, then the E field that controls extrusion requires N+1 values separated by spaces after it like this:M160 S4G1 X90.6 Y13.8 E22.4 0.1 0.1 0.1 0.7G1 X70.6 E42.4 0.0 0.0 0.0 1.0G1 E42.4 1.0 0.0 0.0 0.0The second line moves straight to the point (90.6, 13.8) extruding 22.4mm of filament. The mix ratio at the end of the move is 0.1:0.1:0.1:0.7.The third line moves back 20mm in X extruding 20mm of filament. The mix varies linearly from 0.1:0.1:0.1:0.7 to 0:0:0:1 as the move is made.The fourth line has no physical effect, but sets the mix proportions for the start of the next move to 1:0:0:0.M203: Record Z adjustmentExample: M203 Z-0.75This records a Z offset in non-volatile memory in RepRap's microcontroller where it remains active until next set, even when the power is turned off and on again. If the first layer is too close to the bed, you need to effectively move the bed down, so the Z value will be negative. If the nozzle is too far from the bed during the first layer, the Z value should be positive to raise the bed. The maximum adjustment is +/-1.27mm.M226: Gcode Initiated PauseExample: M226Initiates a pause in the same way as if the pause button is pressed.M227: Enable Automatic Reverse and PrimeExample: M227 P1600 S1600P and S are steps.M228: Disable Automatic Reverse and PrimeExample: M228M229: Enable Automatic Reverse and PrimeExample: M229 P1.0 S1.0P and S are extruder screw rotations.M230: Disable / Enable Wait for Temperature ChangeExample: M230 S1S1 Disable wait for temperature change S0 Enable wait for temperature changeM240: Start conveyor belt motorExample: M240The conveyor belt allows to start mass production of a part with a reprapM241: Stop conveyor belt motorExample: M241M245: Start coolerExample: M245used to cool parts/heated-bed down after printing for easy remove of the parts after printM246: Stop coolerExample: M246M300: Play beep soundUsage: M300 S<frequency Hz> P<duration ms>Example: M300 S300 P1000Play beep sound, use to notify important events like the end of printing. See working example on R2C2 electronics.T: Select ToolExample: T1Select extruder number 1 to build with. Extruder numbering starts at 0.Proposed EEPROM configuration codesBRIEFLY: each RepRap has a number of physical parameters that should be persistent, but easily configurable, such as extrusion steps/mm, various max values, etc. Those parameters are currently hardcoded in the firmware, so that a user has to modify, recompile and re-flash the firmware for any adjustments. These configs can be stored in MCU's EEPROM and modified via some M-codes. Please see the detailed proposal at M-codes for EEPROM config. (This is proposed by --AlexRa on 11-March-2011. There is currently no working implementation of the proposed commands).Replies from the RepRap machine to the host computerAll communication is in printable ASCII characters. Messages sent back to the host computer are terminated by a newline and look like this:xx [line number to resend] [T:93.2 B:22.9] [C: X:9.2 Y:125.4 Z:3.7 E:1902.5] [Some debugging or other information may be here]xx can be one of:okrs!!ok means that no error has been detected.rs means resend, and is followed by the line number to resend.!! means that a hardware fault has been detected. The RepRap machine will shut down immediately after it has sent this message.The T: and B: values are the temperature of the currently-selected extruder and the bed respectively, and are only sent in response to M105. If such temperatures don't exist (for example for an extruder that works at room temperature and doesn't have a sensor) then a value below absolute zero (-273oC) is returned.C: means that coordinates follow. Those are the X: Y: etc values. These are only sent in response to M114 and M117.The RepRap machine may also send lines that look like this:// This is some debugging or other information on a line on its own. It may be sent at any time.Such lines will always be preceded by //.The most common response is simply:okWhen the machine boots up it sends the stringstartonce to the host before sending anything else. This should not be replaced or augmented by version numbers and the like. M115 (see above) requests those.All this means that every line sent by RepRap to the host computer except the start line has a two-character prefix (one of ok, rs, !! or //). The machine should never send a line without such a prefix.。