Quote Originally Posted by maar1201 View Post
Yes, expanding the Gcodes M500, M501 and M502 commands and save, restore and load the Bed Level Correction Matrix from EEPROM are a solution to me, but how to do this?
In configurationstore.cpp there are 3 functions: void Config_StoreSettings(), void Config_PrintSettings(), void Config_RetrieveSettings()

In the store function... I would change:

EEPROM_WRITE_VAR(i,zprobe_zoffset);

to

EEPROM_WRITE_VAR(i,zprobe_zoffset);

EEPROM_WRITE_VAR(i,plan_bed_level_matrix[0][0]);
EEPROM_WRITE_VAR(i,plan_bed_level_matrix[0][1]);
EEPROM_WRITE_VAR(i,plan_bed_level_matrix[0][2]);

EEPROM_WRITE_VAR(i, plan_bed_level_matrix[1][0] );
EEPROM_WRITE_VAR(i, plan_bed_level_matrix[1][1] );
EEPROM_WRITE_VAR(i, plan_bed_level_matrix[1][2]);

EEPROM_WRITE_VAR(i, plan_bed_level_matrix[2][0] );
EEPROM_WRITE_VAR(i, plan_bed_level_matrix[2][1] );
EEPROM_WRITE_VAR(i, plan_bed_level_matrix[2][2] );

Corresponding changes would need to be made to the Config and Retrieve functions.


Quote Originally Posted by maar1201 View Post
Can you give me some clues on Marlin code to find the function where as You said: "it just does a matrix multiply of the coordinate and the correction matrix."

Thanks
The matrix name with the correction matrix is called: plan_bed_level_matrix

You can find references to it in Marlin_main.cpp, Planner.cpp and Planner.h The Planner code is where Marlin 'Plans' its moves. That is where the coordinates are actually 'corrected'. It does this by doing: apply_rotation_xyz(plan_bed_level_matrix, x, y, z);

This function is defined in vector_3.cpp It looks like this:


void vector_3::apply_rotation(matrix_3x3 matrix)
{
float resultX = x * matrix.matrix[3*0+0] + y * matrix.matrix[3*1+0] + z * matrix.matrix[3*2+0];
float resultY = x * matrix.matrix[3*0+1] + y * matrix.matrix[3*1+1] + z * matrix.matrix[3*2+1];
float resultZ = x * matrix.matrix[3*0+2] + y * matrix.matrix[3*1+2] + z * matrix.matrix[3*2+2];

x = resultX;
y = resultY;
z = resultZ;
}

That would be a [1x3] matrix multiplied by a [3x3] matrix. [x,y,z] * [bed level correction matrix]