View Single Post
  #1   Spotlight this post!  
Unread 02-04-2015, 05:16 PM
curtis0gj curtis0gj is offline
Registered User
FRC #5033 (Beavertronics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2015
Location: Canada
Posts: 121
curtis0gj will become famous soon enough
Limit Swtich Help

Hi guys, our team is trying to use a limit switch to stop the lifting mech powered by 2 victor motor controllers from bottoming out or flying off the top. But I can't get the switch to work properly.

Code:
public class Robot extends SampleRobot {
	
    RobotDrive robot;
    Joystick stick;
    Joystick xbox;

    Victor victor1;
    Victor victor2;
    DigitalInput limit;
    
    
    boolean limitPressed = false;

    boolean buttonPressedForwardVictor = false;

public Robot() {
    	
    	robot = new RobotDrive(0, 1);
        stick = new Joystick(1);
        xbox = new Joystick(0);

        limit = new DigitalInput(4);	
        
        victor1 = new Victor(4);
        victor2 = new Victor(5);
 
    }

public void operatorControl() {
    	
    	while (isOperatorControl() && isEnabled()) {
        	
            stick.getThrottle();
            robot.arcadeDrive(stick.getY(), stick.getX());
            Timer.delay(0.1);
     
            if(limit.get()) {
            	
            	limitPressed = true;
            	
            }
            
            if(limitPressed = true) {
            	
            	victor1.set(0);
            	victor2.set(0);
            	
            }
            
            if (xbox.getRawButton(4)) {
            	
            	victor1.set(1);
            	victor2.set(1);
            	buttonPressedForwardVictor = true;
            	
            } else if (buttonPressedForwardVictor = true) {
            	
            	victor1.set(0);
            	victor2.set(0);
            	buttonPressedForwardVictor = false;
            } 
            
            if (xbox.getRawButton(1)) {
            	
            	victor1.set(-1);
            	victor2.set(-1);
            }
            
            	
            }
            
    	}
Reply With Quote