Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. #include "main.h"
  2. using namespace vex;
  3. vex::brain Brain;
  4. vex::competition Competition;
  5. motor right_fwd = vex::motor (vex::PORT1);
  6. motor left_fwd = vex::motor (vex::PORT2);
  7. motor right_back = vex::motor (vex::PORT3);
  8. motor left_back = vex::motor (vex::PORT4);
  9.  
  10. /**
  11. * A callback function for LLEMU's center button.
  12. *
  13. * When this callback is fired, it will toggle line 2 of the LCD text between
  14. * "I was pressed!" and nothing.
  15. */
  16. void on_center_button() {
  17. static bool pressed = false;
  18. pressed = !pressed;
  19. if (pressed) {
  20. pros::lcd::set_text(2, "I was pressed!");
  21. } else {
  22. pros::lcd::clear_line(2);
  23. }
  24. }
  25.  
  26. /**
  27. * Runs initialization code. This occurs as soon as the program is started.
  28. *
  29. * All other competition modes are blocked by initialize; it is recommended
  30. * to keep execution time for this mode under a few seconds.
  31. */
  32. void initialize() {
  33. pros::lcd::initialize();
  34. pros::lcd::set_text(1, "Hello PROS User!");
  35.  
  36. pros::lcd::register_btn1_cb(on_center_button);
  37. }
  38.  
  39. /**
  40. * Runs while the robot is in the disabled state of Field Management System or
  41. * the VEX Competition Switch, following either autonomous or opcontrol. When
  42. * the robot is enabled, this task will exit.
  43. */
  44. void disabled() {}
  45.  
  46. /**
  47. * Runs after initialize(), and before autonomous when connected to the Field
  48. * Management System or the VEX Competition Switch. This is intended for
  49. * competition-specific initialization routines, such as an autonomous selector
  50. * on the LCD.
  51. *
  52. * This task will exit when the robot is enabled and autonomous or opcontrol
  53. * starts.
  54. */
  55. void competition_initialize() {}
  56.  
  57. /**
  58. * Runs the user autonomous code. This function will be started in its own task
  59. * with the default priority and stack size whenever the robot is enabled via
  60. * the Field Management System or the VEX Competition Switch in the autonomous
  61. * mode. Alternatively, this function may be called in initialize or opcontrol
  62. * for non-competition testing purposes.
  63. *
  64. * If the robot is disabled or communications is lost, the autonomous task
  65. * will be stopped. Re-enabling the robot will restart the task, not re-start it
  66. * from where it left off.
  67. */
  68. void autonomous() {}
  69.  
  70. int right;
  71. int left;
  72. int control = 1; //1 is red top 2 is red bottom, 3 ...
  73. if (control == 1){
  74. right = 100;
  75. left = 100;
  76. }
  77. if (control == 2){
  78. right = 0;
  79. left = 0;
  80. }
  81. if (control == 3){
  82. right = 100;
  83. left = 0;
  84. }
  85. if (control == 4){
  86. right = 0;
  87. left = 100;
  88. }
  89. while (true){
  90. left_fwd = left;
  91. right_fwd = right;
  92. left_back = left;
  93. right_back = right;
  94. }
  95. */
  96. void opcontrol() {
  97. while (true) {
  98. int fwd ;
  99. int rotation ;
  100. int left;
  101. int right;
  102.  
  103. if (master.get_digital(DIGITAL_RIGHT)) {
  104. left_fwd.spin(directionType::fwd,100, velocityUnints::pct);
  105. right_fwd.spin(directionType::fwd,-100, velocityUnints::pct);
  106. left_back.spin(directionType::fwd,-100, velocityUnints::pct);
  107. right_back.spin(directionType::fwd,100, velocityUnints::pct);
  108. }
  109. else if (master.get_digital(DIGITAL_LEFT)){
  110. left_fwd.spin(directionType::fwd,-100, velocityUnints::pct);
  111. right_fwd.spin(directionType::fwd,100, velocityUnints::pct);
  112. left_back.spin(directionType::fwd,100, velocityUnints::pct);
  113. right_back.spin(directionType::fwd,-100, velocityUnints::pct);
  114. }
  115. else{
  116. fwd = master.get_analog(ANALOG_RIGHT_Y);
  117. rotation = master.get_analog(ANALOG_RIGHT_X);
  118. left = fwd + rotation;
  119. right = fwd - rotation;
  120. right_fwd.spin(fwd, right, velocityUnints::pct);
  121. right_back.spin(fwd, right, velocityUnints::pct);
  122. left_fwd.spin(fwd, left, velocityUnints::pct);
  123. left_back.spin(fwd, left, velocityUnints::pct);
  124. }
  125. if (master.get_digital(DIGITAL_R2) == 1){
  126. left_lift.spin(directionType::fwd,100, velocityUnints::pct);
  127. right_lift.spin(directionType::fwdl,-100, velocityUnints::pct);
  128. }
  129. else if (master.get_digital(DIGITAL_R1) == 1){
  130. left_lift.spin(directionType::fwd,-100, velocityUnints::pct);
  131. right_lift.spin(directionType::fwd,100, velocityUnints::pct);
  132. }
  133. else if (master.get_digital(DIGITAL_R1) == 0 && master.get_digital(DIGITAL_R2) == 0){
  134. left_lift.stop(vex::hold);
  135. right_lift.stop(vex::hold);
  136. }
  137.  
  138. pros::delay(2);
  139.  
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement