Skip to content

Commit

Permalink
Added changes for dynamic ABL where dimensions for probe region are s…
Browse files Browse the repository at this point in the history
…upplied in the G29

See: https://github.com/ErikZalm/Marlin/pull/1022
Parameters:
L: left side (X min, overwrites LEFT_PROBE_BED_POSITION)
R: right side (X max, overwrites RIGHT_PROBE_BED_POSITION)
F: front side (Y min, overwrites FRONT_PROBE_BED_POSITION)
B: back side (Y max, overwrites BACK_PROBE_BED_POSITION)
A: number of probes (overwrites AUTO_BED_LEVELING_GRID_POINTS)
E.g. G29 L95 F95 R105 B105 A3
  • Loading branch information
beckdac committed Sep 25, 2014
1 parent a555037 commit f9dcfec
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
Binary file added Marlin/.Marlin_main.cpp.swp
Binary file not shown.
62 changes: 46 additions & 16 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,30 +1694,62 @@ int retract_flag=0, verbose_level=1, topo_flag=0, n_points=3;

feedrate = homing_feedrate[Z_AXIS];
#ifdef AUTO_BED_LEVELING_GRID
// probe at the points of a lattice grid
int r_probe_bed_position = RIGHT_PROBE_BED_POSITION;
int l_probe_bed_position = LEFT_PROBE_BED_POSITION;
int f_probe_bed_position = FRONT_PROBE_BED_POSITION;
int b_probe_bed_position = BACK_PROBE_BED_POSITION;
int a_bed_leveling_points = AUTO_BED_LEVELING_GRID_POINTS;
if(code_seen('R')) {
r_probe_bed_position = code_value();
}

if(code_seen('L')) {
l_probe_bed_position = code_value();
}

if(code_seen('F')) {
f_probe_bed_position = code_value();
}

int xGridSpacing = (RIGHT_PROBE_BED_POSITION - LEFT_PROBE_BED_POSITION) / (n_points-1);
int yGridSpacing = (BACK_PROBE_BED_POSITION - FRONT_PROBE_BED_POSITION) / (n_points-1);
if(code_seen('B')) {
b_probe_bed_position = code_value();
}

if(code_seen('A')) {
a_bed_leveling_points = code_value();
}

if((f_probe_bed_position == b_probe_bed_position) || (r_probe_bed_position == l_probe_bed_position)) {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM(MSG_EMPTY_PLANE);

// solve the plane equation ax + by + d = z
Stop();
return;
}

// probe at the points of a lattice grid
int xGridSpacing = (r_probe_bed_position - l_probe_bed_position) / (a_bed_leveling_points-1);
int yGridSpacing = (b_probe_bed_position - f_probe_bed_position) / (a_bed_leveling_points-1);

// solve the plane equation ax + by + d = z
// A is the matrix with rows [x y 1] for all the probed points
// B is the vector of the Z positions
// the normal vector to the plane is formed by the coefficients of the plane equation in the standard form, which is Vx*x+Vy*y+Vz*z+d = 0
// so Vx = -a Vy = -b Vz = 1 (we want the vector facing towards positive Z

// "A" matrix of the linear system of equations
double eqnAMatrix[AUTO_BED_LEVELING_GRID_POINTS*AUTO_BED_LEVELING_GRID_POINTS*3];
double* eqnAMatrix = (double*)malloc(sizeof(double) * (a_bed_leveling_points*a_bed_leveling_points*3));
// "B" vector of Z points
double eqnBVector[AUTO_BED_LEVELING_GRID_POINTS*AUTO_BED_LEVELING_GRID_POINTS];
double* eqnBVector = (double*)malloc(sizeof(double) * (a_bed_leveling_points*a_bed_leveling_points));


double mean=0.0;


int probePointCounter = 0;
bool zig = true;

for (int yProbe=FRONT_PROBE_BED_POSITION; yProbe <= BACK_PROBE_BED_POSITION; yProbe += yGridSpacing)
for (int yProbe=f_probe_bed_position; yProbe <= b_probe_bed_position; yProbe += yGridSpacing)
{
int xProbe, xInc;

Expand All @@ -1730,19 +1762,17 @@ int retract_flag=0, verbose_level=1, topo_flag=0, n_points=3;

if (zig)
{
xProbe = LEFT_PROBE_BED_POSITION;
//xEnd = RIGHT_PROBE_BED_POSITION;
xProbe = l_probe_bed_position;
xInc = xGridSpacing;
zig = false;
} else // zag
{
xProbe = RIGHT_PROBE_BED_POSITION;
//xEnd = LEFT_PROBE_BED_POSITION;
xProbe = r_probe_bed_position;
xInc = -xGridSpacing;
zig = true;
}

for (int xCount=0; xCount < n_points; xCount++)
for (int xCount=0; xCount < a_bed_leveling_points; xCount++)
{
float z_before;
if (probePointCounter == 0)
Expand All @@ -1761,9 +1791,9 @@ int retract_flag=0, verbose_level=1, topo_flag=0, n_points=3;

eqnBVector[probePointCounter] = measured_z;

eqnAMatrix[probePointCounter + 0*n_points*n_points] = xProbe;
eqnAMatrix[probePointCounter + 1*n_points*n_points] = yProbe;
eqnAMatrix[probePointCounter + 2*n_points*n_points] = 1;
eqnAMatrix[probePointCounter + 0*a_bed_leveling_points*a_bed_leveling_points] = xProbe;
eqnAMatrix[probePointCounter + 1*a_bed_leveling_points*a_bed_leveling_points] = yProbe;
eqnAMatrix[probePointCounter + 2*a_bed_leveling_points*a_bed_leveling_points] = 1;

probePointCounter++;
xProbe += xInc;
Expand All @@ -1773,7 +1803,7 @@ int retract_flag=0, verbose_level=1, topo_flag=0, n_points=3;
clean_up_after_endstop_move();

// solve lsq problem
double *plane_equation_coefficients = qr_solve(n_points*n_points, 3, eqnAMatrix, eqnBVector);
double *plane_equation_coefficients = qr_solve(a_bed_leveling_points*a_bed_leveling_points, 3, eqnAMatrix, eqnBVector);

if (verbose_level ) {

Expand Down
1 change: 1 addition & 0 deletions Marlin/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
#define MSG_ENDSTOP_HIT "TRIGGERED"
#define MSG_ENDSTOP_OPEN "open"
#define MSG_HOTEND_OFFSET "Hotend offsets:"
#define MSG_EMPTY_PLANE "Autolevel can only be execute on an actual plane, make sure width and height are not 0!"

#define MSG_SD_CANT_OPEN_SUBDIR "Cannot open subdir"
#define MSG_SD_INIT_FAIL "SD init fail"
Expand Down

0 comments on commit f9dcfec

Please sign in to comment.