logics.ino 2.6 KB

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