|
|
|
@@ -50,10 +50,8 @@ static const int RotEnc_Clk_Pin = 32; |
|
|
|
static const int RotEnc_Dta_Pin = 33; |
|
|
|
|
|
|
|
static const int MOVE_DOWNWARD = -1; // motor rotation counter clock wise |
|
|
|
//static const int MOVE_UPWARD = 1; // motor rotation clock wise |
|
|
|
//static const int MOVE_UPWARD = 1; // motor rotation clock wise |
|
|
|
|
|
|
|
//byte limitSwitchState = 1; |
|
|
|
//int previousDirection = 0; |
|
|
|
int nullingTLS_intermediateState = 0; |
|
|
|
|
|
|
|
ExEzButton RedButton(RedBtn_Pin, false, 2000); |
|
|
|
@@ -84,7 +82,6 @@ void printStatus(String actualStatus) { |
|
|
|
//*** Limit switch interrupt routine |
|
|
|
//********************************** |
|
|
|
void limitSwitchHandler() { |
|
|
|
// limitSwitchState = digitalRead(LIMIT_SWITCH); |
|
|
|
Router_Elevator.limitSwitchHandler(); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -192,8 +189,6 @@ void loop() { |
|
|
|
case NULLING: |
|
|
|
printStatus("NULLING"); |
|
|
|
if (RedButton.isPressed()) { |
|
|
|
// Stepper.setCurrentPositionInMillimeters(0); |
|
|
|
// Stepper.setTargetPositionRelativeInMillimeters(0); |
|
|
|
Router_Elevator.setZeroPosition(); |
|
|
|
actualStatus = IDLE; |
|
|
|
} |
|
|
|
@@ -204,7 +199,6 @@ void loop() { |
|
|
|
if (nullingTLS_intermediateState == 0) { |
|
|
|
printStatus("NULLING_TLS,0"); |
|
|
|
//Move elevator to lowest point (lower limit switch triggers) |
|
|
|
// Stepper.setTargetPositionRelativeInMillimeters(300 * MOVE_DOWNWARD); |
|
|
|
Router_Elevator.moveToLowerLimitSwitch(); |
|
|
|
actualStatus = MOVING_ELEVATOR; |
|
|
|
nullingTLS_intermediateState = 1; |
|
|
|
@@ -212,7 +206,6 @@ void loop() { |
|
|
|
printStatus("NULLING_TLS,1"); |
|
|
|
if (RedButton.isPressed()) { |
|
|
|
//Move elevator until it touch the TLS (WLS_PIN goes HIGH) |
|
|
|
// Stepper.setTargetPositionRelativeInMillimeters(300 * MOVE_UPWARD); |
|
|
|
Router_Elevator.moveToUpperLimitSwitch(); |
|
|
|
actualStatus = MOVING_ELEVATOR; |
|
|
|
nullingTLS_intermediateState = 2; |
|
|
|
@@ -228,8 +221,6 @@ void loop() { |
|
|
|
} else { // nullingTLS_intermediateState is 3 |
|
|
|
printStatus("NULLING_TLS,3"); |
|
|
|
//Set the 0-Position as actual position |
|
|
|
// Stepper.setCurrentPositionInMillimeters(0); |
|
|
|
// Stepper.setTargetPositionRelativeInMillimeters(0); |
|
|
|
Router_Elevator.setZeroPosition(); |
|
|
|
actualStatus = IDLE; |
|
|
|
nullingTLS_intermediateState = 0; |
|
|
|
@@ -254,32 +245,17 @@ void loop() { |
|
|
|
|
|
|
|
case MOVING_ELEVATOR: |
|
|
|
printStatus("MOVING_ELEVATOR"); |
|
|
|
// if (limitSwitchState == LOW) { |
|
|
|
if (Router_Elevator.isLimitSwitchTriggerd()) { |
|
|
|
// this will cause to stop any motion that is currently going on and block further movement in the same direction as long as the switch is active |
|
|
|
// Stepper.setLimitSwitchActive(Stepper.LIMIT_SWITCH_COMBINED_BEGIN_AND_END); |
|
|
|
delay(200); |
|
|
|
actualStatus = RELEASE_SWITCH; |
|
|
|
} else { // limitSwitchState is HIGH |
|
|
|
// if (Stepper.getDistanceToTargetSigned() == 0) { |
|
|
|
if (Router_Elevator.isTargetPositionReached()) { |
|
|
|
Serial.println("isTargetPositionReached"); |
|
|
|
actualStatus = originStatus; |
|
|
|
delay(200); |
|
|
|
} else if (Router_Elevator.isWLSTriggerd()) { |
|
|
|
// } else if (WlsDetect.isConnected()) { |
|
|
|
// if (Wls.isPlugged()) { |
|
|
|
// Serial.println("The Tool is away from WLS"); |
|
|
|
// Stepper.clearLimitSwitchActive(); |
|
|
|
// } else if (Wls.isUnplugged()) { |
|
|
|
// Serial.println("The Tool touched the WLS"); |
|
|
|
// Stepper.setLimitSwitchActive(Stepper.LIMIT_SWITCH_COMBINED_BEGIN_AND_END); |
|
|
|
actualStatus = originStatus; |
|
|
|
delay(200); |
|
|
|
// } |
|
|
|
} |
|
|
|
// Stepper.clearLimitSwitchActive(); |
|
|
|
// previousDirection = Stepper.getDirectionOfMotion(); |
|
|
|
Router_Elevator.clearLimitSwitch(); |
|
|
|
Router_Elevator.checkDirection(); |
|
|
|
} |
|
|
|
@@ -287,9 +263,7 @@ void loop() { |
|
|
|
|
|
|
|
case RELEASE_SWITCH: |
|
|
|
printStatus("RELEASE_SWITCH"); |
|
|
|
// if (limitSwitchState == LOW) { |
|
|
|
if (Router_Elevator.isLimitSwitchTriggerd()) { |
|
|
|
// Stepper.moveRelativeInMillimeters(0.05 * previousDirection * -1); // move in opposite direction (away from switch) |
|
|
|
Router_Elevator.tryReleaseLimitSwitch(); |
|
|
|
} else { |
|
|
|
actualStatus = originStatus; |