logics.ino 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Main logic handlers
  3. This file store the behavior of the robot
  4. when the switch is pressed
  5. */
  6. /* Pushing Sequences */
  7. void executePushAnimationSequence(int seqID) {
  8. if (seqID < 3) {
  9. //Default push back
  10. setAnimationCode('a');
  11. delay(4000);
  12. pushSwitchDelayed(1000, 1000);
  13. } else if (seqID < 4) {
  14. //Hesitation push back
  15. setAnimationCode('a');
  16. delay(4000);
  17. pushWithHesitation();
  18. } else if (seqID < 5) {
  19. //Hesitation push and walk back
  20. setAnimationCode('a');
  21. delay(4000);
  22. servoCoverPusher.write(90);
  23. delay(1000);
  24. servoSwitchPusher.write(90 + SERVO_ALIGNMENT_OFFSET);
  25. delay(2000);
  26. backward(100);
  27. delay(1000);
  28. servoSwitchPusher.write(130 + SERVO_ALIGNMENT_OFFSET);
  29. delay(1000);
  30. servoCoverPusher.write(0);
  31. servoSwitchPusher.write(0);
  32. } else if (seqID < 8) {
  33. //Annoy push back
  34. setAnimationCode('b');
  35. delay(2000);
  36. pushSwitchDelayed(300, 300);
  37. delay(3000);
  38. //Do not return to clear-frames when annoyed
  39. return;
  40. } else if (seqID < 10) {
  41. //Faster annoyed push back
  42. setAnimationCode('b');
  43. delay(500);
  44. pushSwitchNow();
  45. delay(1000);
  46. //Do not return to clear-frames when annoyed
  47. return;
  48. } else if (seqID < 11) {
  49. //Shake its head and push back
  50. setAnimationCode('f');
  51. delay(500);
  52. rotateClockwise(50);
  53. rotateAntiClockwise(100);
  54. rotateClockwise(100);
  55. rotateAntiClockwise(50);
  56. pushSwitchDelayed(1000, 300);
  57. delay(2000);
  58. setAnimationCode('g');
  59. return;
  60. } else {
  61. //fallback default push back
  62. setAnimationCode('a');
  63. delay(4000);
  64. pushSwitchDelayed(1000, 1000);
  65. }
  66. clearFrame();
  67. delay(3000);
  68. }
  69. //Debug sequence to test all movement functions
  70. void runDebugSequence() {
  71. //setAnimationCode('a');
  72. //delay(10000);
  73. //Stepper test
  74. forward(50);
  75. delay(3000);
  76. backward(50);
  77. delay(3000);
  78. rotateAntiClockwise(100);
  79. delay(1000);
  80. //rotate backward
  81. rotateClockwise(100);
  82. delay(3000);
  83. //setAnimationCode('j');
  84. //delay(10000);
  85. //Servo test
  86. servoCoverPusher.write(90 + SERVO_ALIGNMENT_OFFSET);
  87. delay(1000);
  88. servoSwitchPusher.write(130 + SERVO_ALIGNMENT_OFFSET);
  89. delay(1000);
  90. servoCoverPusher.write(0);
  91. servoSwitchPusher.write(0);
  92. delay(3000);
  93. //Switch test
  94. bool switchPushed = getSwitchState();
  95. if (switchPushed) {
  96. Serial.println("Switch pushed");
  97. } else {
  98. Serial.println("Switch idle");
  99. }
  100. }