Advertisement
Trainlover08

Untitled

Feb 19th, 2024 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.32 KB | None | 0 0
  1. #pragma region VEXcode Generated Robot Configuration
  2. // Make sure all required headers are included.
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <stdbool.h>
  6. #include <math.h>
  7. #include <string.h>
  8.  
  9.  
  10. #include "vex.h"
  11.  
  12. using namespace vex;
  13.  
  14. // Brain should be defined by default
  15. brain Brain;
  16.  
  17.  
  18. // START V5 MACROS
  19. #define waitUntil(condition) \
  20. do { \
  21. wait(5, msec); \
  22. } while (!(condition))
  23.  
  24. #define repeat(iterations) \
  25. for (int iterator = 0; iterator < iterations; iterator++)
  26. // END V5 MACROS
  27.  
  28.  
  29. // Robot configuration code.
  30. motor Left1MotorA = motor(PORT4, ratio6_1, false);
  31. motor Left1MotorB = motor(PORT5, ratio6_1, false);
  32. motor_group Left1 = motor_group(Left1MotorA, Left1MotorB);
  33.  
  34. motor Left2 = motor(PORT21, ratio6_1, false);
  35.  
  36. motor Right1MotorA = motor(PORT11, ratio6_1, true);
  37. motor Right1MotorB = motor(PORT14, ratio6_1, true);
  38. motor_group Right1 = motor_group(Right1MotorA, Right1MotorB);
  39.  
  40. motor Right2 = motor(PORT15, ratio6_1, true);
  41.  
  42. motor Intake = motor(PORT10, ratio6_1, false);
  43.  
  44. digital_out Wings = digital_out(Brain.ThreeWirePort.G);
  45. digital_out Intakepnumatic = digital_out(Brain.ThreeWirePort.F);
  46. controller Controller1 = controller(primary);
  47. motor Cata = motor(PORT17, ratio36_1, true);
  48.  
  49. pot PotentiometerB = pot(Brain.ThreeWirePort.B);
  50.  
  51.  
  52. // Helper to make playing sounds from the V5 in VEXcode easier and
  53. // keeps the code cleaner by making it clear what is happening.
  54. void playVexcodeSound(const char *soundName) {
  55. printf("VEXPlaySound:%s\n", soundName);
  56. wait(5, msec);
  57. }
  58.  
  59.  
  60.  
  61. // define variable for remote controller enable/disable
  62. bool RemoteControlCodeEnabled = true;
  63.  
  64. #pragma endregion VEXcode Generated Robot Configuration
  65.  
  66. // Include the V5 Library
  67. #include "vex.h"
  68.  
  69. // Allows for easier use of the VEX Library
  70. using namespace vex;
  71.  
  72. competition Competition;
  73.  
  74. float myVariable;
  75.  
  76. // "when started" hat block
  77. int whenStarted1() {
  78. Left1.setMaxTorque(50.0, percent);
  79. Left2.setMaxTorque(50.0, percent);
  80. Right1.setMaxTorque(50.0, percent);
  81. Right2.setMaxTorque(50.0, percent);
  82. Intake.setVelocity(50.0, percent);
  83. Intake.spin(forward);
  84. Cata.setStopping(brake);
  85. Cata.setVelocity(100.0, percent);
  86. Cata.setMaxTorque(100.0, percent);
  87. return 0;
  88. }
  89.  
  90. // "when Controller1 ButtonR1 pressed" hat block
  91. void onevent_Controller1ButtonR1_pressed_0() {
  92. Wings.set(true);
  93. }
  94.  
  95. // "when Controller1 ButtonR1 released" hat block
  96. void onevent_Controller1ButtonR1_released_0() {
  97. Wings.set(false);
  98. }
  99.  
  100. // "when driver control" hat block
  101. int ondriver_drivercontrol_0() {
  102. float L1 = 0.0;
  103. float L2 = 0.0;
  104. float L3 = 0.0;
  105. float R1 = 0.0;
  106. float R2 = 0.0;
  107. float R3 = 0.0;
  108. float cata = 0.0;
  109. float intake = 0.0;
  110. while (true) {
  111. Left1.spin(forward);
  112. Left2.spin(forward);
  113. Right1.spin(forward);
  114. Right2.spin(forward);
  115. if ((5.0 > Controller1.Axis3.position() && Controller1.Axis3.position() > -5.0) && (5.0 > Controller1.Axis1.position() && Controller1.Axis1.position() > -5.0)) {
  116. Left1.setVelocity(0.0, percent);
  117. Left2.setVelocity(0.0, percent);
  118. Right1.setVelocity(0.0, percent);
  119. Right2.setVelocity(0.0, percent);
  120. }
  121. else {
  122. Left1.setVelocity((Controller1.Axis3.position() + Controller1.Axis1.position() * 0.25), percent);
  123. Left2.setVelocity((Controller1.Axis3.position() + Controller1.Axis1.position() * 0.25), percent);
  124. Right1.setVelocity(((Controller1.Axis3.position() - Controller1.Axis1.position() * 0.25) - 5.0), percent);
  125. Right2.setVelocity(((Controller1.Axis3.position() - Controller1.Axis1.position() * 0.25) - 5.0), percent);
  126. }
  127. if (Controller1.ButtonR1.pressing()) {
  128. Intake.setVelocity(100.0, percent);
  129. Intake.spin(forward);
  130. wait(100, msec);
  131. } else if(Controller1.ButtonR2.pressing()){
  132. Intake.setVelocity(-100.0, percent);
  133. Intake.spin(forward);
  134. wait(100, msec);
  135. } else {
  136. Intake.stop();
  137. wait(100, msec);
  138. }
  139. if(Controller1.ButtonB.pressing()){
  140. Cata.spin(forward);
  141. } else {
  142. Cata.stop();
  143. }
  144. if(Controller1.ButtonL1.pressing()){
  145. Wings.set(true);
  146. } else {
  147. Wings.set(false);
  148. }
  149.  
  150. L1 = Left1MotorA.velocity(rpm);
  151. L2 = Left1MotorB.velocity(rpm);
  152. L3 = Left2.velocity(rpm);
  153. R1 = Right1MotorA.velocity(rpm);
  154. R2 = Right1MotorB.velocity(rpm);
  155. R3 = Right2.velocity(rpm);
  156. cata = Cata.velocity(rpm);
  157. intake = Intake.velocity(rpm);
  158. printf("%f,\t%f,\t%f,\t%f,\t%f,\t%f,\t%f,\t%f,\n",L1,L2,L3,R1,R2,R3,cata,intake);
  159. wait(10, msec);
  160. }
  161. return 0;
  162. }
  163.  
  164. // "when autonomous" hat block
  165. int onauton_autonomous_0() {
  166. float values[] = {0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 30.000000,
  167. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, -45.200001,
  168. 9.000000, 26.400000, 6.600000, 14.200000, 12.600000, 15.600000, -0.000000, 17.799999,
  169. 24.799999, 17.400000, 30.000000, 17.600000, 19.600000, 33.000000, -0.000000, 21.799999,
  170. 82.000000, 87.599998, 88.400002, 49.799999, 52.200001, 46.400002, -0.000000, 0.000000,
  171. 126.400002, 133.800003, 156.800003, 87.800003, 96.800003, 112.000000, -0.000000, 0.000000,
  172. 135.800003, 147.199997, 142.000000, 103.599998, 80.800003, 85.400002, -0.000000, 0.000000,
  173. 125.000000, 79.199997, 130.600006, 71.199997, 98.800003, 101.800003, -0.000000, 0.000000,
  174. 63.400002, 74.800003, 75.599998, 59.799999, 69.800003, 58.000000, -0.000000, 0.000000,
  175. 29.400000, 31.200001, 25.799999, 26.799999, 30.799999, 36.599998, -0.000000, 0.000000,
  176. 14.800000, 19.799999, 20.799999, -0.000000, 18.799999, 25.799999, -0.000000, 0.000000,
  177. 0.000000, 0.000000, 0.000000, -9.200000, -0.000000, -16.600000, -0.000000, 0.000000,
  178. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  179. -22.200001, -13.600000, 0.000000, -11.400000, -14.400000, -13.000000, -0.000000, 0.000000,
  180. -46.599998, -45.400002, -39.599998, -51.599998, -53.599998, -65.800003, -0.000000, 0.000000,
  181. -124.400002, -145.600006, -128.800003, -137.000000, -121.800003, -135.600006, -0.000000, 0.000000,
  182. -198.399994, -201.399994, -194.199997, -211.800003, -262.200012, -238.600006, -0.000000, 0.000000,
  183. -174.199997, -201.199997, -183.399994, -220.399994, -231.000000, -267.399994, -0.000000, 0.000000,
  184. -185.600006, -219.399994, -180.000000, -226.199997, -169.000000, -182.600006, -3.900000, 0.000000,
  185. -18.000000, 0.000000, -40.799999, -11.200000, -79.000000, -65.000000, -0.000000, 0.000000,
  186. -7.200000, -21.799999, -18.799999, 11.400000, -0.000000, -0.000000, -0.000000, 0.000000,
  187. -6.200000, -16.200001, -20.600000, 54.599998, 45.200001, 55.000000, -0.000000, 0.000000,
  188. -35.799999, -35.799999, -38.599998, 92.800003, 99.800003, 96.599998, -0.000000, 0.000000,
  189. -62.200001, -20.600000, -18.400000, 105.800003, 35.599998, 34.200001, -0.000000, 0.000000,
  190. -16.200001, -31.000000, -14.200000, 70.000000, 49.200001, 61.400002, -0.000000, 0.000000,
  191. 0.000000, 0.000000, 0.000000, 31.200001, 32.799999, 33.000000, -0.000000, 0.000000,
  192. 0.000000, 0.000000, 0.000000, 15.800000, 23.799999, 14.600000, -0.000000, 0.000000,
  193. -31.799999, -39.799999, -18.400000, 12.200000, 19.600000, 17.400000, -0.000000, 0.000000,
  194. 0.000000, 14.800000, 6.800000, 32.200001, -0.000000, 33.400002, -0.000000, 0.000000,
  195. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  196. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  197. 11.800000, 12.600000, 13.200000, -34.599998, -36.400002, -13.600000, -0.000000, 0.000000,
  198. 22.400000, 19.000000, 24.400000, -45.599998, -54.400002, -44.200001, -0.000000, 0.000000,
  199. -14.400000, -18.799999, 0.000000, -15.600000, -40.799999, -5.600000, -0.000000, 0.000000,
  200. 0.000000, 0.000000, 18.799999, -18.200001, -21.200001, -19.200001, -0.000000, 0.000000,
  201. 0.000000, 0.000000, 0.000000, -13.200000, -9.200000, -13.400000, -0.000000, 0.000000,
  202. 44.200001, 29.799999, 38.599998, -17.200001, -21.799999, -25.799999, -0.000000, 0.000000,
  203. 15.800000, 7.000000, 18.400000, -31.600000, -34.599998, -29.200001, -0.000000, 0.000000,
  204. -18.400000, -6.200000, -4.200000, -31.600000, -38.599998, 5.600000, -0.000000, 0.000000,
  205. 0.000000, 0.000000, 0.000000, -14.600000, -14.200000, -20.000000, -0.000000, 0.000000,
  206. 0.000000, 0.000000, 0.000000, -9.200000, -15.200000, -13.800000, -0.000000, 0.000000,
  207. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  208. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  209. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  210. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  211. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  212. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  213. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  214. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  215. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  216. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  217. 0.000000, 0.000000, 0.000000, -0.000000, -0.000000, -0.000000, -0.000000, 0.000000,
  218. };
  219. int math1 = -8;
  220. int math2 = -7;
  221. int math3 = -6;
  222. int math4 = -5;
  223. int math5 = -4;
  224. int math6 = -3;
  225. int math7 = -2;
  226. int math8 = -1;
  227. while(true){
  228. Right1.setMaxTorque(100, percent);
  229. Left1.setMaxTorque(100, percent);
  230. Right2.setMaxTorque(100, percent);
  231. Left2.setMaxTorque(100, percent);
  232. math1 = math1 + 8;
  233. math2 = math2 + 8;
  234. math3 = math3 + 8;
  235. math4 = math4 + 8;
  236. math5 = math5 + 8;
  237. math6 = math6 + 8;
  238. math7 = math7 + 8;
  239. math8 = math8 + 8;
  240. Right1MotorA.setVelocity(values[math1], rpm);
  241. Right1MotorB.setVelocity(values[math2], rpm);
  242. Right2.setVelocity(values[math3], rpm);
  243. Left1MotorA.setVelocity(values[math4], rpm);
  244. Left1MotorB.setVelocity(values[math5], rpm);
  245. Left2.setVelocity(values[math6], rpm);
  246. Cata.setVelocity(values[math7], rpm);
  247. Intake.setVelocity(values[math8], rpm);
  248. wait(10, msec);
  249. }
  250. return 0;
  251. }
  252.  
  253. void VEXcode_driver_task() {
  254. // Start the driver control tasks....
  255. vex::task drive0(ondriver_drivercontrol_0);
  256. while(Competition.isDriverControl() && Competition.isEnabled()) {this_thread::sleep_for(10);}
  257. drive0.stop();
  258. return;
  259. }
  260.  
  261. void VEXcode_auton_task() {
  262. // Start the auton control tasks....
  263. vex::task auto0(onauton_autonomous_0);
  264. while(Competition.isAutonomous() && Competition.isEnabled()) {this_thread::sleep_for(10);}
  265. auto0.stop();
  266. return;
  267. }
  268.  
  269.  
  270.  
  271. int main() {
  272. vex::competition::bStopTasksBetweenModes = false;
  273. Competition.autonomous(VEXcode_auton_task);
  274. Competition.drivercontrol(VEXcode_driver_task);
  275.  
  276. // register event handlers
  277. Controller1.ButtonR1.pressed(onevent_Controller1ButtonR1_pressed_0);
  278. Controller1.ButtonR1.released(onevent_Controller1ButtonR1_released_0);
  279.  
  280. wait(15, msec);
  281. // post event registration
  282.  
  283. // set default print color to black
  284. printf("\033[30m");
  285.  
  286. // wait for rotation sensor to fully initialize
  287. wait(30, msec);
  288.  
  289. whenStarted1();
  290. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement