Log in

View Full Version : Sequences of Commands


WilliamR
11-11-2014, 16:10
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
This is a situation where you will want to use CommandGroups (https://wpilib.screenstepslive.com/s/3120/m/7952/l/80210-creating-groups-of-commands).

JamieKilburn
11-11-2014, 19:27
This is a situation where you will want to use CommandGroups (https://wpilib.screenstepslive.com/s/3120/m/7952/l/80210-creating-groups-of-commands).

CommandGroups are definitely what you want here.

WilliamR
12-11-2014, 23:09
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
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);
}

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:


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:
shooter.winch(x)

You will use this to tell the command when it is finished:

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):

public void end() {
shooter.winch(0);
}

WilliamR
13-11-2014, 14:26
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