コード例 #1
0
ファイル: MyRobot.cpp プロジェクト: Team537/RobotCode
	void OperatorControl()
	{
		tank.StartDrive();
		kick.StartKicker();
		while (IsOperatorControl())
		{
			comp.checkCompressor();
			tank.Drive(PrimaryController.GetRawAxis(LEFT_JOYSTICK), PrimaryController.GetRawAxis(RIGHT_JOYSTICK), (int)PrimaryController.GetRawButton(BUTTON_HIGH_DRIVE_SHIFT), (int)PrimaryController.GetRawButton(BUTTON_LOW_DRIVE_SHIFT));
			kick.StateMachine(PrimaryController.GetRawButton(BUTTON_KICK));
			collect.runCollector(PrimaryController.GetRawButton(BUTTON_ROLLER_ON));
		}
	}
コード例 #2
0
ファイル: RobotMain.cpp プロジェクト: RAR1741/RA13_RobotCode
    void TeleopPeriodic() {
    	//Target * target = GetLatestTarget();
    	//Begin DRIVER input section
    	if(driverGamepad->GetDPad()==Gamepad::kUp)
    		lc->setMode(1);
    	else if(driverGamepad->GetDPad()==Gamepad::kDown)
    		lc->setMode(6);
    	else
    		lc->setMode(0);
    	if(driverGamepad->GetDPad() == Gamepad::kRight)
    	{
    		cameraLight->Set(Relay::kOff);
    	}
    	else if(driverGamepad->GetDPad() == Gamepad::kLeft)
    	{
    		cameraLight->Set(Relay::kOn);
    	}
    	
    	if(driverGamepad->GetB())
    	{
    		cout << "Resetting the gyro! :D" << endl;
    		//driveGyro->Reset();
    		magicBox->resetGyro();
   		}
    	
    	bool modifySpeed = driverGamepad->GetRightBumper();
    	bool halfSpeed = driverGamepad->GetLeftBumper();
    	
    	/*
    	try {
    		std::string temp = SmartDashboard::GetString("TargetInfo");
    		cout << "temp: " << endl;
    	} catch (exception ex) {
    		cout << "bah! " << ex.what() << endl;
    	}*/
    	
    	//Target t = GetLatestTarget();
    	
    	/*
    	if (t.IsValid()) {
    		cout << "Valid target (" << (t.IsCenter() ? "center" : "side") << "):" << t.Distance() << " ft, " << t.X() << "," << t.Y() << endl;
    	} else {
    		//cout << "No valid target." << endl;
    	} */
    		
    	if(driverGamepad->GetBack())
    	{
    		cout << "Now driving in relation to the robot" << endl;
    			myDrive->setGyroDrive(false);
    	}
    	if(driverGamepad->GetStart())
    	{
    		cout << "Now driving in relation to the field (gyro)" << endl;
    		myDrive->setGyroDrive(true);
    	}
    	
    	// If the driver is holding the X button 
    	/*
    	if (driverGamepad->GetX()) {
    		// Stop using the joysticks to drive the robot, and let this function do it
    	    PointAtTarget(t);
    	} else { */
    		// We aren't auto-targeting. Reset the sequence.
    		target_state = RA13Robot::READY;
    		// Drive based on joysticks.
    		myDrive->Drive(driverGamepad->GetLeftX(), driverGamepad->GetLeftY(), 
    		    			driverGamepad->GetRightX(), magicBox->getGyroAngle(), modifySpeed,halfSpeed);
    	//}
    	//End DRIVER input section
    	
    	Gamepad::DPadDirection dir = operatorGamepad->GetDPad();
    	
    	if (dir != lastdir) {
    		switch(dir) {
    		case Gamepad::kUp:
    			manualAngle += 1;
    			break;
    		case Gamepad::kDown:
    			manualAngle -= 1;
    			break;
    		case Gamepad::kRight:
    			manualAngle += 0.25;
    			break;
    		case Gamepad::kLeft:
    			manualAngle -= 0.25;
    			break;
    		default:
    			break;
    		}
    	}
    	
    	//cout << "Current target angle: " << manualAngle << endl;
    	
    	//Begin OPERATOR input section
    		
    	if(operatorGamepad->GetBack())
    	{
    		myShooter->ResetShooterProcess(); // Re-homes the shooter
    	}
    	
    	if(operatorGamepad->GetLeftTrigger())
		{
    		myShooter->SetSpeeds(SHOOTER_FRONTWHEEL_SPEED,SHOOTER_REARWHEEL_SPEED); // (RPM,RPM)
		}
    	else if (operatorGamepad->GetLeftBumper())
    	{
    		myShooter->SetSpeeds(Config::GetSetting("shooter_main_speed_pyramid", 1500),
    							 Config::GetSetting("shooter_secondary_speed_pyramid", 2000));
    	}
    	else
    	{
    		myShooter->SetSpeeds(0,0); // (RPM,RPM)
    	}
    	
    	if(operatorGamepad->GetRightTrigger())
    	{
    		// TODO: Make this selectable somehow. This is probably too powerful for
    		// distant shots.
    		myShooter->ChamberFrisbee(Config::GetSetting("loader_power",-1));
    	}
    	else
    	{
    		myShooter->StopLoader();
    	}
    	
    	if(operatorGamepad->GetY())
    	{
    		myShooter->SetAngle(manualAngle);
    	}
    	if(operatorGamepad->GetX())
    	{
    		myShooter->SetAngle(Config::GetSetting("shooter_loading_angle",0)); //Angle for reloading
    		manualAngle = Config::GetSetting("shooter_loading_angle",0);
    	}
    	if(operatorGamepad->GetA()) //Shooting from load zone
    	{
    		myShooter->SetAngle(Config::GetSetting("load_zone_shooting_angle",13.25));
    		manualAngle = Config::GetSetting("load_zone_shooting_angle",13.25);
    	}
    	if(operatorGamepad->GetB())
    	{
    		myShooter->SetAngle(Config::GetSetting("pyramid_shooting_angle",23.25));
    		manualAngle = Config::GetSetting("pyramid_shooting_angle",23.25);
    	}
    	if(operatorGamepad->GetRightBumper())
    	{
    		//myShooter->SetAngle(Config::GetSetting("funnel_release_angle",35));
    		myShooter->SetAngle(Config::GetSetting("pyramid_basket_angle", 45));
    		manualAngle = Config::GetSetting("pyramid_basket_angle", 45);
    	}
    	if (operatorGamepad->GetLeftPush()) {
    		myShooter->ResetShooterProcess();
    	}
    	
    	// Do something similar, but don't touch the AngleJag.
    	if (operatorGamepad->GetRightPush()) {
    		myShooter->ResetShooterMotors();
    	}
    	
    	//pneumatics section
    	if(!driverGamepad->GetLeftTrigger())
    	{
    		pneumatics->extendEndgame();
    	}
    	else
    	{
    		pneumatics->retractEndgame();
    		myShooter->SetAngle(3);
    	}
    	
    	if(driverGamepad->GetRightTrigger())
    	{
    		pneumatics->extendCollector();
    	}
    	else
    	{
    		pneumatics->retractCollector();
    	}
    	//end pneumatics section
    	
    	lastdir = dir;
    	
    	myShooter->Process();
    	
    	//cout << "Shooter rear wheel" << myShooter->getRearWheelSpeed() << endl;
    	//End OPERATOR input section
   
    	
    	/*Manual control of the angle motor position using PID
    	 * THIS ASSUMES THE SHOOTER HAS BEEN ZERO'ED TO THE HOME POSITION SOMEHOW
    	if(operatorGamepad->GetLeftTrigger())
    	{
    		myShooter->ManualAngleControl(16); // (theta)
    	}
    	else
    	{
    		myShooter->ManualAngleControl(0);
    	}
    	*/ 
    	/*if (target != NULL) {
    		cout << "Target located. (" << target->X() << ',' << target->Y() << ") range is " << target->Distance() << " feet" << endl;
    	}
    	*/
//    	switch(myShooter->getFiringState())
//    	{
//    	case 1:
//    		lc->setMode(4);
////    		cout << "Spinning up!!" << endl;
//    		break;
//    	case 2:
//    		lc->setMode(5);
////    		cout << "Firing!!" << endl;
//    		break;
//    	default:
//    		lc->setMode(1);
//    		break;
//    	}
    	lc->useLights();
    	BuildAndSendPacket();
    	logdata();
    }
コード例 #3
0
ファイル: RobotMain.cpp プロジェクト: RAR1741/RA14_RobotCode
	/**
	 * Periodic code for autonomous mode should go here.
	 *
	 * Use this method for code which will be called periodically at a regular
	 * rate while the robot is in autonomous mode.
	 */
	void RA14Robot::AutonomousPeriodic() {
		StartOfCycleMaintenance();

		target->Parse(server->GetLatestPacket());
		float speed = Config::GetSetting("auto_speed", .5);
		cout<<"Auto Speed: "<<Config::GetSetting("auto_speed", 0)<<endl; // original .1
		float angle = gyro->GetAngle();
		float error = targetHeading - angle;
		float corrected = error * Config::GetSetting("auto_heading_p", .01);
		//float corrected = error * Config::GetSetting("auto_heading_p", .01);
		cout <<"Gyro angle: "<<angle<<endl;
		cout <<"Error: " << error << endl;
		//float lDrive = Config::GetSetting("auto_speed", -0.3) + (error * Config::GetSetting("auto_heading_p", .01));
		//float rDrive = Config::GetSetting("auto_speed", -0.3) - (error * Config::GetSetting("auto_heading_p", .01));
		// Reading p value from the config file does not appear to be working. When we get p from config, the math is not correct.
		float lDrive = Config::GetSetting("auto_speed", -0.3) + (error*0.01);
		float rDrive = Config::GetSetting("auto_speed", -0.3) - (error*0.01);
		cout << "Left: " << lDrive << endl;
		cout << "Right: " << rDrive << endl;
									
		
#ifndef DISABLE_AUTONOMOUS
		switch(auto_case)
		{
			case 0:
				// start master autonomous mode
				switch (auto_state) {
				case 0: // start
					auto_timer->Reset();
					auto_timer->Start();
					myCam->Process(false, false, false);
					break;
				case 1:
					myCam->Process(false, false, false);
					if (target->IsValid()) {
						auto_state = 2;
					} else if (auto_timer->Get() >= Config::GetSetting("auto_target_timeout", 1)) {
						auto_state = 10;
					}
					break;
				case 2:
					myCam->Process(false, false, false);
					if (target->IsHot()) {
						auto_state = 10;
					} else {
						if (auto_timer->Get() >= Config::GetSetting("auto_target_hot_timeout", 5)) {
							auto_state = 10;
						}
					}
					break;
				case 10:
					myCam->Process(true, false, false);
					if (myCam->IsReadyToRearm()) {
						auto_state = 11;
					}
					break;
				case 11:
					myCam->Process(false, false, false);
					myDrive->DriveArcade(corrected, speed);
					if (myDrive->GetOdometer() >= Config::GetSetting("auto_drive_distance", 100))
					{
						myDrive->Drive(0,0);
					}
					break;
				case 12:
					myDrive->Drive(0,0);
					break;
				default:
					cout << "Unknown state #" << auto_state << endl; 
					break;
				}
				// end master autonomous mode
				break;
			case 1:
				if( target->IsHot() && target->IsValid() )
				{
					cout << "Target is HOTTT taking the shot" << endl;
					//Drive forward and shoot right away
					//if( target->IsLeft() || target->IsRight() )
					//{
					if(myDrive->GetOdometer() <= 216 - Config::GetSetting("auto_firing_distance", 96)) //216 is distance from robot to goal
					{
						myDrive->Drive(corrected,speed);
					}
					else
					{
						myDrive->Drive(0,0);
						cout << "FIRING" << endl;
#ifndef DISABLE_SHOOTER
						myCam->Process(1,0,0);
#endif //Ends DISABLE_SHOOTER
					}
				/*}
				else
				{
					cout<<"Error"<<endl;
				}*/
				}
				else if(target->IsValid())
				{
					cout << "Target is valid, but cold. Driving and waiting" << endl;
					//Drive forward and wait to shoot 
					if(myDrive->GetOdometer() <= 216 - Config::GetSetting("auto_firing_distance", 96)) //216 is distance from robot to goal
					{
						myDrive->Drive(corrected, speed);
					}
					else
					{
						// now at the firing spot.
						myDrive->Drive(0,0);
						if( target->IsHot() )
						{
							cout << "FIRING" << endl;
#ifndef DISABLE_SHOOTER
							myCam->Process(1,0,0);
#endif //Ends DISABLE_SHOOTER
						}
					}
				}
				else
				{
					//Not valid
					cout << "Not valid target." << endl;
				}
				break;
			
			case 2:
#ifndef DISABLE_SHOOTER
			myCam->Process(false,false,false);
			if(auto_timer->Get() >= 4.0)
			{
				myCam->Process(true,false,false);
			}
#endif //Ends DISABLE_SHOOTER
			
			/*if(myDrive->GetOdometer() <= 216 - Config::GetSetting("auto_firing_distance", 96)) //216 is distance from robot to goal
			{
				cout<<"Distance traveled: "<<myDrive->GetOdometer()<<" inches"<<endl;
				myDrive->Drive(corrected, speed);
			}
			else
			{
				myDrive->Drive(0,0);
				cout << "FIRING" << endl;
			}*/
			if(auto_timer->Get() < 5.0)
			{
				cout<<"Waiting....."<<endl;
			}
			else
			{
				cout<<"Distance traveled: "<<myDrive->GetOdometer()<<" inches"<<endl;
				myDrive->Drive(-.5, -.5);
			}
				
			break;
			
			case 3:
#ifndef DISABLE_SHOOTER
			switch(auto_state) {
				case 0:
					// Home/rearm
					// fire, rearm, eject
					myCam->Process(false, false, false);
					if (myCam->IsReadyToFire()) {
						auto_state = 1;
					}
					break;
				case 1:
					// fire
					myCam->Process(true, false, false);
					if (myCam->IsReadyToRearm()) {
						auto_state = 2;
					}
					break;
				case 2:
					// rearm
					myCam->Process(false, true, false);
					if (myCam->IsReadyToFire()) {
						auto_state = 3;
						auto_timer->Reset();
						auto_timer->Start();
					}
					break;
				case 3:
					myCam->Process(false, false, false);
					myCollection->SpinMotor(Config::GetSetting("intake_roller_speed", .7));
					if (auto_timer->HasPeriodPassed( Config::GetSetting("auto_collection_delay", 1.0) )) {
						auto_state = 4;
					}
					break;
				case 4:
					// fire again!
					myCam->Process(true, false, false);
					auto_state = 5;
					break;
				case 5:
					myCam->Process(false, false, false);
					
					if(myDrive->GetOdometer() <= 216 - Config::GetSetting("auto_firing_distance", 96)) //216 is distance from robot to goal
					{
						myDrive->Drive(corrected, speed);
					} else {
						// now at the firing spot.
						auto_state = 6;
						myDrive->Drive(0,0);
					}
					break;
				case 6:
					myCollection->RetractArm();
					break;
				default:
					cout << "Error, unrecognized state " << auto_state << endl;
			}
#endif //Ends DISABLE_SHOOTER
			
			break;
			
			case 4:	/* One ball Autonomous - Drive forward specific distance, stop then shoot.*/
#ifndef DISABLE_SHOOTER
		
					switch(auto_state) {
		
						case 0:		//Reset odometer, lower the arm and set launcher to ready to fire
							myDrive->ShiftUp();
							myDrive->ResetOdometer();
							myCollection->ExtendArm();
							myCam->Process(false,true,false);
							auto_state = 1;
							break;
						case 1:		// Start driving forward
							// myDrive->Drive(-.5, -.5);
							//myDrive->Drive(lDrive, rDrive);
							myDrive->DriveArcade(corrected, speed);
							auto_state = 2;
							break;
						case 2:		// Continue driving until required distance
							if(myDrive->GetOdometer() >= Config::GetSetting("auto_drive_distance", 96)) {
								myDrive->Drive(0, 0);
								auto_state = 3;
							}
							break;
						case 3:		// Fire launcher
							myCam->Process(true,false,false);
							auto_state = 4;
							break;
						case 4:		// Idle state
							break;
					}
			
#endif //Ends DISABLE_SHOOTER
			
			break;
			
			case 5:	// Two Ball Autonomous - Drag ball 2 while driving forward specific distance, stop then shoot, load shoot next ball
#ifndef DISABLE_SHOOTER
				// By Hugh Meyer - April 1, 2014
				
					switch(auto_state) {
					cout << "Executing mr m's auton" << endl;
				
						case 0:		// Set low gear, reset odometer, extend pickup arm, set launcher ready to fire, set wait timer
							//myDrive->ShiftUp();				// Shift to low gear
							myDrive->ShiftDown();
							myDrive->ResetOdometer();			// Reset odometer to zero
							myCollection->ExtendArm();			// Extend arm to pickup position
							myCam->Process(false,true,false);	// Set launcher to ready to fire position
							auto_timer->Reset();				// Set timer to zero
							auto_timer->Start();				// Start the timer for a short delay while pickup extends
							auto_state = 1;						// Go on  to next state
							break;
																			
						case 1:		// Wait for timer to expire - Let arm get extended and stabalized
							if (auto_timer->HasPeriodPassed( Config::GetSetting("auton5_extend_delay", 1.0) )) {
								auto_state = 2;
							}
							break;
						case 21: 	//reset gyro and reset timer
							gyro->Reset();
							auto_timer->Reset();
							auto_timer->Start();
							auto_state = 22;
							break;
						case 22:
							if(auto_timer->HasPeriodPassed(Config::GetSetting("auton5_gyro_reset_delay", 2) )){
								auto_state = 2;
							}	
							break;								
						case 2:		// Activate pickup roller motor to drag speed, start driving forward
							myCollection->SpinMotor(Config::GetSetting("auton5_drag_speed", 0.3));	// Start motor to drag ball 2
							//myDrive->DriveArcade(corrected, speed);		// Drive straight
							myDrive->DriveArcade(0.0, Config::GetSetting("auton5_drive_speed", -0.7)); //Start driving forwards
							auto_state = 3;
							break;
						case 3:		// Continue driving until required distance, stop driving, stop pickup roller motor
							if(myDrive->GetOdometer() >= Config::GetSetting("auton5_drive_distance", 96.0))
							{
								myCollection->SpinMotor(0);		// Stop collector pickup motor
								myDrive->Drive(0, 0);			// Stop driving
								auto_state = 31;				// On to next state
							}
							break;
						case 31: // slightly un-eject herded ball to avoid contact with launch ball
							myCollection->SpinMotor(Config::GetSetting("auton5_eject_speed", 0.3));
							auto_timer->Reset();
							auto_timer->Start(); // setup timer to time un-eject
							auto_state = 32;
							break;
						case 32: // once timer has run out, stop ejection and fire
							if (auto_timer->HasPeriodPassed(Config::GetSetting("auton5_uneject_time", 0.25))) {
								myCollection->SpinMotor(0); // stop spinner
								auto_state = 4;
							}
							break;
						case 4:		// Fire launcher to shoot first ball, set wait timer
							myCam->Process(true,false,false);	// Fire ball # 1
							auto_timer->Reset();				// Set timer to zero
							auto_timer->Start();				// Start the timer for a short delay while ball launches
							auto_state = 5;						// On to next state
							break;
						case 5:		// Wait for timer to expire after ball one launches
							if (auto_timer->HasPeriodPassed( Config::GetSetting("auton5_ball_1_launch_delay", 1.0) )) {
								auto_state = 6;					// On to next state
							}
							break;
						case 6:		// set launcher ready to fire for ball 2, set wait timer
							myCam->Process(false,true,false);	// Set launcher to ready to fire position
							auto_timer->Reset();				// Set timer to zero
							auto_timer->Start();				// Start the timer for a short delay while ball launches
							auto_state = 7;						// On to next state
							break;
						case 7:		// Wait for timer to expire
							if (auto_timer->HasPeriodPassed( Config::GetSetting("auton5_ball_2_ready2fire_delay", 1.0) )) {
								auto_state = 8;					// Wait for launcher to get ready to accept ball 2
							}
							break;
						case 8:		// Activate pickup roller motor to load ball 2, set wait timer
							myCollection->SpinMotor(Config::GetSetting("auton5_intake_roller_speed", 0.7));
							auto_timer->Reset();				// Set timer to zero
							auto_timer->Start();				// Start the timer for a short delay while ball 2 loads
							auto_state = 9;						// On to next state
							break;
						case 9:		// Wait for timer to expire while ball 2 gets collected into launcher
							if (auto_timer->HasPeriodPassed( Config::GetSetting("auton5_ball_2_settle_delay", 1.0) )) {
								auto_state = 10;				// Wait for ball 2 to be collected and settle
							}
							break;

						case 19:	// Drive backwards a little bit, set wait timer
							myDrive->DriveArcade(-1*corrected, -1*speed);		// Drive straight
							auto_timer->Reset();				// Set timer to zero
							auto_timer->Start();				// Start the timer for a short delay while ball launches
							auto_state = 20;				// Wait for ball 2 to be collected and settle
							break;
		
							
						case 20:		// Wait for timer to expire while ball 2 gets collected into launcher
							if (myDrive->GetOdometer() <= 
									  Config::GetSetting("auton5_drive_distance", 96) 
									- Config::GetSetting("auton5_backup_distance", 6))	{
								myDrive->Drive(0,0);
								auto_state = 10;
							}
							break;
						case 10:	// Fire launcher to shoot second ball and stop roller
							myCam->Process(true,false,false);	// Fire ball # 2
							myCollection->SpinMotor(0);			// Stop spinning the roller
							auto_state = 11;					// All done so go to idle state
							break;
						case 11:	// Idle state
							auto_state = 11;
							break;
/*						case 12:	// More states if we need them for changes.
							auto_state = 13;
							break;
						case 13:	// 
							auto_state = 14;
							break;
						case 14:	// 
							auto_state = 15;
							break;
						case 15:	// 
							auto_state = 15;
							break;
*/
					}
					
#endif //Ends DISABLE_SHOOTER
					
			break;
				
			
			case 6:	// Two Ball Autonomous - Drive forward specific distance, stop then shoot, backup get second ball, drive, shoot
#ifndef DISABLE_SHOOTER
				// By Hugh Meyer - April 1, 2014
					
					switch(auto_state) {
						
						case 0:		// Set low gear, reset odometer, extend pickup arm, set launcher ready to fire
							myDrive->ShiftDown();				// Shift to low gear
							myDrive->ResetOdometer();			// Reset odometer to zero
							myCollection->ExtendArm();			// Extend arm to pickup position
							myCam->Process(false,true,false);	// Set launcher to ready to fire position
							auto_state = 1;						// Go on to next state
							break;
						case 1:		// Drive forward
							myDrive->DriveArcade(corrected, speed);
							auto_state = 2;						// On to next state
							break;
						case 2:		// Continue driving forward until the specific distance is traveled
							if(myDrive->GetOdometer() >= Config::GetSetting("auton6_drive_forward_distance", 96.0)) {
								myDrive->Drive(0, 0);
								auto_state = 3;
							}
							break;
						case 3:		// Fire launcher to launch first ball, set timer
							myCam->Process(true,false,false);	// Launch ball # 1
							auto_timer->Reset();				// Set timer to zero
							auto_timer->Start();				// Start the timer for a short delay while ball launches
							auto_state = 4;						// On to next state
							break;	
						case 4:		// Wait for timer while ball launcher fires
							if (auto_timer->HasPeriodPassed( Config::GetSetting("auton6_ball_1_fire_delay", 1.0) )) {
								auto_state = 5;					// On to next state
							}
							break;
						case 5:		// Reset Odometer, Drive backwards, set launcher to ready to fire position, turn on pickup
							cout<<"Corrected Values: "<<corrected<<endl; 
							cout<<"Speed: "<< -1 * speed<<endl;
							myDrive->ResetOdometer();				// Reset odometer to zero
							myDrive->DriveArcade(-1* corrected, -1 * speed);	// Drive backwards
							myCam->Process(false,true,false);		// Set launcher to ready to fire position
							myCollection->SpinMotor(-1 * Config::GetSetting("auton6_intake_roller_speed", 0.7));	// Turn on pickup
							auto_state = 6;						// On to next state
							break;
						case 6:		// Continue driving backwards a specific distance
							if(myDrive->GetOdometer() <= -1 * Config::GetSetting("auton6_drive_forward_distance", -96.0)) {
								auto_state = 7;					// On to next state
							}
							break;
						case 7:		// Set timer
							auto_timer->Reset();				// Set timer to zero
							auto_timer->Start();				// Start the timer for a short delay while ball launches
							auto_state = 8;						// On to next state
							break;
						case 8:		// Wait for timer while ball loads and settles
							if (auto_timer->HasPeriodPassed( Config::GetSetting("auton6_ball_2_load_delay", 1.0) )) {
								auto_state = 9;					// On to next state
								myDrive->ResetOdometer();
							}
							break;
						case 9:		// Drive forwards
							myDrive->DriveArcade(/*corrected*/ 0.01, speed);
							auto_state = 10;					// On to next state
							break;
						case 10:	// Continue driving forward until the specific distance is traveled
							cout << "I am driving forward: " << myDrive->GetOdometer() << endl;
							myDrive->DriveArcade(0.01, speed);
							if(myDrive->GetOdometer() >= Config::GetSetting("auton6_drive_forward_distance", 96.0)) {
								myDrive->Drive(0, 0);
								auto_state = 11;				// On to next state
							}
							break;
						case 11:	// Fire launcher to launch second ball
							myCam->Process(true,false,false);	// Launch ball # 2
							auto_state = 15;					// On to next state
							break;
/*						case 12:	// 
							auto_state = 13;					// On to next state
							break;
						case 13:	// 
							auto_state = 14;					// On to next state
							break;
						case 14:	// 
							auto_state = 15;					// All done so go to idle state
							break;
*/
						case 15:	// Idle state
							auto_state = 15;
							break;

					}
					cout << myDrive->GetOdometer() << endl;
							
#endif //Ends DISABLE_SHOOTER
							
			break;
			case 7:	// Two Ball Autonomous - Drag ball 2 while driving forward specific distance, stop then shoot, load shoot next ball
			#ifndef DISABLE_SHOOTER
							// By Hugh Meyer - April 1, 2014
							
								switch(auto_state) {
								cout << "Executing mr m's auton" << endl;
							
									case 0:		// Set low gear, reset odometer, extend pickup arm, set launcher ready to fire, set wait timer
										myDrive->ShiftUp();				// Shift to high gear
										//myDrive->ShiftDown();
										myDrive->ResetOdometer();			// Reset odometer to zero
										myCollection->ExtendArm();			// Extend arm to pickup position
										myCam->Process(false,true,false);	// Set launcher to ready to fire position
										auto_timer->Reset();				// Set timer to zero
										auto_timer->Start();				// Start the timer for a short delay while pickup extends
										auto_state = 1;						// Go on  to next state
										break;
																						
									case 1:		// Wait for timer to expire - Let arm get extended and stabalized
										if (auto_timer->HasPeriodPassed( Config::GetSetting("auton7_extend_delay", 1.0) )) {
											auto_state = 2;
										}
										break;
									case 21: 	//reset gyro and reset timer
										gyro->Reset();
										auto_timer->Reset();
										auto_timer->Start();
										auto_state = 22;
										break;
									case 22:
										if(auto_timer->HasPeriodPassed(Config::GetSetting("auton7_gyro_reset_delay", 2) )){
											auto_state = 2;
										}	
										break;								
									case 2:		// Activate pickup roller motor to drag speed, start driving forward
										myCollection->SpinMotor(Config::GetSetting("auton7_drag_speed", 0.3));	// Start motor to drag ball 2
										//myDrive->DriveArcade(corrected, speed);		// Drive straight
										myDrive->DriveArcade(0.05, speed);
										auto_state = 3;
										break;
									case 3:		// Continue driving until required distance, stop driving, stop pickup roller motor
										if(myDrive->GetOdometer() >= Config::GetSetting("auton7_drive_distance", 96.0))
										{
											myCollection->SpinMotor(0);		// Stop collector pickup motor
											myDrive->Drive(0, 0);			// Stop driving
											auto_state = 31;				// On to next state
										}
										break;
									case 31: // slightly un-eject herded ball to avoid contact with launch ball
										myCollection->SpinMotor(Config::GetSetting("auton7_eject_speed", 0.3));
										auto_timer->Reset();
										auto_timer->Start(); // setup timer to time un-eject
										auto_state = 32;
										break;
									case 32: // once timer has run out, stop ejection and fire
										if (auto_timer->HasPeriodPassed(Config::GetSetting("auton7_uneject_time", 0.25))) {
											myCollection->SpinMotor(0); // stop spinner
											auto_state = 4;
										}
										break;
									case 4:		// Fire launcher to shoot first ball, set wait timer
										myCam->Process(true,false,false);	// Fire ball # 1
										auto_timer->Reset();				// Set timer to zero
										auto_timer->Start();				// Start the timer for a short delay while ball launches
										auto_state = 5;						// On to next state
										break;
									case 5:		// Wait for timer to expire after ball one launches
										if (auto_timer->HasPeriodPassed( Config::GetSetting("auton7_ball_1_launch_delay", 1.0) )) {
											auto_state = 6;					// On to next state
										}
										break;
									case 6:		// set launcher ready to fire for ball 2, set wait timer
										myCam->Process(false,true,false);	// Set launcher to ready to fire position
										auto_timer->Reset();				// Set timer to zero
										auto_timer->Start();				// Start the timer for a short delay while ball launches
										auto_state = 7;						// On to next state
										break;
									case 7:		// Wait for timer to expire
										if (auto_timer->HasPeriodPassed( Config::GetSetting("auton7_ball_2_ready2fire_delay", 1.0) )) {
											auto_state = 8;					// Wait for launcher to get ready to accept ball 2
										}
										break;
									case 8:		// Activate pickup roller motor to load ball 2, set wait timer
										myCollection->SpinMotor(Config::GetSetting("auton7_intake_roller_speed", 0.7));
										auto_timer->Reset();				// Set timer to zero
										auto_timer->Start();				// Start the timer for a short delay while ball 2 loads
										auto_state = 9;						// On to next state
										break;
									case 9:		// Wait for timer to expire while ball 2 gets collected into launcher
										if (auto_timer->HasPeriodPassed( Config::GetSetting("auton7_ball_2_settle_delay", 1.0) )) {
											auto_state = 10;				// Wait for ball 2 to be collected and settle
										}
										break;

									case 19:	// Drive backwards a little bit, set wait timer
										myDrive->DriveArcade(-1*corrected, -1*speed);		// Drive straight
										auto_timer->Reset();				// Set timer to zero
										auto_timer->Start();				// Start the timer for a short delay while ball launches
										auto_state = 20;				// Wait for ball 2 to be collected and settle
										break;
					
										
									case 20:		// Wait for timer to expire while ball 2 gets collected into launcher
										if (myDrive->GetOdometer() <= 
												  Config::GetSetting("auton7_drive_distance", 96) 
												- Config::GetSetting("auton7_backup_distance", 6))	{
											myDrive->Drive(0,0);
											auto_state = 10;
										}
										break;
									case 10:	// Fire launcher to shoot second ball and stop roller
										myCam->Process(true,false,false);	// Fire ball # 2
										myCollection->SpinMotor(0);			// Stop spinning the roller
										auto_state = 11;					// All done so go to idle state
										break;
									case 11:	// Idle state
										auto_state = 11;
										break;
			/*						case 12:	// More states if we need them for changes.
										auto_state = 13;
										break;
									case 13:	// 
										auto_state = 14;
										break;
									case 14:	// 
										auto_state = 15;
										break;
									case 15:	// 
										auto_state = 15;
										break;
			*/
								}
								
			#endif //Ends DISABLE_SHOOTER
								
						break;
/*			
			
			case 7:	// Extra structure for more changes
#ifndef DISABLE_SHOOTER
				// By Hugh Meyer - April 1, 2014
					
					switch(auto_state) {
						
						case 0:		// Set low gear, reset odometer, extend pickup arm, set launcher ready to fire, drive foward
							myDrive->ShiftDown();				// Shift to low gear
							myDrive->ResetOdometer();			// Reset odometer to zero
							myCollection->ExtendArm();			// Extend arm to pickup position
							myCam->Process(false,true,false);	// Set launcher to ready to fire position
							myDrive->Drive(lDrive, rDrive);		// Drive straight
							auto_state = 1;						// Go on  to next state
							break;
						case 1:		// 
							auto_state = 2;						// On to next state
							break;
						case 2:		// 
							auto_state = 3;						// On to next state
							break;
						case 3:		// 
							auto_state = 4;						// On to next state
							break;	
						case 4:		// 
							auto_state = 5;						// On to next state
							break;
						case 5:		// 
							auto_state = 6;						// On to next state
							break;
						case 6:		// 
							auto_state = 7;						// On to next state
							break;
						case 7:		// 
							auto_state = 8;						// On to next state
							break;
						case 8:		// 
							auto_state = 9;						// On to next state
							break;
						case 9:		// 
							auto_state = 10;					// On to next state
							break;
						case 10:	// 
							auto_state = 11;					// On to next state
							break;
						case 11:	// 
							auto_state = 12;					// On to next state
							break;
						case 12:	// 
							auto_state = 13;					// On to next state
							break;
						case 13:	// 
							auto_state = 14;					// On to next state
							break;
						case 14:	// 
							auto_state = 15;					// All done so go to idle state
							break;
						case 15:	// Idle state
							auto_state = 15;
							break;
					}
								
#endif //Ends DISABLE_SHOOTER
									
			break;
*/								
			
			default:
			cout<<"Error in autonomous, unrecognized case: "<<auto_case<<endl;
		}
//#else
//		if (myDrive->GetOdometer() <= (4 * acos(-1) ) ) //216 is distance from robot to goal
//		{
//			float speed = Config::GetSetting("auto_speed", .3);
//			cout << myDrive->GetOdometer() << endl;
//			myDrive->Drive(speed, speed);
//		} else {
//			cout << "Finished driving";
//			myDrive->Drive(0, 0);
//		}
#endif //Ends DISABLE_AUTONOMOUS

		EndOfCycleMaintenance();
	}
コード例 #4
0
ファイル: Robot.cpp プロジェクト: Team2530/RobotCode2016
	//completes all necessary functions for teleop driving/operating
	void TeleopPeriodic(){
		Drive->Drive();
		Drive->stayAtTheTop();

	}