Advertisement
Trainlover08

VEX_AI_SIM/robot_controller/include/test.cpp)

Oct 29th, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.34 KB | None | 0 0
  1. // (VEX_AI_SIM/robot_controller/include/test.cpp)
  2.  
  3. #include "include/robotFunctions.cpp"
  4.  
  5. Bot bot;
  6.  
  7. class Test{
  8. private:
  9.  
  10. public:
  11. int systemsTest() {
  12. int errorCode;
  13.  
  14. /* error code list
  15.  
  16. error 1: lifting upper arm failed
  17. error 2: lowering upper arm failed
  18. error 3: upper arm device not found
  19. error 4: intake holder activation failed
  20. error 5: intake holder deactivation failed
  21. error 6: intake holder device not found
  22. error 7: spinning intake failed
  23. error 8: stopping intake failed
  24. error 9: intake device not found
  25. error 10: ring clamp activation failed
  26. error 11: ring clamp deactivation failed
  27. error 12: ring clamp device(s) not found
  28. error 13: wing activation failed
  29. error 14: wing deactivation failed
  30. error 15: wing device not found
  31.  
  32. conveyor stuff
  33.  
  34. error 16: sending on emitter failed
  35. error 17: receiving on receiver failed
  36. error 18: emitter device not found
  37. error 19: receiver device not found
  38. error 20: hook activation failed
  39. error 21: hook deactivation failed
  40. error 22: hook device not found
  41. error 23: drive forward command failed
  42. error 24: drive backward command failed
  43. error 25: turn left command failed
  44. error 26: turn right command failed
  45. error 27: a left-drive device not found
  46. error 28: a right-drive device not found
  47.  
  48. */
  49.  
  50. cout << "MAINBOT: system test script start" << endl;
  51. errorCode = isTopArmGood();
  52. outputError(errorCode);
  53. errorCode = isHolderGood();
  54. outputError(errorCode);
  55. errorCode = isIntakeGood();
  56. outputError(errorCode);
  57. errorCode = isRingClampGood();
  58. outputError(errorCode);
  59. errorCode = isEmitterGood();
  60. outputError(errorCode);
  61. errorCode = isReceiverGood();
  62. outputError(errorCode);
  63. errorCode = isHookGood();
  64. outputError(errorCode);
  65. errorCode = isDrivetrainGood();
  66. outputError(errorCode);
  67. cout << "MAINBOT: system test script end, tests successful" << endl;
  68. sim.delay(1, "sec");
  69.  
  70. return errorCode;
  71. }
  72.  
  73. void outputError(int errorID) {
  74. if (errorID != NULL) {
  75. cout << "TESTER: warning: system fault, error code " << errorID << endl;
  76. sim.delay(9999, "sec");
  77. } else {
  78. sim.delay(1, "sec");
  79. }
  80. }
  81.  
  82. int isTopArmGood() {
  83. int errorCode;
  84. if (robot->getFromDef("topRingArm") != NULL) {
  85. bot.topArm(true);
  86. cout << "TESTER: top arm activation signal sent" << endl;
  87. if (topRingArm->getAcceleration() > 0) {
  88. sim.delay(1, "sec");
  89. bot.topArm(false);
  90. cout << "TESTER: top arm deactivation signal sent" << endl;
  91. if (topRingArm->getAcceleration() > 0) {
  92. errorCode = NULL;
  93. sim.delay(1, "sec");
  94. cout << "TESTER: top arm is good" << endl;
  95. } else {
  96. errorCode = 2;
  97. }
  98. } else {
  99. errorCode = 1;
  100. }
  101. } else {
  102. errorCode = 3;
  103. }
  104.  
  105. return errorCode;
  106. }
  107.  
  108. int isHolderGood() {
  109. int errorCode;
  110. if (robot->getFromDef("intakeHold") != NULL) {
  111. bot.holder(true);
  112. cout << "TESTER: intake holder activation signal sent" << endl;
  113. if (intakeHold->getTargetPosition() < 0) {
  114. sim.delay(1, "sec");
  115. bot.holder(false);
  116. cout << "TESTER: intake holder deactivation signal sent" << endl;
  117. if (intakeHold->getTargetPosition() == 0) {
  118. errorCode = NULL;
  119. sim.delay(1, "sec");
  120. cout << "TESTER: intake holder is good" << endl;
  121. } else {
  122. errorCode = 5;
  123. }
  124. } else {
  125. errorCode = 4;
  126. }
  127. } else {
  128. errorCode = 6;
  129. }
  130.  
  131. return errorCode;
  132. }
  133.  
  134. int isIntakeGood() {
  135. int errorCode;
  136. if (robot->getFromDef("intakeRoll") != NULL) {
  137. bot.intake(true);
  138. cout << "TESTER: intake roller activation signal sent" << endl;
  139. if (intakeRoll->getAcceleration() > 0) {
  140. sim.delay(1, "sec");
  141. bot.intake(false);
  142. cout << "TESTER: intake roller deactivation signal sent" << endl;
  143. if (intakeRoll->getAcceleration() > 0) {
  144. errorCode = NULL;
  145. sim.delay(1, "sec");
  146. cout << "TESTER: intake roller is good" << endl;
  147. } else {
  148. errorCode = 8;
  149. }
  150. } else {
  151. errorCode = 7;
  152. }
  153. } else {
  154. errorCode = 9;
  155. }
  156.  
  157. return errorCode;
  158. }
  159.  
  160. int isRingClampGood() {
  161. int errorCode;
  162. if (robot->getFromDef("ringClampL") != NULL) {
  163. bot.clamp(true);
  164. cout << "TESTER: ring clamp activation signal sent" << endl;
  165. if (ringClampL->getAcceleration() > 0 && ringClampR->getAcceleration() > 0) {
  166. sim.delay(1, "sec");
  167. bot.clamp(false);
  168. cout << "TESTER: ring clamp deactivation signal sent" << endl;
  169. if (ringClampL->getAcceleration() > 0 && ringClampR->getAcceleration() > 0) {
  170. errorCode = NULL;
  171. sim.delay(1, "sec");
  172. cout << "TESTER: ring clamp is good" << endl;
  173. } else {
  174. errorCode = 11;
  175. }
  176. } else {
  177. errorCode = 10;
  178. }
  179. } else {
  180. errorCode = 12;
  181. }
  182.  
  183. return errorCode;
  184. }
  185.  
  186. int isWingGood() {
  187. int errorCode;
  188.  
  189. return errorCode;
  190. }
  191.  
  192. int isConveyorGood() {
  193. int errorCode;
  194. if (robot->getFromDef("conveyor") != NULL) {
  195. bot.Conveyor(true);
  196. cout << "TESTER: conveyor activation signal sent" << endl;
  197. if (conveyor->getAcceleration() > 0) {
  198. sim.delay(1, "sec");
  199. bot.Conveyor(false);
  200. cout << "TESTER: conveyor deactivation signal sent" << endl;
  201. if (conveyor->getAcceleration() > 0) {
  202. errorCode = NULL;
  203. sim.delay(1, "sec");
  204. cout << "TESTER: conveyor is good" << endl;
  205. } else {
  206. errorCode = 14;
  207. }
  208. } else {
  209. errorCode = 13;
  210. }
  211. } else {
  212. errorCode = 15;
  213. }
  214.  
  215. return errorCode;
  216. }
  217.  
  218. int isEmitterGood() {
  219. int errorCode;
  220. const char* yes = "systemTest";
  221. if (robot->getFromDef("emit") != NULL) {
  222. sim.sendMessage(yes, strlen(yes) + 1);
  223. cout << "TESTER: testing emitter" << endl;
  224. if (emit->getChannel() == 0) {
  225. errorCode = NULL;
  226. sim.delay(1, "sec");
  227. cout << "TESTER: emitter is good" << endl;
  228. } else {
  229. errorCode = 16;
  230. }
  231. } else {
  232. errorCode = 18;
  233. }
  234.  
  235. return errorCode;
  236. }
  237.  
  238. int isReceiverGood() {
  239. int errorCode;
  240. if (robot->getFromDef("receiv") != NULL) {
  241. sim.receive();
  242. cout << "TESTER: testing receiver" << endl;
  243. if (receiv->getQueueLength() > 0) {
  244. errorCode = NULL;
  245. sim.delay(1, "sec");
  246. cout << "TESTER: receiver is good" << endl;
  247. } else {
  248. errorCode = 17;
  249. }
  250. } else {
  251. errorCode = 19;
  252. }
  253.  
  254. return errorCode;
  255. }
  256.  
  257. int isHookGood() {
  258. int errorCode;
  259. if (robot->getFromDef("Hook") != NULL) {
  260. bot.hook(true);
  261. cout << "TESTER: clamp activation signal sent" << endl;
  262. if (Hook->getTargetPosition() > 0) {
  263. sim.delay(1, "sec");
  264. bot.hook(false);
  265. cout << "TESTER: clamp deactivation signal sent" << endl;
  266. if (Hook->getTargetPosition() == 0) {
  267. errorCode = NULL;
  268. sim.delay(1, "sec");
  269. cout << "TESTER: clamp is good" << endl;
  270. } else {
  271. errorCode = 21;
  272. }
  273. } else {
  274. errorCode = 20;
  275. }
  276. } else {
  277. errorCode = 22;
  278. }
  279.  
  280. return errorCode;
  281. }
  282.  
  283. int isDrivetrainGood() {
  284. int errorCode;
  285. if (robot->getFromDef("left1") != NULL && robot->getFromDef("left2") != NULL && robot->getFromDef("left3") != NULL) {
  286. if (robot->getFromDef("right1") != NULL && robot->getFromDef("right2") != NULL && robot->getFromDef("right3") != NULL) {
  287. sim.moveBot(1);
  288. cout << "TESTER: drivetrain forward command sent" << endl;
  289. if (left1->getAcceleration() > 0 && right1->getAcceleration() > 0) {
  290. sim.delay(1, "sec");
  291. sim.moveBot(2);
  292. cout << "TESTER: drivetrain reverse command sent" << endl;
  293. sim.delay(50, "msec");
  294. if (left1->getAcceleration() > 0 && right1->getAcceleration() > 0) {
  295. sim.delay(1, "sec");
  296. sim.moveBot(3);
  297. cout << "TESTER: drivetrain left command sent" << endl;
  298. sim.delay(50, "msec");
  299. if (left1->getAcceleration() > 0) {
  300. sim.delay(1, "sec");
  301. sim.moveBot(4);
  302. cout << "TESTER: drivetrain right command sent" << endl;
  303. sim.delay(50, "msec");
  304. if (right1->getAcceleration() > 0) {
  305. errorCode = NULL;
  306. sim.delay(1, "sec");
  307. cout << "TESTER: drivetrain is good" << endl;
  308. sim.moveBot(0);
  309. } else {
  310. errorCode = 26;
  311. }
  312. } else {
  313. errorCode = 25;
  314. }
  315. } else {
  316. errorCode = 24;
  317. }
  318. } else {
  319. errorCode = 23;
  320. }
  321. } else {
  322. errorCode = 28;
  323. }
  324. } else {
  325. errorCode = 27;
  326. }
  327.  
  328. return errorCode;
  329. }
  330. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement