Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. int colourReading()
  2. {
  3. int readingsCount[8] = {0,0,0,0,0,0,0,0};
  4. int readings[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  5.  
  6. for (int reading =0; reading <15; reading++)
  7. {
  8. motor[motorA] = 30;
  9. wait1Msec(20);
  10. motor[motorA] = 0;
  11. wait1Msec(20);
  12. motor[motorA] = -30;
  13. wait1Msec(10);
  14. motor[motorA] = 0;
  15. wait1Msec(20);
  16. readings[reading] = SensorValue[S1];
  17. }
  18. for (int reading =0; reading < 15; reading++)
  19. readingsCount[readings[reading]] ++;
  20.  
  21. for (int size =0; size <8; size++)
  22. {
  23. if (readingsCount[size] > 6)
  24. {
  25. displayString(5, "%d", SensorValue[S1]);
  26. return size;
  27. }
  28. }
  29. return 0;
  30. }
  31.  
  32. void userInput(int *jars)
  33. {
  34. string colourNames[3] = {"yellow", "blue", "brown"};//DO NOT REMOVE
  35. for(int count =0; count <3; count++)
  36. {
  37. displayString(3,"What jar would you like %s skittles in?", colourNames[count]);
  38.  
  39. while(!getButtonPress(buttonAny))
  40. {}
  41.  
  42. if(getButtonPress(buttonLeft))//if statement for each colour
  43. {
  44. while(getButtonPress(buttonLeft))
  45. {}
  46. jars[count] = -90; //populate array with motor encoder values of each jar
  47. }
  48. else if (getButtonPress(buttonUp))
  49. {
  50. while(getButtonPress(buttonUp))
  51. {}
  52. jars[count] = -60;
  53. }
  54.  
  55. else if(getButtonPress(buttonRight))
  56. {
  57. while(getButtonPress(buttonRight))
  58. {}
  59. jars[count] = -30;
  60. }
  61. }
  62. eraseDisplay();
  63. }
  64.  
  65. bool rotate()
  66. {
  67. time1[T1] =0;
  68.  
  69. motor[motorB] = 30;
  70.  
  71. while(SensorValue[S1] == 6 && time1[T1] < 20000)//may see something when nothing is there and give a false positive
  72. {}
  73. motor[motorB] = 0;
  74. displayString(15,"Time: %d", time1[T1]);
  75. if(time1[T1] > 19998)
  76. return false;
  77. return true;
  78.  
  79. }
  80.  
  81. void openChamber(tMotor motorA)
  82. {
  83. motor[motorA] = -50; //make sure that the correct motor is being called and the power moves it in the right direction
  84. while(nMotorEncoder[motorA] >-30)
  85. {}
  86. motor[motorA] =0;
  87. wait1Msec(50); //test for time that works
  88.  
  89. motor[motorA] = 50; //make sure that the correct motor is being called and the power moves it in the right direction
  90. while(nMotorEncoder[motorA] <0)
  91. {}
  92. motor[motorA] =0;
  93. }
  94.  
  95. void display(int time, int skittleCount, int*coloursCount)
  96. {
  97. string colourNames[3] = {"yellow", "blue", "brown"};//DO NOT REMOVE
  98.  
  99. displayString(3, "Total # of skittles sorted: %d", skittleCount/2);
  100. int line = 4;
  101.  
  102. for (int index = 0; index < 3; index++)
  103. {
  104. displayString(line+index, "%s skittle sorted: %d", colourNames[index], coloursCount[index]);
  105. }
  106.  
  107. displayString(7, "Skittles sorted / second: %f ", (float)skittleCount/((time-20000)/1000));//time-20... yes or no?
  108. displayString(8, "Seconds to sort 1: %f ", 1/( (float)skittleCount/((time-20000)/1000)) ) ;
  109. displayString(9, "Time: %f",time);
  110. }
  111.  
  112. void turn_arm(tMotor motorM, int index, int speed) {
  113. int i_angle = nMotorEncoder[motorM];
  114. if(index - i_angle > 0)
  115. {
  116. motor[motorM] = speed;
  117. while(nMotorEncoder[motorM] < i_angle + (index - i_angle))
  118. {}
  119. motor[motorM] = 0;
  120. }
  121. else
  122. {
  123. motor[motorM] = -speed;
  124. while(nMotorEncoder[motorM] >= i_angle + (index - i_angle))
  125. {}
  126. motor[motorM] = 0;
  127. }
  128. }
  129.  
  130. void zeroArm()
  131. {
  132. motor[motorD] = 40;
  133. while(SensorValue[S2] == 0){}
  134. motor[motorD] = 0;
  135. nMotorEncoder[motorD] = 0;
  136. }
  137.  
  138. void CalibrateMotors(){
  139. zeroArm();
  140. if(SensorValue[S1] != (int)colorWhite)
  141. {
  142. motor[motorA] = 30;
  143. wait1Msec(400);
  144. while(SensorValue[S1] != (int)colorWhite){}
  145. motor[motorA] = motor[motorD] = 0;
  146. }
  147. nMotorEncoder[motorA] = 0;
  148. }
  149.  
  150.  
  151. task main()
  152. {
  153. displayString(1,"Jess ur a CUNT");
  154. SensorType[S1] = sensorEV3_Color;
  155. wait1Msec(50);
  156. SensorMode[S1] = modeEV3Color_Color;
  157. wait1Msec(50);
  158. SensorType[S2] = sensorEV3_Touch;
  159. CalibrateMotors();
  160.  
  161.  
  162. int currentColour =0, skittleCount = 0;
  163. int colours[3] = {4,2,7};
  164. int jarsIndex[3] ={0,0,0};
  165. string colourNames[3] = {"yellow", "blue", "brown"};
  166. int coloursCount[3] = {0,0,0};
  167.  
  168. //displayString(1,"Jess ur a CUNT");
  169. userInput(jarsIndex);
  170.  
  171. time1[T2] = 0; //timing the entire sorting process
  172.  
  173. while(rotate())
  174. {
  175. currentColour = colourReading();
  176. displayString(5, "%d", currentColour);
  177. if (currentColour == 0)
  178. {
  179. turn_arm(motorD, 0, 30);
  180. }
  181. else
  182. {
  183. for (int index = 0; index <3; index++)
  184. {
  185. if(currentColour == 1 && colours[index] == 7)
  186. {
  187. turn_arm(motorD,jarsIndex[index], 40);
  188. coloursCount[2]++;
  189. skittleCount++;
  190. }
  191.  
  192. else if (colours[index] == currentColour)
  193. {
  194. displayString(1,"%d", jarsIndex[index]);
  195. turn_arm(motorD, jarsIndex[index], 40);//move leading arm
  196. if(colours[index] == 2)
  197. {
  198. coloursCount[1]++;
  199. skittleCount++;
  200. }
  201. else if(colours[index] == 4)
  202. {
  203. coloursCount[0]++;
  204. skittleCount++;
  205. }
  206. else if(colours[index] == 7)
  207. {
  208. coloursCount[2]++;
  209. skittleCount++;
  210. }
  211.  
  212.  
  213. }
  214. }
  215. }
  216. wait1Msec(200);
  217. displayString(1,"Jess has homosexual attributes");
  218. openChamber(motorA);//make sure its the right motor
  219. skittleCount ++;
  220. }
  221. displayString(1,"Homosexuality defines Jess");
  222.  
  223. zeroArm();
  224.  
  225. /*
  226. for (int index = 0; index < 3; index++)
  227. {
  228. displayString(4+index, "%s skittle sorted: %d", colourNames[index], coloursCount[index]);
  229. }
  230. displayString(7, "Skittles per second: %f", (float)skittleCount/(time1[T2]-20));
  231.  
  232. */
  233.  
  234.  
  235. display(time1[T2], skittleCount, coloursCount);
  236. wait1Msec(200000000);
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement