View Single Post
  #9   Spotlight this post!  
Unread 04-02-2015, 22:58
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Electrical/Programming Mentor
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,784
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Limit Swtich Help

Quote:
Originally Posted by curtis0gj View Post
I have setup the limit switch program with the suggestions but I am attempting to setup reverse for the victors. Also I am trying to setup the same if statement layout for my relays does this look okay?
Code:
public class Robot extends SampleRobot {
    RobotDrive robot;
    Joystick stick;
    Joystick xbox;
    Relay spike1;
    Relay spike2;
    Victor victor1;
    Victor victor2;
    DigitalInput limit;
    boolean limitPressed = false;

    public Robot() {
    	robot = new RobotDrive(0, 1);
        stick = new Joystick(1);
        xbox = new Joystick(0);
        spike1 = new Relay(0);
        spike2 = new Relay(1);
        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());
            limitPressed = limit.get(); //Do I want this out side of my while operator control loop?
            System.out.println("limitPressed=" + limitPressed); //Read the RoboRIO log for some values before you go all out on your motors.
            
            if(limitPressed) {
            	victor1.set(0);
            	victor2.set(0);
            } else if (xbox.getRawButton(4)) {
            	victor1.set(1);
            	victor2.set(1);
            } else {
            	victor1.set(0);
            	victor1.set(0);
            }
            if(xbox.getRawButton(1)) {
            	victor1.set(-1);
            	victor1.set(-1);
            } else {
            	victor1.set(0);
            	victor2.set(0);
            }
            if(xbox.getRawButton(3)) {
            	spike1.set(Relay.Value.kForward);
            	spike2.set(Relay.Value.kForward);
            } else {
            	spike1.set(Relay.Value.kOff);
            	spike2.set(Relay.Value.kOff);            	
            }
            if(xbox.getRawButton(2)) {
            	spike1.set(Relay.Value.kReverse);
            	spike2.set(Relay.Value.kReverse);	
            } else {
            	spike1.set(Relay.Value.kOff);
            	spike2.set(Relay.Value.kOff);
            }    
    	}
    }
The relays look good. In addition to double victor1's which have already been pointed out, consider the effect of pushing buttons 1 and 4 at the same time - you'll oscillate between full speed forward and full speed reverse. It's probably not a big deal, as your driver shouldn't be pushing them both at the same time anyways, but I personally like to prevent that sort of situation. Using some fairly simple logic, you can reduce everything dealing with the victors to a single if/else-if/else block. Something like:
Code:
if ()//the conditions you want it to go up
{
    //go up
}
else if ()//the conditions you want it to go down
{
    //go down
}
else
{
    //stop
}
You can set up the conditionals using the AND (&&) operator, the OR (||) operator, and the not (!). For example, to say "when button 4 is pressed and the limit switch is not pressed", you would do "xbox.getRawButton(4) || !limitPressed". Figuring out how to use logic like this is a very powerful tool while programming!
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016; Galileo 2016; Iowa 2017
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
Reply With Quote