View Single Post
  #39   Spotlight this post!  
Unread 06-02-2015, 21:36
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
Re: Limit Swtich Help

I have one final question, I noticed that when my victors are set in reverse and I press the limit switch the victors don't stop very well. Is there anyway to fix this or is it fine the way it is. Here's the code

Code:
public void operatorControl() {
    	
    	while (isOperatorControl() && isEnabled()) {
    	    double leftaxis = xbox.getRawAxis(1);
            robot.arcadeDrive(stick.getY() * 0.5, stick.getX() * 0.5); //Change the 0.5 for sensitivity, I removed get throttle I may need it again.
            limitPressed = limit.get(); 
            limitPressed2 = limit2.get();
            limitPressed3 = limit3.get();
            limitPressed4 = limit4.get();
            
            /*limitPressed will be the bottom of the lead screw.
             * limitPressed2 will be the top of the lead screw.
             * limitPressed3 will the for the left minimum arm distance.
             * limitPressed4 will be for the max arm distance.
             * The print lines are helpful for testing boolean states.
            //System.out.println("limitPressed=" + limitPressed); //Read the RoboRIO log for some values.
            //System.out.println("limitPressed2=" + limitPressed2);
            //System.out.println("limitPressed3=" + limitPressed3);
            //System.out.println("limitPressd4=" + limitPressed4);
            */

            if(limitPressed || limitPressed2 == false || limitPressed3 == false || limitPressed4 == false) {
            	victor1.set(0);
            	victor2.set(0);
            } else if (-leftaxis > 0.5) {
            	victor1.set(1);
            	victor2.set(1);
            } else {
            	victor1.set(0);
            	victor2.set(0);
            }
            if(leftaxis > 0.5) {
            	victor1.set(-1);
            	victor2.set(-1);
            } else {
            	victor1.set(0);
            	victor2.set(0);
            }
            if(xbox.getRawButton(4)) {
            	spike1.set(Relay.Value.kForward);
            	spike2.set(Relay.Value.kForward);
            } else if(xbox.getRawButton(1)) {
            	spike1.set(Relay.Value.kReverse);
            	spike2.set(Relay.Value.kReverse);     
            } else {
            	spike1.set(Relay.Value.kOff);
            	spike2.set(Relay.Value.kOff);            	
            }
    	}
    }
Reply With Quote