Frästisch mit elektronischer Höhenverstellung mittels Schrittmotoren.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RouterElevator.cpp 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * RouterElevator.cpp
  3. *
  4. * Created on: 12.02.2022
  5. * Author: FSmilari
  6. */
  7. #include "RouterElevator.h"
  8. RouterElevator::RouterElevator(ESP_FlexyStepper &_Stepper, Display &_display, WLS &_WlsDetect, WLS &_Wls, int _LimitSwitch, int _DOWNWARD_DIR) :
  9. Stepper(_Stepper), display(_display), WlsDetect(_WlsDetect), Wls(_Wls) {
  10. LimitSwitch = _LimitSwitch;
  11. DOWNWARD_DIR = _DOWNWARD_DIR;
  12. UPWARD_DIR = -DOWNWARD_DIR;
  13. }
  14. void RouterElevator::setZeroPosition() {
  15. Stepper.setCurrentPositionInMillimeters(0);
  16. Stepper.setTargetPositionRelativeInMillimeters(0);
  17. }
  18. void RouterElevator::moveRelativeInMillimeters(float distanceInMillimeters) {
  19. Stepper.setTargetPositionInMillimeters(distanceInMillimeters);
  20. }
  21. void RouterElevator::moveToLowerLimitSwitch(void) {
  22. Stepper.setTargetPositionInMillimeters(300 * DOWNWARD_DIR);
  23. }
  24. void RouterElevator::moveToUpperLimitSwitch(void) {
  25. Stepper.setTargetPositionInMillimeters(300 * UPWARD_DIR);
  26. }
  27. void RouterElevator::clearLimitSwitch(void) {
  28. Stepper.clearLimitSwitchActive();
  29. }
  30. void RouterElevator::tryReleaseLimitSwitch(void) {
  31. Stepper.moveRelativeInMillimeters(0.05 * previousDirection * -1); // move in opposite direction (away from switch)
  32. }
  33. bool RouterElevator::isLimitSwitchTriggerd() {
  34. return limitSwitchState == LOW;
  35. }
  36. bool RouterElevator::isTargetPositionReached() {
  37. return Stepper.getDistanceToTargetSigned() == 0;
  38. }
  39. bool RouterElevator::isWLSTriggerd() {
  40. if (WlsDetect.isConnected()) {
  41. if (Wls.isPlugged()) {
  42. Serial.println("The Tool is away from WLS");
  43. Stepper.clearLimitSwitchActive();
  44. return false;
  45. } else if (Wls.isUnplugged()) {
  46. Serial.println("The Tool touched the WLS");
  47. Stepper.setLimitSwitchActive(Stepper.LIMIT_SWITCH_COMBINED_BEGIN_AND_END);
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
  53. void RouterElevator::limitSwitchHandler() {
  54. limitSwitchState = digitalRead(LimitSwitch);
  55. if (limitSwitchState == LOW) {
  56. // 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
  57. Stepper.setLimitSwitchActive(Stepper.LIMIT_SWITCH_COMBINED_BEGIN_AND_END);
  58. } else {
  59. // clear the limit switch flag to allow movement in both directions again
  60. clearLimitSwitch();
  61. }
  62. }
  63. void RouterElevator::checkDirection() {
  64. previousDirection = Stepper.getDirectionOfMotion();
  65. }