Results 1 to 10 of 172
Threaded View
-
10-30-2014, 04:30 PM #1
Saving G29 Bed Level Correction Matrix to EEPROM
Several people have expressed an interest in not having to perform a G29 Auto Bed Leveling command prior to each print. This post has the instructions to do that. However, it has not been tested yet. My printer's power supply died and it will be a while until I can replace it. The changes and theory are fairly simple, but with that said, when this many trivial changes get made, usually something doesn't work right. If you proceed with that warning and run into a problem, just make a post detailing what is wrong and I'm pretty sure we can get the problem fixed.
The theory is simple. The EEPROM (if enabled in Marlin's Configuration.h file) can save many settings that override the default settings. The changes we will make will stop the G28 homing command from resetting the Bed Level Correction Matrix. Instead, we will only do that when a G29 command is issued. Once this is accomplished, we just need to add a small amount of support to the EEPROM routines to make them smart enough to save and restore this matrix besides all of the other values they already save and restore. And of course, we add some code so the matrix can be printed out also.
To use the code, the user would first issue a M502 (Restore Default Settings) command followed by a M500 (Save Current Settings to EEPROM). This is necessary to do once because the format of the data stored in the EEPROM is going to change. By doing a M502 followed by a M500 command we are forcing the EEPROM to conform to the new data format which includes space for the Bed Level Correction matrix. Failure to do this is going to result in your printer restoring all kinds of bad values from EEPROM into important variables that it uses to behave in a sane and rational way.
Once the EEPROM is made aware of the new configuration, you need to issue a G28 followed by a suitable G29 command and if the values work as expected, an M500 command. From then on, you will only use the G29 command if you don't see the first layer going down perfect. The M500 will store the Bed Level Correction Matrix so the next time the Marlin firmware initializes itself, it will grab the last saved matrix.
To make the firmware changes do the following:
In Configuration.h find:
Code:#define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line) #define Z_PROBE_REPEATABILITY_TEST // If not commented out, Z-Probe Repeatability test will be included if Auto Bed Leveling is Enabled.
Code:#define ENABLE_AUTO_BED_LEVELING // Delete the comment to enable (remove // at the start of the line) #define Z_PROBE_REPEATABILITY_TEST // If not commented out, Z-Probe Repeatability test will be included if Auto Bed Leveling is Enabled. #define SAVE_G29_CORRECTION_MATRIX // if not commented out and the EEPROM is used to save settings, the G29 information will also be saved.
Code:case 28: //G28 Home all Axis one at a time #ifdef ENABLE_AUTO_BED_LEVELING plan_bed_level_matrix.set_to_identity(); //Reset the plane ("erase" all leveling data) #endif //ENABLE_AUTO_BED_LEVELING
Delete the last 3 of those lines so you only have:
Code:case 28: //G28 Home all Axis one at a time
Code:#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
Code:#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 plan_bed_level_matrix.set_to_identity(); //Reset the plane ("erase" all leveling data)
Code:void Config_StoreSettings() { char ver[4]= "000"; int i=EEPROM_OFFSET; EEPROM_WRITE_VAR(i,ver); // invalidate data first EEPROM_WRITE_VAR(i,axis_steps_per_unit); EEPROM_WRITE_VAR(i,max_feedrate); EEPROM_WRITE_VAR(i,max_acceleration_units_per_sq_second); EEPROM_WRITE_VAR(i,acceleration);
Code:void Config_StoreSettings() { char ver[4]= "000"; int i=EEPROM_OFFSET; EEPROM_WRITE_VAR(i,ver); // invalidate data first EEPROM_WRITE_VAR(i,axis_steps_per_unit); EEPROM_WRITE_VAR(i,max_feedrate); EEPROM_WRITE_VAR(i,max_acceleration_units_per_sq_second); EEPROM_WRITE_VAR(i,acceleration); #ifdef SAVE_G29_CORRECTION_MATRIX EEPROM_WRITE_VAR(i,plan_bed_level_matrix); #endif
Code:void Config_RetrieveSettings() { int i=EEPROM_OFFSET; char stored_ver[4]; char ver[4]=EEPROM_VERSION; EEPROM_READ_VAR(i,stored_ver); //read stored version // SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]"); if (strncmp(ver,stored_ver,3) == 0) { // version number match EEPROM_READ_VAR(i,axis_steps_per_unit); EEPROM_READ_VAR(i,max_feedrate); EEPROM_READ_VAR(i,max_acceleration_units_per_sq_second); // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner) reset_acceleration_rates(); EEPROM_READ_VAR(i,acceleration);
Code:void Config_RetrieveSettings() { int i=EEPROM_OFFSET; char stored_ver[4]; char ver[4]=EEPROM_VERSION; EEPROM_READ_VAR(i,stored_ver); //read stored version // SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]"); if (strncmp(ver,stored_ver,3) == 0) { // version number match EEPROM_READ_VAR(i,axis_steps_per_unit); EEPROM_READ_VAR(i,max_feedrate); EEPROM_READ_VAR(i,max_acceleration_units_per_sq_second); // steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner) reset_acceleration_rates(); EEPROM_READ_VAR(i,acceleration); #ifdef SAVE_G29_CORRECTION_MATRIX EEPROM_READ_VAR(i,plan_bed_level_matrix); #endif
Code:void Config_ResetDefault() { float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT; float tmp2[]=DEFAULT_MAX_FEEDRATE; long tmp3[]=DEFAULT_MAX_ACCELERATION;
Code:void Config_ResetDefault() { float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT; float tmp2[]=DEFAULT_MAX_FEEDRATE; long tmp3[]=DEFAULT_MAX_ACCELERATION; #ifdef SAVE_G29_CORRECTION_MATRIX plan_bed_level_matrix.set_to_identity(); #endif
Code:void Config_PrintSettings() { // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Steps per unit:"); SERIAL_ECHO_START; SERIAL_ECHOPAIR(" M92 X",axis_steps_per_unit[0]); SERIAL_ECHOPAIR(" Y",axis_steps_per_unit[1]); SERIAL_ECHOPAIR(" Z",axis_steps_per_unit[2]); SERIAL_ECHOPAIR(" E",axis_steps_per_unit[3]); SERIAL_ECHOLN("");
Code:void Config_PrintSettings() { // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Steps per unit:"); SERIAL_ECHO_START; SERIAL_ECHOPAIR(" M92 X",axis_steps_per_unit[0]); SERIAL_ECHOPAIR(" Y",axis_steps_per_unit[1]); SERIAL_ECHOPAIR(" Z",axis_steps_per_unit[2]); SERIAL_ECHOPAIR(" E",axis_steps_per_unit[3]); SERIAL_ECHOLN(""); #ifdef SAVE_G29_CORRECTION_MATRIX SERIAL_ECHO_START; plan_bed_level_matrix.debug("\n\nBed Level Correction Matrix:"); SERIAL_ECHOLN(""); #endif
Last edited by Roxy; 11-01-2014 at 08:39 AM. Reason: Allow Configuration.h to select whether correction matrix is saved.
Ender 3v2 poor printing quality
10-28-2024, 09:08 AM in Tips, Tricks and Tech Help