logics.ino 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 if (seqID < 13) {
  67. //Annoyed fast push back
  68. setAnimationCode('g');
  69. delay(500);
  70. pushSwitchNow();
  71. delay(1000);
  72. return;
  73. } else if (seqID < 14) {
  74. //Angry & Movement
  75. setAnimationCode('y');
  76. delay(5000);
  77. setAnimationCode('c');
  78. delay(2000);
  79. servoCoverPusher.write(90);
  80. delay(1000);
  81. forward(100);
  82. backward(100);
  83. forward(100);
  84. backward(100);
  85. pushSwitchNow();
  86. return;
  87. } else if (seqID < 17) {
  88. //Angry fast push
  89. delay(500);
  90. if (seqID % 2 == 0) {
  91. forward(100);
  92. } else {
  93. backward(100);
  94. }
  95. pushSwitchNow();
  96. delay(1000);
  97. return;
  98. } else if (seqID < 18) {
  99. setAnimationCode('h');
  100. delay(1000);
  101. setAnimationCode('i');
  102. delay(1000);
  103. setAnimationCode('j');
  104. forward(50);
  105. backward(50);
  106. forward(50);
  107. rotateClockwise(50);
  108. rotateAntiClockwise(100);
  109. rotateClockwise(100);
  110. rotateAntiClockwise(50);
  111. pushSwitchDelayed(1000, 300);
  112. return;
  113. } else if (seqID < 22) {
  114. delay(500);
  115. pushSwitchDelayed(1000, 300);
  116. return;
  117. } else if (seqID < 25) {
  118. setAnimationCode('d');
  119. delay(500);
  120. pushWithHesitation();
  121. return;
  122. } else {
  123. //fallback default push back
  124. delay(500);
  125. int expression = random(0, 4);
  126. if (expression == 0) {
  127. setAnimationCode('a');
  128. delay(3000);
  129. pushSwitchDelayed(1000, 1000);
  130. delay(500);
  131. } else if (expression == 1) {
  132. setAnimationCode('b');
  133. delay(500);
  134. pushSwitchNow();
  135. delay(500);
  136. } else if (expression == 2) {
  137. setAnimationCode('g');
  138. pushWithHesitation();
  139. delay(500);
  140. } else {
  141. setAnimationCode('e');
  142. pushSwitchNow();
  143. return;
  144. }
  145. }
  146. clearFrame();
  147. delay(500);
  148. }
  149. //Debug sequence to test all movement functions
  150. void runDebugSequence() {
  151. //setAnimationCode('a');
  152. //delay(10000);
  153. //Stepper test
  154. forward(50);
  155. delay(3000);
  156. backward(50);
  157. delay(3000);
  158. rotateAntiClockwise(100);
  159. delay(1000);
  160. //rotate backward
  161. rotateClockwise(100);
  162. delay(3000);
  163. //setAnimationCode('j');
  164. //delay(10000);
  165. //Servo test
  166. servoCoverPusher.write(90 + SERVO_ALIGNMENT_OFFSET);
  167. delay(1000);
  168. servoSwitchPusher.write(130 + SERVO_ALIGNMENT_OFFSET);
  169. delay(1000);
  170. servoCoverPusher.write(0);
  171. servoSwitchPusher.write(0);
  172. delay(3000);
  173. //Switch test
  174. bool switchPushed = getSwitchState();
  175. if (switchPushed) {
  176. Serial.println("Switch pushed");
  177. } else {
  178. Serial.println("Switch idle");
  179. }
  180. }