Skip to content

Commit

Permalink
Fixed printed filamenet computation
Browse files Browse the repository at this point in the history
  • Loading branch information
repetier committed Feb 6, 2015
1 parent 69b4a95 commit c4dd0c1
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/ArduinoAVR/Repetier/Eeprom.cpp
Expand Up @@ -754,12 +754,12 @@ void EEPROM::init()
void EEPROM::updatePrinterUsage()
{
#if EEPROM_MODE != 0
if(Printer::filamentPrinted == 0) return; // No miles only enabled
if(Printer::filamentPrinted == 0 || (Printer::flag2 & PRINTER_FLAG2_RESET_FILAMENT_USAGE) != 0) return; // No miles only enabled
uint32_t seconds = (HAL::timeInMilliseconds() - Printer::msecondsPrinting) / 1000;
seconds += HAL::eprGetInt32(EPR_PRINTING_TIME);
HAL::eprSetInt32(EPR_PRINTING_TIME,seconds);
HAL::eprSetFloat(EPR_PRINTING_DISTANCE,HAL::eprGetFloat(EPR_PRINTING_DISTANCE) + Printer::filamentPrinted * 0.001);
Printer::filamentPrinted = 0;
Printer::flag2 |= PRINTER_FLAG2_RESET_FILAMENT_USAGE;
Printer::msecondsPrinting = HAL::timeInMilliseconds();
updateChecksum();
Commands::reportPrinterUsage();
Expand Down
16 changes: 10 additions & 6 deletions src/ArduinoAVR/Repetier/Extruder.cpp
Expand Up @@ -398,10 +398,10 @@ void Extruder::initExtruder()
void TemperatureController::updateTempControlVars()
{
#if TEMP_PID
if(heatManager==HTR_PID && pidIGain!=0) // prevent division by zero
if(heatManager == HTR_PID && pidIGain != 0) // prevent division by zero
{
tempIStateLimitMax = (float)pidDriveMax*10.0f/pidIGain;
tempIStateLimitMin = (float)pidDriveMin*10.0f/pidIGain;
tempIStateLimitMax = (float)pidDriveMax * 10.0f / pidIGain;
tempIStateLimitMin = (float)pidDriveMin * 10.0f / pidIGain;
}
#endif
}
Expand All @@ -417,7 +417,7 @@ void Extruder::selectExtruderById(uint8_t extruderId)
if(extruderId >= VIRTUAL_EXTRUDER)
extruderId = 0;
for(uint8_t i = 0; i < NUM_EXTRUDER; i++)
Extruder::setMixingWeight(i,extruder[i].virtualWeights[extruderId]);
Extruder::setMixingWeight(i, extruder[i].virtualWeights[extruderId]);
extruderId = 0;
#endif
if(extruderId >= NUM_EXTRUDER)
Expand Down Expand Up @@ -490,7 +490,7 @@ void Extruder::setTemperatureForExtruder(float temperatureInCelsius,uint8_t extr
extr = 0; // map any virtual extruder number to 0
#endif // MIXING_EXTRUDER
bool alloffs = true;
for(uint8_t i=0; i<NUM_EXTRUDER; i++)
for(uint8_t i = 0; i < NUM_EXTRUDER; i++)
if(tempController[i]->targetTemperatureC > 15) alloffs = false;
#ifdef MAXTEMP
if(temperatureInCelsius > MAXTEMP) temperatureInCelsius = MAXTEMP;
Expand All @@ -500,6 +500,7 @@ void Extruder::setTemperatureForExtruder(float temperatureInCelsius,uint8_t extr
if(tc->sensorType == 0) temperatureInCelsius = 0;
//if(temperatureInCelsius==tc->targetTemperatureC) return;
tc->setTargetTemperature(temperatureInCelsius);
tc->updateTempControlVars();
if(beep && temperatureInCelsius > 30)
tc->setAlarm(true);
if(temperatureInCelsius >= EXTRUDER_FAN_COOL_TEMP) extruder[extr].coolerPWM = extruder[extr].coolerSpeed;
Expand Down Expand Up @@ -536,8 +537,11 @@ void Extruder::setTemperatureForExtruder(float temperatureInCelsius,uint8_t extr
if(alloff && !alloffs) // All heaters are now switched off?
EEPROM::updatePrinterUsage();
#endif
if(alloffs && !alloff) // heaters are turned on, start measuring printing time
if(alloffs && !alloff) { // heaters are turned on, start measuring printing time
Printer::msecondsPrinting = HAL::timeInMilliseconds();
Printer::filamentPrinted = 0; // new print, new counter
Printer::flag2 &= ~PRINTER_FLAG2_RESET_FILAMENT_USAGE;
}
}

void Extruder::setHeatedBedTemperature(float temperatureInCelsius,bool beep)
Expand Down
8 changes: 4 additions & 4 deletions src/ArduinoAVR/Repetier/Printer.cpp
Expand Up @@ -904,7 +904,7 @@ void Printer::setup()
#if defined(SERVO3_NEUTRAL_POS) && SERVO3_NEUTRAL_POS >= 500
HAL::servoMicroseconds(3,SERVO3_NEUTRAL_POS, 1000);
#endif
#endif
#endif
}

void Printer::defaultLoopActions()
Expand Down Expand Up @@ -1004,15 +1004,15 @@ void Printer::homeZAxis() // Delta z homing
dx -= dm; // now all dxyz are positive
dy -= dm;
dz -= dm;
currentPositionSteps[X_AXIS] = 0;
currentPositionSteps[X_AXIS] = 0; // here we should be
currentPositionSteps[Y_AXIS] = 0;
currentPositionSteps[Z_AXIS] = zMaxSteps;
transformCartesianStepsToDeltaSteps(currentPositionSteps,currentDeltaPositionSteps);
currentDeltaPositionSteps[A_TOWER] -= dx;
currentDeltaPositionSteps[B_TOWER] -= dy;
currentDeltaPositionSteps[C_TOWER] -= dz;
PrintLine::moveRelativeDistanceInSteps(0,0,dm,0,homingFeedrate[Z_AXIS],true,false);
currentPositionSteps[X_AXIS] = 0;
PrintLine::moveRelativeDistanceInSteps(0, 0, dm, 0, homingFeedrate[Z_AXIS], true, false);
currentPositionSteps[X_AXIS] = 0; // now we are really here
currentPositionSteps[Y_AXIS] = 0;
currentPositionSteps[Z_AXIS] = zMaxSteps; // Extruder is now exactly in the delta center
coordinateOffset[X_AXIS] = 0;
Expand Down
11 changes: 6 additions & 5 deletions src/ArduinoAVR/Repetier/Printer.h
Expand Up @@ -88,6 +88,7 @@ union wizardVar {
#define PRINTER_FLAG1_ALLOW_COLD_EXTRUSION 128
#define PRINTER_FLAG2_BLOCK_RECEIVING 1
#define PRINTER_FLAG2_AUTORETRACT 2
#define PRINTER_FLAG2_RESET_FILAMENT_USAGE 4

// define an integer number of steps more than large enough to get to endstop from anywhere
#define HOME_DISTANCE_STEPS (Printer::zMaxSteps-Printer::zMinSteps+1000)
Expand Down Expand Up @@ -737,22 +738,22 @@ class Printer
}
static inline speed_t updateStepsPerTimerCall(speed_t vbase)
{
if(vbase>STEP_DOUBLER_FREQUENCY)
if(vbase > STEP_DOUBLER_FREQUENCY)
{
#if ALLOW_QUADSTEPPING
if(vbase>STEP_DOUBLER_FREQUENCY*2)
if(vbase > STEP_DOUBLER_FREQUENCY * 2)
{
Printer::stepsPerTimerCall = 4;
return vbase>>2;
return vbase >> 2;
}
else
{
Printer::stepsPerTimerCall = 2;
return vbase>>1;
return vbase >> 1;
}
#else
Printer::stepsPerTimerCall = 2;
return vbase>>1;
return vbase >> 1;
#endif
}
else
Expand Down
12 changes: 7 additions & 5 deletions src/ArduinoAVR/Repetier/motion.cpp
Expand Up @@ -163,14 +163,15 @@ void PrintLine::queueCartesianMove(uint8_t check_endstops,uint8_t pathOptimize)
p->dir = 0;
Printer::constrainDestinationCoords();
//Find direction
for(uint8_t axis=0; axis < 4; axis++)
for(uint8_t axis = 0; axis < 4; axis++)
{
p->delta[axis] = Printer::destinationSteps[axis] - Printer::currentPositionSteps[axis];
if(axis == E_AXIS)
{
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];
Printer::filamentPrinted += delta[E_AXIS] * Printer::invAxisStepsPerMM[axis];
}
if(p->delta[axis] >= 0)
p->setPositiveDirectionForAxis(axis);
Expand All @@ -186,7 +187,6 @@ void PrintLine::queueCartesianMove(uint8_t check_endstops,uint8_t pathOptimize)
resetPathPlanner();
return; // No steps included
}
Printer::filamentPrinted += axis_diff[E_AXIS];
float xydist2;
#if ENABLE_BACKLASH_COMPENSATION
if((p->isXYZMove()) && ((p->dir & XYZ_DIRPOS)^(Printer::backlashDir & XYZ_DIRPOS)) & (Printer::backlashDir >> 3)) // We need to compensate backlash, add a move
Expand Down Expand Up @@ -1481,10 +1481,12 @@ uint8_t PrintLine::queueDeltaMove(uint8_t check_endstops,uint8_t pathOptimize, u
Printer::extrudeMultiplyError += (static_cast<float>(difference[E_AXIS]) * Printer::extrusionFactor);
difference[E_AXIS] = static_cast<int32_t>(Printer::extrudeMultiplyError);
Printer::extrudeMultiplyError -= difference[E_AXIS];
}
axis_diff[axis] = fabs(difference[axis] * Printer::invAxisStepsPerMM[axis]);
axis_diff[E_AXIS] = difference[E_AXIS] * Printer::invAxisStepsPerMM[E_AXIS];
Printer::filamentPrinted += axis_diff[E_AXIS];
axis_diff[E_AXIS] = fabs(axis_diff[E_AXIS]);
} else
axis_diff[axis] = fabs(difference[axis] * Printer::invAxisStepsPerMM[axis]);
}
Printer::filamentPrinted += axis_diff[E_AXIS];

float cartesianDistance;
flag8_t cartesianDir;
Expand Down
5 changes: 2 additions & 3 deletions src/ArduinoAVR/Repetier/ui.cpp
Expand Up @@ -422,7 +422,7 @@ void lcdWriteByte(uint8_t c,uint8_t rs)
WRITE(UI_DISPLAY_D5_PIN, c & 0x20);
WRITE(UI_DISPLAY_D6_PIN, c & 0x40);
WRITE(UI_DISPLAY_D7_PIN, c & 0x80);
DELAY1MICROSECOND;
HAL::delayMicroseconds(2);
WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); // enable pulse must be >450ns
HAL::delayMicroseconds(2);
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
Expand All @@ -440,12 +440,11 @@ void lcdWriteByte(uint8_t c,uint8_t rs)

void initializeLCD()
{

// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
// according to datasheet, we need at least 40ms after power rises above 2.7V
// before sending commands. Arduino can turn on way before 4.5V.
// is this delay long enough for all cases??
HAL::delayMilliseconds(335);
HAL::delayMilliseconds(235);
SET_OUTPUT(UI_DISPLAY_D4_PIN);
SET_OUTPUT(UI_DISPLAY_D5_PIN);
SET_OUTPUT(UI_DISPLAY_D6_PIN);
Expand Down
4 changes: 2 additions & 2 deletions src/ArduinoDUE/Repetier/Eeprom.cpp
Expand Up @@ -754,12 +754,12 @@ void EEPROM::init()
void EEPROM::updatePrinterUsage()
{
#if EEPROM_MODE != 0
if(Printer::filamentPrinted == 0) return; // No miles only enabled
if(Printer::filamentPrinted == 0 || (Printer::flag2 & PRINTER_FLAG2_RESET_FILAMENT_USAGE) != 0) return; // No miles only enabled
uint32_t seconds = (HAL::timeInMilliseconds() - Printer::msecondsPrinting) / 1000;
seconds += HAL::eprGetInt32(EPR_PRINTING_TIME);
HAL::eprSetInt32(EPR_PRINTING_TIME,seconds);
HAL::eprSetFloat(EPR_PRINTING_DISTANCE,HAL::eprGetFloat(EPR_PRINTING_DISTANCE) + Printer::filamentPrinted * 0.001);
Printer::filamentPrinted = 0;
Printer::flag2 |= PRINTER_FLAG2_RESET_FILAMENT_USAGE;
Printer::msecondsPrinting = HAL::timeInMilliseconds();
updateChecksum();
Commands::reportPrinterUsage();
Expand Down
16 changes: 10 additions & 6 deletions src/ArduinoDUE/Repetier/Extruder.cpp
Expand Up @@ -398,10 +398,10 @@ void Extruder::initExtruder()
void TemperatureController::updateTempControlVars()
{
#if TEMP_PID
if(heatManager==HTR_PID && pidIGain!=0) // prevent division by zero
if(heatManager == HTR_PID && pidIGain != 0) // prevent division by zero
{
tempIStateLimitMax = (float)pidDriveMax*10.0f/pidIGain;
tempIStateLimitMin = (float)pidDriveMin*10.0f/pidIGain;
tempIStateLimitMax = (float)pidDriveMax * 10.0f / pidIGain;
tempIStateLimitMin = (float)pidDriveMin * 10.0f / pidIGain;
}
#endif
}
Expand All @@ -417,7 +417,7 @@ void Extruder::selectExtruderById(uint8_t extruderId)
if(extruderId >= VIRTUAL_EXTRUDER)
extruderId = 0;
for(uint8_t i = 0; i < NUM_EXTRUDER; i++)
Extruder::setMixingWeight(i,extruder[i].virtualWeights[extruderId]);
Extruder::setMixingWeight(i, extruder[i].virtualWeights[extruderId]);
extruderId = 0;
#endif
if(extruderId >= NUM_EXTRUDER)
Expand Down Expand Up @@ -490,7 +490,7 @@ void Extruder::setTemperatureForExtruder(float temperatureInCelsius,uint8_t extr
extr = 0; // map any virtual extruder number to 0
#endif // MIXING_EXTRUDER
bool alloffs = true;
for(uint8_t i=0; i<NUM_EXTRUDER; i++)
for(uint8_t i = 0; i < NUM_EXTRUDER; i++)
if(tempController[i]->targetTemperatureC > 15) alloffs = false;
#ifdef MAXTEMP
if(temperatureInCelsius > MAXTEMP) temperatureInCelsius = MAXTEMP;
Expand All @@ -500,6 +500,7 @@ void Extruder::setTemperatureForExtruder(float temperatureInCelsius,uint8_t extr
if(tc->sensorType == 0) temperatureInCelsius = 0;
//if(temperatureInCelsius==tc->targetTemperatureC) return;
tc->setTargetTemperature(temperatureInCelsius);
tc->updateTempControlVars();
if(beep && temperatureInCelsius > 30)
tc->setAlarm(true);
if(temperatureInCelsius >= EXTRUDER_FAN_COOL_TEMP) extruder[extr].coolerPWM = extruder[extr].coolerSpeed;
Expand Down Expand Up @@ -536,8 +537,11 @@ void Extruder::setTemperatureForExtruder(float temperatureInCelsius,uint8_t extr
if(alloff && !alloffs) // All heaters are now switched off?
EEPROM::updatePrinterUsage();
#endif
if(alloffs && !alloff) // heaters are turned on, start measuring printing time
if(alloffs && !alloff) { // heaters are turned on, start measuring printing time
Printer::msecondsPrinting = HAL::timeInMilliseconds();
Printer::filamentPrinted = 0; // new print, new counter
Printer::flag2 &= ~PRINTER_FLAG2_RESET_FILAMENT_USAGE;
}
}

void Extruder::setHeatedBedTemperature(float temperatureInCelsius,bool beep)
Expand Down
8 changes: 4 additions & 4 deletions src/ArduinoDUE/Repetier/Printer.cpp
Expand Up @@ -904,7 +904,7 @@ void Printer::setup()
#if defined(SERVO3_NEUTRAL_POS) && SERVO3_NEUTRAL_POS >= 500
HAL::servoMicroseconds(3,SERVO3_NEUTRAL_POS, 1000);
#endif
#endif
#endif
}

void Printer::defaultLoopActions()
Expand Down Expand Up @@ -1004,15 +1004,15 @@ void Printer::homeZAxis() // Delta z homing
dx -= dm; // now all dxyz are positive
dy -= dm;
dz -= dm;
currentPositionSteps[X_AXIS] = 0;
currentPositionSteps[X_AXIS] = 0; // here we should be
currentPositionSteps[Y_AXIS] = 0;
currentPositionSteps[Z_AXIS] = zMaxSteps;
transformCartesianStepsToDeltaSteps(currentPositionSteps,currentDeltaPositionSteps);
currentDeltaPositionSteps[A_TOWER] -= dx;
currentDeltaPositionSteps[B_TOWER] -= dy;
currentDeltaPositionSteps[C_TOWER] -= dz;
PrintLine::moveRelativeDistanceInSteps(0,0,dm,0,homingFeedrate[Z_AXIS],true,false);
currentPositionSteps[X_AXIS] = 0;
PrintLine::moveRelativeDistanceInSteps(0, 0, dm, 0, homingFeedrate[Z_AXIS], true, false);
currentPositionSteps[X_AXIS] = 0; // now we are really here
currentPositionSteps[Y_AXIS] = 0;
currentPositionSteps[Z_AXIS] = zMaxSteps; // Extruder is now exactly in the delta center
coordinateOffset[X_AXIS] = 0;
Expand Down
11 changes: 6 additions & 5 deletions src/ArduinoDUE/Repetier/Printer.h
Expand Up @@ -88,6 +88,7 @@ union wizardVar {
#define PRINTER_FLAG1_ALLOW_COLD_EXTRUSION 128
#define PRINTER_FLAG2_BLOCK_RECEIVING 1
#define PRINTER_FLAG2_AUTORETRACT 2
#define PRINTER_FLAG2_RESET_FILAMENT_USAGE 4

// define an integer number of steps more than large enough to get to endstop from anywhere
#define HOME_DISTANCE_STEPS (Printer::zMaxSteps-Printer::zMinSteps+1000)
Expand Down Expand Up @@ -737,22 +738,22 @@ class Printer
}
static inline speed_t updateStepsPerTimerCall(speed_t vbase)
{
if(vbase>STEP_DOUBLER_FREQUENCY)
if(vbase > STEP_DOUBLER_FREQUENCY)
{
#if ALLOW_QUADSTEPPING
if(vbase>STEP_DOUBLER_FREQUENCY*2)
if(vbase > STEP_DOUBLER_FREQUENCY * 2)
{
Printer::stepsPerTimerCall = 4;
return vbase>>2;
return vbase >> 2;
}
else
{
Printer::stepsPerTimerCall = 2;
return vbase>>1;
return vbase >> 1;
}
#else
Printer::stepsPerTimerCall = 2;
return vbase>>1;
return vbase >> 1;
#endif
}
else
Expand Down
12 changes: 7 additions & 5 deletions src/ArduinoDUE/Repetier/motion.cpp
Expand Up @@ -163,14 +163,15 @@ void PrintLine::queueCartesianMove(uint8_t check_endstops,uint8_t pathOptimize)
p->dir = 0;
Printer::constrainDestinationCoords();
//Find direction
for(uint8_t axis=0; axis < 4; axis++)
for(uint8_t axis = 0; axis < 4; axis++)
{
p->delta[axis] = Printer::destinationSteps[axis] - Printer::currentPositionSteps[axis];
if(axis == E_AXIS)
{
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];
Printer::filamentPrinted += delta[E_AXIS] * Printer::invAxisStepsPerMM[axis];
}
if(p->delta[axis] >= 0)
p->setPositiveDirectionForAxis(axis);
Expand All @@ -186,7 +187,6 @@ void PrintLine::queueCartesianMove(uint8_t check_endstops,uint8_t pathOptimize)
resetPathPlanner();
return; // No steps included
}
Printer::filamentPrinted += axis_diff[E_AXIS];
float xydist2;
#if ENABLE_BACKLASH_COMPENSATION
if((p->isXYZMove()) && ((p->dir & XYZ_DIRPOS)^(Printer::backlashDir & XYZ_DIRPOS)) & (Printer::backlashDir >> 3)) // We need to compensate backlash, add a move
Expand Down Expand Up @@ -1481,10 +1481,12 @@ uint8_t PrintLine::queueDeltaMove(uint8_t check_endstops,uint8_t pathOptimize, u
Printer::extrudeMultiplyError += (static_cast<float>(difference[E_AXIS]) * Printer::extrusionFactor);
difference[E_AXIS] = static_cast<int32_t>(Printer::extrudeMultiplyError);
Printer::extrudeMultiplyError -= difference[E_AXIS];
}
axis_diff[axis] = fabs(difference[axis] * Printer::invAxisStepsPerMM[axis]);
axis_diff[E_AXIS] = difference[E_AXIS] * Printer::invAxisStepsPerMM[E_AXIS];
Printer::filamentPrinted += axis_diff[E_AXIS];
axis_diff[E_AXIS] = fabs(axis_diff[E_AXIS]);
} else
axis_diff[axis] = fabs(difference[axis] * Printer::invAxisStepsPerMM[axis]);
}
Printer::filamentPrinted += axis_diff[E_AXIS];

float cartesianDistance;
flag8_t cartesianDir;
Expand Down
5 changes: 2 additions & 3 deletions src/ArduinoDUE/Repetier/ui.cpp
Expand Up @@ -422,7 +422,7 @@ void lcdWriteByte(uint8_t c,uint8_t rs)
WRITE(UI_DISPLAY_D5_PIN, c & 0x20);
WRITE(UI_DISPLAY_D6_PIN, c & 0x40);
WRITE(UI_DISPLAY_D7_PIN, c & 0x80);
DELAY1MICROSECOND;
HAL::delayMicroseconds(2);
WRITE(UI_DISPLAY_ENABLE_PIN, HIGH); // enable pulse must be >450ns
HAL::delayMicroseconds(2);
WRITE(UI_DISPLAY_ENABLE_PIN, LOW);
Expand All @@ -440,12 +440,11 @@ void lcdWriteByte(uint8_t c,uint8_t rs)

void initializeLCD()
{

// SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION!
// according to datasheet, we need at least 40ms after power rises above 2.7V
// before sending commands. Arduino can turn on way before 4.5V.
// is this delay long enough for all cases??
HAL::delayMilliseconds(335);
HAL::delayMilliseconds(235);
SET_OUTPUT(UI_DISPLAY_D4_PIN);
SET_OUTPUT(UI_DISPLAY_D5_PIN);
SET_OUTPUT(UI_DISPLAY_D6_PIN);
Expand Down

0 comments on commit c4dd0c1

Please sign in to comment.