2 Attachment(s)
Auto_Bed_Leveling: Enhanced G29 command
People!!! Please notice this is a very old thread. It was created a long time ago and provide some very nice enhancements to the Marlin G29 Auto Bed Leveling command. Since this time a number of things have happened.
This code first made it into the BeckDac Marlin fork. That can be found here: https://github.com/beckdac/Marlin This fork was done to clean up the MakerFarm release of Marlin and to add the G29 (and M48) enhancements. If you have a MakerFarm printer, it should pretty much load and go.
After the BeckDac fork, the M48 and G29 enhancements (along with other improvements first published here at 3DPrintBoard) made it into the real Marlin code base. Unfortunately, as of today (8-19-2015) that code base is not stable and you are much better off using the BeckDac fork. With that said, very soon the main branch of Marlin at Github ( https://github.com/MarlinFirmware/Marlin ) will have stable code with these enhancements. At that point in time, you would be best off going straight to the GitHub repository to get this code.
You should note, in either of the above cases, you no longer need to edit your Marlin code base to get the enhancements. They are included in both of those repositories.
This thread is still monitored. If you have issues with your Auto Bed Leveling you can post in this thread and get assistance with your problem.
----------------------------------------------------------------------------------------
Quote:
We are like dwarfs sitting on the shoulders of giants. We see more, and things that are more distant, than they did, not because our sight is superior or because we are taller than they, but because they raise us up, and by their great stature add to ours.
John of Salisbury 1159
Here is the enhanced version of the Auto_Bed_Leveling G29 code:
It has a number of features that the main line code base is lacking:
- It allows the selection at run time of how many points to probe. It allows you to pick a bigger or smaller number depending upon your needs for a particular print.
- It allows you to engage the Z-Probe and leave it down. This helps the accuracy of the measurements because you are not engaging and retracting the probe for each measurement (unless you tell it to do that because you want that done) It also raises the Z-Probe prior to retracting it at the end of measurements.
- Lastly, it will print a topographical map of your bed so you can easily see how it is tilted and where you have high and low spots on the bed. Many people are going to be surprised by how 'unflat' their bed is. I know I was! This is a very helpful tool for getting your bed very very level. And of course, the Auto_Bed_Leveling code handles the rest of the error.
Instructions to add this to your code base:
- Pull your current Marlin_Main.cpp file into a text editor. Verify you can find the text AUTO_BED_LEVELING_GRID in the code. If you do not have this text, your code base is too old and you should upgrade to the latest firmware being distributed at: https://github.com/ErikZalm/Marlin
- Search for 29: You should see code that looks like this:
endstops_hit_on_purpose();
break;
#ifdef ENABLE_AUTO_BED_LEVELING
case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points.
{
#if Z_MIN_PIN == -1
#error "You must have a Z_MIN endstop in order to enable Auto Bed Leveling feature!!! Z_MIN_PIN must point to a valid hardware pin."
#endif
- Delete everything from (and including) the case 29: for about 140 lines. Leave this code that follows the G29 command alone. Do not delete this!
case 30: // G30 Single Z Probe
{
engage_z_probe(); // Engage Z Servo end-stop if available
- Insert the G29.cpp code attached to this post where you deleted the original G29 code.
- At the top of the newly inserted code, enable one of the four lines that corresponds to your printer's configuration. If your origin is at the front left of your bed, you don't have to do anything. That is enabled by default.
//#define ORIGIN_BACK_LEFT
//#define ORIGIN_FRONT_RIGHT
//#define ORIGIN_BACK_RIGHT
#define ORIGIN_FRONT_LEFT
- Search for the probe_pt() function. It will look like this: static float probe_pt(float x, float y, float z_before) Delete it. It is roughly 20 lines long. Replace it with the probe_pt.c code attached to this post.
- Save the changes to Marlin_Main.cpp and pull your Configuration.h file into the text editor.
- Enable and change #define AUTO_BED_LEVELING_GRID_POINTS 5
- Make sure you have #define AUTO_BED_LEVELING_GRID enabled. (And save the file!)
- This step is optional but highly recommended. If you are having difficulties getting the G29 code working, you should do this step because it will provide a lot of detail to anybody trying to help you. The "Bed Level Correction Matrix:" does not get printed with sufficient precision to have any use in the original G29 code. Pull Vector_3.cpp into your editor. Search for: void matrix_3x3::debug(char* title) This will be about 180 lines from the start of the file. Go down about 9 lines and change the line to be: SERIAL_PROTOCOL_F(matrix[count],6); (And save the file!) That will print the numbers of the matrix with a higher precision.
- This step is also optional. Because of how some people's Z-Probe is constructed, it is best to raise the nozzle prior to retracting the probe. The Enhanced G29 code handles this circumstance. But as it turns out, the stock G28 command is also guilty of this bad behavior. If you need the G28 command to raise the nozzle prior to retracting the probe, make the following changes in Marlin_Main.cpp :
Find the following code:
// Retract Servo endstop if enabled
#ifdef SERVO_ENDSTOPS
if (servo_endstops[axis] > -1) {
servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2 + 1]);
}
#endif
#if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
if (axis==Z_AXIS) retract_z_probe();
#endif
add these lines of code immediately after the "// Retract Servo endstop if enabled" comment.
#if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
if (axis==Z_AXIS)
do_blocking_move_relative(0, 0, Z_RAISE_BEFORE_PROBING);
#endif
It should look like this when you have made the change:
// Retract Servo endstop if enabled
#if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
if (axis==Z_AXIS)
do_blocking_move_relative(0, 0, Z_RAISE_BEFORE_PROBING);
#endif
#ifdef SERVO_ENDSTOPS
if (servo_endstops[axis] > -1) {
servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2 + 1]);
}
#endif
#if defined (ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
if (axis==Z_AXIS) retract_z_probe();
#endif
- Compile and load the firmware into your controller board.
How to Use:
The E parameter:
OK, first, the Z-Probe isn't going to be engaging and disengaging any more. That is good from an accuracy perspective. But if you want that to happen, you can give the G29 command a parameter E. Both upper and lower case E's will cause engaging and disengaging the probe on each measurement. You can send a G29 E to your printer and it will behave like it used to as it takes measurements.
The V parameter:
The V parameter controls how verbose the command will be. You can specify values from 0 to 4. Both upper and lower case V's are honored. You can send your G29 V 4 to your printer to get the full level of output.
The T parameter:
The T parameter controls printing of the topographical map of your bed. Both upper and lower case T's are treated the same. If the verboseness level is at 3 or 4 the topographical information will be printed. If the T parameter is specified the verboseness level does not matter and the topographical map will be printed unconditionally. Sending a G29 T to the printer will cause a topographical map to be printed with a 3x3 set of sampled points. A typical usage of the T parameter might be G29 T n5
The grid of numbers printed will tell you how high or low each point on the bed is compared to the mean. The orientation of that set of numbers should be correct for how your printer is configured. You should be able to look at the top left number and correlate that to your back left corner of the bed. The bottom right number displayed at the end of the G29 command should correlate to the front right of your printer's bed.
It is most useful to do this with a high number of points (such as 5). When you get the topographical information you will see how much one side is raised or lowered. Go ahead and zero things out as much as possible. Once you have zero'ed out those numbers your bed should be very flat. BUT... here is where it gets interesting: If you scan across a row or column of numbers in the topographical map you may see the numbers go from positive to negative and back to positive. Or vice verse. This means (and is proof) that your bed is ***NOT*** flat!!!
The n parameter
The n parameter controls how many points to sample for the generation of the bed level correction matrix. This parameter must be a lower case n because Marlin uses the capital N in its communication protocol. Marlin will get highly annoyed if you try to use a capital n for this. If you are using the Repetier client you will have problems even with a lower case n. You can use u instead (and upside down n). Valid numbers are from 2 to whatever you set your AUTO_BED_LEVELING_GRID_POINTS define in Configuration.h at. It defaults to a 3 x 3 grid. A typical usage of the n parameter might be something like G29 n4
Enjoy...