GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing linuxcnc.org — M-Codes M-CodesTable of Contents
1. M-Code Quick Reference Table
2. M0, M1 Program Pause
3. M2, M30 Program End
Both of these commands have the following effects:
4. M60 Pallet Change Pause
5. M3, M4, M5 Spindle Control
Use $ to operate on specific spindles. If $ is omitted then the commands default to operating on spindle 0. Use $-1 to operate on all active spindles. This example will start spindles 0, 1, and 2 simultaneously at different speeds: S100 $0 S200 $1 S300 $2 M3 $-1 This example will then reverse spindle 1 but leave the other spindles rotating forwards: M4 $1 And this will stop spindle 2 and leave the other spindles rotating: M5 $2 If the $ is omitted then behaviour is exactly as normal for a single spindle machine. It is OK to use M3 or M4 if the S spindle speed is set to zero. If this is done (or if the speed override switch is enabled and set to zero), the spindle will not start turning. If, later, the spindle speed is set above zero (or the override switch is turned up), the spindle will start turning. It is OK to use M3 or M4 when the spindle is already turning or to use M5 when the spindle is already stopped. 6. M6 Tool Change6.1. Manual Tool ChangeIf the HAL component hal_manualtoolchange is loaded, M6 will stop the spindle and prompt the user to change the tool based on the last T- number programmed. For more information on hal_manualtoolchange see the Manual Tool Change section. 6.2. Tool ChangerTo change a tool in the spindle from the tool currently in the spindle to the tool most recently selected (using a T word - see section Select Tool), program M6. When the tool change is complete:
The tool change may include axis motion. It is OK (but not useful) to program a change to the tool already in the spindle. It is OK if there is no tool in the selected slot; in that case, the spindle will be empty after the tool change. If slot zero was last selected, there will definitely be no tool in the spindle after a tool change. The tool changer will have to be setup to perform the tool change in HAL and possibly ClassicLadder. 7. M7, M8, M9 Coolant Control
Connect one or both of the coolant control pins in HAL before M7 or M8 will control an output. M7 and M8 can be used to turn on any output via G-code. It is OK to use any of these commands, regardless of the current coolant state. 8. M19 Orient SpindleM19 R- Q- [P-] [$-]
M19 is a command of modal group 7, like M3, M4 and M5. M19 is cleared by any of M3,M4,M5. Spindle orientation requires a quadrature encoder to sense the spindle shaft position and direction of rotation. INI Settings in the [RS274NGC] section:
9. M48, M49 Speed and Feed Override Control
These commands also take an optional $ parameter to determine which spindle they operate on. It is OK to enable or disable the controls when they are already enabled or disabled. See the Feed Rate section for more details. They also can be be toggled individually using M50 and M51, see below. 10. M50 Feed Override Control
While disabled the feed override will have no influence, and the motion will be executed at programmed feed rate. (unless there is an adaptive feed rate override active). 11. M51 Spindle Speed Override Control
While disabled the spindle speed override will have no influence, and the spindle speed will have the exact program specified value of the S-word (described in the Spindle Speed section). 12. M52 Adaptive Feed Control
When adaptive feed is enabled, some external input value is used together with the user interface feed override value and the commanded feed rate to set the actual feed rate. In LinuxCNC, the HAL pin motion.adaptive-feed is used for this purpose. Values on motion.adaptive-feed should range from -1 (programmed speed in reverse) to 1 (full speed). 0 is equivalent to feed-hold.
13. M53 Feed Stop Control
14. M61 Set Current Tool
It is an error if:
15. M62 - M65 Digital Output Control
The P- word specifies the digital output number. The P-word ranges from 0 to a default value of 3. If needed the the number of I/O can be increased by using the num_dio parameter when loading the motion controller. See the Motion section for more information. The M62 & M63 commands will be queued. Subsequent commands referring to the same output number will overwrite the older settings. More than one output change can be specified by issuing more than one M62/M63 command. The actual change of the specified outputs will happen at the beginning of the next motion command. If there is no subsequent motion command, the queued output changes won’t happen. It’s best to always program a motion G-code (G0, G1, etc) right after the M62/63. M64 & M65 happen immediately as they are received by the motion controller. They are not synchronized with movement, and they will break blending.
16. M66 Wait on InputM66 P- | E- <L->
M66 Example Lines
M66 P0 L3 Q5 (wait up to 5 seconds for digital input 0 to turn on) M66 wait on an input stops further execution of the program, until the selected event (or the programmed timeout) occurs. It is an error to program M66 with both a P-word and an E-word (thus selecting both an analog and a digital input). In LinuxCNC these inputs are not monitored in real time and thus should not be used for timing-critical applications. The number of I/O can be increased by using the num_dio or num_aio parameter when loading the motion controller. See the Motion section for more information.
Example HAL Connection
17. M67 Analog Output, SynchronizedM67 E- Q-
The actual change of the specified outputs will happen at the beginning of the next motion command. If there is no subsequent motion command, the queued output changes won’t happen. It’s best to always program a motion G-code (G0, G1, etc) right after the M67. M67 functions the same as M62-63. The number of I/O can be increased by using the num_dio or num_aio parameter when loading the motion controller. See the Motion section for more information.
18. M68 Analog Output, ImmediateM68 E- Q-
M68 output happen immediately as they are received by the motion controller. They are not synchronized with movement, and they will break blending. M68 functions the same as M64-65. The number of I/O can be increased by using the num_dio or num_aio parameter when loading the motion controller. See the Motion section for more information.
19. M70 Save Modal StateTo explicitly save the modal state at the current call level, program M70. Once modal state has been saved with M70, it can be restored to exactly that state by executing an M72. A pair of M70 and M72 instructions will typically be used to protect a program against inadvertent modal changes within subroutines. M70 Saved state The state saved consists of:
Note that in particular, the motion mode (G1 etc) is NOT restored. current call level means either:
A recursive invocation of a subroutine introduces a new call level. 20. M71 Invalidate Stored Modal StateModal state saved with an M70 or by an M73 at the current call level is invalidated (cannot be restored from anymore). A subsequent M72 at the same call level will fail. If executed in a subroutine which protects modal state by an M73, a subsequent return or endsub will not restore modal state. The usefulness of this feature is dubious. It should not be relied upon as it might go away. 21. M72 Restore Modal StateModal state saved with an M70 code can be restored by executing an M72. The handling of G20/G21 is specially treated as feeds are interpreted differently depending on G20/G21: if length units (mm/in) are about to be changed by the restore operation, 'M72 'will restore the distance mode first, and then all other state including feed to make sure the feed value is interpreted in the correct unit setting. It is an error to execute an M72 with no previous M70 save operation at that level. The following example demonstrates saving and explicitly restoring modal state around a subroutine call using M70 and M72. Note that the imperialsub subroutine is not "aware" of the M7x features and can be used unmodified: O<showstate> sub (DEBUG, imperial=#<_imperial> absolute=#<_absolute> feed=#<_feed> rpm=#<_rpm>) O<showstate> endsub O<imperialsub> sub g20 (imperial) g91 (relative mode) F5 (low feed) S300 (low rpm) (debug, in subroutine, state now:) o<showstate> call O<imperialsub> endsub ; main program g21 (metric) g90 (absolute) f200 (fast speed) S2500 (high rpm) (debug, in main, state now:) o<showstate> call M70 (save caller state in at global level) O<imperialsub> call M72 (explicitly restore state) (debug, back in main, state now:) o<showstate> call m2 22. M73 Save and Autorestore Modal StateTo save modal state within a subroutine, and restore state on subroutine endsub or any return path, program M73. Aborting a running program in a subroutine which has an M73 operation will not restore state . Also, the normal end (M2) of a main program which contains an M73 will not restore state. The suggested use is at the beginning of a O-word subroutine as in the following example. Using M73 this way enables designing subroutines which need to modify modal state but will protect the calling program against inadvertent modal changes. Note the use of predefined named parameters in the showstate subroutine. O<showstate> sub (DEBUG, imperial=#<_imperial> absolute=#<_absolute> feed=#<_feed> rpm=#<_rpm>) O<showstate> endsub O<imperialsub> sub M73 (save caller state in current call context, restore on return or endsub) g20 (imperial) g91 (relative mode) F5 (low feed) S300 (low rpm) (debug, in subroutine, state now:) o<showstate> call ; note - no M72 is needed here - the following endsub or an ; explicit 'return' will restore caller state O<imperialsub> endsub ; main program g21 (metric) g90 (absolute) f200 (fast speed) S2500 (high rpm) (debug, in main, state now:) o<showstate> call o<imperialsub> call (debug, back in main, state now:) o<showstate> call m2 23. M98 and M99The interpreter supports Fanuc-style main- and sub-programs with the M98 and M99 M-codes. See Fanuc-Style Programs. 23.1. Selectively Restoring Modal StateExecuting an M72 or returning from a subroutine which contains an M73 will restore all modal state saved. If only some aspects of modal state should be preserved, an alternative is the usage of predefined named parameters, local parameters and conditional statements. The idea is to remember the modes to be restored at the beginning of the subroutine, and restore these before exiting. Here is an example, based on snippet of nc_files/tool-length-probe.ngc: O<measure> sub (measure reference tool) ; #<absolute> = #<_absolute> (remember in local variable if G90 was set) ; g30 (above switch) g38.2 z0 f15 (measure) g91 g0z.2 (off the switch) #1000=#5063 (save reference tool length) (print,reference length is #1000) ; O<restore_abs> if [#<absolute>] g90 (restore G90 only if it was set on entry:) O<restore_abs> endif ; O<measure> endsub 24. M100-M199 User Defined CommandsM1-- <P- Q->
The external program named M100 through M199 (no extension, a capital M, found in directory pointed by [DISPLAY] PROGRAM_PREFIX parameter of the INI file) is executed with the optional P and Q values as its two arguments. Execution of the G-code file pauses until the external program exits. If the external program exits with exit code other than 0 gcode program execution is stopped. Any valid executable file can be used. The file must be located in the search path specified in the INI file configuration. See the Display section for more information on search paths. After creating a new M1nn program, the GUI should be restarted so that the new program is taken into account, otherwise a Unknown M-code error will occur.
The error Unknown M-code used denotes one of the following:
For example to open and close a collet closer that is controlled by a parallel port pin using a bash script file using M101 and M102. Create two files named M101 and M102. Set them as executable files (typically right click/properties/permissions) before running LinuxCNC. Make sure the parallel port pin is not connected to anything in a HAL file. M101 Example File
M102 Example File
To pass a variable to a M1nn file you use the P and Q option like this: M100 P123.456 Q321.654 M100 Example file
To display a graphic message and stop until the message window is closed use a graphic display program like Eye of Gnome to display the graphic file. When you close it the program will resume. M110 Example file
To display a graphic message and continue processing the G-code file suffix an ampersand to the command. M110 Example display and keep going
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |