Skip to content

Commit

Permalink
Fatal errors introduced for bed leveling
Browse files Browse the repository at this point in the history
  • Loading branch information
repetier committed Feb 6, 2016
1 parent afb55d4 commit ce05b5f
Show file tree
Hide file tree
Showing 29 changed files with 390 additions and 87 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Repetier.depend
Repetier.layout
activate*.bat
src/Repetier-Atmel7/*
src/ArduinoDUE/Repetier.zip
src/ArduinoDUE/Repetier.zip
src/ArduinoAVR/Repetier.zip
5 changes: 3 additions & 2 deletions src/ArduinoAVR/Repetier/BedLeveling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ S = 0 : Do not update length - use this if you have not homed before or you mess
S = 1 : Measure zLength so homing works
S = 2 : Like s = 1 plus store results in EEPROM for next connection.
*/
void runBedLeveling(GCode *com) {
bool runBedLeveling(GCode *com) {
float h1,h2,h3,hc,oldFeedrate = Printer::feedrate;
int s = com->hasS() ? com->S : -1;
#if DISTORTION_CORRECTION
Expand Down Expand Up @@ -303,7 +303,7 @@ void runBedLeveling(GCode *com) {
#endif
if(!measureAutolevelPlane(plane)) {
Com::printErrorFLN(PSTR("Probing had returned errors - autoleveling canceled."));
return;
return false;
}
correctAutolevel(com,plane);

Expand Down Expand Up @@ -352,6 +352,7 @@ void runBedLeveling(GCode *com) {
Printer::homeAxis(true, true, true); // shifting z makes positioning invalid, need to recalibrate
#endif
Printer::feedrate = oldFeedrate;
return true;
}

#endif
Expand Down
33 changes: 26 additions & 7 deletions src/ArduinoAVR/Repetier/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ void Commands::processArc(GCode *com) {
PrintLine::arc(position, target, offset, r, isclockwise);
}
#endif
extern void runBedLeveling(GCode *com);
extern bool runBedLeveling(GCode *com);
/**
\brief Execute the G command stored in com.
*/
Expand Down Expand Up @@ -1018,8 +1018,8 @@ void Commands::processGCode(GCode *com) {
Printer::currentPositionSteps[Z_AXIS] = sum * Printer::axisStepsPerMM[Z_AXIS];
float zup = Printer::runZMaxProbe();
if(zup == ILLEGAL_Z_PROBE) {
break;
}
ok = false;
} else
Printer::zLength = zup + sum - ENDSTOP_Z_BACK_ON_HOME;
#endif // DELTA
Com::printInfoFLN(Com::tZProbeZReset);
Expand All @@ -1031,13 +1031,17 @@ void Commands::processGCode(GCode *com) {
}
Printer::feedrate = oldFeedrate;
Printer::setAutolevelActive(oldAutolevel);
if(com->hasS() && com->S == 2)
if(ok && com->hasS() && com->S == 2)
EEPROM::storeDataIntoEEPROM();
}
Printer::updateCurrentPosition(true);
printCurrentPosition(PSTR("G29 "));
Printer::finishProbing();
Printer::feedrate = oldFeedrate;
if(!ok) {
GCode::fatalError(PSTR("G29 leveling failed!"));
break;
}
#if defined(Z_PROBE_MIN_TEMPERATURE) && Z_PROBE_MIN_TEMPERATURE && Z_PROBE_REQUIRES_HEATING
#if ZHOME_HEAT_ALL
for(int i = 0; i < NUM_EXTRUDER; i++) {
Expand All @@ -1057,7 +1061,10 @@ void Commands::processGCode(GCode *com) {
case 30:
{ // G30 single probe set Z0
uint8_t p = (com->hasP() ? (uint8_t)com->P : 3);
Printer::runZProbe(p & 1,p & 2);
if(Printer::runZProbe(p & 1,p & 2) == ILLEGAL_Z_PROBE) {
GCode::fatalError(PSTR("G29 leveling failed!"));
break;
}
Printer::updateCurrentPosition(p & 1);
}
break;
Expand Down Expand Up @@ -1090,7 +1097,10 @@ void Commands::processGCode(GCode *com) {
Extruder::setTemperatureForExtruder(RMath::max(actTemp[Extruder::current->id],static_cast<float>(ZPROBE_MIN_TEMPERATURE)),Extruder::current->id,false,true);
#endif
#endif
runBedLeveling(com);
if(!runBedLeveling(com)) {
GCode::fatalError(PSTR("G32 leveling failed!"));
break;
}
#if defined(Z_PROBE_MIN_TEMPERATURE) && Z_PROBE_MIN_TEMPERATURE && Z_PROBE_REQUIRES_HEATING
#if ZHOME_HEAT_ALL
for(int i = 0; i < NUM_EXTRUDER; i++) {
Expand Down Expand Up @@ -1141,7 +1151,10 @@ void Commands::processGCode(GCode *com) {
#endif
#endif
float oldFeedrate = Printer::feedrate;
Printer::measureDistortion();
if(!Printer::measureDistortion()) {
GCode::fatalError(PSTR("G33 failed!"));
break;
}
Printer::feedrate = oldFeedrate;
#if defined(Z_PROBE_MIN_TEMPERATURE) && Z_PROBE_MIN_TEMPERATURE && Z_PROBE_REQUIRES_HEATING
#if ZHOME_HEAT_ALL
Expand Down Expand Up @@ -2371,6 +2384,12 @@ void Commands::processMCode(GCode *com) {
EEPROM::setVersion(com->S);
break;
#endif
case 999: // Stop fatal error take down
if(com->hasS())
GCode::fatalError(PSTR("Testing fatal error"));
else
GCode::resetFatalError();
break;
default:
if(!EVENT_UNHANDLED_M_CODE(com) && Printer::debugErrors()) {
Com::printF(Com::tUnknownCommand);
Expand Down
1 change: 1 addition & 0 deletions src/ArduinoAVR/Repetier/Communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ FSTRINGVALUE(Com::tSpaceRaw," RAW")
FSTRINGVALUE(Com::tColon,":")
FSTRINGVALUE(Com::tSlash,"/")
FSTRINGVALUE(Com::tSpaceSlash," /")
FSTRINGVALUE(Com::tFatal,"fatal:")
#if JSON_OUTPUT
FSTRINGVALUE(Com::tJSONDir,"{\"dir\":\"")
FSTRINGVALUE(Com::tJSONFiles,"\",\"files\":[")
Expand Down
1 change: 1 addition & 0 deletions src/ArduinoAVR/Repetier/Communication.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ FSTRINGVAR(tFreeRAM)
FSTRINGVAR(tXColon)
FSTRINGVAR(tSlash)
FSTRINGVAR(tSpaceSlash)
FSTRINGVAR(tFatal)
#if JSON_OUTPUT
FSTRINGVAR(tJSONDir)
FSTRINGVAR(tJSONFiles)
Expand Down
4 changes: 4 additions & 0 deletions src/ArduinoAVR/Repetier/Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ Each of the following events describe the parameter and when it is called.
#define EVENT_START_NEXTPREVIOUS(action,increment) {}
// Gets called before a move is queued. Gives the ability to limit moves.
#define EVENT_CONTRAIN_DESTINATION_COORDINATES
// Gets called when a fatal error occurs and all actions should be stopped
#define EVENT_FATAL_ERROR_OCCURED
// Gets called after a M999 to continue from fatal errors
#define EVENT_CONTINUE_FROM_FATAL_ERROR

// Called to initialize laser pins. Return false to prevent default initialization.
#define EVENT_INITALIZE_LASER true
Expand Down
6 changes: 6 additions & 0 deletions src/ArduinoAVR/Repetier/Extruder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ void Extruder::unpauseExtruders()
extruder[i].tempControl.waitForTargetTemperature();
}

void TemperatureController::resetAllErrorStates() {
for(int i = 0;i < NUM_TEMPERATURE_LOOPS; i++) {
tempController[i]->removeErrorStates();
}
}

#if EXTRUDER_JAM_CONTROL
void TemperatureController::setJammed(bool on)
{
Expand Down
8 changes: 6 additions & 2 deletions src/ArduinoAVR/Repetier/Extruder.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//#endif

// Updates the temperature of all extruders and heated bed if it's time.
// Toggels the heater power if necessary.
// Toggles the heater power if necessary.
extern bool reportTempsensorError(); ///< Report defect sensors
extern uint8_t manageMonitor;
#define HTR_OFF 0
Expand All @@ -25,7 +25,7 @@ extern uint8_t manageMonitor;
#define TEMPERATURE_CONTROLLER_FLAG_JAM 32 //< Indicates a jammed filament
#define TEMPERATURE_CONTROLLER_FLAG_SLOWDOWN 64 //< Indicates a slowed down extruder

/** TemperatureController manages one heater-temperature sensore loop. You can have up to
/** TemperatureController manages one heater-temperature sensor loop. You can have up to
4 loops allowing pid/bang bang for up to 3 extruder and the heated bed.
*/
Expand Down Expand Up @@ -77,6 +77,9 @@ class TemperatureController
{
return flags & TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_FULL;
}
inline void removeErrorStates() {
flags &= ~(TEMPERATURE_CONTROLLER_FLAG_ALARM | TEMPERATURE_CONTROLLER_FLAG_SENSDEFECT | TEMPERATURE_CONTROLLER_FLAG_SENSDECOUPLED);
}
inline bool isDecoupleFullOrHold()
{
return flags & (TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_FULL | TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_HOLD);
Expand Down Expand Up @@ -122,6 +125,7 @@ class TemperatureController
{
return flags & TEMPERATURE_CONTROLLER_FLAG_SENSDECOUPLED;
}
static void resetAllErrorStates();
#if EXTRUDER_JAM_CONTROL
inline bool isJammed()
{
Expand Down
10 changes: 6 additions & 4 deletions src/ArduinoAVR/Repetier/Printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ void Printer::kill(uint8_t only_steppers)
#endif
pwm_pos[PWM_BOARD_FAN] = 0;
#endif // FAN_BOARD_PIN
Commands::printTemperatures(false);
}

void Printer::updateAdvanceFlags()
Expand Down Expand Up @@ -1890,9 +1891,9 @@ void Printer::showConfiguration() {

Distortion Printer::distortion;

void Printer::measureDistortion(void)
bool Printer::measureDistortion(void)
{
distortion.measure();
return distortion.measure();
}

Distortion::Distortion()
Expand Down Expand Up @@ -2016,7 +2017,7 @@ void Distortion::extrapolateCorners()
extrapolateCorner(m, m,-1,-1);
}

void Distortion::measure(void)
bool Distortion::measure(void)
{
fast8_t ix, iy;
float z = EEPROM::zProbeBedDistance() + (EEPROM::zProbeHeight() > 0 ? EEPROM::zProbeHeight() : 0);
Expand Down Expand Up @@ -2053,7 +2054,7 @@ void Distortion::measure(void)
if(zp == ILLEGAL_Z_PROBE) {
Com::printErrorFLN(PSTR("Stopping distortion measurement due to errors."));
Printer::finishProbing();
return;
return false;
}
setMatrix(floor(0.5f + Printer::axisStepsPerMM[Z_AXIS] * (z -zp)) + zCorrection,
matrixIndex(ix,iy));
Expand Down Expand Up @@ -2087,6 +2088,7 @@ void Distortion::measure(void)
}
showMatrix();
enable(true);
return true;
//Printer::homeAxis(false, false, true);
}

Expand Down
4 changes: 2 additions & 2 deletions src/ArduinoAVR/Repetier/Printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Distortion
void init();
void enable(bool permanent = true);
void disable(bool permanent = true);
void measure(void);
bool measure(void);
int32_t correct(int32_t x, int32_t y, int32_t z) const;
void updateDerived();
void reportStatus();
Expand Down Expand Up @@ -1098,7 +1098,7 @@ class Printer
static void buildTransformationMatrix(float h1,float h2,float h3);
#endif
#if DISTORTION_CORRECTION
static void measureDistortion(void);
static bool measureDistortion(void);
static Distortion distortion;
#endif
static void MemoryPosition();
Expand Down
10 changes: 7 additions & 3 deletions src/ArduinoAVR/Repetier/Repetier.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// ##########################################################################################
// ## Debug configuration ##
// ##########################################################################################
// These are run time sqitchable debug flags
// These are run time switchable debug flags
enum debugFlags {DEB_ECHO = 0x1, DEB_INFO = 0x2, DEB_ERROR = 0x4,DEB_DRYRUN = 0x8,
DEB_COMMUNICATION = 0x10, DEB_NOMOVES = 0x20, DEB_DEBUG = 0x40
};
Expand All @@ -39,14 +39,14 @@ enum debugFlags {DEB_ECHO = 0x1, DEB_INFO = 0x2, DEB_ERROR = 0x4,DEB_DRYRUN = 0x
/** write infos about path planner changes */
//#define DEBUG_PLANNER
/** Allows M111 to set bit 5 (16) which disables all commands except M111. This can be used
to test your data througput or search for communication problems. */
to test your data throughput or search for communication problems. */
#define INCLUDE_DEBUG_COMMUNICATION 1
/** Allows M111 so set bit 6 (32) which disables moves, at the first tried step. In combination
with a dry run, you can test the speed of path computations, which are still performed. */
#define INCLUDE_DEBUG_NO_MOVE 1
/** Writes the free RAM to output, if it is less then at the last test. Should always return
values >500 for safety, since it doesn't catch every function call. Nice to tweak cache
usage or for seraching for memory induced errors. Switch it off for production, it costs execution time. */
usage or for searching for memory induced errors. Switch it off for production, it costs execution time. */
//#define DEBUG_FREE_MEMORY
//#define DEBUG_ADVANCE
/** If enabled, writes the created generic table to serial port at startup. */
Expand Down Expand Up @@ -194,6 +194,10 @@ usage or for seraching for memory induced errors. Switch it off for production,

#include "Configuration.h"

#ifndef MAX_JERK_DISTANCE
#define MAX_JERK_DISTANCE 0.6
#endif

inline void memcopy2(void *dest,void *source) {
*((int16_t*)dest) = *((int16_t*)source);
}
Expand Down
43 changes: 39 additions & 4 deletions src/ArduinoAVR/Repetier/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ int8_t GCode::waitingForResend = -1; ///< Waiting for line to be resend. -1 =
volatile uint8_t GCode::bufferLength = 0; ///< Number of commands stored in gcode_buffer
millis_t GCode::timeOfLastDataPacket = 0; ///< Time, when we got the last data packet. Used to detect missing uint8_ts.
uint8_t GCode::formatErrors = 0;
FSTRINGPARAM(GCode::fatalErrorMsg) = NULL; ///< message unset = no fatal error

/** \page Repetier-protocol
Expand Down Expand Up @@ -229,7 +230,11 @@ void GCode::checkAndPushCommand()
requestResend();
return;
}
pushCommand();
if(GCode::hasFatalError() && !(hasM() && M==999)) {
GCode::reportFatalError();
} else {
pushCommand();
}
#ifdef DEBUG_COM_ERRORS
if(hasM() && M == 667)
return; // omit ok
Expand Down Expand Up @@ -424,7 +429,7 @@ void GCode::readFromSerial()
}
else
{
if(ch == ';') commentDetected = true; // ignore new data until lineend
if(ch == ';') commentDetected = true; // ignore new data until line end
if(commentDetected) commandsReceivingWritePosition--;
}
}
Expand Down Expand Up @@ -507,7 +512,7 @@ void GCode::readFromSerial()
}
else
{
if(ch == ';') commentDetected = true; // ignore new data until lineend
if(ch == ';') commentDetected = true; // ignore new data until line end
if(commentDetected) commandsReceivingWritePosition--;
}
}
Expand Down Expand Up @@ -1017,11 +1022,41 @@ void GCode::printCommand()
Com::println();
}

void GCode::fatalError(FSTRINGPARAM(message)) {
fatalErrorMsg = message;
#if SDSUPPORT
if(sd.sdmode != 0) { // stop sd print to prevent damage
sd.stopPrint();
}
#endif
if(Printer::currentPosition[Z_AXIS] < Printer::zMin + Printer::zLength - 15)
PrintLine::moveRelativeDistanceInStepsReal(0,0,10*Printer::axisStepsPerMM[Z_AXIS],0,Printer::homingFeedrate[Z_AXIS],true,true);
EVENT_FATAL_ERROR_OCCURED
Commands::waitUntilEndOfAllMoves();
Printer::kill(true);
reportFatalError();
}

void GCode::reportFatalError() {
Com::printF(Com::tFatal);
Com::printF(fatalErrorMsg);
Com::printFLN(PSTR(" Printer stopped and heaters disabled due to this error. Fix error and restart with M999."));
UI_ERROR_UPD(fatalErrorMsg)
}

void GCode::resetFatalError() {
TemperatureController::resetAllErrorStates();
fatalErrorMsg = NULL;
UI_ERROR("");
EVENT_CONTINUE_FROM_FATAL_ERROR
Com::printFLN(PSTR("info:Continue from fatal state"));
}

#if JSON_OUTPUT

// --------------------------------------------------------------- //
// Code that gets gcode information is adapted from RepRapFirmware //
// Originally licenced under GPL //
// Originally licensed under GPL //
// Authors: reprappro, dc42, dcnewman, others //
// Source: https://github.com/dcnewman/RepRapFirmware //
// Copy date: 15 Nov 2015 //
Expand Down
Loading

0 comments on commit ce05b5f

Please sign in to comment.