Close



Page 1 of 76 1231151 ... LastLast
Results 1 to 10 of 757
  1. #1
    Super Moderator Roxy's Avatar
    Join Date
    Apr 2014
    Location
    Lone Star State
    Posts
    2,182

    Post 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.

    ----------------------------------------------------------------------------------------


    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...
    Attached Files Attached Files
    Last edited by Roxy; 08-19-2015 at 11:09 AM.

  2. #2
    Student
    Join Date
    Mar 2014
    Location
    Vienna
    Posts
    47
    Congrats, very well done!

    At the moment I have no time to change the Marlin_Main.cpp but I will give it a try in a few days. My current version of auto-bed-levelings works quite well, but i´m curios to try yours.

    For all our friends here which do not have that much experience with this feature it would make some sense if you would add the other settings needed to be done in configuration.h, such as #define NUM_SERVOS aso.
    Last edited by ciutateivissa; 04-29-2014 at 05:08 PM. Reason: Fixed a spelling error.

  3. #3
    Super Moderator Roxy's Avatar
    Join Date
    Apr 2014
    Location
    Lone Star State
    Posts
    2,182
    Yeah, I guess I could do that. But this is an upgrade so most likely they already have the basic code running...

  4. #4
    Hi Roxy,

    I was trying to implement your changes to my latest marlin v1 release code. I wasn't able to compile it because the probe_pt() function has extra parameters. Can you post your probe_pt() function as well?

    Thanks!

  5. #5
    Super Moderator Roxy's Avatar
    Join Date
    Apr 2014
    Location
    Lone Star State
    Posts
    2,182
    You should be all set. There is a Probe_pt.cpp file attached with expanded directions.

  6. #6
    Awesome! Thanks for the work you've done on this. I'll give it a try.

  7. #7
    Technician
    Join Date
    Apr 2014
    Location
    Netherlands
    Posts
    76
    Hi Roxy, would it be possible to do something like they do with the Marlin firmware?
    With normal PLA I have no problems but I can't get Lay-wood to stick on my mirror build plate so I'm using a acrylic plate on top of it which seems to stick much better.
    However this plate has a few bumps and cracks but nothing worth compensating for. But after doing the G29 I get a very messy first layer because of the uneven spots.
    I would like the auto calibration to only pick 3 points (delta printer) and only compensate for that, do you think this is possible with Marlin?
    Last edited by Egon van Engelen; 05-07-2014 at 02:52 PM.

  8. #8
    Super Moderator Roxy's Avatar
    Join Date
    Apr 2014
    Location
    Lone Star State
    Posts
    2,182
    Quote Originally Posted by Egon van Engelen View Post
    Hi Roxy, would it be possible to do something like they do with the Repetier firmware?
    Yes, that should be possible. The logic should map over. But I don't think very many people are using Repetier. Is that assumption not correct?

    Quote Originally Posted by Egon van Engelen View Post
    With normal PLA I have no problems but I can't get Lay-wood to stick on my mirror build plate so I'm using a acrylic plate on top of it which seems to stick much better.
    However this plate has a few bumps and cracks but nothing worth compensating for. But after doing the G29 I get a very messy first layer because of the uneven spots.
    I would like the auto calibration to only pick 3 points (delta printer) and only compensate for that, do you think this is possible with Marlin?
    Well... I'm not sure if I followed everything, but it sounds like that acrylic plate is not very flat. Is that what you mean by 'uneven spots' ? As far as only doing 3 spots on a Delta printer, that should be just a matter of turning on the right options and setting where the 3 measurements will be taken on the bed. I would encourage you to do more than 3 spots, but if your bed is pretty flat and level, you may get good results with that.

  9. #9
    Technician
    Join Date
    Apr 2014
    Location
    Netherlands
    Posts
    76
    I'm sorry I made a big mistake in the first question, I meant of course to do this in Marlin because in Repetier it already works like that for delta printers, I was wondering if something similar would be possible with Marlin.

  10. #10
    Super Moderator Roxy's Avatar
    Join Date
    Apr 2014
    Location
    Lone Star State
    Posts
    2,182
    The G29 Auto_Bed_Leveling is independent from whether you are running on a Delta or not. The G28 command makes an 'identity' correction matrix (1's running down the diagonal) that it multiplies against any future coordinate it gets. The G29 command just warms over that correction matrix so it reflects what is really going on with the bed. If you turn on both Delta support and Auto_Bed_Leveling, you should have what you want.

    Unfortunately, I don't have a Delta printer so I can't verify that.

Page 1 of 76 1231151 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •