Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. #include "ASEIO.h"
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4.  
  5. void FD(int s){
  6. SetMoto(0,s);
  7. SetMoto(1,-s);
  8. }
  9.  
  10. void BK(int s){
  11. SetMoto(0,-s);
  12. SetMoto(1,s);
  13. }
  14. void RT(int s){
  15. SetMoto(0,s);
  16. SetMoto(1,s);
  17. }
  18. void LT(int s){
  19. SetMoto(0,-s);
  20. SetMoto(1,-s);
  21. }
  22.  
  23. void lineway_time(float i){
  24. resettime();
  25. float tim_1 = 0.0f;
  26. while(tim_1 < i)
  27. {
  28. if (AI(0)>ReadEEPROM(0) || AI(4)>ReadEEPROM(0))
  29. FD(250);
  30. else if(AI(1) > ReadEEPROM(0)) {
  31. LT(250);
  32. } else if (AI(3) > ReadEEPROM(0)) {
  33. RT(250);
  34. } else if(AI(2) > ReadEEPROM(0)) {
  35. FD(250);
  36. }
  37. tim_1=seconds();
  38. }
  39. }
  40.  
  41.  
  42. void lineway_cross( int i) {
  43. while(AI(i)< ReadEEPROM(0))
  44. {
  45. if(AI(1) > ReadEEPROM(0)){SetMoto(0,-250);SetMoto(1,-250);}
  46. else if(AI(3) > ReadEEPROM(0)){SetMoto(0,250);SetMoto(1,250);}
  47. else if(AI(2) > ReadEEPROM(0)){SetMoto(0,250);SetMoto(1,-250);}
  48. else ;
  49. }
  50. while(AI(0) > ReadEEPROM(0)){}
  51. SetMoto(0,0);SetMoto(1,0);
  52. }
  53.  
  54. void turn_around( int i)
  55. {
  56. if(i==0)
  57. {
  58. FD(250);
  59. wait(0.2);
  60. LT(250);
  61. while (AI(2)>ReadEEPROM(0));
  62. while (AI(2)<ReadEEPROM(0));
  63. FD(0);
  64. }
  65. else if(i==4)
  66. {
  67. FD(250);
  68. wait(0.2);
  69. RT(250);
  70. while (AI(2)>ReadEEPROM(0));
  71. while (AI(2)<ReadEEPROM(0));
  72. FD(0);
  73. }
  74. }
  75.  
  76. void lineway(){
  77. int flag = 1;
  78. while(flag == 1)
  79. {
  80. if((AI(1) < ReadEEPROM(0) && AI(2) < ReadEEPROM(0) && AI(3) < ReadEEPROM(0)))
  81. {
  82. FD(0);
  83. break;
  84. }
  85. if (AI(0)>ReadEEPROM(0) || AI(4)>ReadEEPROM(0)){
  86. FD(250);
  87. }
  88. else if(AI(1) > ReadEEPROM(0)) {
  89. LT(250);
  90. } else if (AI(3) > ReadEEPROM(0)) {
  91. RT(250);
  92. } else if(AI(2) > ReadEEPROM(0)) {
  93. FD(250);
  94. }
  95. }
  96. }
  97.  
  98. void energy9(){
  99. lineway_time(2.5);
  100. RT(250);
  101. wait(0.5);
  102. while (AI(2) > ReadEEPROM(0));
  103. while (AI(2) < ReadEEPROM(0));
  104. lineway_time(1);
  105. BK(250);
  106. wait(4);
  107. BK(0);
  108. }
  109.  
  110. void energy8(){
  111. SetMoto(1,-150);
  112. wait(0.3);
  113. while (AI(2) < ReadEEPROM(0));
  114. int flag = 1;
  115. lineway_time(0.6);
  116. BK(250);
  117. wait(3.5);
  118. BK(0);
  119. }
  120.  
  121. void energy7(){
  122. SetMoto(0,150);
  123. wait(0.3);
  124. while (AI(2) < ReadEEPROM(0));
  125. int flag = 1;
  126. lineway_time(0.55);
  127. BK(250);
  128. wait(3.5);
  129. BK(0);
  130. }
  131.  
  132. void energy6(){
  133. SetMoto(1,-150);
  134. wait(0.3);
  135. while (AI(2) < ReadEEPROM(0));
  136. int flag = 1;
  137. lineway_time(1);
  138. lineway();
  139. BK(250);
  140. wait(4);
  141. BK(0);
  142. }
  143.  
  144. void energy4(){
  145. SetMoto(1,-150);
  146. wait(0.3);
  147. while (AI(2) < ReadEEPROM(0));
  148. lineway_time(0.15);
  149. LT(250);
  150. wait(0.3);
  151. while (AI(2) < ReadEEPROM(0));
  152. lineway_time(0.8);
  153. BK(250);
  154. wait(3);
  155. BK(0);
  156. }
  157.  
  158. void energy3(){
  159. SetMoto(0,150);
  160. wait(0.3);
  161. while (AI(2) < ReadEEPROM(0));
  162. int flag = 1;
  163. lineway_time(1);
  164. BK(250);
  165. wait(2);
  166. wait(4);
  167. BK(0);
  168. }
  169.  
  170. void energy2(){
  171. SetMoto(0,150);
  172. wait(0.3);
  173. while (AI(2) < ReadEEPROM(0));
  174. int flag = 1;
  175. lineway_time(0.3);
  176. lineway();
  177. BK(250);
  178. wait(4);
  179. BK(0);
  180. }
  181.  
  182. void energy1(){
  183. SetMoto(1,-150);
  184. wait(0.3);
  185. while (AI(2) < ReadEEPROM(0));
  186. int flag = 1;
  187. lineway_time(0.8);
  188. BK(250);
  189. wait(5);
  190. BK(0);
  191. }
  192.  
  193. void WER(){
  194. lineway_cross(4);
  195. energy4();
  196. }
  197.  
  198. void main()
  199. {
  200. FD(250);
  201. wait(0.3);
  202. WER();
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement