BoeBot.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package boebot;
  2. import stamp.core.*;
  3. public class BoeBot{
  4. MotorAansturing motor;
  5. Botsingdetectie botsingdetectie;
  6. FysiekeIndicator fysiekeindicator;
  7. Aansturing aansturing;
  8. Lijnvolger lijnvolger;
  9. Bluetooth bluetooth;
  10. char route[];
  11. static int currentCase = 4;
  12. static int currentStep = 0;
  13. public BoeBot(){
  14. motor = new MotorAansturing();
  15. botsingdetectie = new Botsingdetectie();
  16. aansturing = new Aansturing(4,4);
  17. lijnvolger = new Lijnvolger();
  18. fysiekeindicator = new FysiekeIndicator();
  19. bluetooth = new Bluetooth();
  20. motor.setSnelheid(100);
  21. motor.setRichting(true);
  22. route = new char[]{'v','v','v','l','l','r','r','v','r','v', ' '};
  23. for(int i = 0; i < route.length; i++){
  24. System.out.println(route[i]);
  25. }
  26. System.out.println("de huidige stappen:" );
  27. //variabele om functies in en uit te schakelen.
  28. boolean afstandsbediening = true;
  29. boolean obstakelDetectie = false;
  30. boolean routeplanner = true;
  31. boolean sparcours = false;
  32. boolean routeafgerond = true;
  33. while(true){
  34. bluetooth.getRoute();
  35. if(obstakelDetectie){
  36. obstakelDetectie();
  37. }
  38. if(afstandsbediening){
  39. }
  40. if(routeplanner){
  41. if(routeafgerond){
  42. routeafgerond = routeplanner();
  43. }
  44. }
  45. if(sparcours){
  46. }
  47. }
  48. }
  49. public void obstakelDetectie(){
  50. if(botsingdetectie.detectEdge()){
  51. CPU.writePin(CPU.pin1,true);
  52. motor.noodStop();
  53. motor.setRichting(false);
  54. motor.start();
  55. CPU.delay(2000);
  56. motor.noodStop();
  57. motor.turn(180);
  58. motor.setRichting(true);
  59. motor.start();
  60. }else if(botsingdetectie.detectObject() == 1){
  61. motor.noodStop();
  62. motor.setRichting(false);
  63. motor.start();
  64. CPU.delay(2000);
  65. motor.noodStop();
  66. motor.turn(90);
  67. motor.setRichting(true);
  68. motor.start();
  69. }else if(botsingdetectie.detectObject() == 2){
  70. motor.noodStop();
  71. motor.setRichting(false);
  72. motor.start();
  73. CPU.delay(2000);
  74. motor.noodStop();
  75. motor.turn(270);
  76. motor.setRichting(true);
  77. motor.start();
  78. }else if(botsingdetectie.detectObject() == 3){
  79. motor.noodStop();
  80. motor.setRichting(false);
  81. motor.start();
  82. CPU.delay(2000);
  83. motor.noodStop();
  84. motor.turn(180);
  85. motor.setRichting(true);
  86. motor.start();
  87. }
  88. }
  89. public boolean routeplanner(){
  90. if(currentStep == 0){
  91. verwerkAansturing(route[currentStep]);
  92. }
  93. int getalLijnvolger = lijnvolger.readSensor();
  94. switch(getalLijnvolger){
  95. case 0:
  96. if(currentCase != 0){
  97. motor.setSnelheid(100);
  98. motor.setRichting(true);
  99. motor.rijden();
  100. currentCase = 0;
  101. }
  102. break;
  103. case 1:
  104. if(currentCase != 1){
  105. motor.setSnelheidL(10);
  106. motor.setSnelheidR(100);
  107. motor.setRichting(true);
  108. motor.rijden();
  109. currentCase = 1;
  110. }
  111. break;
  112. case 2:
  113. if(currentCase != 2){
  114. motor.setSnelheidL(100);
  115. motor.setSnelheidR(10);
  116. motor.setRichting(true);
  117. motor.rijden();
  118. currentCase = 2;
  119. }
  120. break;
  121. case 4:
  122. if(currentCase != 4){
  123. if(route[currentStep] != ' '){
  124. verwerkAansturing(route[currentStep]);
  125. System.out.println(route[currentStep-1]);
  126. CPU.delay(1000);
  127. }else{
  128. motor.noodStop();
  129. System.out.println("klaar");
  130. return false;
  131. }
  132. currentCase = 4;
  133. }
  134. break;
  135. case 5:
  136. if(currentCase != 5){
  137. motor.noodStop();
  138. System.out.println("Gat!!");
  139. currentCase = 5;
  140. return false;
  141. }
  142. default:
  143. // motor.noodStop();
  144. }
  145. return true;
  146. }
  147. public void verwerkAansturing(char opdracht){
  148. switch(opdracht){
  149. case 'v':
  150. motor.rijden();
  151. CPU.delay(200);
  152. break;
  153. case 'a':
  154. CPU.delay(1200);
  155. motor.noodStop();
  156. CPU.delay(200);
  157. motor.turn(180);
  158. break;
  159. case 'r':
  160. motor.setSnelheid(100);
  161. motor.setRichting(true);
  162. motor.rijden();
  163. CPU.delay(1200);
  164. motor.noodStop();
  165. CPU.delay(200);
  166. motor.turn(90);
  167. break;
  168. case 'l':
  169. motor.setSnelheid(100);
  170. motor.setRichting(true);
  171. motor.rijden();
  172. CPU.delay(1200);
  173. motor.noodStop();
  174. CPU.delay(200);
  175. motor.turn(270);
  176. break;
  177. default:
  178. motor.noodStop();
  179. break;
  180. }
  181. currentStep++;
  182. }
  183. }