Advertisement
Trainlover08

Untitled

Feb 19th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 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 Pot = pot(Brain.ThreeWirePort.B);
  50. distance Distance1 = distance(PORT19);
  51.  
  52.  
  53.  
  54. // Helper to make playing sounds from the V5 in VEXcode easier and
  55. // keeps the code cleaner by making it clear what is happening.
  56. void playVexcodeSound(const char *soundName) {
  57. printf("VEXPlaySound:%s\n", soundName);
  58. wait(5, msec);
  59. }
  60.  
  61.  
  62.  
  63. // define variable for remote controller enable/disable
  64. bool RemoteControlCodeEnabled = true;
  65.  
  66. #pragma endregion VEXcode Generated Robot Configuration
  67.  
  68. // Include the V5 Library
  69. #include "vex.h"
  70.  
  71. // Allows for easier use of the VEX Library
  72. using namespace vex;
  73.  
  74. competition Competition;
  75.  
  76. float myVariable;
  77.  
  78. // "when started" hat block
  79. int whenStarted1() {
  80. Left1.setMaxTorque(100.0, percent);
  81. Left2.setMaxTorque(100.0, percent);
  82. Right1.setMaxTorque(100.0, percent);
  83. Right2.setMaxTorque(100.0, percent);
  84. Intake.setVelocity(100.0, percent);
  85. Intake.spin(forward);
  86. Cata.setStopping(hold);
  87. Cata.setVelocity(100.0, percent);
  88. Cata.setMaxTorque(100.0, percent);
  89. return 0;
  90. }
  91.  
  92. // "when Controller1 ButtonR1 pressed" hat block
  93. void onevent_Controller1ButtonR1_pressed_0() {
  94. Wings.set(true);
  95. }
  96.  
  97. // "when Controller1 ButtonR1 released" hat block
  98. void onevent_Controller1ButtonR1_released_0() {
  99. Wings.set(false);
  100. }
  101.  
  102. // "when driver control" hat block
  103. int ondriver_drivercontrol_0() {
  104. while (true) {
  105. Left1.spin(forward);
  106. Left2.spin(forward);
  107. Right1.spin(forward);
  108. Right2.spin(forward);
  109. if ((5.0 > Controller1.Axis3.position() && Controller1.Axis3.position() > -5.0) && (5.0 > Controller1.Axis1.position() && Controller1.Axis1.position() > -5.0)) {
  110. Left1.setVelocity(0.0, percent);
  111. Left2.setVelocity(0.0, percent);
  112. Right1.setVelocity(0.0, percent);
  113. Right2.setVelocity(0.0, percent);
  114. }
  115. else {
  116. Left1.setVelocity((Controller1.Axis3.position() + Controller1.Axis1.position() * 0.25), percent);
  117. Left2.setVelocity((Controller1.Axis3.position() + Controller1.Axis1.position() * 0.25), percent);
  118. Right1.setVelocity(((Controller1.Axis3.position() - Controller1.Axis1.position() * 0.25) - 5.0), percent);
  119. Right2.setVelocity(((Controller1.Axis3.position() - Controller1.Axis1.position() * 0.25) - 5.0), percent);
  120. }
  121. if (Controller1.ButtonR1.pressing()) {
  122. Intake.setVelocity(100.0, percent);
  123. Intake.spin(forward);
  124. wait(100, msec);
  125. } else if(Controller1.ButtonR2.pressing()){
  126. Intake.setVelocity(-100.0, percent);
  127. Intake.spin(forward);
  128. wait(100, msec);
  129. } else {
  130. Intake.stop();
  131. wait(100, msec);
  132. }
  133. if(Controller1.ButtonL1.pressing()){
  134. Wings.set(true);
  135. } else {
  136. Wings.set(false);
  137. }
  138. //if(Controller1.ButtonB.pressing()){
  139. if(Pot.angle(percent) > 64 && Pot.angle(percent) < 68){
  140. if(Controller1.ButtonA.pressing() || Distance1.objectDistance(inches) < 6){
  141. Cata.setVelocity(100, percent);
  142. Cata.spinFor(forward, 60, degrees);
  143. Controller1.rumble(rumbleShort);
  144. } else {
  145. Cata.stop();
  146. }
  147. } else {
  148. Cata.spin(forward);
  149. if(Pot.angle(percent) > 55 && Pot.angle(percent) < 60){
  150. Cata.setVelocity(50, percent);
  151. } else if(Pot.angle(percent) > 60 && Pot.angle(percent) < 64){
  152. Cata.setVelocity(25, percent);
  153. } else {
  154. Cata.setVelocity(100, percent);
  155. }
  156. }
  157. //}
  158. wait(5, msec);
  159. }
  160. return 0;
  161. }
  162.  
  163. // "when autonomous" hat block
  164. int onauton_autonomous_0() {
  165. return 0;
  166. }
  167.  
  168. void VEXcode_driver_task() {
  169. // Start the driver control tasks....
  170. vex::task drive0(ondriver_drivercontrol_0);
  171. while(Competition.isDriverControl() && Competition.isEnabled()) {this_thread::sleep_for(10);}
  172. drive0.stop();
  173. return;
  174. }
  175.  
  176. void VEXcode_auton_task() {
  177. // Start the auton control tasks....
  178. vex::task auto0(onauton_autonomous_0);
  179. while(Competition.isAutonomous() && Competition.isEnabled()) {this_thread::sleep_for(10);}
  180. auto0.stop();
  181. return;
  182. }
  183.  
  184.  
  185.  
  186. int main() {
  187. vex::competition::bStopTasksBetweenModes = false;
  188. Competition.autonomous(VEXcode_auton_task);
  189. Competition.drivercontrol(VEXcode_driver_task);
  190.  
  191. // register event handlers
  192. Controller1.ButtonR1.pressed(onevent_Controller1ButtonR1_pressed_0);
  193. Controller1.ButtonR1.released(onevent_Controller1ButtonR1_released_0);
  194.  
  195. wait(15, msec);
  196. // post event registration
  197.  
  198. // set default print color to black
  199. printf("\033[30m");
  200.  
  201. // wait for rotation sensor to fully initialize
  202. wait(30, msec);
  203.  
  204. whenStarted1();
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement