adding calibration commands
parent
662a27f7e7
commit
1a23d9e570
|
@ -64,6 +64,13 @@ CommandCodeEnum Command::getGCodeEnum(char* code) {
|
|||
return F22;
|
||||
}
|
||||
|
||||
if (strcmp(code, "F31") == 0) {
|
||||
return F31;
|
||||
}
|
||||
if (strcmp(code, "F32") == 0) {
|
||||
return F32;
|
||||
}
|
||||
|
||||
if (strcmp(code, "F81") == 0) {
|
||||
return F81;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ enum CommandCodeEnum
|
|||
F20 = 120,
|
||||
F21 = 121,
|
||||
F22 = 122,
|
||||
F31 = 131,
|
||||
F32 = 132,
|
||||
F81 = 181,
|
||||
F82 = 182,
|
||||
F83 = 183
|
||||
|
|
|
@ -56,7 +56,9 @@ const long MOVEMENT_MAX_SPD_X_DEFAULT = 1000;
|
|||
const long MOVEMENT_MAX_SPD_Y_DEFAULT = 1000;
|
||||
const long MOVEMENT_MAX_SPD_Z_DEFAULT = 1000;
|
||||
|
||||
const long STATUS_GENERAL_DEFAULT = 0;
|
||||
|
||||
const String SOFTWARE_VERSION = "GENESIS V.01.02";
|
||||
|
||||
const String SOFTWARE_VERSION = "GENESIS V.01.03";
|
||||
|
||||
#endif /* CONFIG_H_ */
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
/*
|
||||
* F31Handler.cpp
|
||||
*
|
||||
* Created on: 15 maj 2014
|
||||
* Author: MattLech
|
||||
*/
|
||||
|
||||
#include "F31Handler.h"
|
||||
|
||||
|
||||
static F31Handler* instance;
|
||||
|
||||
F31Handler * F31Handler::getInstance() {
|
||||
if (!instance) {
|
||||
instance = new F31Handler();
|
||||
};
|
||||
return instance;
|
||||
}
|
||||
;
|
||||
|
||||
F31Handler::F31Handler() {
|
||||
}
|
||||
|
||||
int F31Handler::execute(Command* command) {
|
||||
|
||||
StatusList::getInstance()->readValue(command->getP());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
/*
|
||||
* F31Handler.h
|
||||
*
|
||||
* Created on: 15 maj 2014
|
||||
* Author: MattLech
|
||||
*/
|
||||
|
||||
#ifndef F31HANDLER_H_
|
||||
#define F31HANDLER_H_
|
||||
#include "GCodeHandler.h"
|
||||
#include "Config.h"
|
||||
#include "CurrentState.h"
|
||||
#include "pins.h"
|
||||
#include "Config.h"
|
||||
#include "StepperControl.h"
|
||||
#include "StatusList.h"
|
||||
|
||||
class F31Handler : public GCodeHandler {
|
||||
public:
|
||||
static F31Handler* getInstance();
|
||||
int execute(Command*);
|
||||
private:
|
||||
F31Handler();
|
||||
F31Handler(F31Handler const&);
|
||||
void operator=(F31Handler const&);
|
||||
//long adjustStepAmount(long);
|
||||
//long getNumberOfSteps(double, double);
|
||||
};
|
||||
|
||||
#endif /* F31HANDLER_H_ */
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
/*
|
||||
* F32Handler.cpp
|
||||
*
|
||||
* Created on: 15 maj 2014
|
||||
* Author: MattLech
|
||||
*/
|
||||
|
||||
#include "F32Handler.h"
|
||||
|
||||
|
||||
static F32Handler* instance;
|
||||
|
||||
F32Handler * F32Handler::getInstance() {
|
||||
if (!instance) {
|
||||
instance = new F32Handler();
|
||||
};
|
||||
return instance;
|
||||
}
|
||||
;
|
||||
|
||||
F32Handler::F32Handler() {
|
||||
}
|
||||
|
||||
int F32Handler::execute(Command* command) {
|
||||
|
||||
StatusList::getInstance()->readValue(command->getP());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
/*
|
||||
* F32Handler.h
|
||||
*
|
||||
* Created on: 15 maj 2014
|
||||
* Author: MattLech
|
||||
*/
|
||||
|
||||
#ifndef F32HANDLER_H_
|
||||
#define F32HANDLER_H_
|
||||
#include "GCodeHandler.h"
|
||||
#include "Config.h"
|
||||
#include "CurrentState.h"
|
||||
#include "pins.h"
|
||||
#include "Config.h"
|
||||
#include "StepperControl.h"
|
||||
#include "StatusList.h"
|
||||
|
||||
class F32Handler : public GCodeHandler {
|
||||
public:
|
||||
static F32Handler* getInstance();
|
||||
int execute(Command*);
|
||||
private:
|
||||
F32Handler();
|
||||
F32Handler(F32Handler const&);
|
||||
void operator=(F32Handler const&);
|
||||
long adjustStepAmount(long);
|
||||
long getNumberOfSteps(double, double);
|
||||
};
|
||||
|
||||
#endif /* F32HANDLER_H_ */
|
||||
|
||||
|
||||
|
|
@ -57,13 +57,16 @@ GCodeHandler* GCodeProcessor::getGCodeHandler(CommandCodeEnum codeEnum) {
|
|||
case F13:
|
||||
return F13Handler::getInstance();
|
||||
|
||||
// case F20:
|
||||
// return F20Handler::getInstance();
|
||||
case F21:
|
||||
return F21Handler::getInstance();
|
||||
case F22:
|
||||
return F22Handler::getInstance();
|
||||
|
||||
case F31:
|
||||
return F31Handler::getInstance();
|
||||
case F32:
|
||||
return F32Handler::getInstance();
|
||||
|
||||
|
||||
case F81:
|
||||
return F81Handler::getInstance();
|
||||
|
|
|
@ -19,10 +19,12 @@
|
|||
#include "F12Handler.h"
|
||||
#include "F13Handler.h"
|
||||
|
||||
//#include "F20Handler.h"
|
||||
#include "F21Handler.h"
|
||||
#include "F22Handler.h"
|
||||
|
||||
#include "F31Handler.h"
|
||||
#include "F32Handler.h"
|
||||
|
||||
#include "F81Handler.h"
|
||||
#include "F82Handler.h"
|
||||
#include "F83Handler.h"
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
#include "StatusList.h"
|
||||
|
||||
static StatusList* instanceParam;
|
||||
long statusValues[150];
|
||||
|
||||
StatusList * StatusList::getInstance() {
|
||||
if (!instanceParam) {
|
||||
instanceParam = new StatusList();
|
||||
};
|
||||
return instanceParam;
|
||||
}
|
||||
|
||||
StatusList::StatusList() {
|
||||
|
||||
|
||||
statusValues[STATUS_GENERAL] = STATUS_GENERAL_DEFAULT;
|
||||
|
||||
//paramValues[MOVEMENT_MAX_SPD_X] = MOVEMENT_MAX_SPD_X_DEFAULT;
|
||||
//paramValues[MOVEMENT_MAX_SPD_Y] = MOVEMENT_MAX_SPD_Y_DEFAULT;
|
||||
//paramValues[MOVEMENT_MAX_SPD_Z] = MOVEMENT_MAX_SPD_Z_DEFAULT;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int StatusList::readValue(int id) {
|
||||
|
||||
long value = statusValues[id];
|
||||
|
||||
|
||||
Serial.print("R31");
|
||||
Serial.print(" ");
|
||||
Serial.print("P");
|
||||
Serial.print(id);
|
||||
Serial.print(" ");
|
||||
Serial.print("V");
|
||||
Serial.print(value);
|
||||
Serial.print("\n");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
long StatusList::getValue(int id) {
|
||||
|
||||
/*
|
||||
Serial.print("R99");
|
||||
Serial.print(" ");
|
||||
Serial.print("getValue");
|
||||
Serial.print(" id ");
|
||||
Serial.print(id);
|
||||
Serial.print(" value");
|
||||
Serial.print(paramValues[id]);
|
||||
Serial.print("\n");
|
||||
*/
|
||||
|
||||
return statusValues[id];
|
||||
}
|
||||
|
||||
int StatusList::setValue(int id, long value) {
|
||||
|
||||
statusValues[id] = value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#ifndef STATUSLIST_H_
|
||||
#define STATUSLIST_H_
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Config.h"
|
||||
|
||||
|
||||
//#define NULL 0
|
||||
|
||||
|
||||
enum StatusListEnum
|
||||
{
|
||||
STATUS_GENERAL = 0,
|
||||
|
||||
//MOVEMENT_MAX_SPD_X = 71,
|
||||
//MOVEMENT_MAX_SPD_Y = 72,
|
||||
//MOVEMENT_MAX_SPD_Z = 73
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
#define NULL 0
|
||||
*/
|
||||
|
||||
class StatusList {
|
||||
StatusListEnum statusListEnum;
|
||||
public:
|
||||
static StatusList* getInstance();
|
||||
int writeValue(int id, long value);
|
||||
int readValue(int id);
|
||||
long getValue(int id);
|
||||
int setValue(int id, long value);
|
||||
private:
|
||||
StatusList();
|
||||
StatusList(StatusList const&);
|
||||
void operator=(StatusList const&);
|
||||
};
|
||||
|
||||
|
||||
#endif /* STATUSLIST_H_ */
|
|
@ -235,30 +235,47 @@ void enableMotors(bool enable) {
|
|||
}
|
||||
}
|
||||
|
||||
void setDirections(long* currentPoint, long* destinationPoint, bool* homeAxis) {
|
||||
void setDirectionAxis(int* dirPin, long* currentPoint, long* destinationPoint, bool* goHome, bool* homeIsUp, bool* motorInv) {
|
||||
|
||||
if (((!goHome && currentPoint < destinationPoint) || (goHome && homeIsUp)) ^ motorInv) {
|
||||
digitalWrite(dirPin, HIGH);
|
||||
} else {
|
||||
digitalWrite(dirPin, LOW);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void setDirections(long* currentPoint, long* destinationPoint, bool* homeAxis, bool* motorInv) {
|
||||
|
||||
bool homeIsUp[3] = { ParameterList::getInstance()->getValue(MOVEMENT_HOME_UP_X),
|
||||
ParameterList::getInstance()->getValue(MOVEMENT_HOME_UP_Y),
|
||||
ParameterList::getInstance()->getValue(MOVEMENT_HOME_UP_Z) };
|
||||
|
||||
setDirectionAxis(X_DIR_PIN, currentPoint[0], destinationPoint[0], homeAxis[0], homeIsUp[0], motorInv[0]);
|
||||
setDirectionAxis(Y_DIR_PIN, currentPoint[1], destinationPoint[1], homeAxis[1], homeIsUp[1], motorInv[1]);
|
||||
setDirectionAxis(Z_DIR_PIN, currentPoint[2], destinationPoint[2], homeAxis[2], homeIsUp[2], motorInv[2]);
|
||||
|
||||
/*
|
||||
//if (currentPoint[0] < destinationPoint[0]) {
|
||||
if ((!homeAxis[0] && currentPoint[0] < destinationPoint[0]) || (homeAxis[0] && homeIsUp[0]) ) {
|
||||
if (((!homeAxis[0] && currentPoint[0] < destinationPoint[0]) || (homeAxis[0] && homeIsUp[0])) ^ motorInv[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] && homeIsUp[1]) ) {
|
||||
if (((!homeAxis[1] && currentPoint[1] < destinationPoint[1]) || (homeAxis[1] && homeIsUp[1])) ^ motorInv[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] && homeIsUp[2]) ) {
|
||||
if (((!homeAxis[2] && currentPoint[2] < destinationPoint[2]) || (homeAxis[2] && homeIsUp[2])) ^ motorInv[2]) {
|
||||
digitalWrite(Z_DIR_PIN, HIGH);
|
||||
} else {
|
||||
digitalWrite(Z_DIR_PIN, LOW);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
unsigned long getLength(long l1, long l2) {
|
||||
|
@ -301,6 +318,17 @@ void storeEndStops() {
|
|||
CurrentState::getInstance()->storeEndStops();
|
||||
}
|
||||
|
||||
/**
|
||||
* water is dosed by setting the pin for the water high for a number of miliseconds
|
||||
*
|
||||
*/
|
||||
|
||||
void doseWaterByTime(long time) {
|
||||
digitalWrite(HEATER_1_PIN, HIGH);
|
||||
delay(time);
|
||||
digitalWrite(HEATER_1_PIN, LOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* xDest - destination X in steps
|
||||
* yDest - destination Y in steps
|
||||
|
@ -398,7 +426,7 @@ int StepperControl::moveAbsoluteConstant( long xDest, long yDest, long zDest,
|
|||
reportEndStops();
|
||||
enableMotors(true);
|
||||
|
||||
setDirections(currentPoint, destinationPoint, homeAxis);
|
||||
setDirections(currentPoint, destinationPoint, homeAxis, motorInv);
|
||||
|
||||
|
||||
// Limit normal movmement to the home position
|
||||
|
@ -449,7 +477,7 @@ int StepperControl::moveAbsoluteConstant( long xDest, long yDest, long zDest,
|
|||
error = 1;
|
||||
} else {
|
||||
|
||||
|
||||
if ()
|
||||
// If end stop reached, don't move anymore
|
||||
if ((homeAxis[i] && !endStopAxisReached(i, false)) || (!homeAxis[i] && !endStopAxisReached(i, !movementToHome) && currentPoint[i] != destinationPoint[i] )) {
|
||||
moving = true;
|
||||
|
@ -515,3 +543,146 @@ int StepperControl::moveAbsoluteConstant( long xDest, long yDest, long zDest,
|
|||
|
||||
return error;
|
||||
}
|
||||
|
||||
//
|
||||
// Calibration
|
||||
//
|
||||
|
||||
/*
|
||||
int StepperControl::calibrateAxis(int axis) {
|
||||
|
||||
|
||||
long speedMinLst[3] = { ParameterList::getInstance()->getValue(MOVEMENT_MIN_SPD_X),
|
||||
ParameterList::getInstance()->getValue(MOVEMENT_MIN_SPD_Y),
|
||||
ParameterList::getInstance()->getValue(MOVEMENT_MIN_SPD_Z) };
|
||||
|
||||
long speedMin = speedMinLst[axis];
|
||||
|
||||
long stepPin[3] = { X_STEP_PIN,
|
||||
Y_STEP_PIN,
|
||||
Z_STEP_PIN };
|
||||
|
||||
long dirPin[3] = { X_DIR_PIN,
|
||||
Y_DIR_PIN,
|
||||
Z_DIR_PIN };
|
||||
|
||||
// Set the coordinate variables for homing, so the default functions can be used for settign direction
|
||||
|
||||
long sourcePoint[3] = {
|
||||
long destinationPoint[3] = { xDest, yDest, zDest };
|
||||
|
||||
|
||||
|
||||
// long timeOut[3] = { ParameterList::getInstance()->getValue(MOVEMENT_TIMEOUT_X),
|
||||
// ParameterList::getInstance()->getValue(MOVEMENT_TIMEOUT_X),
|
||||
// ParameterList::getInstance()->getValue(MOVEMENT_TIMEOUT_X) };
|
||||
|
||||
unsigned long currentMillis = 0;
|
||||
|
||||
unsigned long currentSteps = 0;
|
||||
unsigned long lastStepMillis = 0;
|
||||
|
||||
unsigned long timeStart = millis();
|
||||
|
||||
bool movementDone = false;
|
||||
//bool movementUp = false;
|
||||
//bool movementToHome = false;
|
||||
//bool moving = false;
|
||||
//bool stepMade = false;
|
||||
//int axisSpeed = 0;
|
||||
|
||||
int error = 0;
|
||||
|
||||
|
||||
// Prepare for movement
|
||||
|
||||
storeEndStops();
|
||||
reportEndStops();
|
||||
enableMotors(true);
|
||||
|
||||
// Move towards home
|
||||
|
||||
movementDone = false;
|
||||
setDirectionAxis(dirPin[0], 0, -1, homeAxis[0], homeIsUp[0], motorInv[0]);
|
||||
|
||||
while (!movementDone) {
|
||||
|
||||
// Move until the end stop for home position is reached
|
||||
if (!endStopAxisReached(axis,false)) {
|
||||
|
||||
if (millis() - timeStart > timeOut[i] * MOVEMENT_SPEED_BASE_TIME) {
|
||||
movementDone = true;
|
||||
error = 1;
|
||||
} else {
|
||||
|
||||
// If end stop reached, don't move anymore
|
||||
if ((homeAxis[i] && !endStopAxisReached(i, false)) || (!homeAxis[i] && !endStopAxisReached(i, !movementToHome) && currentPoint[i] != destinationPoint[i] )) {
|
||||
|
||||
moving = true;
|
||||
|
||||
// Only do a step every x milliseconds (x is calculated above)
|
||||
if (currentMillis - lastStepMillis[i] >= MOVEMENT_SPEED_BASE_TIME / speedMin) {
|
||||
digitalWrite(X_STEP_PIN, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
// If end stop for home is active, set the position to zero
|
||||
if (endStopAxisReached(i, false))
|
||||
{
|
||||
currentPoint[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
delayMicroseconds(MOVEMENT_DELAY/2);
|
||||
currentMillis++;
|
||||
digitalWrite(X_STEP_PIN, LOW);
|
||||
delayMicroseconds(MOVEMENT_DELAY/2);
|
||||
|
||||
} else {
|
||||
movementDone = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Move into the other direction now, and measure the number of steps
|
||||
|
||||
digitalWrite(X_STEP_PIN, LOW);
|
||||
|
||||
|
||||
|
||||
// Start movement
|
||||
|
||||
|
||||
|
||||
stepMade = false;
|
||||
moving = false;
|
||||
|
||||
} else {
|
||||
movementDone = true;
|
||||
}
|
||||
|
||||
if (stepMade) {
|
||||
currentSteps++;
|
||||
}
|
||||
digitalWrite(Y_STEP_PIN, LOW);
|
||||
digitalWrite(Z_STEP_PIN, LOW);
|
||||
if (!moving)
|
||||
{
|
||||
movementDone = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enableMotors(false);
|
||||
|
||||
CurrentState::getInstance()->setX(currentPoint[0]);
|
||||
CurrentState::getInstance()->setY(currentPoint[1]);
|
||||
CurrentState::getInstance()->setZ(currentPoint[2]);
|
||||
|
||||
storeEndStops();
|
||||
reportEndStops();
|
||||
reportPosition();
|
||||
|
||||
return error;
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue