reverse direction homing
parent
012116f225
commit
dc93740186
|
@ -15,4 +15,9 @@ const unsigned int MAX_ACCELERATION_STEPS_PER_SECOND = 2;
|
|||
const unsigned int HOME_MOVEMENT_SPEED_S_P_S = 200;
|
||||
const unsigned int INVERT_ENDSTOPS = 1;
|
||||
|
||||
const bool AXIS_HOME_FORWARD_X = false;
|
||||
const bool AXIS_HOME_FORWARD_Y = false;
|
||||
const bool AXIS_HOME_FORWARD_Z = true;
|
||||
|
||||
|
||||
#endif /* CONFIG_H_ */
|
||||
|
|
|
@ -13,8 +13,8 @@ StepperControl * StepperControl::getInstance() {
|
|||
StepperControl::StepperControl() {
|
||||
}
|
||||
|
||||
unsigned int getMaxLength(unsigned int lengths[3]) {
|
||||
unsigned int max = lengths[0];
|
||||
unsigned long getMaxLength(unsigned long lengths[3]) {
|
||||
unsigned long max = lengths[0];
|
||||
for (int i = 1; i < 3; i++) {
|
||||
if (lengths[i] > max) {
|
||||
max = lengths[i];
|
||||
|
@ -23,8 +23,8 @@ unsigned int getMaxLength(unsigned int lengths[3]) {
|
|||
return max;
|
||||
}
|
||||
|
||||
void step(int axis, unsigned int ¤tPoint, unsigned int steps,
|
||||
unsigned int destinationPoint) {
|
||||
void step(int axis, long ¤tPoint, unsigned int steps,
|
||||
long destinationPoint) {
|
||||
if (currentPoint < destinationPoint) {
|
||||
currentPoint += steps;
|
||||
} else if (currentPoint > destinationPoint) {
|
||||
|
@ -46,8 +46,8 @@ void step(int axis, unsigned int ¤tPoint, unsigned int steps,
|
|||
}
|
||||
}
|
||||
|
||||
bool pointReached(unsigned int currentPoint[3],
|
||||
unsigned int destinationPoint[3]) {
|
||||
bool pointReached(long currentPoint[3],
|
||||
long destinationPoint[3]) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (destinationPoint[i] != currentPoint[i]) {
|
||||
return false;
|
||||
|
@ -101,7 +101,7 @@ void enableMotors(bool enable) {
|
|||
}
|
||||
}
|
||||
|
||||
void setDirections(unsigned int* currentPoint, unsigned int* destinationPoint) {
|
||||
void setDirections(long* currentPoint, long* destinationPoint) {
|
||||
if (currentPoint[0] < destinationPoint[0]) {
|
||||
digitalWrite(X_DIR_PIN, HIGH);
|
||||
} else {
|
||||
|
@ -119,7 +119,7 @@ void setDirections(unsigned int* currentPoint, unsigned int* destinationPoint) {
|
|||
}
|
||||
}
|
||||
|
||||
unsigned int getLength(unsigned int l1,unsigned int l2) {
|
||||
unsigned long getLength(long l1, long l2) {
|
||||
if(l1 > l2) {
|
||||
return l1 - l2;
|
||||
} else {
|
||||
|
@ -134,13 +134,13 @@ unsigned int getLength(unsigned int l1,unsigned int l2) {
|
|||
* maxStepsPerSecond - maximum number of steps per second
|
||||
* maxAccelerationStepsPerSecond - maximum number of acceleration in steps per second
|
||||
*/
|
||||
int StepperControl::moveAbsolute(unsigned int xDest, unsigned int yDest,
|
||||
unsigned int zDest, unsigned int maxStepsPerSecond,
|
||||
int StepperControl::moveAbsolute(long xDest, long yDest,
|
||||
long zDest, unsigned int maxStepsPerSecond,
|
||||
unsigned int maxAccelerationStepsPerSecond) {
|
||||
unsigned int currentPoint[3] = { CurrentState::getInstance()->getX(),
|
||||
long currentPoint[3] = { CurrentState::getInstance()->getX(),
|
||||
CurrentState::getInstance()->getY(),
|
||||
CurrentState::getInstance()->getZ() };
|
||||
unsigned int destinationPoint[3] = { xDest, yDest, zDest };
|
||||
long destinationPoint[3] = { xDest, yDest, zDest };
|
||||
|
||||
Serial.print("Destination point:");
|
||||
Serial.print(destinationPoint[0]);
|
||||
|
@ -156,10 +156,10 @@ int StepperControl::moveAbsolute(unsigned int xDest, unsigned int yDest,
|
|||
Serial.println(currentPoint[2]);
|
||||
|
||||
|
||||
unsigned int movementLength[3] = { getLength(destinationPoint[0], currentPoint[0]),
|
||||
unsigned long movementLength[3] = { getLength(destinationPoint[0], currentPoint[0]),
|
||||
getLength(destinationPoint[1], currentPoint[1]),
|
||||
getLength(destinationPoint[2], currentPoint[2])};
|
||||
unsigned int maxLenth = getMaxLength(movementLength);
|
||||
unsigned long maxLenth = getMaxLength(movementLength);
|
||||
double lengthRatio[3] = { 1.0 * movementLength[0] / maxLenth, 1.0
|
||||
* movementLength[1] / maxLenth, 1.0 * movementLength[2] / maxLenth };
|
||||
Serial.print("Max length:");
|
||||
|
@ -323,25 +323,26 @@ int reportEndStops() {
|
|||
* maxStepsPerSecond - maximum number of steps per second
|
||||
* maxAccelerationStepsPerSecond - maximum number of acceleration in steps per second
|
||||
*/
|
||||
int StepperControl::moveAbsoluteConstant(unsigned int xDest, unsigned int yDest,
|
||||
unsigned int zDest, unsigned int maxStepsPerSecond, bool home) {
|
||||
int StepperControl::moveAbsoluteConstant(long xDest, long yDest,
|
||||
long zDest, unsigned int maxStepsPerSecond, bool home) {
|
||||
|
||||
unsigned int currentPoint[3] = { CurrentState::getInstance()->getX(),
|
||||
long currentPoint[3] = { CurrentState::getInstance()->getX(),
|
||||
CurrentState::getInstance()->getY(),
|
||||
CurrentState::getInstance()->getZ() };
|
||||
unsigned int destinationPoint[3] = { xDest, yDest, zDest };
|
||||
long destinationPoint[3] = { xDest, yDest, zDest };
|
||||
|
||||
unsigned int movementLength[3] = { getLength(destinationPoint[0], currentPoint[0]),
|
||||
unsigned long movementLength[3] = { getLength(destinationPoint[0], currentPoint[0]),
|
||||
getLength(destinationPoint[1], currentPoint[1]),
|
||||
getLength(destinationPoint[2], currentPoint[2])};
|
||||
unsigned int maxLenth = getMaxLength(movementLength);
|
||||
unsigned long maxLenth = getMaxLength(movementLength);
|
||||
double lengthRatio[3] = { 1.0 * movementLength[0] / maxLenth, 1.0
|
||||
* movementLength[1] / maxLenth, 1.0 * movementLength[2] / maxLenth };
|
||||
bool homeMoveReverse[3] = { AXIS_HOME_FORWARD_X, AXIS_HOME_FORWARD_Y, AXIS_HOME_FORWARD_Z };
|
||||
|
||||
unsigned int currentMillis = 0;
|
||||
unsigned int currentStepsPerSecond = maxStepsPerSecond;
|
||||
unsigned int currentSteps = 0;
|
||||
unsigned int lastStepMillis[3] = { 0, 0, 0 };
|
||||
unsigned long currentMillis = 0;
|
||||
unsigned long currentStepsPerSecond = maxStepsPerSecond;
|
||||
unsigned long currentSteps = 0;
|
||||
unsigned long lastStepMillis[3] = { 0, 0, 0 };
|
||||
|
||||
|
||||
/*
|
||||
|
@ -376,7 +377,7 @@ int StepperControl::moveAbsoluteConstant(unsigned int xDest, unsigned int yDest,
|
|||
forwardMovement = (currentPoint[i] < destinationPoint[i]);
|
||||
if (home){
|
||||
// When home is active, keep moving until end point reached
|
||||
forwardMovement = false;
|
||||
forwardMovement = homeMoveReverse[i];
|
||||
}
|
||||
if (!endStopAxisReached(i, forwardMovement))
|
||||
{
|
||||
|
@ -389,7 +390,11 @@ int StepperControl::moveAbsoluteConstant(unsigned int xDest, unsigned int yDest,
|
|||
currentMillis - lastStepMillis[i] >
|
||||
1000 / HOME_MOVEMENT_SPEED_S_P_S
|
||||
) {
|
||||
unsigned int curVal = 1;
|
||||
long curVal = 1;
|
||||
if (homeMoveReverse[i] == true)
|
||||
{
|
||||
curVal = -1;
|
||||
}
|
||||
step(i, curVal, 1, 0);
|
||||
stepMade = true;
|
||||
lastStepMillis[i] = currentMillis;
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
class StepperControl {
|
||||
public:
|
||||
static StepperControl* getInstance();
|
||||
int moveAbsolute(unsigned int xDest, unsigned int yDest,
|
||||
unsigned int zDest, unsigned int maxStepsPerSecond,
|
||||
int moveAbsolute(long xDest, long yDest,
|
||||
long zDest, unsigned int maxStepsPerSecond,
|
||||
unsigned int maxAccelerationStepsPerSecond);
|
||||
int moveAbsoluteConstant(unsigned int xDest, unsigned int yDest,
|
||||
unsigned int zDest, unsigned int maxStepsPerSecond, bool home);
|
||||
int moveAbsoluteConstant(long xDest, long yDest,
|
||||
long zDest, unsigned int maxStepsPerSecond, bool home);
|
||||
private:
|
||||
StepperControl();
|
||||
StepperControl(StepperControl const&);
|
||||
|
|
Loading…
Reference in New Issue