Frästisch mit elektronischer Höhenverstellung mittels Schrittmotoren.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RouterElevator.cpp 2.1KB

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