Thread: arcade drive
View Single Post
  #3   Spotlight this post!  
Unread 13-03-2015, 16:00
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is online now
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,722
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: arcade drive

I cleaned your code up a bit. One issue you had was that you were creating new references to your pistons every ~20ms which is a bad thing to do. You were also sharing the same reference for ever single piston, also a bad thing to do. You can see that I moved the created 2 more pistons and created their references in robotInit().

Code:
package org.usfirst.frc.team5676.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.RobotDrive; 



public class Robot extends IterativeRobot {
    RobotDrive myRobot;
    Joystick stick;
    DoubleSolenoid piston1;
	DoubleSolenoid piston2;
	DoubleSolenoid piston3;
    
    public void robotInit() {
    	myRobot = new RobotDrive (0, 1, 2, 3);
    	stick = new Joystick(0);
    	piston1 = new DoubleSolenoid(0, 1)
		piston2 = new DoubleSolenoid(2, 3);
		piston3 = new DoubleSolenoid(4, 5);
    }
    
    public void autonomousPeriodic() {

    }

	public void teleopPeriodic() {
        	
		myRobot.arcadeDrive(stick);
			  
					
		if (stick.getRawButton(5)) {
			piston1.set(DoubleSolenoid.Value.kForward);	
			ystem.out.println("'A' button is pressed: Piston moves forward");
		} else if (stick.getRawButton(6)) {
			piston1.set(DoubleSolenoid.Value.kReverse); 
			System.out.println("'B' button is pressed: Piston moves backward");
		} else {
			piston1.set(DoubleSolenoid.Value.kOff);		
		}
			
		if (stick.getRawButton(3)) {
			Ppiston2.set(DoubleSolenoid.Value.kForward);	
			System.out.println("'A' button is pressed: Piston moves forward");
		} else if (stick.getRawButton(4)) m{
			piston2.set(DoubleSolenoid.Value.kReverse); 
			System.out.println("'B' button is pressed: Piston moves backward");
		} else {
			piston2.set(DoubleSolenoid.Value.kOff);		
		}
		
		if (stick.getRawButton(1)) {
			piston3.set(DoubleSolenoid.Value.kForward);	
			System.out.println("'A' button is pressed: Piston moves forward");
		} else if (stick.getRawButton(2)) {
			piston3.set(DoubleSolenoid.Value.kReverse); 
			System.out.println("'B' button is pressed: Piston moves backward");
		} else {
			piston3.set(DoubleSolenoid.Value.kOff); 
		}
	}

    /**
     * This function is called periodically during test mode
     */

    public void testPeriodic() {
    
    }  
}
Reply With Quote