Configuring and calibrating a delta printer using the dc42 fork of RepRapFirmware

From RepRap
Revision as of 13:51, 10 August 2015 by Dc42 (talk | contribs) (Setting up the auto calibration file)
Jump to: navigation, search

Telling RepRapFirmware that your printer is a delta

To tell RepRapFirmware that your printer is a delta and to define its parameters, put command M665 L### R### H### B### X### Y### in your sys/config.g file on the SD card, where ### represents a number. The L parameter is the diagonal rod length. The R parameter is your estimate of the delta radius. The H parameter is the height of the nozzle above the bed when the carriages are activating the endstop switches. The B parameter is the printable radius of the bed. X and Y are the angular offsets of the X and Y towers, and may be omitted or set to zero. All these values may include decimal portions.

You can also use an M666 command to set the homing switch corrections.

You also need to tell RepRapFirmware that the endstop switches are all at the high end using the M574 command. Here is an extract from a sample config.g file for the Mini Kossel:

; Axis and motor configuration
M569 P0 S1                    ; Drive 0 (X) goes forwards
M569 P1 S1                    ; Drive 1 (Y) goes forwards
M569 P2 S1                    ; Drive 2 (Z) goes forwards
M569 P3 S1                    ; Drive 3 (E0) goes forwards
M569 P4 S1                    ; Drive 4 (E1) goes forwards
M574 X2 Y2 Z2 S1              ; all endstops at high end, active high
M665 R105.6 L215.0 B85 H235   ; set delta radius, diagonal rod length, printable radius and homed height
M666 X0 Y0 Z0                 ; put your endstop adjustments here

If your endstop switches produce active low outputs instead of active high, replace S1 in the M574 command by S0.

If your delta printer intentionally does not place the towers at the corners of an equilateral triangle, you can use the X and Y parameters to describe this. Consider a circle that passes through all three towers. The origin (i.e. bed centre assumed by the firmware) will be the centre of that circle. Label the towers X Y and Z moving around the circle in an anticlockwise direction as seen from above. Let X' and Y' be the points on the circle where the X and Y towers would be if the towers were all 120 degrees apart, leaving the Z tower position alone. Then the M665 X parameter is the angle from X' to X, and the Y parameter is the angle from Y' to Y, measured in degrees moving anticlockwise seen from above.

Example: a "square delta" has the towers at three of the four corners of a square. If Z is the middle tower, then the M665 X and Y parameters should be +30 and -30 respectively.

Setting up the homing file

You need to set up the homing commands in file sys/homedelta.g on the SD card. When configured for a delta printer, RepRapFirmware will always home all three towers when any G28 command is processed, ignoring any X, Y or Z parameters. Typical contents of homedelta.g would be:

G91                         ; use relative positioning
G1 S1 X250 Y250 Z250 F5000  ; move all carriages up 250mm, stopping at the endstops
G1 S2 X-5 Y-5 Z-5           ; move all towers down 5mm
G1 S1 X8 Y8 Z8 F500         ; move towers slowly up 8mm, stopping at the endstops
G1 S2 X-5 Y-5 Z-5 F10000    ; move carriages down 5mm
G90                         ; back to absolute positioning

Adjust the “250” numbers in the first line to be somewhat greater than your maximum print height, to ensure that the carriages reach the endstops. During initial testing, you may wish to reduce the homing speed value “5000” in the second line to a lower value, to give yourself more time to press the reset or power button if something goes wrong. Alternatively, reduce the motor currents during initial testing using the M906 command.

The above works because when the S1 or S2 parameter is used in a G0 or G1 command, the X, Y and Z values in the command are used as values for the individual towers instead of the head coordinates. In the case of S1, the endstops are activated too.

Configuring the Z probe

[This section is applicable to all printers, not just deltas.]

The M558 command enables the Z probe. The P parameter specifies the type, as follows:

P0 - no Z probe installed

P1 - analog sensor feeding the AD10 pin on the expansion connector (also brought out as the S pin on the 4-pin Z probe connector on the Duet Shield). Suitable for an unmodulated IR sensor (not recommended), smart IR sensor, and many other types. Pin D52 on the Duet is driven high.

P2 - simple modulated IR sensor. RepRapFirmware generates a modulation signal on pin D52 (also brought out as the T pin on the 4-pin Z probe connector on the Duet shield) for use by the sensor.

P3 - as P1 but pin D52 is driven low instead of high. Allows a compatible Z probe to be switched to a different mode.

P4 - microswitch (normally-closed by default) connected to the E0 endstop connector, or anything that emulates one.

The XYZ parameters in the M558 command define which axes the Z probe is used to home (0 = Z probe not used to home this axis, 1 = Z probe used). By default, RepRapFirmware uses the Z probe to home the X and Y axes. On a delta printer, you must use X0 Y0 Z0.

The H parameter defines the Z probe dive height, which is the height above the trigger height from which probing starts. The default is 3mm. You may wish to increase it during initial calibration.

The G31 command sets the Z probe trigger height and threshold. It must come after the M558 command, because you can have multiple Z probe types with different G31 parameters. The P parameter sets the threshold. For a smart IR probe such as my own differential IR height sensor, use 500. For a switch I also suggest 500, although a lower value may provide faster triggering if the switch has intermittant contact when first triggered..

The Z parameter sets the trigger height (the nozzle height above the bed at which the Z probe output exceeds the threshold). For a Z probe which relies on the nozzle pushing the bed down, the trigger height will be negative.

There are also X and Y parameters to define the horizontal offset of the Z probe from the nozzle, but on a delta printer these must be left at zero. This is because the calibration routine needs to know where the nozzle has been placed, not where the probe is.

Here is a sample extract from a config.g file for a Kossel with a smart IR probe:

M558 P1 X0 Y0 Z0 H3  ; smart IR Z probe, not used for homing, dive height 3mm
G31 P500 Z1.65       ; set threshold and nozzle height when triggered

Setting up the Z probe deploy and retract files

If your machine has a mechanical Z probe that needs to be deployed by moving the head in certain ways (e.g. standard Mini Kossel), then you need to set up macro files for deploying and retracting the probe. These are typically named sys/deployprobe.g and sys/retractprobe.g. Here is a sample deployprobe.g file:

M564 S0                ; don't apply limits
G1 X25 Y93 Z40 F10000  ; put probe arm next to belt
G1 X-5 F500            ; move probe arm slowly across belt
G1 X12 F1000           ; move probe back
G1 X0 Y0 F10000        ; move to somewhere sensible
M564 S1                ; apply limits again

Here is a sample retractprobe.g file:

M564 S0           ; don't apply limits
G1 Z40 F10000     ; raise head
G1 X-59 Y66 Z35   ; move over the post
G1 Z7 F500        ; push probe down on post
G1 Z35 F10000     ; raise head again
G1 X0 Y0          ; move to somewhere sensible
M564 S1           ; apply limits again

Setting up the auto calibration file

RepRapFirmware-dc42 supports a fast auto-calibration process. From a single set of bed probe readings, the firmware uses a mathematical model of the delta geometry to calculate the corrections needed so as to minimise the sum of the squares of the height errors at the probe points. It reports the RMS (root-mean-square) of the bed probe height error before probing, and the expected RMS error when the calibration has been done. On a typical delta printer, the auto calibration process takes about 30 seconds, this being the time taken to probe the bed.

The mathematical model of delta geometry used by RepRapFirmware assumes that the bed is flat, all diagonal rods have the same lengths, and all three towers are perpendicular to the bed. If these constraints are satisfied, then a single auto calibration cycle is sufficient. If not, you may need to run auto calibration two or three times before the corrections converge.

Auto calibration is performed by sending command G32 (which is the same command used to do auto bed compensation on a Cartesian printer). This command runs macro file sys/bed.g, so all the work is done there. Here is a sample bed.g file:

M561                            ; clear any bed transform, otherwise homing may be at the wrong height
G31 X0 Y0                       ; don't want any probe offset for this
G28                             ; home the printer

;*** Remove the following two lines if your Z probe does not need to be deployed
M98 Pdeployprobe.g              ; deploy the mechanical Z probe
G30 P0 X0 Y0 Z-99999            ; dummy probe, because the mechanical probe gives inaccurate results the first time it is used after deployment

; Probe the bed and do 6-factor auto calibration
G30 P0 X-73.6 Y-42.5 Z-99999    ; X tower
G30 P1 X0 Y-85 Z-99999          ; between X and Y towers
G30 P2 X73.6 Y-42.5 Z-99999     ; Y tower
G30 P3 X73.6 Y20 Z-99999        ; between Y and Z towers
G30 P4 X0 Y67 Z-99999           ; Z tower
G30 P5 X-73.6 Y20 Z-99999       ; between Z and X towers
G30 P6 X-36.8 Y-21.25 Z-99999   ; half way to X tower
G30 P7 X36.8 Y-21.25 Z-99999    ; half way to Y tower
G30 P8 X0 Y42.5 Z-99999         ; half way to Z tower
G30 P9 X0 Y0 Z-99999 S6         ; centre, and auto-calibrate 6 factors

;*** Remove the following line if your Z probe does not need to be retracted
M98 Pretractprobe.g             ; retract the mechanical Z probe

G1 X0 Y0 Z150 F15000            ; get the head out of the way of the bed

The probing is commanded by the G30 commands. You can have up to 16 probe points, numbered P0 to P15. The probe positions and order are not critical, but you should cover at least the centre and the extremities of the bed. The XY coordinates are where the nozzle will be, so if the Z probe is displaced from the nozzle then you must ensure that the probe is always over the bed, even if this means moving some of the probe points in from the edge.

This example uses ten points: six around the periphery, one at the centre, and three halfway between the centre and the periphery. For large delta printers, add at least 3 more probe points halfway to the periphery.

If your Z probe has different trigger heights at different XY positions, you can add an H parameter to each G30 command. This gives the value that must be added to the G31 Z parameter to get the actual trigger height at that point. Set the G31 Z parameter so that it is accurate when probing the centre of the bed, and use the H parameter to correct for different trigger heights at the other bed probe points.

The S parameter on the final G30 command defines what calculation is actually done, as follows:

S=-1 Don't adjust anything, just print the height error at each probe point

S=0 Equivalent to S=<number_of_points_probed>

S=3 Adjust homing switch corrections only

S=4 Adjust homing switch corrections and delta radius

S=6 Adjust homing switch corrections, delta radius, and X and Y tower position offsets

S=7 Adjust homing switch corrections, delta radius, X and Y tower position offsets, and diagonal rod length

The adjustments are made so as to minimise the sum of the squares of the height errors.

If your printer is accurately built, then 4-factor calibration may be sufficient. For normal use I recommend 6-factor calibration. I don't recommend 7-factor calibration, because the diagonal rod length is not very well defined by the probing errors, and adjusting diagonal rod length will alter the XY dimensions of your prints.

If you wish, you can define several variants of bed.g and run them using the M98 command, or just 'print' them like any other gcode file. In particular, it is useful to have a variant that uses S-1 on the final G30 command, so that you can check the height errors multiple times without adjusting anything, to get an idea of how reproducible the Z probe height readings are.

Updating config.g

If the calibration errors are small, a single execution of bed.g will calibrate your printer accurately. Larger errors my require 2 or 3 runs to calibrate out. So I suggest the following procedure:

1. Run auto calibration, then use the M665 and M666 commands with no parameters to see the adjustments made.

2. Repeat (1) until the M665 and M666 results converge.

3. Edit those results into the M665 and M666 commands in config.g.

After this, a single auto calibration run will be sufficient. Note that the X and Y parameters of the M665 command are only supported in firmware version 1.09d-dc42 and later.

Testing the motors individually

You can test the three tower motors individually by putting the printer in relative mode (G91 command) and then using the G1 command with S2 parameter. For example, sending G1 S2 X10 should move the X carriage up 10mm, and sending G1 S2 X-10 should move the X carriage down 10mm. Similarly for Y and Z. If a motor moves the wrong way, you can reverse it by changing the corresponding M569 command in config.g. For example, if the X motor moves the wrong way, change M569 P0 S1 to M569 P0 S0.