Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.43 KB | None | 0 0
  1. #include "robot-config.h"
  2. /*---------------------------------------------------------------------------*/
  3. /* */
  4. /* Description: Competition template for VCS VEX V5 */
  5. /* */
  6. /*---------------------------------------------------------------------------*/
  7.  
  8. //Creates a competition object that allows access to Competition methods.
  9. vex::competition Competition;
  10. void drivef(int distance, int speed){//Drive Foward
  11. Right.rotateFor(distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  12. RightB.rotateFor(distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  13. Left.rotateFor(distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  14. LeftB.rotateFor(distance, rotationUnits::deg,speed,velocityUnits::pct);
  15. }
  16. void driver(int distance, int speed){//Drive Reverse
  17. Right.rotateFor(-distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  18. RightB.rotateFor(-distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  19. Left.rotateFor(-distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  20. LeftB.rotateFor(-distance, rotationUnits::deg,speed,velocityUnits::pct);
  21. }
  22. void right(int distance, int speed){//Drive Right
  23. Right . rotateFor(distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  24. RightB . rotateFor(distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  25. Left . rotateFor(-distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  26. LeftB . rotateFor(-distance, rotationUnits::deg,speed,velocityUnits::pct);
  27. }
  28. void left(int distance, int speed){//Drive Left
  29. Right . rotateFor(-distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  30. RightB . rotateFor(-distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  31. Left . rotateFor(distance, rotationUnits::deg,speed,velocityUnits::pct,false);
  32. LeftB . rotateFor(distance, rotationUnits::deg,speed,velocityUnits::pct);
  33. }
  34. void armu(int position, int speed){//Arm Control
  35. Arm.rotateTo(position,rotationUnits::deg,speed,velocityUnits::pct);
  36. }
  37.  
  38.  
  39. //Autonomous Idea!
  40. //Grab the two closest orange blocks to the wall, push them both, make at least one block in,
  41. //and use the claw to stack the other orange claw on top of each other.
  42. /*---------------------------------------------------------------------------*/
  43. /* Pre-Autonomous Functions */
  44. /* */
  45. /* You may want to perform some actions before the competition starts. */
  46. /* Do them in the following function. You must return from this function */
  47. /* or the autonomous and usercontrol tasks will not be started. This */
  48. /* function is only called once after the cortex has been powered on and */
  49. /* not every time that the robot is disabled. */
  50. /*---------------------------------------------------------------------------*/
  51.  
  52. void pre_auton( void ) {
  53. // All activities that occur before the competition starts
  54. // Example: clearing encoders, setting servo positions, ...
  55.  
  56. }
  57.  
  58. /*---------------------------------------------------------------------------*/
  59. /* */
  60. /* Autonomous Task */
  61. /* */
  62. /* This task is used to control your robot during the autonomous phase of */
  63. /* a VEX Competition. */
  64. /* */
  65. /* You must modify the code to add your own robot specific commands here. */
  66. /*---------------------------------------------------------------------------*/
  67.  
  68. void autonomous( void ) {
  69. // ..........................................................................
  70. // Insert autonomous user code here.
  71.  
  72. // ..........................................................................
  73.  
  74. }
  75.  
  76. /*----------------------------------------------------------------------------*/
  77. /* */
  78. /* User Control Task */
  79. /* */
  80. /* This task is used to control your robot during the user control phase of */
  81. /* a VEX Competition. */
  82. /* */
  83. /* You must modify the code to add your own robot specific commands here. */
  84. /*----------------------------------------------------------------------------*/
  85.  
  86. void usercontrol( void ) {
  87. // User control code here, inside the loop
  88. while (1){
  89. // This is the main execution loop for the user control program.
  90. // Each time through the loop your program should update motor + servo
  91. // values based on feedback from the joysticks.
  92.  
  93. // ........................................................................
  94. // Insert user code here. This is where you use the joystick values to
  95. // update your motors, etc.
  96. // ........................................................................
  97.  
  98. int ArmSpeedPCT = 75;
  99. int ClawSpeedPCT = 75;
  100.  
  101. Left.spin(vex::directionType::fwd, Controller1.Axis3.value() + Controller1.Axis1.value(), vex::velocityUnits::pct);
  102. LeftB.spin(vex::directionType::fwd, Controller1.Axis3.value() + Controller1.Axis1.value(), vex::velocityUnits::pct);
  103. Right.spin(vex::directionType::fwd, Controller1.Axis2.value() - Controller1.Axis1.value(), vex::velocityUnits::pct);
  104. RightB.spin(vex::directionType::fwd, Controller1.Axis2.value() - Controller1.Axis1.value(), vex::velocityUnits::pct);
  105.  
  106.  
  107. { if(Controller1.ButtonR1.pressing()) {
  108. Arm.spin(vex::directionType::fwd, ArmSpeedPCT, vex::velocityUnits::pct);
  109. }
  110. else if(Controller1.ButtonR2.pressing()) {
  111. Arm.spin(vex::directionType::rev, ArmSpeedPCT, vex::velocityUnits::pct);
  112. }
  113. else {
  114. Arm.stop(vex::brakeType::brake);
  115. }
  116.  
  117.  
  118. if(Controller1.ButtonL1.pressing()) {
  119. Claw.spin(vex::directionType::fwd, ClawSpeedPCT, vex::velocityUnits::pct);
  120. }
  121. else if(Controller1.ButtonL2.pressing()) {
  122. Claw.spin(vex::directionType::rev, ClawSpeedPCT, vex::velocityUnits::pct);
  123. }
  124. else {
  125. Claw.stop(vex::brakeType::brake);
  126. }
  127.  
  128.  
  129. }
  130.  
  131.  
  132.  
  133. }
  134.  
  135.  
  136. vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources.
  137. }
  138.  
  139.  
  140. //
  141. // Main will set up the competition functions and callbacks.
  142. //
  143. int main() {
  144.  
  145. //Run the pre-autonomous function.
  146. pre_auton();
  147.  
  148. //Set up callbacks for autonomous and driver control periods.
  149. Competition.autonomous( autonomous );
  150. Competition.drivercontrol( usercontrol );
  151.  
  152. //Prevent main from exiting with an infinite loop.
  153. while(1) {
  154. vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
  155. }
  156. //Our first program :-D
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement