Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 65 additions & 69 deletions autoleveller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ autoleveller::autoleveller( const boost::program_options::variables_map &options
callSub2[Software::MACH3] = "#" + globalVar0 + "=%2$s\n%5$s#" + globalVar1 + "=%3$s\n%6$s#" + globalVar2 + "=%4$s\n%7$sM98 P%1$s\n";
}

string autoleveller::getVarName( int i, int j )
{
return '#' + to_string(i * numYPoints + j + 500); //getVarName(10,8) returns (numYPoints=10) #180
string autoleveller::getVarName(unsigned int i, unsigned int j) {
return '#' + to_string(i * numYPoints + j + 500); //getVarName(10,8) returns (numYPoints=10) #180
}

box_type_fp computeWorkarea(const vector<pair<coordinate_type_fp, multi_linestring_type_fp>>& toolpaths) {
Expand Down Expand Up @@ -300,75 +299,72 @@ static inline T clamp(const T& x, const T& min_x, const T& max_x) {
return std::max(min_x, std::min(x, max_x));
}

string autoleveller::interpolatePoint ( point_type_fp point )
{
unsigned int xminindex;
unsigned int yminindex;
double x_minus_x0_rel;
double y_minus_y0_rel;

// Calculate point index for measurement point below and to the left
// of `point`
xminindex = floor((point.x() - startPointX) / XProbeDist);
xminindex = clamp(xminindex, 0U, numXPoints - 1);

yminindex = floor((point.y() - startPointY) / YProbeDist);
yminindex = clamp(yminindex, 0U, numYPoints - 1);

// Get fraction of the distance to the next measurement point up and
// to the left that `point` is.
x_minus_x0_rel = ( point.x() - startPointX - xminindex * XProbeDist ) / XProbeDist;
y_minus_y0_rel = ( point.y() - startPointY - yminindex * YProbeDist ) / YProbeDist;

if ( y_minus_y0_rel == 0 ) {

if ( x_minus_x0_rel == 0 ) {

// If `point` is on top of a measurement point, just copy
// the measured height over
return str( format( "#%2$s=%1$s\n" ) %
getVarName( xminindex, yminindex ) %
returnVar );

} else {

// If `point` has the same y coordinate as a row of points,
// interpolate between the points to the left and right of
// it
return str( format( "#%4$s=[%1$s+[%2$s-%1$s]*%3$.5f]\n" ) %
getVarName( xminindex, yminindex ) %
getVarName( xminindex + 1, yminindex ) %
x_minus_x0_rel % returnVar );

}
string autoleveller::interpolatePoint(point_type_fp point) {
unsigned int xminindex;
unsigned int yminindex;
double x_minus_x0_rel;
double y_minus_y0_rel;

// Calculate point index for measurement point below and to the left
// of `point`
xminindex = floor((point.x() - startPointX) / XProbeDist);
xminindex = clamp(xminindex, 0U, numXPoints - 2);

yminindex = floor((point.y() - startPointY) / YProbeDist);
yminindex = clamp(yminindex, 0U, numYPoints - 2);

// Get fraction of the distance to the next measurement point up and
// to the left that `point` is.
x_minus_x0_rel = (point.x() - startPointX - xminindex * XProbeDist) / XProbeDist;
x_minus_x0_rel = clamp(x_minus_x0_rel, 0.0, 1.0);
y_minus_y0_rel = (point.y() - startPointY - yminindex * YProbeDist) / YProbeDist;
y_minus_y0_rel = clamp(y_minus_y0_rel, 0.0, 1.0);

if (x_minus_x0_rel == 1.0) {
x_minus_x0_rel -= 1;
xminindex += 1;
}
if (y_minus_y0_rel == 1.0) {
y_minus_y0_rel -= 1;
yminindex += 1;
}

if (y_minus_y0_rel == 0) {
if (x_minus_x0_rel == 0) {
// If `point` is on top of a measurement point, just copy
// the measured height over
return str(format("#%2$s=%1$s\n")
% getVarName(xminindex, yminindex)
% returnVar);
} else {

if ( x_minus_x0_rel == 0 ) {

// If `point` has the same x coordinate as a column of
// points, interpolate between the points above and below it
return str( format( "#%4$s=[%2$s+[%1$s-%2$s]*%3$.5f]\n" ) %
getVarName( xminindex, yminindex + 1 ) %
getVarName( xminindex, yminindex ) %
y_minus_y0_rel % returnVar );

} else {

// ...else use bilinear interpolation between all four
// points around it
return str( format( "#%7$s=[%3$s+[%1$s-%3$s]*%5$.5f]\n#%8$s=[%4$s+[%2$s-%4$s]*%5$.5f]\n#%9$s=[#%7$s+[#%8$s-#%7$s]*%6$.5f]\n" ) %
getVarName( xminindex, yminindex + 1 ) %
getVarName( xminindex + 1, yminindex + 1 ) %
getVarName( xminindex, yminindex ) %
getVarName( xminindex + 1, yminindex ) %
y_minus_y0_rel % x_minus_x0_rel %
globalVar4 % globalVar5 % returnVar );

}

// If `point` has the same y coordinate as a row of points,
// interpolate between the points to the left and right of
// it
return str(format("#%4$s=[%1$s+[%2$s-%1$s]*%3$.5f]\n")
% getVarName(xminindex, yminindex)
% getVarName(xminindex + 1, yminindex)
% x_minus_x0_rel % returnVar);
}

} else {
if (x_minus_x0_rel == 0) {
// If `point` has the same x coordinate as a column of
// points, interpolate between the points above and below it
return str(format("#%4$s=[%2$s+[%1$s-%2$s]*%3$.5f]\n")
% getVarName(xminindex, yminindex + 1)
% getVarName(xminindex, yminindex)
% y_minus_y0_rel % returnVar);
} else {
// ...else use bilinear interpolation between all four
// points around it
return str(format("#%7$s=[%3$s+[%1$s-%3$s]*%5$.5f]\n#%8$s=[%4$s+[%2$s-%4$s]*%5$.5f]\n#%9$s=[#%7$s+[#%8$s-#%7$s]*%6$.5f]\n")
% getVarName(xminindex, yminindex + 1)
% getVarName(xminindex + 1, yminindex + 1)
% getVarName(xminindex, yminindex)
% getVarName(xminindex + 1, yminindex)
% y_minus_y0_rel % x_minus_x0_rel
% globalVar4 % globalVar5 % returnVar);
}
}
}


Expand Down
2 changes: 1 addition & 1 deletion autoleveller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class autoleveller

// getVarName returns the string containing the variable name associated with the probe point with
// the indexes i and j
std::string getVarName( int i, int j );
std::string getVarName(unsigned int i, unsigned int j);

// interpolatePoint finds the correct 4 probed points and computes a bilinear interpolation of point.
// The result of the interpolation is saved in the parameter number RESULT_VAR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3538,9 +3538,7 @@ G00 Z0.08000 ( retract )
G00 X-4.81301 Y-2.94286 ( rapid move to begin. )
G01 F180.00000
( Mill infeed pass 1/1 )
#105=[#597+[#598-#597]*0.08889]
#106=[#603+[#604-#603]*0.08889]
#100=[#105+[#106-#105]*0.00000]
#100=[#597+[#598-#597]*0.08889]
G01 Z[-0.04000+#100]
G04 P0 ( dwell for no time -- G64 should not smooth over this point )
G01 F360.00000
Expand Down Expand Up @@ -3840,9 +3838,7 @@ X-4.81601 Y-2.92779 Z[#100+-0.04000]
X-4.81377 Y-2.93518 Z[#100+-0.04000]
#100=[#597+[#598-#597]*0.08889]
X-4.81301 Y-2.94286 Z[#100+-0.04000]
#105=[#597+[#598-#597]*0.08889]
#106=[#603+[#604-#603]*0.08889]
#100=[#105+[#106-#105]*0.00000]
#100=[#597+[#598-#597]*0.08889]
X-4.81301 Y-2.94286 Z[#100+-0.04000]
G04 P0 ( dwell for no time -- G64 should not smooth over this point )
G00 Z0.08000 ( retract )
Expand Down Expand Up @@ -5052,9 +5048,7 @@ G00 Z0.08000 ( retract )
G00 X-4.81301 Y-1.66885 ( rapid move to begin. )
G01 F180.00000
( Mill infeed pass 1/1 )
#105=[#600+[#601-#600]*0.45553]
#106=[#606+[#607-#606]*0.45553]
#100=[#105+[#106-#105]*0.00000]
#100=[#600+[#601-#600]*0.45553]
G01 Z[-0.04000+#100]
G04 P0 ( dwell for no time -- G64 should not smooth over this point )
G01 F360.00000
Expand Down Expand Up @@ -5348,9 +5342,7 @@ X-4.81601 Y-1.65378 Z[#100+-0.04000]
X-4.81377 Y-1.66116 Z[#100+-0.04000]
#100=[#600+[#601-#600]*0.45553]
X-4.81301 Y-1.66885 Z[#100+-0.04000]
#105=[#600+[#601-#600]*0.45553]
#106=[#606+[#607-#606]*0.45553]
#100=[#105+[#106-#105]*0.00000]
#100=[#600+[#601-#600]*0.45553]
X-4.81301 Y-1.66885 Z[#100+-0.04000]
G04 P0 ( dwell for no time -- G64 should not smooth over this point )
G00 Z0.08000 ( retract )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5690,9 +5690,7 @@ X10.95151 Y-3.30348 Z[#111+-0.04000]
#117=[#612+[#613-#612]*0.14648]
#111=[#116+[#117-#116]*0.99904]
X10.95258 Y-3.30188 Z[#111+-0.04000]
#116=[#612+[#613-#612]*0.15169]
#117=[#619+[#620-#619]*0.15169]
#111=[#116+[#117-#116]*0.00000]
#111=[#612+[#613-#612]*0.15169]
X10.95295 Y-3.30000 Z[#111+-0.04000]
#116=[#605+[#606-#605]*0.15689]
#117=[#612+[#613-#612]*0.15689]
Expand Down Expand Up @@ -7350,9 +7348,7 @@ X10.95151 Y-2.02946 Z[#111+-0.04000]
#117=[#615+[#616-#615]*0.66516]
#111=[#116+[#117-#116]*0.99904]
X10.95258 Y-2.02787 Z[#111+-0.04000]
#116=[#615+[#616-#615]*0.67036]
#117=[#622+[#623-#622]*0.67036]
#111=[#116+[#117-#116]*0.00000]
#111=[#615+[#616-#615]*0.67036]
X10.95295 Y-2.02598 Z[#111+-0.04000]
#116=[#608+[#609-#608]*0.67557]
#117=[#615+[#616-#615]*0.67557]
Expand Down