commit
fe72c5593f
|
@ -20,6 +20,7 @@ const char COMM_REPORT_CMD_ERROR[4] = {'R', '0', '3', '\0'};
|
||||||
const char COMM_REPORT_CMD_BUSY[4] = {'R', '0', '4', '\0'};
|
const char COMM_REPORT_CMD_BUSY[4] = {'R', '0', '4', '\0'};
|
||||||
const char COMM_REPORT_CMD_STATUS[4] = {'R', '0', '5', '\0'};
|
const char COMM_REPORT_CMD_STATUS[4] = {'R', '0', '5', '\0'};
|
||||||
const char COMM_REPORT_CALIB_STATUS[4] = {'R', '0', '6', '\0'};
|
const char COMM_REPORT_CALIB_STATUS[4] = {'R', '0', '6', '\0'};
|
||||||
|
const char COMM_REPORT_CMD_RETRY[4] = { 'R', '0', '7', '\0' };
|
||||||
|
|
||||||
const char COMM_REPORT_ENCODER_SCALED[4] = { 'R', '8', '4', '\0' };
|
const char COMM_REPORT_ENCODER_SCALED[4] = { 'R', '8', '4', '\0' };
|
||||||
const char COMM_REPORT_ENCODER_RAW[4] = { 'R', '8', '5', '\0' };
|
const char COMM_REPORT_ENCODER_RAW[4] = { 'R', '8', '5', '\0' };
|
||||||
|
@ -54,6 +55,7 @@ const long PARAM_TEST_DEFAULT = 0;
|
||||||
const long PARAM_CONFIG_OK_DEFAULT = 0;
|
const long PARAM_CONFIG_OK_DEFAULT = 0;
|
||||||
const long PARAM_USE_EEPROM_DEFAULT = 1;
|
const long PARAM_USE_EEPROM_DEFAULT = 1;
|
||||||
const long PARAM_E_STOP_ON_MOV_ERR_DEFAULT = 0;
|
const long PARAM_E_STOP_ON_MOV_ERR_DEFAULT = 0;
|
||||||
|
const long PARAM_MOV_NR_RETRY_DEFAULT = 3;
|
||||||
|
|
||||||
const long MOVEMENT_TIMEOUT_X_DEFAULT = 120;
|
const long MOVEMENT_TIMEOUT_X_DEFAULT = 120;
|
||||||
const long MOVEMENT_TIMEOUT_Y_DEFAULT = 120;
|
const long MOVEMENT_TIMEOUT_Y_DEFAULT = 120;
|
||||||
|
|
|
@ -14,6 +14,7 @@ long z = 0;
|
||||||
unsigned int speed = 0;
|
unsigned int speed = 0;
|
||||||
bool endStopState[3][2];
|
bool endStopState[3][2];
|
||||||
long Q = 0;
|
long Q = 0;
|
||||||
|
int lastError = 0;
|
||||||
|
|
||||||
CurrentState *CurrentState::getInstance()
|
CurrentState *CurrentState::getInstance()
|
||||||
{
|
{
|
||||||
|
@ -31,6 +32,7 @@ CurrentState::CurrentState()
|
||||||
z = 0;
|
z = 0;
|
||||||
speed = 0;
|
speed = 0;
|
||||||
Q = 0;
|
Q = 0;
|
||||||
|
lastError = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long CurrentState::getX()
|
long CurrentState::getX()
|
||||||
|
@ -69,6 +71,16 @@ void CurrentState::setZ(long newZ)
|
||||||
z = newZ;
|
z = newZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CurrentState::getLastError()
|
||||||
|
{
|
||||||
|
return lastError;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CurrentState::setLastError(int error)
|
||||||
|
{
|
||||||
|
lastError = error;
|
||||||
|
}
|
||||||
|
|
||||||
void CurrentState::setEndStopState(unsigned int axis, unsigned int position, bool state)
|
void CurrentState::setEndStopState(unsigned int axis, unsigned int position, bool state)
|
||||||
{
|
{
|
||||||
endStopState[axis][position] = state;
|
endStopState[axis][position] = state;
|
||||||
|
|
|
@ -23,6 +23,9 @@ public:
|
||||||
void setY(long);
|
void setY(long);
|
||||||
void setZ(long);
|
void setZ(long);
|
||||||
|
|
||||||
|
int getLastError();
|
||||||
|
void setLastError(int error);
|
||||||
|
|
||||||
void setEndStopState(unsigned int, unsigned int, bool);
|
void setEndStopState(unsigned int, unsigned int, bool);
|
||||||
void printPosition();
|
void printPosition();
|
||||||
String getPosition();
|
String getPosition();
|
||||||
|
|
|
@ -27,11 +27,31 @@ int GCodeProcessor::execute(Command *command)
|
||||||
{
|
{
|
||||||
|
|
||||||
int execution = 0;
|
int execution = 0;
|
||||||
|
bool isMovement = false;
|
||||||
|
|
||||||
|
int attempt = 0;
|
||||||
|
int maximumAttempts = ParameterList::getInstance()->getValue(PARAM_MOV_NR_RETRY);
|
||||||
|
|
||||||
long Q = command->getQ();
|
long Q = command->getQ();
|
||||||
CurrentState::getInstance()->setQ(Q);
|
CurrentState::getInstance()->setQ(Q);
|
||||||
|
|
||||||
|
if
|
||||||
|
(
|
||||||
|
command->getCodeEnum() == G00 ||
|
||||||
|
command->getCodeEnum() == G01 ||
|
||||||
|
command->getCodeEnum() == F11 ||
|
||||||
|
command->getCodeEnum() == F12 ||
|
||||||
|
command->getCodeEnum() == F13 ||
|
||||||
|
command->getCodeEnum() == F14 ||
|
||||||
|
command->getCodeEnum() == F15 ||
|
||||||
|
command->getCodeEnum() == F16
|
||||||
|
)
|
||||||
|
{
|
||||||
|
isMovement = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Only allow reset of emergency stop when emergency stop is engaged
|
//Only allow reset of emergency stop when emergency stop is engaged
|
||||||
|
|
||||||
if (CurrentState::getInstance()->isEmergencyStop())
|
if (CurrentState::getInstance()->isEmergencyStop())
|
||||||
|
@ -106,13 +126,37 @@ int GCodeProcessor::execute(Command *command)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the command, report start and end
|
// Report start of command
|
||||||
|
|
||||||
Serial.print(COMM_REPORT_CMD_START);
|
Serial.print(COMM_REPORT_CMD_START);
|
||||||
CurrentState::getInstance()->printQAndNewLine();
|
CurrentState::getInstance()->printQAndNewLine();
|
||||||
|
|
||||||
execution = handler->execute(command);
|
// Execute command with retry
|
||||||
|
CurrentState::getInstance()->setLastError(0);
|
||||||
|
while (attempt < 1 || (attempt < maximumAttempts && execution != 0))
|
||||||
|
{
|
||||||
|
Serial.print("R99 attempt ");
|
||||||
|
Serial.print(attempt);
|
||||||
|
Serial.print(" from ");
|
||||||
|
Serial.print(maximumAttempts);
|
||||||
|
|
||||||
|
Serial.print("\r\n");
|
||||||
|
|
||||||
|
attempt++;
|
||||||
|
if (attempt > 1)
|
||||||
|
{
|
||||||
|
Serial.print(COMM_REPORT_CMD_RETRY);
|
||||||
|
CurrentState::getInstance()->printQAndNewLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
handler->execute(command);
|
||||||
|
execution = CurrentState::getInstance()->getLastError();
|
||||||
|
|
||||||
|
Serial.print("R99 execution ");
|
||||||
|
Serial.print(execution);
|
||||||
|
Serial.print("\r\n");
|
||||||
|
|
||||||
|
}
|
||||||
// Clean serial buffer
|
// Clean serial buffer
|
||||||
while (Serial.available() > 0)
|
while (Serial.available() > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -245,7 +245,9 @@ void ParameterList::loadDefaultValue(int id)
|
||||||
case PARAM_E_STOP_ON_MOV_ERR:
|
case PARAM_E_STOP_ON_MOV_ERR:
|
||||||
paramValues[id] = PARAM_E_STOP_ON_MOV_ERR_DEFAULT;
|
paramValues[id] = PARAM_E_STOP_ON_MOV_ERR_DEFAULT;
|
||||||
break;
|
break;
|
||||||
|
case PARAM_MOV_NR_RETRY:
|
||||||
|
paramValues[id] = PARAM_MOV_NR_RETRY_DEFAULT;
|
||||||
|
break;
|
||||||
case MOVEMENT_TIMEOUT_X:
|
case MOVEMENT_TIMEOUT_X:
|
||||||
paramValues[id] = MOVEMENT_TIMEOUT_X_DEFAULT;
|
paramValues[id] = MOVEMENT_TIMEOUT_X_DEFAULT;
|
||||||
break;
|
break;
|
||||||
|
@ -509,6 +511,7 @@ bool ParameterList::validParam(int id)
|
||||||
case PARAM_CONFIG_OK:
|
case PARAM_CONFIG_OK:
|
||||||
case PARAM_USE_EEPROM:
|
case PARAM_USE_EEPROM:
|
||||||
case PARAM_E_STOP_ON_MOV_ERR:
|
case PARAM_E_STOP_ON_MOV_ERR:
|
||||||
|
case PARAM_MOV_NR_RETRY:
|
||||||
case MOVEMENT_TIMEOUT_X:
|
case MOVEMENT_TIMEOUT_X:
|
||||||
case MOVEMENT_TIMEOUT_Y:
|
case MOVEMENT_TIMEOUT_Y:
|
||||||
case MOVEMENT_TIMEOUT_Z:
|
case MOVEMENT_TIMEOUT_Z:
|
||||||
|
|
|
@ -17,6 +17,8 @@ enum ParamListEnum
|
||||||
PARAM_USE_EEPROM = 3,
|
PARAM_USE_EEPROM = 3,
|
||||||
PARAM_E_STOP_ON_MOV_ERR = 4,
|
PARAM_E_STOP_ON_MOV_ERR = 4,
|
||||||
|
|
||||||
|
PARAM_MOV_NR_RETRY = 5,
|
||||||
|
|
||||||
// stepper motor settings
|
// stepper motor settings
|
||||||
|
|
||||||
MOVEMENT_TIMEOUT_X = 11,
|
MOVEMENT_TIMEOUT_X = 11,
|
||||||
|
|
|
@ -433,6 +433,10 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
||||||
encoderX.setPosition(0);
|
encoderX.setPosition(0);
|
||||||
axisX.setCurrentPosition(0);
|
axisX.setCurrentPosition(0);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (axisY.isAxisActive() && motorConsMissedSteps[1] > motorConsMissedStepsMax[1])
|
if (axisY.isAxisActive() && motorConsMissedSteps[1] > motorConsMissedStepsMax[1])
|
||||||
|
@ -450,6 +454,10 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
||||||
encoderY.setPosition(0);
|
encoderY.setPosition(0);
|
||||||
axisY.setCurrentPosition(0);
|
axisY.setCurrentPosition(0);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (axisZ.isAxisActive() && motorConsMissedSteps[2] > motorConsMissedStepsMax[2])
|
if (axisZ.isAxisActive() && motorConsMissedSteps[2] > motorConsMissedStepsMax[2])
|
||||||
|
@ -468,6 +476,10 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
||||||
encoderZ.setPosition(0);
|
encoderZ.setPosition(0);
|
||||||
axisZ.setCurrentPosition(0);
|
axisZ.setCurrentPosition(0);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (axisX.endStopAxisReached(false))
|
if (axisX.endStopAxisReached(false))
|
||||||
|
@ -652,7 +664,14 @@ int StepperControl::moveToCoords(long xDest, long yDest, long zDest,
|
||||||
CurrentState::getInstance()->setEmergencyStop();
|
CurrentState::getInstance()->setEmergencyStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Serial.print("R99 error ");
|
||||||
|
Serial.print(error);
|
||||||
|
Serial.print("\r\n");
|
||||||
|
|
||||||
|
|
||||||
// Return error
|
// Return error
|
||||||
|
CurrentState::getInstance()->setLastError(error);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue