G28 läuft für X Y Z

This commit is contained in:
jens 2021-05-26 21:42:43 +02:00
parent 14c405b2b8
commit fe85e1abe8

View File

@ -54,7 +54,7 @@
#define Z_CS_PIN 34 // Chip select #define Z_CS_PIN 34 // Chip select
#define Z_LIMIT 45 // Limit Switch #define Z_LIMIT 45 // Limit Switch
#else #else
#define Z_EN_PIN 31 // Enable #define Z_EN_PIN 62 // Enable
#define Z_STEP_PIN 46 // Step #define Z_STEP_PIN 46 // Step
#define Z_DIR_PIN 48 // Direction #define Z_DIR_PIN 48 // Direction
#define Z_CS_PIN 40 // Chip select #define Z_CS_PIN 40 // Chip select
@ -175,8 +175,8 @@ boolean homeP;
//Total step per revolution = full steps/rev * microsteps //Total step per revolution = full steps/rev * microsteps
//200 full steps * 16 microsteps = 3200 digital steps //200 full steps * 16 microsteps = 3200 digital steps
int x_steps_mm = 80; int x_steps_mm = 80;
int y_steps_mm = 400; int y_steps_mm = 80;
int z_steps_mm = 400; int z_steps_mm = 80;
int p_steps_mm = 157.5; int p_steps_mm = 157.5;
@ -193,6 +193,8 @@ int locP_in_steps;
#ifdef jfs #ifdef jfs
int locX_max = 27000; int locX_max = 27000;
int locY_max = -31200;
int locZ_max = 4000;
#endif #endif
// variables to hold LED data // variables to hold LED data
@ -389,7 +391,7 @@ void parseData() { // split the data into its parts
} }
if (strtokIndx[0] == 'Y'){ if (strtokIndx[0] == 'Y'){
memmove(strtokIndx, strtokIndx+1, strlen(strtokIndx)); memmove(strtokIndx, strtokIndx+1, strlen(strtokIndx));
locY_in_mm = atof(strtokIndx); locY_in_mm = -atof(strtokIndx);
} }
if (strtokIndx[0] == 'Z'){ if (strtokIndx[0] == 'Z'){
memmove(strtokIndx, strtokIndx+1, strlen(strtokIndx)); memmove(strtokIndx, strtokIndx+1, strlen(strtokIndx));
@ -426,9 +428,21 @@ void parseData() { // split the data into its parts
Serial.println(" X off limits "); Serial.println(" X off limits ");
locX_in_steps = locX_max; locX_in_steps = locX_max;
} }
#endif #endif
locY_in_steps = locY_in_mm * y_steps_mm; locY_in_steps = locY_in_mm * y_steps_mm;
#ifdef jfs
if (locY_in_steps < locY_max) {
Serial.println(" Y off limits ");
locY_in_steps = locY_max;
}
#endif
locZ_in_steps = locZ_in_mm * z_steps_mm; locZ_in_steps = locZ_in_mm * z_steps_mm;
#ifdef jfs
if (locZ_in_steps > locZ_max) {
Serial.println(" Z off limits ");
locZ_in_steps = locZ_max;
}
#endif
locP_in_steps = locP_in_mm * p_steps_mm; locP_in_steps = locP_in_mm * p_steps_mm;
} }
@ -576,14 +590,16 @@ void coordinateMove(){
Serial.println( stepperX.currentPosition()); Serial.println( stepperX.currentPosition());
Serial.print("Y Position "); Serial.print("Y Position ");
Serial.println( stepperY.currentPosition()); Serial.println( stepperY.currentPosition());
Serial.print("Y Position "); Serial.print("Z Position ");
Serial.println( stepperY.currentPosition()); Serial.println( stepperZ.currentPosition());
} }
else if (strcmp(mode, "J1") == 0){
//Serial.println(digitalRead(X_LIMIT)); //***** G28 - Homing Cycle *****
//Serial.println(digitalRead(Y_LIMIT)); // For this code to work as written the limit switches must be located at
//Serial.println(digitalRead(Z_LIMIT)); // X - Mininum
// Y - Minimun
// Z - Minimun
else if (strcmp(mode, "G28") == 0){
//Homing X at min //Homing X at min
stepperX.setMaxSpeed(5000); stepperX.setMaxSpeed(5000);
stepperX.setAcceleration(2000); stepperX.setAcceleration(2000);
@ -600,112 +616,49 @@ void coordinateMove(){
} }
} }
} }
stepperX.setMaxSpeed(100.0); stepperX.setMaxSpeed(10000);
initial_homing=0; stepperX.setAcceleration(5000);
while (digitalRead(X_LIMIT) == 1) { stepperX.setCurrentPosition(0);
initial_homing--; //Homing Y at min
stepperX.moveTo(initial_homing); stepperY.setMaxSpeed(5000);
stepperX.run(); stepperY.setAcceleration(2000);
} initial_homing = stepperY.currentPosition();
stepperX.setCurrentPosition(0); homeY = false;
Serial.println("X at Home"); while (homeY == false){
}
//***** G28 - Homing Cycle *****
// For this code to work as written the limit switches must be located at
// X - Maximum
// Y - Maximum
// Z - Maximum
else if (strcmp(mode, "G28") == 0){
stepperX.setMaxSpeed(3000);
stepperX.setAcceleration(1000);
stepperY.setMaxSpeed(5000);
stepperY.setAcceleration(5000);
stepperZ.setMaxSpeed(2000);
stepperZ.setAcceleration(1000);
// Z-Axis Homing
int initial_homing = stepperZ.currentPosition();
homeZ = false;
while (homeZ == false){
initial_homing++;
stepperZ.moveTo(initial_homing);
stepperZ.run();
if (digitalRead(Z_LIMIT) != 0) {
delay(1);
if (digitalRead(Z_LIMIT) !=0){
homeZ = true;
}
}
}
stepperZ.setMaxSpeed(100.0);
initial_homing=0;
while (digitalRead(Z_LIMIT) == 1) {
initial_homing--;
stepperZ.move(initial_homing);
stepperZ.runSpeed();
}
stepperZ.setCurrentPosition(0);
// X-Axis Homing
initial_homing = stepperX.currentPosition();
homeX = false;
while (homeX == false){
initial_homing--;
stepperX.moveTo(initial_homing);
stepperX.run();
if (digitalRead(X_LIMIT) != 0) {
delay(1);
if (digitalRead(X_LIMIT) !=0){
homeX = true;
}
}
}
stepperX.setMaxSpeed(100.0);
initial_homing=0;
while (digitalRead(X_LIMIT) == 1) {
initial_homing++;
stepperX.moveTo(initial_homing);
stepperX.run();
}
stepperX.setCurrentPosition(0);
// Y-Axis Homing
initial_homing=stepperY.currentPosition();
homeY = false;
while (homeY == false){
initial_homing++; initial_homing++;
stepperY.moveTo(initial_homing); stepperY.moveTo(initial_homing);
stepperY.run(); stepperY.run();
if (digitalRead(Y_LIMIT) != 0) { if (digitalRead(Y_LIMIT) != 1) {
delay(1); delay(1);
if (digitalRead(Y_LIMIT) !=0){ if (digitalRead(Y_LIMIT) !=1){
homeY = true; homeY = true;
} }
}
}
stepperY.setMaxSpeed(10000);
stepperY.setAcceleration(5000);
stepperY.setCurrentPosition(0);
//Homing Z at min
stepperZ.setMaxSpeed(5000);
stepperZ.setAcceleration(2000);
initial_homing = stepperZ.currentPosition();
homeZ = false;
while (homeZ == false){
initial_homing--;
stepperZ.moveTo(initial_homing);
stepperZ.run();
if (digitalRead(Z_LIMIT) != 1) {
delay(1);
if (digitalRead(Z_LIMIT) !=1){
homeZ = true;
}
} }
} }
stepperY.setMaxSpeed(100.0);
initial_homing=0;
while (digitalRead(Y_LIMIT) == 1) {
initial_homing--;
stepperY.moveTo(initial_homing);
stepperY.run();
}
stepperY.setCurrentPosition(0);
stepperY.setMaxSpeed(1000.0);
stepperX.setCurrentPosition(26400);
stepperY.setCurrentPosition(144000);
stepperZ.setCurrentPosition(0);
stepperP.setCurrentPosition(0);
stepperX.setMaxSpeed(10000);
stepperX.setAcceleration(5000);
stepperY.setMaxSpeed(10000);
stepperY.setAcceleration(1500);
stepperZ.setMaxSpeed(10000); stepperZ.setMaxSpeed(10000);
stepperZ.setAcceleration(5000); stepperZ.setAcceleration(5000);
stepperZ.setCurrentPosition(0);
stepperP.setCurrentPosition(0);
Serial.println("<OK Homed>"); Serial.println("<OK Homed>");
} }