Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanded distortion correction for cartesian printers #488

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/ArduinoAVR/Repetier/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ Overridden if EEPROM activated.*/
// 12 is 100k RS thermistor 198-961
// 13 is PT100 for E3D/Ultimaker
// 14 is 100K NTC 3950
// 15 is PT100, like E3D on thermistor input.
// 5 is userdefined thermistor table 0
// 6 is userdefined thermistor table 1
// 7 is userdefined thermistor table 2
Expand Down
15 changes: 12 additions & 3 deletions src/ArduinoAVR/Repetier/Extruder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,12 @@ const short temptable_14[NUMTEMPS_14][2] PROGMEM = {
{571*4,8*105}, {611*4,8*100}, {681*4,8*90}, {711*4,8*85}, {811*4,8*69}, {831*4,8*65}, {881*4,8*55},
{901*4,8*51}, {941*4,8*39}, {971*4,8*28}, {981*4,8*23}, {991*4,8*17}, {1001*4,8*9}, {1021*4,8*-27},{1023*4,8*-200}
};
#define NUMTEMPS_15 49 //PT100 on Thermistor Input
const short temptable_15[NUMTEMPS_15][2] PROGMEM = {
{85,0},{976,8},{1008,80},{1048,160},{1080,240},{1112,320},{1144,400},{1176,480},{1208,560},{1240,640},{1272,720},{1305,800},{1337,880},{1377,960},{1409,1040},
{1433,1120},{1465,1200},{1497,1280},{1529,1360},{1561,1440},{1593,1520},{1625,1600},{1658,1680},{1690,1760},{1722,1840},{1746,1920},{1778,2000},{1810,2080},
{1834,2160},{1866,2240},{1898,2320},{1922,2400},{1954,2480},{1986,2560},{2018,2640},{2043,2720},{2075,2800},{2099,2880},{2131,2960},{2155,3040},{2187,3120},
{2219,3200},{2492,4000},{2756,4800},{2997,5600},{3238,6400},{3462,7200},{3679,8000},{3879,8800}};

#if NUM_TEMPS_USERTHERMISTOR0 > 0
const short temptable_5[NUM_TEMPS_USERTHERMISTOR0][2] PROGMEM = USER_THERMISTORTABLE0 ;
Expand All @@ -1489,7 +1495,7 @@ const short temptable_6[NUM_TEMPS_USERTHERMISTOR1][2] PROGMEM = USER_THERMISTORT
#if NUM_TEMPS_USERTHERMISTOR2 > 0
const short temptable_7[NUM_TEMPS_USERTHERMISTOR2][2] PROGMEM = USER_THERMISTORTABLE2 ;
#endif
const short * const temptables[14] PROGMEM = {(short int *)&temptable_1[0][0],(short int *)&temptable_2[0][0],(short int *)&temptable_3[0][0],(short int *)&temptable_4[0][0]
const short * const temptables[15] PROGMEM = {(short int *)&temptable_1[0][0],(short int *)&temptable_2[0][0],(short int *)&temptable_3[0][0],(short int *)&temptable_4[0][0]
#if NUM_TEMPS_USERTHERMISTOR0 > 0
,(short int *)&temptable_5[0][0]
#else
Expand All @@ -1512,9 +1518,10 @@ const short * const temptables[14] PROGMEM = {(short int *)&temptable_1[0][0],(s
,(short int *)&temptable_12[0][0]
,(short int *)&temptable_13[0][0]
,(short int *)&temptable_14[0][0]
,(short int *)&temptable_15[0][0]
};
const uint8_t temptables_num[14] PROGMEM = {NUMTEMPS_1,NUMTEMPS_2,NUMTEMPS_3,NUMTEMPS_4,NUM_TEMPS_USERTHERMISTOR0,NUM_TEMPS_USERTHERMISTOR1,NUM_TEMPS_USERTHERMISTOR2,NUMTEMPS_8,
NUMTEMPS_9,NUMTEMPS_10,NUMTEMPS_11,NUMTEMPS_12,NUMTEMPS_13,NUMTEMPS_14
const uint8_t temptables_num[15] PROGMEM = {NUMTEMPS_1,NUMTEMPS_2,NUMTEMPS_3,NUMTEMPS_4,NUM_TEMPS_USERTHERMISTOR0,NUM_TEMPS_USERTHERMISTOR1,NUM_TEMPS_USERTHERMISTOR2,NUMTEMPS_8,
NUMTEMPS_9,NUMTEMPS_10,NUMTEMPS_11,NUMTEMPS_12,NUMTEMPS_13,NUMTEMPS_14,NUMTEMPS_15
};


Expand All @@ -1541,6 +1548,7 @@ void TemperatureController::updateCurrentTemperature()
case 11:
case 12:
case 14:
case 15:
case 97:
case 98:
case 99:
Expand Down Expand Up @@ -1589,6 +1597,7 @@ void TemperatureController::updateCurrentTemperature()
case 11:
case 12:
case 14:
case 15:
{
type--;
uint8_t num = pgm_read_byte(&temptables_num[type]) << 1;
Expand Down
54 changes: 53 additions & 1 deletion src/ArduinoAVR/Repetier/Printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,31 @@ void Printer::homeYAxis()
}
#endif

#if (FEATURE_AUTOLEVEL || DISTORTION_CORRECTION)
bool Printer::SafeZ4Homing(){
//Check if there is enough space to move Z-Axis down. There is enough space, if Printer has Z-Max.
if((MAX_HARDWARE_ENDSTOP_Z && Z_MAX_PIN > -1 && Z_HOME_DIR == 1)){
//TODO: calculate highest possible distortion, to move less up
//check if z is higher than Z-Probe safty height (It is only correct, because after restart z is zero). If it is not move to the safty distance (mot more far)
if(Printer::realZPosition() < EEPROM::zProbeBedDistance()){
float distance2SaftyDistance = EEPROM::zProbeBedDistance() - Printer::realZPosition();
PrintLine::moveRelativeDistanceInSteps(0,0,distance2SaftyDistance * axisStepsPerMM[Z_AXIS],0,homingFeedrate[Z_AXIS],true,true);
return true;
}
}
return false;
}


int Printer::UnsafeZ4Homing(bool safedZ4Home, bool zaxis){
//check if it could crash, when Z-position before homing was lower bed at home position
//no need to move back, if z was homed. Because safeZ4Home only works, when z is homed to z max

return EEPROM::zProbeBedDistance();

}
#endif //FEATURE_AUTOLEVEL || DISTORTION_CORRECTION

void Printer::homeZAxis() // Cartesian homing
{
long steps;
Expand Down Expand Up @@ -1591,6 +1616,14 @@ void Printer::homeAxis(bool xaxis,bool yaxis,bool zaxis) // home non-delta print
float startX,startY,startZ;
realPosition(startX, startY, startZ);
setHomed(true);
#if (FEATURE_AUTOLEVEL || DISTORTION_CORRECTION)
bool safedZ4Home = false;
if(xaxis || yaxis){
// Move Z Plane to avoid crash (nozzle to bed)
safedZ4Home = SafeZ4Homing();
}
#endif //FEATURE_AUTOLEVEL || DISTORTION_CORRECTION

#if !defined(HOMING_ORDER)
#define HOMING_ORDER HOME_ORDER_XYZ
#endif
Expand Down Expand Up @@ -1697,7 +1730,12 @@ void Printer::homeAxis(bool xaxis,bool yaxis,bool zaxis) // home non-delta print
}
}
#endif

#if HOMING_ORDER != HOME_ORDER_ZXYTZ
//Undo Z safe, if z was not homed
#if (FEATURE_AUTOLEVEL || DISTORTION_CORRECTION)
startZ = UnsafeZ4Homing(safedZ4Home,zaxis);
#endif //FEATURE_AUTOLEVEL || DISTORTION_CORRECTION
if(xaxis)
{
if(X_HOME_DIR < 0) startX = Printer::xMin;
Expand Down Expand Up @@ -2181,7 +2219,8 @@ int32_t Distortion::correct(int32_t x, int32_t y, int32_t z) const
Com::printF(PSTR(" iy= "), fyFloor); Com::printFLN(PSTR(" fy= "), fy);
}
if (z > zStart && z > 0)
correction_z = (correction_z * (zEnd - z)) / (zEnd - zStart);
//All variables are type int. For calculation we need float values
correction_z = (correction_z * static_cast<float>(zEnd - z) / (zEnd - zStart));
/* if(correction_z > 20 || correction_z < -20) {
Com::printFLN(PSTR("Corr. error too big:"),correction_z);
Com::printF(PSTR("fxf"),(int)fxFloor);
Expand All @@ -2200,6 +2239,19 @@ int32_t Distortion::correct(int32_t x, int32_t y, int32_t z) const
return correction_z;
}

int32_t Distortion::correctExtrusion(int32_t x, int32_t y, int32_t z, int32_t e) const
{
//TODO Retracts are multiplied at the moment. This causes strings in layers. (zStart < layers < zEnd)
if (!enabled || z > zEnd || z < zStart || Printer::isZProbingActive()){
return e;
}
//calculate Extrusionmultiplier for zStart < z < zEnd
int32_t zCor = correct(x, y, 0);
//float correction_e = static_cast<float>((zEnd - zStart) - zCor) / (zEnd - zStart);
float correction_e = static_cast<float>((zEnd - zStart) - zCor) / (zEnd - zStart);
return round(correction_e * e);
}

void Distortion::set(float x,float y,float z) {
#if DRIVE_SYSTEM == DELTA
int ix = (x * Printer::axisStepsPerMM[Z_AXIS] + radiusCorrectionSteps + step / 2) / step;
Expand Down
7 changes: 6 additions & 1 deletion src/ArduinoAVR/Repetier/Printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class Distortion
void disable(bool permanent = true);
bool measure(void);
int32_t correct(int32_t x, int32_t y, int32_t z) const;
void updateDerived();
int32_t correctExtrusion(int32_t x, int32_t y, int32_t z, int32_t e) const;
void updateDerived();
void reportStatus();
bool isEnabled() {return enabled;}
int32_t zMaxSteps() {return zEnd;}
Expand Down Expand Up @@ -1142,6 +1143,10 @@ class Printer
static void homeXAxis();
static void homeYAxis();
static void homeZAxis();
#if (FEATURE_AUTOLEVEL || DISTORTION_CORRECTION)
static bool SafeZ4Homing();
static int UnsafeZ4Homing(bool safedZ4Home, bool zaxis);
#endif //FEATURE_AUTOLEVEL || DISTORTION_CORRECTION
};

#endif // PRINTER_H_INCLUDED
17 changes: 15 additions & 2 deletions src/ArduinoAVR/Repetier/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ void PrintLine::moveRelativeDistanceInStepsReal(int32_t x, int32_t y, int32_t z,
/* Special version which adds distortion correction to z. Gets called from queueCartesianMove if needed. */
void PrintLine::queueCartesianSegmentTo(uint8_t check_endstops, uint8_t pathOptimize) {

int32_t z_old = Printer::destinationSteps[Z_AXIS];
// Correct the bumps
Printer::zCorrectionStepsIncluded = Printer::distortion.correct(Printer::destinationSteps[X_AXIS],Printer::destinationSteps[Y_AXIS],Printer::destinationSteps[Z_AXIS]);
Printer::destinationSteps[Z_AXIS] += Printer::zCorrectionStepsIncluded;
Expand Down Expand Up @@ -175,6 +176,10 @@ void PrintLine::moveRelativeDistanceInStepsReal(int32_t x, int32_t y, int32_t z,
{
if(Printer::mode == PRINTER_MODE_FFF)
{
#if DISTORTION_CORRECTION
p->delta[axis] = Printer::distortion.correctExtrusion(Printer::destinationSteps[X_AXIS],Printer::destinationSteps[Y_AXIS],z_old ,p->delta[axis]);
#endif

Printer::extrudeMultiplyError += (static_cast<float>(p->delta[E_AXIS]) * Printer::extrusionFactor);
p->delta[E_AXIS] = static_cast<int32_t>(Printer::extrudeMultiplyError);
Printer::extrudeMultiplyError -= p->delta[E_AXIS];
Expand Down Expand Up @@ -278,8 +283,16 @@ void PrintLine::queueCartesianMove(uint8_t check_endstops, uint8_t pathOptimize)
// including a z correction
int32_t deltas[E_AXIS_ARRAY],start[E_AXIS_ARRAY];
for(fast8_t i = 0;i < E_AXIS_ARRAY;i++) {
deltas[i] = Printer::destinationSteps[i] - Printer::currentPositionSteps[i];
start[i] = Printer::currentPositionSteps[i];
if(i==Z_AXIS){
//TODO Printer::destinationSteps is not perfect here. It should be the current Z-position without distortion correction (That's not currentPosition)
//when z in GCode is constant over one layer, it is no problem.
int32_t zCor = Printer::distortion.correct(Printer::currentPositionSteps[X_AXIS],Printer::currentPositionSteps[Y_AXIS],Printer::destinationSteps[Z_AXIS]);
start[i] = Printer::currentPositionSteps[i] - zCor;
}
else{
start[i] = Printer::currentPositionSteps[i];
}
deltas[i] = Printer::destinationSteps[i] - start[i];
}
float dx = Printer::invAxisStepsPerMM[X_AXIS] * deltas[X_AXIS];
float dy = Printer::invAxisStepsPerMM[Y_AXIS] * deltas[Y_AXIS];
Expand Down