Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Sequences of Commands (http://www.chiefdelphi.com/forums/showthread.php?t=131100)

WilliamR 11-11-2014 16:10

Sequences of Commands
 
We had trouble getting a command to work after another command in autonomous mode. We used a while statement and ended the command with a limit switch changing states, but the next command did not trigger the pnuematic cylinder to fire. Any hints?

BigJ 11-11-2014 16:23

Re: Sequences of Commands
 
This is a situation where you will want to use CommandGroups.

JamieKilburn 11-11-2014 19:27

Re: Sequences of Commands
 
Quote:

Originally Posted by BigJ (Post 1408228)
This is a situation where you will want to use CommandGroups.

CommandGroups are definitely what you want here.

WilliamR 12-11-2014 23:09

Re: Sequences of Commands
 
Quote:

Originally Posted by JamieKilburn (Post 1408248)
CommandGroups are definitely what you want here.

Here is the code that we are using to test the latching of our winch after a limit switch is activated.

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);
}

notmattlythgoe 13-11-2014 11:24

Re: Sequences of Commands
 
Quote:

Originally Posted by WilliamR (Post 1408397)
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);
}


WilliamR 13-11-2014 14:26

Re: Sequences of Commands
 
This is why I like being involve with FRC. I appreciate all the tips and advice.
Thanks to everyone who responded. The information will be put to good use on Saturday when our programming group get together to work on this small project for preparation for the new game in January.
Thanks again
William


All times are GMT -5. The time now is 22:37.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi