removing errors

pull/4/head
TimEvWw 2014-08-07 20:05:30 -01:00
parent fe04f69942
commit 30b86302a4
15 changed files with 139 additions and 81 deletions

View File

@ -1,14 +1,16 @@
#include "Command.h"
const char axisCodes[3] = { 'X', 'Y', 'Z' };
const char axisSpeedCodes[3] = { 'A', 'B', 'C' };
const char speedCode = 'S';
const char parameterIdCode = 'P';
const char parameterValueCode = 'V';
double axisValue[3] = { 0.0, 0.0, 0.0 };
double speedValue = 0.0;
long parameterId = 0;
long parameterValue = 0;
double axisValue[3] = { 0.0, 0.0, 0.0 };
long axisSpeedValue[3] = { 0, 0, 0 };
double speedValue = 0.0;
long parameterId = 0;
long parameterValue = 0;
CommandCodeEnum commandCodeEnum = CODE_UNDEFINED;
@ -89,6 +91,14 @@ void Command::getParameter(char* charPointer) {
axisValue[1] = atof(charPointer + 1);
} else if (charPointer[0] == axisCodes[2]) {
axisValue[2] = atof(charPointer + 1);
} else if (charPointer[0] == axisSpeedCodes[0]) {
axisSpeedValue[0] = atof(charPointer + 1);
} else if (charPointer[0] == axisSpeedCodes[1]) {
axisSpeedValue[1] = atof(charPointer + 1);
} else if (charPointer[0] == axisSpeedCodes[2]) {
axisSpeedValue[2] = atof(charPointer + 1);
} else if (charPointer[0] == speedCode) {
speedValue = atof(charPointer + 1);
} else if (charPointer[0] == parameterIdCode) {
@ -127,6 +137,18 @@ double Command::getZ() {
return axisValue[2];
}
long Command::getA() {
return axisValue[0];
}
long Command::getB() {
return axisValue[1];
}
long Command::getC() {
return axisValue[2];
}
double Command::getP() {
return parameterId;
}

View File

@ -36,6 +36,11 @@ public:
double getY();
double getZ();
double getS();
double getP();
double getV();
long getA();
long getB();
long getC();
private:
CommandCodeEnum getGCodeEnum(char* code);
void getParameter(char* charPointer);

View File

@ -28,7 +28,7 @@ int F11Handler::execute(Command* command) {
Serial.print("R99 HOME X\n");
}
StepperControl::getInstance()->moveAbsoluteConstant(0,0,0,0, true, false, false);
StepperControl::getInstance()->moveAbsoluteConstant(0,0,0, 0,0,0, true, false, false);
if (LOGGING) {
CurrentState::getInstance()->print();
}

View File

@ -28,7 +28,7 @@ int F12Handler::execute(Command* command) {
Serial.print("R99 HOME Y\n");
}
StepperControl::getInstance()->moveAbsoluteConstant(0,0,0,0, false, true, false);
StepperControl::getInstance()->moveAbsoluteConstant(0,0,0, 0,0,0, false, true, false);
if (LOGGING) {
CurrentState::getInstance()->print();
}

View File

@ -30,7 +30,7 @@ Serial.print("home\n");
Serial.print("R99 HOME Z\n");
}
StepperControl::getInstance()->moveAbsoluteConstant(0,0,0,0, false, false, true);
StepperControl::getInstance()->moveAbsoluteConstant(0,0,0, 0,0,0, false, false, true);
if (LOGGING) {
CurrentState::getInstance()->print();
}

View File

@ -1,4 +1,4 @@
y/*
/*
* F21Handler.cpp
*
* Created on: 15 maj 2014
@ -23,7 +23,7 @@ F21Handler::F21Handler() {
int F21Handler::execute(Command* command) {
ParameterList::getInstance()-readValue(command->getP());
//ParameterList::getInstance()->readValue(command->getP());
return 0;
}

View File

@ -23,7 +23,7 @@ F22Handler::F22Handler() {
int F22Handler::execute(Command* command) {
ParameterList::getInstance()-readValue(command->getP() , command->getS());
//ParameterList::getInstance()->readValue(command->getP());
return 0;
}

View File

@ -23,8 +23,8 @@ private:
F22Handler();
F22Handler(F22Handler const&);
void operator=(F22Handler const&);
long adjustStepAmount(long);
long getNumberOfSteps(double, double);
//long adjustStepAmount(long);
//long getNumberOfSteps(double, double);
};
#endif /* F22HANDLER_H_ */

View File

@ -22,8 +22,9 @@ G00Handler::G00Handler() {
}
int G00Handler::execute(Command* command) {
StepperControl::getInstance()->moveAbsoluteConstant(command->getX(),
command->getY(), command->getZ(), command->getS(),
StepperControl::getInstance()->moveAbsoluteConstant(
command->getX(), command->getY(), command->getZ(),
command->getA(), command->getB(), command->getC(),
false, false, false);
if (LOGGING) {
CurrentState::getInstance()->print();

View File

@ -25,8 +25,8 @@ int G28Handler::execute(Command* command) {
Serial.print("home\n");
StepperControl::getInstance()->moveAbsoluteConstant(0,0,0,0, false, false, true);
StepperControl::getInstance()->moveAbsoluteConstant(0,0,0,0, true, true, false);
StepperControl::getInstance()->moveAbsoluteConstant(0,0,0, 0,0,0, false, false, true);
StepperControl::getInstance()->moveAbsoluteConstant(0,0,0, 0,0,0, true, true, false);
//StepperControl::getInstance()->moveAbsoluteConstant(0,0,0,HOME_MOVEMENT_SPEED_S_P_S,true);
if (LOGGING) {
CurrentState::getInstance()->print();

View File

@ -57,8 +57,8 @@ GCodeHandler* GCodeProcessor::getGCodeHandler(CommandCodeEnum codeEnum) {
case F13:
return F13Handler::getInstance();
case F20:
return F20Handler::getInstance();
// case F20:
// return F20Handler::getInstance();
case F21:
return F21Handler::getInstance();
case F22:

View File

@ -1,4 +1,4 @@
#include "Command.h"
#include "ParameterList.h"
static ParameterList* instance;
@ -69,9 +69,6 @@ int ParameterList::writeValue(int id, long value) {
return 0;
}
int
int ParameterList::readValue(int id) {
long value = paramValues[id];
@ -88,6 +85,6 @@ int ParameterList::readValue(int id) {
}
long ParameterList::getValue(int id {
long ParameterList::getValue(int id) {
return paramValues[id];
}

View File

@ -10,16 +10,35 @@
enum ParamListEnum
{
PARAM_VERSION = 0,
MOVEMENT_TIMEOUT_X,
MOVEMENT_TIMEOUT_Y,
MOVEMENT_TIMEOUT_Z,
MOVEMENT_INVERT_ENDPOINTS_X,
MOVEMENT_INVERT_ENDPOINTS_Y,
MOVEMENT_INVERT_ENDPOINTS_Z,
MOVEMENT_INVERT_MOTOR_X,
MOVEMENT_INVERT_MOTOR_Y,
MOVEMENT_INVERT_MOTOR_Z
PARAM_VERSION = 0,
MOVEMENT_TIMEOUT_X ,
MOVEMENT_TIMEOUT_Y ,
MOVEMENT_TIMEOUT_Z ,
MOVEMENT_INVERT_ENDPOINTS_X ,
MOVEMENT_INVERT_ENDPOINTS_Y ,
MOVEMENT_INVERT_ENDPOINTS_Z ,
MOVEMENT_INVERT_MOTOR_X ,
MOVEMENT_INVERT_MOTOR_Y ,
MOVEMENT_INVERT_MOTOR_Z ,
MOVEMENT_STEPS_ACC_DEC_X ,
MOVEMENT_STEPS_ACC_DEC_Y ,
MOVEMENT_STEPS_ACC_DEC_Z ,
MOVEMENT_HOME_UP_X ,
MOVEMENT_HOME_UP_Y ,
MOVEMENT_HOME_UP_Z ,
MOVEMENT_MIN_SPD_X ,
MOVEMENT_MIN_SPD_Y ,
MOVEMENT_MIN_SPD_Z ,
MOVEMENT_MAX_SPD_X ,
MOVEMENT_MAX_SPD_Y ,
MOVEMENT_MAX_SPD_Z
};
@ -31,12 +50,12 @@ class ParameterList {
ParamListEnum paramListEnum;
public:
static ParameterList* getInstance();
void writeValue(int id, long value);
void readValue(int id);
long getParamValue(int id);
int writeValue(int id, long value);
int readValue(int id);
long getValue(int id);
private:
ParameterList();
virtual ~ParameterList();
// virtual ~ParameterList();
long paramValues[50];
};

View File

@ -25,24 +25,28 @@ unsigned long getMaxLength(unsigned long lengths[3]) {
int endStopAxisReached(int axis_nr, bool movement_forward) {
bool endStInv[3] = { ParameterList::getInstance()->getValue(MOVEMENT_INVERT_ENDPOINTS_X),
ParameterList::getInstance()->getValue(MOVEMENT_INVERT_ENDPOINTS_Y),
ParameterList::getInstance()->getValue(MOVEMENT_INVERT_ENDPOINTS_Z) };
bool min_endstop = false;
bool max_endstop = false;
// for the axis to check, retrieve the end stop status
if (axis_nr == 0) {
min_endstop=(digitalRead(X_MIN_PIN) == INVERT_ENDSTOPS);
max_endstop=(digitalRead(X_MAX_PIN) == INVERT_ENDSTOPS);
min_endstop=(digitalRead(X_MIN_PIN) == endStInv[0]);
max_endstop=(digitalRead(X_MAX_PIN) == endStInv[0]);
}
if (axis_nr == 1) {
min_endstop=(digitalRead(Y_MIN_PIN) == INVERT_ENDSTOPS);
max_endstop=(digitalRead(Y_MAX_PIN) == INVERT_ENDSTOPS);
min_endstop=(digitalRead(Y_MIN_PIN) == endStInv[1]);
max_endstop=(digitalRead(Y_MAX_PIN) == endStInv[1]);
}
if (axis_nr == 2) {
min_endstop=(digitalRead(Z_MIN_PIN) == INVERT_ENDSTOPS);
max_endstop=(digitalRead(Z_MAX_PIN) == INVERT_ENDSTOPS);
min_endstop=(digitalRead(Z_MIN_PIN) == endStInv[2]);
max_endstop=(digitalRead(Z_MAX_PIN) == endStInv[2]);
}
// if moving forward, only check the end stop max
@ -224,20 +228,25 @@ void enableMotors(bool enable) {
}
void setDirections(long* currentPoint, long* destinationPoint, bool* homeAxis) {
bool homeIsUp[3] = { ParameterList::getInstance()->getValue(MOVEMENT_HOME_UP_X),
ParameterList::getInstance()->getValue(MOVEMENT_HOME_UP_Y),
ParameterList::getInstance()->getValue(MOVEMENT_HOME_UP_Z) };
//if (currentPoint[0] < destinationPoint[0]) {
if ((!homeAxis[0] && currentPoint[0] < destinationPoint[0]) || (homeAxis[0] && AXIS_HOME_UP_X) ) {
if ((!homeAxis[0] && currentPoint[0] < destinationPoint[0]) || (homeAxis[0] && homeIsUp[0]) ) {
digitalWrite(X_DIR_PIN, HIGH);
} else {
digitalWrite(X_DIR_PIN, LOW);
}
//if (currentPoint[1] < destinationPoint[1]) {
if ((!homeAxis[1] && currentPoint[1] < destinationPoint[1]) || (homeAxis[1] && AXIS_HOME_UP_Y) ) {
if ((!homeAxis[1] && currentPoint[1] < destinationPoint[1]) || (homeAxis[1] && homeIsUp[1]) ) {
digitalWrite(Y_DIR_PIN, HIGH);
} else {
digitalWrite(Y_DIR_PIN, LOW);
}
//if (currentPoint[2] < destinationPoint[2]) {
if ((!homeAxis[2] && currentPoint[2] < destinationPoint[2]) || (homeAxis[2] && AXIS_HOME_UP_Z) ) {
if ((!homeAxis[2] && currentPoint[2] < destinationPoint[2]) || (homeAxis[2] && homeIsUp[2]) ) {
digitalWrite(Z_DIR_PIN, HIGH);
} else {
digitalWrite(Z_DIR_PIN, LOW);
@ -362,12 +371,17 @@ int StepperControl::moveAbsolute(long xDest, long yDest,
*/
int endStopsReached() {
bool x_min_endstop=(digitalRead(X_MIN_PIN) == INVERT_ENDSTOPS);
bool x_max_endstop=(digitalRead(X_MAX_PIN) == INVERT_ENDSTOPS);
bool y_min_endstop=(digitalRead(Y_MIN_PIN) == INVERT_ENDSTOPS);
bool y_max_endstop=(digitalRead(Y_MAX_PIN) == INVERT_ENDSTOPS);
bool z_min_endstop=(digitalRead(Z_MIN_PIN) == INVERT_ENDSTOPS);
bool z_max_endstop=(digitalRead(Z_MAX_PIN) == INVERT_ENDSTOPS);
bool endStInv[3] = { ParameterList::getInstance()->getValue(MOVEMENT_INVERT_ENDPOINTS_X),
ParameterList::getInstance()->getValue(MOVEMENT_INVERT_ENDPOINTS_Y),
ParameterList::getInstance()->getValue(MOVEMENT_INVERT_ENDPOINTS_Z) };
bool x_min_endstop=(digitalRead(X_MIN_PIN) == endStInv[0]);
bool x_max_endstop=(digitalRead(X_MAX_PIN) == endStInv[0]);
bool y_min_endstop=(digitalRead(Y_MIN_PIN) == endStInv[1]);
bool y_max_endstop=(digitalRead(Y_MAX_PIN) == endStInv[1]);
bool z_min_endstop=(digitalRead(Z_MIN_PIN) == endStInv[2]);
bool z_max_endstop=(digitalRead(Z_MAX_PIN) == endStInv[2]);
if(x_min_endstop || x_max_endstop || y_min_endstop || y_max_endstop || z_min_endstop || z_max_endstop) {
return 1;
}
@ -419,40 +433,40 @@ int StepperControl::moveAbsoluteConstant( long xDest, long yDest, long zDest,
1.0 * movementLength[2] / maxLenth };
//bool homeIsUp[3] = { AXIS_HOME_UP_X, AXIS_HOME_UP_Y, AXIS_HOME_UP_Z };
bool homeIsUp[3] = { ParameterList::getInstance()-getValue(MOVEMENT_HOME_UP_X),
ParameterList::getInstance()-getValue(MOVEMENT_HOME_UP_Y),
ParameterList::getInstance()-getValue(MOVEMENT_HOME_UP_Z) };
bool homeIsUp[3] = { ParameterList::getInstance()->getValue(MOVEMENT_HOME_UP_X),
ParameterList::getInstance()->getValue(MOVEMENT_HOME_UP_Y),
ParameterList::getInstance()->getValue(MOVEMENT_HOME_UP_Z) };
bool speedMax[3] = { ParameterList::getInstance()-getValue(MOVEMENT_MAX_SPD_X),
ParameterList::getInstance()-getValue(MOVEMENT_MAX_SPD_Y),
ParameterList::getInstance()-getValue(MOVEMENT_MAX_SPD_Z) };
bool speedMax[3] = { ParameterList::getInstance()->getValue(MOVEMENT_MAX_SPD_X),
ParameterList::getInstance()->getValue(MOVEMENT_MAX_SPD_Y),
ParameterList::getInstance()->getValue(MOVEMENT_MAX_SPD_Z) };
bool speedMin[3] = { ParameterList::getInstance()-getValue(MOVEMENT_MIN_SPD_X),
ParameterList::getInstance()-getValue(MOVEMENT_MIN_SPD_Y),
ParameterList::getInstance()-getValue(MOVEMENT_MIN_SPD_Z) };
bool speedMin[3] = { ParameterList::getInstance()->getValue(MOVEMENT_MIN_SPD_X),
ParameterList::getInstance()->getValue(MOVEMENT_MIN_SPD_Y),
ParameterList::getInstance()->getValue(MOVEMENT_MIN_SPD_Z) };
bool stepsAcc[3] = { ParameterList::getInstance()-getValue(MOVEMENT_STEPS_ACC_DEC_X),
ParameterList::getInstance()-getValue(MOVEMENT_STEPS_ACC_DEC_Y),
ParameterList::getInstance()-getValue(MOVEMENT_STEPS_ACC_DEC_Z) };
bool stepsAcc[3] = { ParameterList::getInstance()->getValue(MOVEMENT_STEPS_ACC_DEC_X),
ParameterList::getInstance()->getValue(MOVEMENT_STEPS_ACC_DEC_Y),
ParameterList::getInstance()->getValue(MOVEMENT_STEPS_ACC_DEC_Z) };
bool motorInv[3] = { ParameterList::getInstance()-getValue(MOVEMENT_INVERT_MOTOR_X),
ParameterList::getInstance()-getValue(MOVEMENT_INVERT_MOTOR_Y),
ParameterList::getInstance()-getValue(MOVEMENT_INVERT_MOTOR_Z) };
bool motorInv[3] = { ParameterList::getInstance()->getValue(MOVEMENT_INVERT_MOTOR_X),
ParameterList::getInstance()->getValue(MOVEMENT_INVERT_MOTOR_Y),
ParameterList::getInstance()->getValue(MOVEMENT_INVERT_MOTOR_Z) };
bool endStInv[3] = { ParameterList::getInstance()-getValue(MOVEMENT_INVERT_ENDPOINTS_X),
ParameterList::getInstance()-getValue(MOVEMENT_INVERT_ENDPOINTS_Y),
ParameterList::getInstance()-getValue(MOVEMENT_INVERT_ENDPOINTS_Z) };
bool endStInv[3] = { ParameterList::getInstance()->getValue(MOVEMENT_INVERT_ENDPOINTS_X),
ParameterList::getInstance()->getValue(MOVEMENT_INVERT_ENDPOINTS_Y),
ParameterList::getInstance()->getValue(MOVEMENT_INVERT_ENDPOINTS_Z) };
bool timeOut[3] = { ParameterList::getInstance()-getValue(MOVEMENT_TIMEOUT_X),
ParameterList::getInstance()-getValue(MOVEMENT_TIMEOUT_X),
ParameterList::getInstance()-getValue(MOVEMENT_TIMEOUT_X) };
bool timeOut[3] = { ParameterList::getInstance()->getValue(MOVEMENT_TIMEOUT_X),
ParameterList::getInstance()->getValue(MOVEMENT_TIMEOUT_X),
ParameterList::getInstance()->getValue(MOVEMENT_TIMEOUT_X) };
bool homeAxis[3] = { homeX, homeY, homeZ };
bool home = homeX || homeY || homeZ;
bool homeAxis[3] = { xHome, yHome, zHome };
bool home = xHome || yHome || zHome;
unsigned long currentMillis = 0;
unsigned long currentStepsPerSecond = maxStepsPerSecond;
//unsigned long currentStepsPerSecond = maxStepsPerSecond;
unsigned long currentSteps = 0;
unsigned long lastStepMillis[3] = { 0, 0, 0 };
@ -541,7 +555,7 @@ Serial.print("\n");
// axisSpeed = maxStepsPerSecond;
//if (i == 0) {
axisSpeed = calculateSpeed( sourcePoint[i],currentPoint[i],destinationPoint[i],
speedMax[i], speedMax[i], speedAcc[i]);
speedMax[i], speedMax[i], stepsAcc[i]);
//}
if (homeAxis[i]){
// When home is active, the direction is fixed

View File

@ -19,11 +19,11 @@
class StepperControl {
public:
static StepperControl* getInstance();
int moveAbsolute(long xDest, long yDest,
long zDest, unsigned int maxStepsPerSecond,
int moveAbsolute(long xDest, long yDest,long zDest,
unsigned int maxStepsPerSecond,
unsigned int maxAccelerationStepsPerSecond);
int moveAbsoluteConstant(long xDest, long yDest,
long zDest, unsigned int maxStepsPerSecond,
int moveAbsoluteConstant(long xDest, long yDest, long zDest,
unsigned int xMaxSpd, unsigned int yMaxSpd, unsigned int zMaxSpd,
bool homeX, bool homeY, bool homeZ);
private:
StepperControl();