SHARE
TWEET
VCEmblem's FRC 2013 Code
a guest
Feb 12th, 2013
163
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #include "WPILib.h"
- #include "math.h"
- class RobotDemo : public SimpleRobot
- {
- Jaguar frontLeft; // robot drive system
- Jaguar frontRight;
- Jaguar backRight;
- Jaguar backLeft;
- Jaguar shooter;
- Victor conveyor;
- Victor vacuum;
- Victor leftArm;
- Victor rightArm;
- Relay leftIntake;
- Relay rightIntake;
- Joystick driveStick;
- Encoder armEncoder;
- Digital rangeFinder;
- public:
- RobotDemo(void):
- //JAGUARS//
- frontLeft(1), // These must be initialized in the same order
- frontRight(2), // as they are declared above.
- backRight(3),
- backLeft(4),
- shooter(7),
- //VICTORS//
- conveyor(6),
- vacuum(5),
- leftArm(9),
- rightArm(8),
- //RELAYS//
- leftIntake(1),
- rightIntake(2),
- //JOYSTICKS//
- driveStick(1),
- //SENSORS//
- armEncoder(1)
- {
- frontLeft.SetExpiration(0.1);
- frontRight.SetExpiration(0.1);
- backRight.SetExpiration(0.1);
- backLeft.SetExpiration(0.1);
- vacuum.SetExpiration(0.1);
- leftArm.SetExpiration(0.1);
- rightArm.SetExpiration(0.1);
- }
- void shoot()
- {
- if(armEncoder.Get() < x) //x = 0 degress
- {
- while(armEncoder.Get() < x)
- {
- leftArm.Set(-1.0);
- rightArm.Set(-1.0);
- }
- }
- int Ct = 0.1;
- int deg = ((asine((rangeFinder.Get()*9.8*Ct)/(16^+2)))/2);
- lift_to_value(deg, 10);
- }
- void lift_to_value(int target, int error)
- {
- while( (armEncoder.Get() < (target-error)) || (armEncoder.Get() > (target+error)) ) {
- if(armEncoder.Get() < (target-error)) {
- leftArm.Set(-0.6);
- rightArm.Set(-0.6);
- }
- if(armEncoder.Get() > (target+error)) {
- leftArm.Set(0.6);
- rightArm.Set(0.6);
- }
- Wait(0.1);
- }
- }
- // // // // // // // // // // // // // // // // // // // // // // // // // //
- /*void Autonomous(void)
- {
- // PART ONE || PART ONE //
- Wait(1.0);
- leftArm.Set(-1.0);
- rightArm.Set(-1.0);
- Wait(1.5);
- leftArm.Set(0);
- rightArm.Set(0);
- Wait(0.5);
- shooter(0.7);
- Wait(0.5);
- conveyer.Set(0.8);
- Wait(2.0);
- shooter(0);
- conveyer.Set(0);
- // PART TWO || PART TWO //
- }*/
- // // // // // // // // // // // // // // // // // // // // // // // // // //
- void OperatorControl(void)
- {
- while (IsOperatorControl())
- {
- //-------------~~--------------~~---------------//
- // DRIVE MOTORS || DRIVE MOTORS || DRIVE MOTORS //
- //---------------~~--------------~~-------------//
- frontLeft.Set( - ( driveStick.GetRawAxis(2) )
- + ( driveStick.GetRawAxis(3) ) + ( driveStick.GetRawAxis(1) ) );
- frontRight.Set( ( driveStick.GetRawAxis(2) )
- + ( driveStick.GetRawAxis(3) ) + ( driveStick.GetRawAxis(1) ) );
- backRight.Set( ( driveStick.GetRawAxis(2) )
- + ( driveStick.GetRawAxis(3) ) - ( driveStick.GetRawAxis(1) ) );
- backLeft.Set( - ( driveStick.GetRawAxis(2) )
- + ( driveStick.GetRawAxis(3) ) - ( driveStick.GetRawAxis(1) ) );
- //-----------~~------------~~-------------//
- // ARM MOTORS || ARM MOTORS || ARM MOTORS //
- //-------------~~------------~~-----------//
- if(driveStick.GetRawButton(5))
- {
- leftArm.Set(-1.0);
- rightArm.Set(-1.0);
- }
- else if(driveStick.GetRawButton(7))
- {
- leftArm.Set(0.5);
- rightArm.Set(0.5);
- }
- else
- {
- leftArm.Set(0.0);
- rightArm.Set(0.0);
- }
- //---------~~----------~~-----------//
- // CONVEYER || CONVEYER || CONVEYER //
- //-----------~~----------~~---------//
- conveyor.Set( - (driveStick.GetRawAxis(6)) );
- //--------~~---------~~----------//
- // SHOOTER || SHOOTER || SHOOTER //
- //----------~~---------~~--------//
- if(driveStick.GetRawButton(8))
- {
- shooter.Set(0.7);
- }
- else if(driveStick.GetRawButton(6))
- {
- shooter.Set(1.0);
- }
- else if(driveStick.GetRawButton(3))
- {
- shooter.Set(-0.6);
- }
- else
- {
- shooter.Set(0.0);
- }
- //-------~~--------~~---------//
- // INTAKE || INTAKE || INTAKE //
- //---------~~--------~~-------//
- if(driveStick.GetRawButton(2))
- {
- leftIntake.Set(Relay::kForward);
- rightIntake.Set(Relay::kForward);
- //vacuum.Set(1.0);
- }
- else if(driveStick.GetRawButton(4))
- {
- leftIntake.Set(Relay::kReverse);
- rightIntake.Set(Relay::kReverse);
- //vacuum.Set(-1.0);
- }
- else
- {
- leftIntake.Set(Relay::kOff);
- rightIntake.Set(Relay::kOff);
- //vacuum.Set(0.0);
- }
- //---------------~~----------------~~-----------------//
- // STATION OUTPUT || STATION OUTPUT || STATION OUTPUT //
- //-----------------~~----------------~~---------------//
- DriverStationLCD *dsLCD = DriverStationLCD::GetInstance();
- dsLCD->Printf(DriverStationLCD::kUser_Line1, 1, "AX1: %4.1f", driveStick.GetRawAxis(1) );
- dsLCD->Printf(DriverStationLCD::kUser_Line2, 1, "AX2: %4.1f", driveStick.GetRawAxis(2) );
- dsLCD->Printf(DriverStationLCD::kUser_Line3, 1, "AX3: %4.1f", driveStick.GetRawAxis(3) );
- dsLCD->Printf(DriverStationLCD::kUser_Line4, 1, "AX4: %4.1f", driveStick.GetRawAxis(4) );
- dsLCD->Printf(DriverStationLCD::kUser_Line5, 1, "AX5: %4.1f", driveStick.GetRawAxis(5) );
- dsLCD->Printf(DriverStationLCD::kUser_Line6, 1, "AX6: %4.1f", driveStick.GetRawAxis(6) );
- dsLCD->UpdateLCD();
- Wait(0.005); // wait for a motor update time
- }
- }
- /**
- * Runs during test mode
- */
- void Test() {
- }
- };
- START_ROBOT_CLASS(RobotDemo);
RAW Paste Data
