Advertisement
Trainlover08

VEX_AI_SIM/score_checker/include/simFunctions.cpp

Oct 29th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. // (VEX_AI_SIM/score_checker/include/simFunctions.cpp)
  2.  
  3. #define CHANNEL_NUMBER 0.0
  4. #define RANGE 999.9
  5.  
  6. class Sim{
  7. private:
  8. const void* message1 = " ";
  9. int yes = 0;
  10.  
  11. public:
  12. // setup the bot
  13. int programSetup() {
  14. // CAMERAS
  15. // enable actual sensor
  16. moveGoal1->enable(TIME_STEP);
  17. moveGoal2->enable(TIME_STEP);
  18. moveGoal3->enable(TIME_STEP);
  19. moveGoal4->enable(TIME_STEP);
  20. moveGoal5->enable(TIME_STEP);
  21.  
  22. // turn on recognition
  23. moveGoal1->recognitionEnable(TIME_STEP);
  24. moveGoal2->recognitionEnable(TIME_STEP);
  25. moveGoal3->recognitionEnable(TIME_STEP);
  26. moveGoal4->recognitionEnable(TIME_STEP);
  27. moveGoal5->recognitionEnable(TIME_STEP);
  28.  
  29. // CONNECTORS
  30. connect1->enablePresence(TIME_STEP);
  31. connect2->enablePresence(TIME_STEP);
  32. connect3->enablePresence(TIME_STEP);
  33. connect4->enablePresence(TIME_STEP);
  34. connect5->enablePresence(TIME_STEP);
  35.  
  36. // EMITTER AND RECEIVER
  37. receiv1->enable(TIME_STEP);
  38. receiv1->setChannel(CHANNEL_NUMBER);
  39. emit1->setChannel(CHANNEL_NUMBER);
  40. emit1->setRange(RANGE);
  41.  
  42. return 0;
  43. }
  44.  
  45. // delay the program
  46. int delay (double time, const char* unit) {
  47. if (unit == "msec") {
  48. time = time * 0.001;
  49. }
  50. float current_time_1 = float(score_checker->getTime());
  51. float current_time_2= float(score_checker->getTime());
  52. do {
  53. current_time_2 = float(score_checker->getTime());
  54. score_checker->step(1);
  55. } while(current_time_2 < (current_time_1 + time));
  56.  
  57. return 0;
  58. }
  59.  
  60. // send a message through the radio
  61. int sendMessage(const void* data, int size) {
  62. emit1->send(data, size);
  63. //cout << "SCORE: sending message" << endl;
  64.  
  65. return 0;
  66. }
  67.  
  68. // check for a message through the radio
  69. int receive() {
  70. if (receiv1->getQueueLength() != 0) {
  71. message1 = static_cast<const char *>(receiv1->getData());
  72. //cout << "SCORE: received: " << message1 << endl;
  73. } else {
  74. //cout << "SCORE: no messages received" << endl;
  75. }
  76.  
  77. return 0;
  78. }
  79.  
  80. // dismiss the message if called
  81. int dismissMessage() {
  82. receiv1->nextPacket();
  83.  
  84. return 0;
  85. }
  86. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement