View Single Post
  #2   Spotlight this post!  
Unread 16-10-2015, 09:20
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Help first time programmer

It is preferable to use code tags when posting code in a forum. To use a code tag put [/code] at the end of the code and [code] at the beginning.

Code:
public class Robot extends IterativeRobot {

	Jaguar jagLF = new Jaguar(0);// default turn
	Jaguar jagLR = new Jaguar(1); //default turn
	Jaguar jagRF = new Jaguar(2);//default turn
	Jaguar jagRR = new Jaguar(3); // default turn
	Jaguar jagOmF = new Jaguar(6); //omniwheel turn
	Jaguar jagOmB = new Jaguar(7); // omniwheel turn
	RobotDrive drive = new RobotDrive(jagLF, jagLR, jagRF, jagRR);	
	RobotDrive drive1 = new RobotDrive(jagOmF, jagOmB);
	Joystick stick;
	int autoLoopCounter;
	Relay Relay1 = new Relay(0);
	Relay Relay2 = new Relay(1);

	/**
	* This function is run when the robot is first started up and should be
	* used for any initialization code.
	*/
	public void robotInit() {
		stick = new Joystick(0);
	}

	/**
	* This function is run once each time the robot enters autonomous mode
	*/
	public void autonomousInit() {
		autoLoopCounter = 0;
	}

	/**
	* This function is called periodically during autonomous
	*/
	public void autonomousPeriodic() {
		if(autoLoopCounter < 100) //Check if we've completed 100 loops (approximately 2 seconds)
		{
		drive.drive(-0.5, 0.0); // drive forwards half speed
		autoLoopCounter++;
		} else {
		drive.drive(0.0, 0.0); // stop robot
		}
	}

	/**
	* This function is called once each time the robot enters tele-operated mode
	*/
	public void teleopInit(){
	}

	/**
	* This function is called periodically during operator control
	*/
	public void teleopPeriodic() {
		//drive.arcadeDrive(stick);
		//drive1.arcadeDrive(stick);
		boolean omni = false;
		boolean main = true;

		while(main == true)
		{
			drive.arcadeDrive(stick);

			if(stick.getRawButton(3))
			{
			main = false;
			omni = true;
			}
		}

		while(omni == true)
		{
			drive1.arcadeDrive(stick);

			if(stick.getRawButton(3))
			{
				omni = false;
				main = true;
			}
		}
	}
}
One issue is that you are trying to use a while loop when you really want to be using an if statement. The teleopPeriodic() method is already repeatedly called aprox every 20ms, which actually creates a kind of loop for you. What you put in the method body should be similar to a loop body.

First, you need to determine if the button is pressed:
Code:
boolean buttonPressed = stick.getRawButton(3);
Next you can use that to determine which drive to use:
Code:
if (buttonPressed) {
	drive1.arcadeDrive(stick);
} else {
	drive.arcadeDrive(stick);
}
So your teleopPeriodic method should look like this:
Code:
public void teleopPeriodic() {
	boolean buttonPressed = stick.getRawButton(3);

	if (buttonPressed) {
		drive1.arcadeDrive(stick);
	} else {
		drive.arcadeDrive(stick);
	}
}
Reply With Quote