View Single Post
  #5   Spotlight this post!  
Unread 13-11-2014, 11:24
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: Sequences of Commands

Quote:
Originally Posted by WilliamR View Post
Here is the code that we are using to test the latching of our winch after a limit switch is activated.

Code:
void shoot() {
        latchPneumatic.set(DoubleSolenoid.Value.kReverse);
    }
    
    void winch(int direction, double unwindTime) {
        if (direction == 1) {
            while (catapultLimitSwitch.get() == true) {
                winchMotor.set(1);
            }
            //latchPneumatic.set(DoubleSolenoid.Value.kReverse);
            winchMotor.set(0);
        }
        else if (direction == -1) {
            for (int i = 0; i < unwindTime*10000; i++) winchMotor.set(-1);
            winchMotor.set(0);
        }
        else winchMotor.set(0);
    }
What you are doing here is very dangerous when using the Command Based approach. Long acting while loops are a big no no and should be avoided at all costs. What you want to do is use a single command for each action and combine them into a command group to get them to work in sequence. Your command for moving the wench should be similar to this:

Code:
public void execute() {
     shooter.winch(1);
}

public boolean isFinished() {
     if (timeNow - startTime > unwindTime) {
          return true;
     }
}

public void end() {
     shooter.winch(0);
}
This will run the shooter motor at the power level provided in the parameter:
Code:
shooter.winch(x)
You will use this to tell the command when it is finished:
Code:
public boolean isFinished() {
     if (timeNow - startTime > unwindTime) {
          return true;
     }
}
This will stop the motor once the command is finished (the winch runs for the specified time):
Code:
public void end() {
     shooter.winch(0);
}

Last edited by notmattlythgoe : 13-11-2014 at 11:45.
Reply With Quote