Macros
A work in progress page for useful gcode macros.
Introduction
RepRapFirmware allows for gcode sequences, called macros, to be stored on the SD card. these macros can then be called by entering :
Macros can be called from any source of gcode: the console, from a gcode printing off the SD card, from the PanelDue and from another user or system macro. DuetWebControl makes it easy to upload, edit and create new macros.
Macros also allow for naming gcodes with easier to remember names. For example you can create a Macro for "Allow Cold Extrude" to call M302 P1.
The macro folder can divided into sub directories to more easily organise your macros by type.
For more information see Setting up macro files for common tasks
System files are also effectively macros, for example homing files are a sequence of gcodes to run the specific homing sequence for a specific printer type. See here for information on using tool change macros
The RepRap wikialso contains a page of useful macros.
RepRapFirmware configurator
RepRapFirmware configurator will produce appropriate system macros for most basic printer types. These are generally a good start point.
Repository
There is a github repository here for macros.
https://github.com/Duet3D/GcodeMacros
Or here
https://github.com/Duet3D/RRF-machine-co...
It is a work in progress. Please submit pull requests or comment on the forum if you have example macros to share.
Printer management
Start and end gcodes
Macros can be used to complement printer "start gcode" and "end gcode", for example if you have different printers, with different start and ends sequences, but you want to use the same sliced gcode, you could use
M98 P" startprint.g"
Filament management
see Filaments, specific load and unload macros can be defined by filament type.
Calibration and Tuning
Calibration and tuning printer settings often requires repeating the same steps repeatedly, changing one variable at a time. Macros can help automate this.
As set of simple short cuts for tuning various settings like acceleration, jerk, retraction, pressure advance, etc. (from forum user Phaedrux)
Example: Measuring the Z axis for a Z max endstop and saving the result
Here is an example macro that uses the M500 function to measure and save the length of the Z axis using the Z max endstop.
; 0:/macros/Bed Leveling/0_Set Zmax height.g ; Automates measuring the Zmax height ; M291 P"This will set Z0 and calibrate Zmax height" R"Proceed?" S3 M291 P"Heating and Homing all axis. Remove filament." T5 M190 S60 ; Set bed temp to 60 and wait M109 S215 ; Set nozzle temp to 215 and wait G28 ; Home all G90 ; absolute positioning G1 X155 Y140 F6000 ; move probe to center M291 P"Print head will now raise until the Z Max endstop is triggered" S3 M913 Z50 ; drop the motor current of the z axis motor G1 H3 Z300 F400 ; Z up until triggered. set M208 Z max M500 ; save m208 value for z axis to config override M291 P"ZMax homing will now be tested, starting with homing Zmin" S3 M291 P"Homing to Zmin" T5 G1 Z100 F6000 ; move z down a bit quickly M558 F600 A1 ; set single fast probe settings G30 ; probe the bed at center M558 F120 A10 ; set slower multi probe G30 ; probe the bed at center M291 P"Ready to test Zmax homing?" R"Proceed?" S3 M291 P"Homing to Zmax" T5 G28 Z ; home to zmax M291 P"Verify that Z max height is correct by moving to Z0" S3 G1 Z0 F400 ; move the Z axis to Z0 M291 "The nozzle should now be just touching the bed." S3 M913 Z100 ; return z axis motor current to normal M140 S0 ; turn bed heater off M104 S0 ; turn hotend heater off
Other Macros
Sounds
It is possible to use macros to make the PanelDue beeper play simple tunes by using the M300 (play beep) gcode and the G4 (dwell) gcodes.
See examples here: https://forum.duet3d.com/topic/15722/tur...
System Macros
RepRapFirmware uses gcode files to script many user configurable printer actions. The use of these system macros and opposed to hard coding the functionality is one the reasons RepRapFirmware is so flexible. It is recommended to start with a configuration from the RepRapFirmware configurator or a known good configuration as a start point.
Note, all these macros are in /sys/ on the SD card unless otherwise noted
Homing
Homing macros depend on the type of printer you are using. See:
- Cartesian printer homing.
- Delta printer homing.
- Peculiarities of CoreXY homing
- IDEX homing
- SCARA homing
- Polar homing
Bed probing
Deploying and retracting the probe
If you have a z probe that must be deployed before probing and retracted afterwards use deployprobe.g and retractprobe.g to call the appropriate deploy and retract commands. These are called by M401 - Deploy z probe, M402 - Retract z probe.
If you are running RepRapFirmware 3.1 or later and you have more than one Z probe, then use deployprobe0.g and retractprobe0.g for probe 0, deployprobe1.g and retractprobe1.g for probe 1 and so on.
Note: If you do not have a Z probe that needs to deploy or retract you must not have these files in the /sys/ directory
Delta calibration, or true bed levelling using multiple Z motors
bed.g is run in response to the G32 command. See delta calibration and Bed levelling using multiple independent Z motors.
Mesh bed compensation
In RepRapFirmware 3.2 and later, mesh.g is run in response to a G29 command with no parameters. If file mesh.g is not found then it behaves like G29 S0 instead.
Tool change
There are normally three specified tool change macros (any of which can contain no commands if desired) that execute in this order:
- Actions to do with the old tool before it is released - macro name: tfreeN.g where N is the tool number;
- Actions to do with the new tool before it is selected - macro name: tpreN.g where N is the tool number;
- Actions to do with the new tool after it is selected - macro name: tpostN.g where N is the tool number.
See Selecting a tool for more details.
Start, pause, stop and power fail
- start.g is run when you start a print from SD card. Runs immediately before any slicer created gcode.
- pause.g is run when you pause a print.
- resume.g is run when you resume a print.
- cancel.g is optional, but if present is run when you cancel a paused print.
- stop.g is optional, but if present is run when a print finishes normally with an M0 command at the end of the print job.
- sleep.g If M1 is issued the firmware finishes any moves left in its buffer, then shuts down, the macro file sleep.g is run before all heaters and drives are turned off.
- filament-change.g is run if a M600 command is encountered when printing from SD card. if that file is not found then pause.g is run instead.
The Duet can be configured to detect a power failure and store the current state once the power returns if a user wants to resume the print resurrect-prologue.g is run that would contain user commands to home the printer etc before resuming.
Triggers
M581 can be used to setup the external triggers (switches etc). These triggers carry out actions defined in trigger#.g
3D scanner control
M752 runs two macros before and after a 3d scan: before the SCAN command is sent to the scanner, the macro file scan_pre.g is executed and when the scan has finished, the macro file scan_post.g is run.
daemon.g
From RRF3.1.0 and later the file /sys/daemon.g can be used to execute regular tasks. The firmware looks for the file, if the file exists it executes it and once the end of file is reached it waits for a second and then executes it again. If the file is not found it waits for a seconds and then looks for it again.
This can be used in combination with Conditional Gcode to check the object model to look for a particular condition, and then take an action.
Caution must be taken not to start a loop that takes a long time to complete, without having a G4 P500 or similar command to hand control back to the main process every half a second or so.
runonce.g
File runonce.g is supported from RRF3.1.0 and later. If this file is present at startup, it is run after running config.g and activating the network, and then deleted.
0 Comments