SHARE
TWEET

Untitled

a guest Feb 15th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "robot-config.h"
  2. //Creates a competition object that allows access to Competition methods.
  3. vex::competition    Competition;
  4. using namespace vex;
  5.  
  6.  
  7. //Pre Auton
  8. void pre_auton( void )
  9. {
  10.     //reset all encoder value for motors
  11.     Puncher.resetRotation();
  12.     Intake.resetRotation();
  13.     RDriveF.resetRotation();
  14.     RDriveB.resetRotation();
  15.     LDriveF.resetRotation();
  16.     LDriveB.resetRotation();
  17.     Arm.resetRotation();
  18.     Angler.resetRotation();
  19. }
  20.  
  21. //bool canShoot = true;
  22.  
  23. //Ease of Use Tasks
  24. void motorSpin(vex::motor aMotor, int aRpm)
  25. {
  26.     aMotor.spin(directionType::fwd, aRpm, vex::velocityUnits::rpm);
  27. }
  28.  
  29. void motorRotate(vex::motor aMotor, int aRpm, int aRev, bool aWait)
  30. {
  31.     aMotor.rotateTo(aRev, vex::rotationUnits::rev, aRpm, vex::velocityUnits::rpm, false);
  32. }
  33.  
  34. //Robot Tasks
  35.  
  36. void singleShot()
  37. {
  38.     Puncher.rotateFor(1, vex::rotationUnits::rev, 200, vex::velocityUnits::rpm, true);
  39.     //Puncher.stop(brakeType::coast);
  40. }
  41.  
  42. void setAngler(int aAngle)
  43. {
  44.     //canShoot = false;
  45.     if(aAngle > AnglerPot.value(vex::analogUnits::range12bit))
  46.     {
  47.         while(aAngle > AnglerPot.value(vex::analogUnits::range12bit))
  48.         {
  49.             motorSpin(Angler, 200);
  50.             vex::task::sleep(10);
  51.         }
  52.         Angler.stop(brakeType::hold);
  53.     }
  54.     else if(aAngle < AnglerPot.value(vex::analogUnits::range12bit))
  55.     {
  56.         while(aAngle < AnglerPot.value(vex::analogUnits::range12bit))
  57.         {
  58.             motorSpin(Angler, -200);
  59.             vex::task::sleep(10);
  60.         }
  61.         Angler.stop(brakeType::hold);
  62.     }
  63.     //canShoot = true;
  64. }
  65.  
  66. //Auton
  67. void autonomous( void )
  68. {
  69.  
  70. }
  71.  
  72.  
  73. //Driver Control Tasks
  74.  
  75. //Angler
  76.  
  77. int anglerCounter = 0;
  78. int anglerTask()
  79. {
  80.     while (Competition.isDriverControl() && Competition.isEnabled())
  81.     {
  82.         if(Controller1.ButtonR2.pressing())
  83.         {
  84.             while(Controller1.ButtonR2.pressing())
  85.             {
  86.                 vex::task::sleep(10);
  87.             }
  88.             /*switch(anglerCounter)
  89.             {
  90.                 case 0:
  91.                     setAngler(1312);
  92.                     anglerCounter++;
  93.                     break;
  94.                 case 1:
  95.                     setAngler(1450);
  96.                     anglerCounter = 0;
  97.                     break;
  98.             }*/
  99.             setAngler(1312);
  100.         }
  101.         vex::task::sleep(50);
  102.     }
  103.     return 0;
  104. }
  105.  
  106. //Shoot
  107.  
  108. int shootTask()
  109. {
  110.     while (Competition.isDriverControl() && Competition.isEnabled())
  111.     {
  112.         if(Controller1.ButtonR1.pressing())
  113.         {
  114.             while(Controller1.ButtonR1.pressing())
  115.             {
  116.                 vex::task::sleep(10);
  117.             }
  118.             singleShot();
  119.         }
  120.         vex::task::sleep(50);
  121.     }
  122.     return 0;
  123. }
  124.  
  125. //Driver Control
  126.  
  127. void usercontrol( void )
  128. {
  129.     while (Competition.isDriverControl() && Competition.isEnabled())
  130.     {
  131.         vex::task angler = vex::task(anglerTask);
  132.         vex::task shoot = vex::task(shootTask);
  133.         vex::task::sleep(20);
  134.     }
  135. }
  136.  
  137. //
  138. // Main will set up the competition functions and callbacks.
  139. //
  140. int main() {
  141.    
  142.     //Run the pre-autonomous function.
  143.     pre_auton();
  144.    
  145.     //Set up callbacks for autonomous and driver control periods.
  146.     Competition.autonomous( autonomous );
  147.     Competition.drivercontrol( usercontrol );
  148.  
  149.     //Prevent main from exiting with an infinite loop.                        
  150.     while(1) {
  151.       vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
  152.     }    
  153.        
  154. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top