Advertisement
JonPNBHS_Vex

NBN Test Code

Aug 31st, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.43 KB | None | 0 0
  1. #pragma config(Sensor, dgtl1,  touchsense,     sensorTouch)
  2.  
  3. /*
  4.     This program can can be used for NBT on the robots, it is very versitile
  5.     and I hope we can make use of it
  6.    
  7.     By John (31/8/15 - 9/1/2015)
  8. */
  9.  
  10.     //bool to show if flywheel is activating
  11.     bool flywheelrampCurrentlyActive = false;
  12.    
  13.     //bool to tell if flywheel is running
  14.     bool FlyWheelRunning = false;
  15.    
  16.     //constant for motor off
  17.     const int motorOff = 0;
  18.    
  19.     //bool to tell if stopswitch should be active
  20.     bool stopSwitchState = false;
  21.  
  22.     //flywheel acceleration ramp func (void)
  23.     void flywheelramp(int maxMotorSpeed = 127, int rampincreasePerLOOP = 1)
  24.         {
  25.            
  26.             flywheelrampCurrentlyActive = true;
  27.            
  28.             //temporary storage for motor speed
  29.             int tmpMotorSpeed = 10;
  30.            
  31.             //if not max speed then set speed to tmpMotorSpeed and add 1
  32.             while(tmpMotorSpeed < maxMotorSpeed)
  33.                 {
  34.                         motor[port2] = tmpMotorSpeed;
  35.                         motor[port3] = tmpMotorSpeed;
  36.                            
  37.                         //long version of tmpMotorSpeed ++
  38.                         tmpMotorSpeed = tmpMotorSpeed + rampincreasePerLOOP;
  39.                        
  40.                         //give it a secound and dont hog the CPU
  41.                         wait1Msec(35);
  42.                 }
  43.             flywheelrampCurrentlyActive = false;
  44.         }
  45.    
  46.        
  47. //example of code in usage situation
  48. task main()
  49. {
  50.    
  51.     while(true)
  52.     {
  53.         /* AccelFlywheel and maxspeed
  54.         -------------------------------------------------------------------------*/
  55.  
  56.         //Activation button for flywheel ramp and run
  57.         if((vexRT[Btn7U] == 1) && FlyWheelRunning == false)
  58.             {
  59.                 //clear encoders
  60.                 nMotorEncoder[port2] = 0;
  61.                 nMotorEncoder[port3] = 0;
  62.                
  63.                 //runs flywheel ramp func
  64.                 flywheelramp(120,20);
  65.                
  66.                 //set bool to true to show flywheel is running
  67.                 FlyWheelRunning = true;
  68.                
  69.                 //tell the main while loop to start including stopSwitch in runs
  70.                 stopSwitchState = true;
  71.                
  72.             }
  73.            
  74.         /* StopSwitch Section
  75.         -------------------------------------------------------------------------*/
  76.        
  77.         //if the stopswitch is needed to be used
  78.         if(stopSwitchState == true)
  79.             {
  80.                 //if the predesignated stopswitch is pressed
  81.                 if(Btn5D == true)
  82.                     {
  83.                    
  84.                             //set motors to the const MotorOff (or 0)
  85.                             motor[port2] = motorOff;
  86.                             motor[port3] = motorOff;
  87.                            
  88.                             //disable fly wheel currently spinning bool
  89.                             FlyWheelRunning = false;
  90.                            
  91.                             //bool to stop stopSwitch and 'disinclude' it in while runs
  92.                             stopSwitchState = false;
  93.                            
  94.                     }
  95.             }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement